Objectify事务在单元测试中失败

时间:2016-03-17 08:56:31

标签: unit-testing google-app-engine transactions objectify

非常简单的Objectify事务的单元测试总是失败: “多个实体组上的事务仅允许在High Replication应用程序中使用”。只要案例中只使用一个实体。 这样的事务在dev服务器和Google实例上都很好地执行。所以我可能需要一些LocalServiceTestHelper调整。 有人可以帮忙吗?

这是我的单元测试:

[

ERROR] Failed to execute goal on project reports: Could not resolve dependencies for project com.ict:reports:jar:2.2.1-SNAPSHOT: The following artifacts could not be resolved: com.lowagie:itext:jar:2.1.7.js4, org.olap4j:olap4j:jar:0.9.7.309-JS-3, 
ar.com.fdvs:DynamicJasper:jar:5.0.0: Failure to find com.lowagie:itext:jar:2.1.7.js4 in http://localhost:8081/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced -> [Help 1]

以下是我得到的例外情况:

@Test
public void transactionTest() {
    // setup
    final LocalServiceTestHelper helper = new LocalServiceTestHelper(
            new LocalDatastoreServiceTestConfig(),
            new LocalMemcacheServiceTestConfig());      
    helper.setUp();
    Closeable session = ObjectifyService.begin();

    // test
    ofy().transactNew(new VoidWork() {
        @Override
        public void vrun() {
            User user = new User();
            ofy().save().entity(user).now();
        }
    });

    // teardown
    helper.tearDown();
    session.close();
    session = null;
}

1 个答案:

答案 0 :(得分:1)

您必须明确启用HRD - 由于主/从数据存储不再存在,因此今天有点奇怪:

private final LocalServiceTestHelper helper =
        new LocalServiceTestHelper(
                new LocalDatastoreServiceTestConfig().setApplyAllHighRepJobPolicy());