单元测试App Engine Java JDO中的XG Cross Group事务

时间:2012-05-30 07:49:16

标签: java unit-testing google-app-engine transactions jdo

我在app engine java jdo中有一个跨群组交易。

它在本地dev应用引擎服务器上运行良好。

但是,从单元测试中,我得到java.lang.IllegalArgumentException: transactions on multiple entity groups only allowed in High Replication applications

是否可以使用LocalServiceTestHelper模拟高复制应用程序?

我正在使用1.6.6。

这是我的课程,您可以按原样运行它:

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();
        }
}

这是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>

xgTx.begin();

上抛出异常

1 个答案:

答案 0 :(得分:15)

确定。我找到了需要做的事情。

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

如上所示:https://developers.google.com/appengine/docs/java/tools/localunittesting#Writing_HRD_Datastore_Tests

有点模糊的设置,但确实存在。