use of io.realm.entities.CyclicType in project realm-java by realm.
the class RealmObjectTests method setter_list_withObjectFromAnotherThread.
@Test
public void setter_list_withObjectFromAnotherThread() throws InterruptedException {
final CountDownLatch createLatch = new CountDownLatch(1);
final CountDownLatch testEndLatch = new CountDownLatch(1);
final AtomicReference<CyclicType> objFromAnotherThread = new AtomicReference<CyclicType>();
java.lang.Thread thread = new java.lang.Thread() {
@Override
public void run() {
Realm realm = Realm.getInstance(realmConfig);
// 1. Creates an object.
realm.beginTransaction();
objFromAnotherThread.set(realm.createObject(CyclicType.class));
realm.commitTransaction();
createLatch.countDown();
TestHelper.awaitOrFail(testEndLatch);
// 3. Close Realm in this thread and finishes.
realm.close();
}
};
thread.start();
TestHelper.awaitOrFail(createLatch);
// 2. Sets created object to target.
realm.beginTransaction();
try {
CyclicType target = realm.createObject(CyclicType.class);
RealmList<CyclicType> list = new RealmList<CyclicType>();
list.add(realm.createObject(CyclicType.class));
// List contains an object from another thread.
list.add(objFromAnotherThread.get());
list.add(realm.createObject(CyclicType.class));
try {
target.setObjects(list);
fail();
} catch (IllegalArgumentException ignored) {
}
} finally {
testEndLatch.countDown();
realm.cancelTransaction();
}
// Waits for finishing the thread.
thread.join();
}
use of io.realm.entities.CyclicType in project realm-java by realm.
the class RealmObjectTests method setter_list_withUnmanagedObject.
@Test
public void setter_list_withUnmanagedObject() {
CyclicType unmanaged = new CyclicType();
realm.beginTransaction();
try {
CyclicType target = realm.createObject(CyclicType.class);
RealmList<CyclicType> list = new RealmList<CyclicType>();
list.add(realm.createObject(CyclicType.class));
// List contains an unmanaged object
list.add(unmanaged);
list.add(realm.createObject(CyclicType.class));
try {
target.setObjects(list);
fail();
} catch (IllegalArgumentException ignored) {
}
} finally {
realm.cancelTransaction();
}
}
use of io.realm.entities.CyclicType in project realm-java by realm.
the class RealmObjectTests method equals_sameObjectDifferentInstance.
@Test
public void equals_sameObjectDifferentInstance() {
realm.beginTransaction();
CyclicType ct = realm.createObject(CyclicType.class);
ct.setName("Foo");
realm.commitTransaction();
CyclicType ct1 = realm.where(CyclicType.class).findFirst();
CyclicType ct2 = realm.where(CyclicType.class).findFirst();
assertTrue(ct1.equals(ct2));
assertTrue(ct2.equals(ct1));
}
use of io.realm.entities.CyclicType in project realm-java by realm.
the class RealmObjectTests method equals_cyclicObject.
@Test
public void equals_cyclicObject() {
realm.beginTransaction();
CyclicType foo = createCyclicData();
realm.commitTransaction();
assertEquals(foo, realm.where(CyclicType.class).equalTo("name", "Foo").findFirst());
}
use of io.realm.entities.CyclicType in project realm-java by realm.
the class RealmObjectTests method setter_link_objectFromOtherRealm.
@Test
public void setter_link_objectFromOtherRealm() {
RealmConfiguration config = configFactory.createConfiguration("another.realm");
Realm anotherRealm = Realm.getInstance(config);
// noinspection TryFinallyCanBeTryWithResources
try {
anotherRealm.beginTransaction();
CyclicType objFromAnotherRealm = anotherRealm.createObject(CyclicType.class);
anotherRealm.commitTransaction();
realm.beginTransaction();
try {
CyclicType target = realm.createObject(CyclicType.class);
try {
target.setObject(objFromAnotherRealm);
fail();
} catch (IllegalArgumentException ignored) {
}
} finally {
realm.cancelTransaction();
}
} finally {
anotherRealm.close();
}
}
Aggregations