我結束了創建以下BaseTest類,並具有所有我的測試從繼承:
package com.example;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.dev.HighRepJobPolicy;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
public class BaseTest {
public static final class Policy implements HighRepJobPolicy {
static boolean shouldApply = false;
public static void applyAll() {
shouldApply = true;
}
public static void applyNone() {
shouldApply = false;
}
@Override
public boolean shouldApplyNewJob(Key entityGroup) {
return shouldApply;
}
@Override
public boolean shouldRollForwardExistingJob(Key entityGroup) {
return shouldApply;
}
}
public final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()
.setAlternateHighRepJobPolicyClass(Policy.class));
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
}
然後測試可以是這樣的形式:
@Test
public void thingShouldDoX() throws Exception {
Policy.applyAll();
// Do setup here, everything inside will be consistent.
Policy.applyNone();
// Run code under test here, without consistency.
}
你說的「最好的意思?」我迄今爲止所做的關於「最終一致的Google App Engine數據」的軼事搜索表明,「最終」被定義爲相對較短的時間段(大多數情況下不到一秒鐘)。 –
改編我的問題。單元測試文檔建議將未應用的工作百分比設置爲100,這意味着全局(非祖先)查詢將始終無法看到更改,因此我不確定是否在此等待工作。 –