use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmTests method copyToRealm_fromOtherRealm.
@Test
public void copyToRealm_fromOtherRealm() {
realm.beginTransaction();
AllTypes allTypes = realm.createObject(AllTypes.class);
allTypes.setColumnString("Test");
allTypes.setColumnDecimal128(new Decimal128(new BigDecimal("12345")));
allTypes.setColumnObjectId(new ObjectId(TestHelper.randomObjectIdHexString()));
allTypes.setColumnUUID(UUID.randomUUID());
allTypes.setColumnRealmAny(RealmAny.valueOf(UUID.randomUUID()));
realm.commitTransaction();
RealmConfiguration realmConfig = configFactory.createConfiguration("other-realm");
Realm otherRealm = Realm.getInstance(realmConfig);
otherRealm.beginTransaction();
AllTypes copiedAllTypes = otherRealm.copyToRealm(allTypes);
otherRealm.commitTransaction();
// Same object in different Realms is not the same.
assertNotSame(allTypes, copiedAllTypes);
// But data is still the same.
assertEquals(allTypes.getColumnString(), copiedAllTypes.getColumnString());
otherRealm.close();
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmObjectTests method isValid_managedObject.
@Test
public void isValid_managedObject() {
realm.beginTransaction();
AllTypes allTypes = realm.createObject(AllTypes.class);
assertTrue(allTypes.isValid());
realm.commitTransaction();
assertTrue(allTypes.isValid());
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmObjectTests method getter_afterDeleteFromOtherThreadThrows.
@Test
public void getter_afterDeleteFromOtherThreadThrows() {
final CountDownLatch bgRealmDone = new CountDownLatch(1);
realm.beginTransaction();
final AllTypes obj = realm.createObject(AllTypes.class);
realm.commitTransaction();
new Thread(new Runnable() {
@Override
public void run() {
Realm bgRealm = Realm.getInstance(realm.getConfiguration());
bgRealm.beginTransaction();
bgRealm.delete(AllTypes.class);
bgRealm.commitTransaction();
bgRealm.close();
bgRealmDone.countDown();
}
}).start();
TestHelper.awaitOrFail(bgRealmDone);
realm.refresh();
// Object should no longer be available.
assertFalse(obj.isValid());
try {
obj.getColumnLong();
fail();
} catch (IllegalStateException ignored) {
}
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmObjectTests method invalidSurrogates.
// Invalid surrogate pairs:
// Both high and low should lead to an IllegalArgumentException.
@Test
public void invalidSurrogates() {
String high = "Invalid high surrogate \uD83C\uD83C\uDF51";
String low = "Invalid low surrogate \uD83C\uDF51\uDF51";
realm.beginTransaction();
realm.delete(AllTypes.class);
realm.commitTransaction();
realm.beginTransaction();
try {
AllTypes highSurrogate = realm.createObject(AllTypes.class);
highSurrogate.setColumnString(high);
fail();
} catch (IllegalArgumentException ignored) {
}
realm.cancelTransaction();
realm.beginTransaction();
try {
AllTypes lowSurrogate = realm.createObject(AllTypes.class);
lowSurrogate.setColumnString(low);
fail();
} catch (IllegalArgumentException ignored) {
}
realm.cancelTransaction();
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmObjectTests method runMethodOnWrongThread.
private boolean runMethodOnWrongThread(final Method method) throws ExecutionException, InterruptedException {
final AllTypes allTypes = realm.where(AllTypes.class).findFirst();
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<Boolean> future = executorService.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
switch(method) {
case METHOD_GETTER:
allTypes.getColumnFloat();
break;
case METHOD_SETTER:
allTypes.setColumnFloat(1.0f);
break;
case METHOD_DELETE_FROM_REALM:
allTypes.deleteFromRealm();
break;
}
return false;
} catch (IllegalStateException ignored) {
return true;
}
}
});
return future.get();
}
Aggregations