use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmTests method refresh_triggerNotifications.
@Test
public void refresh_triggerNotifications() {
looperThread.runBlocking(() -> {
final CountDownLatch bgThreadDone = new CountDownLatch(1);
final AtomicBoolean listenerCalled = new AtomicBoolean(false);
final Realm realm = Realm.getInstance((realmConfig));
looperThread.closeAfterTest(realm);
RealmResults<AllTypes> results = realm.where(AllTypes.class).findAll();
assertEquals(0, results.size());
results.addChangeListener(new RealmChangeListener<RealmResults<AllTypes>>() {
@Override
public void onChange(RealmResults<AllTypes> results) {
assertEquals(1, results.size());
listenerCalled.set(true);
}
});
// Advance the Realm on a background while blocking this thread. When we refresh, it should trigger
// the listener.
new Thread(() -> {
Realm realm1 = Realm.getInstance(realmConfig);
realm1.beginTransaction();
realm1.createObject(AllTypes.class);
realm1.commitTransaction();
realm1.close();
bgThreadDone.countDown();
}).start();
TestHelper.awaitOrFail(bgThreadDone);
realm.refresh();
assertTrue(listenerCalled.get());
looperThread.testComplete();
});
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmTests method commitTransaction.
@Test
public void commitTransaction() {
populateTestRealm();
realm.beginTransaction();
AllTypes allTypes = realm.createObject(AllTypes.class);
allTypes.setColumnBoolean(true);
realm.commitTransaction();
RealmResults<AllTypes> resultList = realm.where(AllTypes.class).findAll();
assertEquals(TEST_DATA_SIZE + 1, resultList.size());
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmTests method refresh_nonLooperThreadAdvances.
@Test
public void refresh_nonLooperThreadAdvances() {
final CountDownLatch bgThreadDone = new CountDownLatch(1);
RealmResults<AllTypes> results = realm.where(AllTypes.class).findAll();
assertEquals(0, results.size());
new Thread(new Runnable() {
@Override
public void run() {
Realm realm = Realm.getInstance(RealmTests.this.realm.getConfiguration());
realm.beginTransaction();
realm.createObject(AllTypes.class);
realm.commitTransaction();
realm.close();
bgThreadDone.countDown();
}
}).start();
TestHelper.awaitOrFail(bgThreadDone);
realm.refresh();
assertEquals(1, results.size());
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmTests method copyFromRealm.
@Test
public void copyFromRealm() {
populateTestRealm();
AllTypes realmObject = realm.where(AllTypes.class).sort("columnLong").findAll().first();
AllTypes unmanagedObject = realm.copyFromRealm(realmObject);
assertArrayEquals(realmObject.getColumnBinary(), unmanagedObject.getColumnBinary());
assertEquals(realmObject.getColumnString(), unmanagedObject.getColumnString());
assertEquals(realmObject.getColumnLong(), unmanagedObject.getColumnLong());
assertEquals(realmObject.getColumnFloat(), unmanagedObject.getColumnFloat(), 0.00000000001);
assertEquals(realmObject.getColumnDouble(), unmanagedObject.getColumnDouble(), 0.00000000001);
assertEquals(realmObject.isColumnBoolean(), unmanagedObject.isColumnBoolean());
assertEquals(realmObject.getColumnDate(), unmanagedObject.getColumnDate());
assertEquals(realmObject.getColumnObjectId(), unmanagedObject.getColumnObjectId());
assertEquals(realmObject.getColumnDecimal128(), unmanagedObject.getColumnDecimal128());
assertEquals(realmObject.getColumnUUID(), unmanagedObject.getColumnUUID());
assertEquals(realmObject.getColumnRealmAny(), unmanagedObject.getColumnRealmAny());
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmTests method copyToRealmOrUpdate_noPrimaryKeyField.
@Test
public void copyToRealmOrUpdate_noPrimaryKeyField() {
realm.beginTransaction();
thrown.expect(IllegalArgumentException.class);
realm.copyToRealmOrUpdate(new AllTypes());
}
Aggregations