Source:
public void errorHandler_useBackupSyncConfigurationForClientReset() { SyncUser user = createTestUser(); String url = "realm://objectserver.realm.io/default"; final SyncConfiguration config = configFactory.createSyncConfigurationBuilder(user , url) .errorHandler(new SyncSession.ErrorHandler() { @Override public void onError(SyncSession session, ObjectServerError error) { if (error.getErrorCode() != ErrorCode.CLIENT_RESET) { fail("Wrong error " + error.toString()); return; } final ClientResetRequiredError handler = (ClientResetRequiredError) error; looperThread.closeTestRealms(); handler.executeClientReset(); assertFalse(handler.getOriginalFile().exists()); assertTrue(handler.getBackupFile().exists()); SyncConfiguration backupSyncConfiguration = handler.getBackupSyncConfiguration(); assertNotNull(backupSyncConfiguration); assertTrue(backupSyncConfiguration.isSyncConfiguration()); assertTrue(backupSyncConfiguration.isRealmOffline()); Realm backupRealm = Realm.getInstance(backupSyncConfiguration); assertFalse(backupRealm.isEmpty()); assertEquals(1, backupRealm.where(StringOnly.class).count()); assertEquals("Foo", backupRealm.where(StringOnly.class).findAll().first().getChars()); backupRealm.close(); DynamicRealm dynamicRealm = DynamicRealm.getInstance(backupSyncConfiguration); dynamicRealm.getSchema().checkHasTable(StringOnly.CLASS_NAME, "Dynamic Realm should contains " + StringOnly.CLASS_NAME); RealmResults<DynamicRealmObject> all = dynamicRealm.where(StringOnly.CLASS_NAME).findAll(); assertEquals(1, all.size()); assertEquals("Foo", all.first().getString(StringOnly.FIELD_CHARS)); dynamicRealm.close(); looperThread.testComplete(); } }) .modules(new StringOnlyModule()) .build(); Realm realm = Realm.getInstance(config); realm.beginTransaction(); realm.createObject(StringOnly.class).setChars("Foo"); realm.commitTransaction(); looperThread.addTestRealm(realm); SyncManager.simulateClientReset(SyncManager.getSession(config)); }

Target:
public void errorHandler_useBackupSyncConfigurationForClientReset() { SyncUser user = createTestUser(); String url = "realm://objectserver.realm.io/default"; final SyncConfiguration config = configFactory.createSyncConfigurationBuilder(user, url) .errorHandler(new SyncSession.ErrorHandler() { @Override public void onError(SyncSession session, ObjectServerError error) { if (error.getErrorCode() != ErrorCode.CLIENT_RESET) { fail("Wrong error " + error.toString()); return; } final ClientResetRequiredError handler = (ClientResetRequiredError) error; looperThread.closeTestRealms(); handler.executeClientReset(); assertFalse(handler.getOriginalFile().exists()); assertTrue(handler.getBackupFile().exists()); RealmConfiguration backupRealmConfiguration = handler.getBackupRealmConfiguration(); assertNotNull(backupRealmConfiguration); assertFalse(backupRealmConfiguration.isSyncConfiguration()); Realm backupRealm = Realm.getInstance(backupRealmConfiguration); assertFalse(backupRealm.isEmpty()); assertEquals(1, backupRealm.where(StringOnly.class).count()); assertEquals("Foo", backupRealm.where(StringOnly.class).findAll().first().getChars()); backupRealm.close(); DynamicRealm dynamicRealm = DynamicRealm.getInstance(backupRealmConfiguration); dynamicRealm.getSchema().checkHasTable(StringOnly.CLASS_NAME, "Dynamic Realm should contains " + StringOnly.CLASS_NAME); RealmResults<DynamicRealmObject> all = dynamicRealm.where(StringOnly.CLASS_NAME).findAll(); assertEquals(1, all.size()); assertEquals("Foo", all.first().getString(StringOnly.FIELD_CHARS)); dynamicRealm.close(); looperThread.testComplete(); } }) .modules(new StringOnlyModule()) .build(); Realm realm = Realm.getInstance(config); realm.beginTransaction(); realm.createObject(StringOnly.class).setChars("Foo"); realm.commitTransaction(); looperThread.addTestRealm(realm); SyncManager.simulateClientReset(SyncManager.getSession(config)); }