use of io.realm.objectserver.model.TestObject in project realm-java by realm.
the class SendsALot method onCreate.
@Override
public void onCreate() {
super.onCreate();
Realm.init(getApplicationContext());
SyncUser user = UserFactory.createDefaultUser(Constants.AUTH_URL);
String realmUrl = Constants.SYNC_SERVER_URL_2;
final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user, realmUrl).name(SendsALot.class.getSimpleName()).build();
Realm.deleteRealm(syncConfig);
Realm realm = Realm.getInstance(syncConfig);
realm.beginTransaction();
for (int i = 0; i < 100; i++) {
TestObject testObject = realm.createObject(TestObject.class);
testObject.setIntProp(i);
testObject.setStringProp("property " + i);
}
realm.commitTransaction();
//FIXME the close may not give a chance to the sync client to process/upload the changeset
realm.close();
}
use of io.realm.objectserver.model.TestObject in project realm-java by realm.
the class ProcessCommitTests method expectALot.
// 1. Open a sync Realm and listen to changes.
// A. Open the same sync Realm.
// B. Create 100 objects.
// 2. Check if the 100 objects are received.
// #. Repeat B/2 10 times.
@Test
@RunTestWithRemoteService(remoteService = ALotCommitsRemoteService.class, onLooperThread = true)
@RunTestInLooperThread
public void expectALot() throws Throwable {
looperThread.runAfterTest(remoteService.afterRunnable);
remoteService.createHandler(Looper.myLooper());
final SyncUser user = UserFactory.getInstance().createDefaultUser(Constants.AUTH_URL);
String realmUrl = Constants.SYNC_SERVER_URL;
final SyncConfiguration syncConfig = user.createConfiguration(realmUrl).modules(new ProcessCommitTestsModule()).directory(looperThread.getRoot()).build();
final Realm realm = Realm.getInstance(syncConfig);
final RealmResults<TestObject> all = realm.where(TestObject.class).sort("intProp").findAll();
looperThread.keepStrongReference(all);
final AtomicInteger listenerCalledCounter = new AtomicInteger(0);
all.addChangeListener(new RealmChangeListener<RealmResults<TestObject>>() {
@Override
public void onChange(RealmResults<TestObject> element) {
int counter = listenerCalledCounter.incrementAndGet();
int size = all.size();
if (size == 0) {
listenerCalledCounter.decrementAndGet();
return;
}
// Added 100 objects every time.
assertEquals(0, size % 100);
assertEquals(counter * 100 - 1, all.last().getIntProp());
assertEquals("Str" + (counter * 100 - 1), all.last().getStringProp());
if (counter == 10) {
remoteService.triggerServiceStep(ALotCommitsRemoteService.stepC_closeRealm);
realm.close();
user.logOut();
looperThread.testComplete();
} else {
remoteService.triggerServiceStep(ALotCommitsRemoteService.stepB_createObjects);
}
}
});
remoteService.triggerServiceStep(ALotCommitsRemoteService.stepA_openRealm);
remoteService.triggerServiceStep(ALotCommitsRemoteService.stepB_createObjects);
}
Aggregations