Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Testing XG Cross Group Transaction in App Engine Java JDO

I have a cross group transaction in app engine java jdo.

It works great on the local dev app engine server.

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

Is it possible to simulate a High Replication Application using LocalServiceTestHelper?

I am using 1.6.6.

Here is my class, you can run it as it is to reproduce:

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>

The Exception is thrown on xgTx.begin();

like image 257
Patrick Avatar asked May 30 '12 07:05

Patrick


1 Answers

Ok. I found what needs to be done.

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

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

A little obscure setting, but there it is.

like image 133
Patrick Avatar answered Oct 31 '22 18:10

Patrick