XG Cross Group Group Testing Transaction in App Engine Java JDO

I have a cross group transaction in javas jdo application.

It works great on a local application developers server.

However, from unit testing, I get java.lang.IllegalArgumentException: transactions on multiple entity groups only allowed in High Replication applications .

Can I simulate a highly replicated application using LocalServiceTestHelper?

I am using 1.6.6.

Here is my class, you can run it the way it should play:

 public class Ds2Test { private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()); private static final PersistenceManagerFactory pmfXgInstance = JDOHelper.getPersistenceManagerFactory("xg-transactions"); @Before public void setUp() { helper.setUp(); } @After public void tearDown() { helper.tearDown(); } @Test public void testXgTransaction() throws Exception { PersistenceManager xgPm = pmfXgInstance.getPersistenceManager(); Transaction xgTx = xgPm.currentTransaction(); xgTx.begin(); xgTx.commit(); xgPm.close(); } } 

And here is the configuration in jdoconfig.xml:

  <persistence-manager-factory name="xg-transactions"> <property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/> <property name="javax.jdo.option.ConnectionURL" value="appengine"/> <property name="javax.jdo.option.NontransactionalRead" value="true"/> <property name="javax.jdo.option.NontransactionalWrite" value="true"/> <property name="javax.jdo.option.RetainValues" value="true"/> <property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/> <property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/> </persistence-manager-factory> 

Exception xgTx.begin();

+6
source share
1 answer

Ok I found what needs to be done.

 private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()**.setDefaultHighRepJobPolicyUnappliedJobPercentage(100))**; 

As seen at: https://developers.google.com/appengine/docs/java/tools/localunittesting#Writing_HRD_Datastore_Tests

A little obscure setting, but there it is.

+15
source

Source: https://habr.com/ru/post/916980/


All Articles