use of org.activityinfo.ui.client.dispatch.Dispatcher in project activityinfo by bedatadriven.
the class SyncIntegrationTest method failResume.
// AI-864 : we know that
// 1) on customer side location is present but locationadminlink entry is absent.
// 2) location and locationadminlink are updated with single SyncRegion
// Conclusion: the only possible bug is that location was updated but locationadminlink failed to update
// due to some weird problem (network connection failure)
// Test: in this test we will try to emulate connection failure
@Test
@OnDataSet("/dbunit/sites-simple-with-unicode.db.xml")
public void failResume() throws SQLException, InterruptedException {
String databaseName = TestOutput.getFile(getClass(), ".sqlite").getAbsolutePath();
final AtomicBoolean forceFail = new AtomicBoolean(true);
final TestSqliteDatabase localDatabase = new TestSqliteDatabase(databaseName) {
@Override
public String adjustExecuteUpdates(String json) {
JsonParser parser = new JsonParser();
JsonArray list = parser.parse(json).getAsJsonArray();
// ugly : better way to identify when to fail ?
if (list.size() == 2 && json.contains("location") && json.contains("locationadminlink") && forceFail.get()) {
forceFail.set(false);
throw new RuntimeException("Forced to fail locationadminlink update");
}
return json;
}
};
Dispatcher remoteDispatcher = new RemoteDispatcherStub(servlet);
Injector clientSideInjector = Guice.createInjector(new LocalModuleStub(AuthenticationModuleStub.getCurrentUser(), localDatabase, remoteDispatcher));
final InstallPipeline installer = clientSideInjector.getInstance(InstallPipeline.class);
// sync with failure
newRequest();
installer.start();
localDatabase.processEventQueue();
// try again (now without failure)
JdbcScheduler.get().forceCleanup();
newRequest();
installer.start();
localDatabase.processEventQueue();
assertThat(localDatabase.selectString("select Name from Location where LocationId=7"), equalTo("Shabunda"));
assertThat(localDatabase.selectString(adminEntityBy(7, 1)), equalTo("3"));
assertThat(localDatabase.selectString(adminEntityBy(7, 2)), equalTo("12"));
}
use of org.activityinfo.ui.client.dispatch.Dispatcher in project activityinfo by bedatadriven.
the class SyncIntegrationTest method syncWithHugeLocationsCount.
// AI-864, create 50k locations and try to sync them
// Check response time (must be less than 5seconds)
@Test
// we don't want to kill our build time, please run it manually
@Ignore
@OnDataSet("/dbunit/sites-simple-with-unicode.db.xml")
public void syncWithHugeLocationsCount() throws SQLException, InterruptedException {
final TestSqliteDatabase localDatabase = new TestSqliteDatabase("target/localdbtest" + new java.util.Date().getTime());
// before sync, fill in db with locations
int generatedLocationCount = 50000;
final List<Integer> locationIds = addLocationsToServerDatabase(generatedLocationCount);
Dispatcher remoteDispatcher = new RemoteDispatcherStub(servlet);
Injector clientSideInjector = Guice.createInjector(new LocalModuleStub(AuthenticationModuleStub.getCurrentUser(), localDatabase, remoteDispatcher));
final InstallPipeline installer = clientSideInjector.getInstance(InstallPipeline.class);
// sync
newRequest();
installer.start();
localDatabase.processEventQueue();
int locationCountInDataSet = 7;
assertThat(localDatabase.selectInt("select count(*) from Location"), equalTo(generatedLocationCount + locationCountInDataSet));
assertThat(localDatabase.selectString("select Name from Location where LocationId=7"), equalTo("Shabunda"));
assertThat(localDatabase.selectString(adminEntityBy(7, 1)), equalTo("3"));
assertThat(localDatabase.selectString(adminEntityBy(7, 2)), equalTo("12"));
// assert all locations are persisted
for (Integer id : locationIds) {
assertThat(localDatabase.selectInt("select LocationId from Location where LocationId=" + id), equalTo(id));
}
}
Aggregations