gpt4 book ai didi

java - appengine 单元测试仅获取 10 个实体

转载 作者:行者123 更新时间:2023-12-01 18:25:29 26 4
gpt4 key购买 nike

我用 appengine 编写了一个单元测试,在填充 1000 个实体后需要获取 250 个实体。但是我发现大多数时候它只获取 10 个实体。我只见过很少几次它卖到了 250 个。我非常确定临时数据存储区确实有 1000 个实体,因为我在保存时打印它们。

在@Before方法中

System.out.println( "Adding "+players.size()+ "  entries" );
ofy().save().entities(players);

按预期打印 1000

在@Test方法中

List<Player> players = ofy().load().type( Player.class ).order("-score").limit( 250 ).list();
System.out.println( "Fetched "+players.size()+" top players" );

最佳答案

这可能是由于测试数据存储服务模拟了最终一致性行为。检查您未应用的职位百分比配置。

By setting the unapplied job percentage to 100, we are instructing the local datastore to operate with the maximum amount of eventual consistency. Maximum eventual consistency means writes will commit but always fail to apply, so global (non-ancestor) queries will consistently fail to see changes. This is of course not representative of the amount of eventual consistency your application will see when running in production, but for testing purposes, it's very useful to be able to configure the local datastore to behave this way every time.

如果有帮助的话,尝试这样的方法。

@BeforeClass
public static void setUpClass() throws Exception {
localServiceTestHelper = new LocalServiceTestHelper(
new LocalDatastoreServiceTestConfig().setDefaultHighRepJobPolicyUnappliedJobPercentage(0));
}

但是,请注意以下事实。

Note that setDefaultHighRepJobPolicyUnappliedJobPercentage(0) will switch local datastore service to Master/slave mode.

您可以找到更多详细信息here .

关于java - appengine 单元测试仅获取 10 个实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26354832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com