Search in sources :

Example 1 with AllTypes

use of io.realm.entities.AllTypes in project realm-java by realm.

the class RealmObjectTests method changeListener_triggeredWhenObjectIsdeleted.

@Test
@RunTestInLooperThread
public void changeListener_triggeredWhenObjectIsdeleted() {
    final Realm realm = looperThread.realm;
    realm.beginTransaction();
    AllTypes obj = realm.createObject(AllTypes.class);
    realm.commitTransaction();
    obj.addChangeListener(new RealmChangeListener<AllTypes>() {

        @Override
        public void onChange(AllTypes obj) {
            assertFalse(obj.isValid());
            looperThread.testComplete();
        }
    });
    realm.beginTransaction();
    obj.deleteFromRealm();
    realm.commitTransaction();
}
Also used : AllTypes(io.realm.entities.AllTypes) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test)

Example 2 with AllTypes

use of io.realm.entities.AllTypes in project realm-java by realm.

the class RealmQueryBenchmarks method before.

@BeforeExperiment
public void before() {
    RealmConfiguration config = new RealmConfiguration.Builder().build();
    Realm.deleteRealm(config);
    realm = Realm.getInstance(config);
    realm.beginTransaction();
    for (int i = 0; i < DATA_SIZE; i++) {
        AllTypes obj = realm.createObject(AllTypes.class);
        obj.setColumnLong(i);
        obj.setColumnBoolean(i % 2 == 0);
        obj.setColumnString("Foo " + i);
        obj.setColumnDouble(i + 1.234D);
    }
    realm.commitTransaction();
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) AllTypes(io.realm.entities.AllTypes) BeforeExperiment(dk.ilios.spanner.BeforeExperiment)

Example 3 with AllTypes

use of io.realm.entities.AllTypes in project realm-java by realm.

the class RealmResultsBenchmarks method before.

@BeforeExperiment
public void before() {
    Realm.init(InstrumentationRegistry.getTargetContext());
    RealmConfiguration config = new RealmConfiguration.Builder().build();
    Realm.deleteRealm(config);
    realm = Realm.getInstance(config);
    realm.beginTransaction();
    for (int i = 0; i < DATA_SIZE; i++) {
        AllTypes obj = realm.createObject(AllTypes.class);
        obj.setColumnLong(i);
        obj.setColumnBoolean(i % 2 == 0);
        obj.setColumnString("Foo " + i);
        obj.setColumnDouble(i + 1.234D);
    }
    realm.commitTransaction();
    results = realm.where(AllTypes.class).findAll();
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) AllTypes(io.realm.entities.AllTypes) BeforeExperiment(dk.ilios.spanner.BeforeExperiment)

Example 4 with AllTypes

use of io.realm.entities.AllTypes in project realm-java by realm.

the class RxJavaTests method realmResults_emittedOnUpdate.

@Test
@RunTestInLooperThread
public void realmResults_emittedOnUpdate() {
    final AtomicInteger subscriberCalled = new AtomicInteger(0);
    Realm realm = looperThread.realm;
    realm.beginTransaction();
    RealmResults<AllTypes> results = realm.where(AllTypes.class).findAll();
    realm.commitTransaction();
    subscription = results.asObservable().subscribe(new Action1<RealmResults<AllTypes>>() {

        @Override
        public void call(RealmResults<AllTypes> allTypes) {
            if (subscriberCalled.incrementAndGet() == 2) {
                looperThread.testComplete();
            }
        }
    });
    realm.beginTransaction();
    realm.createObject(AllTypes.class);
    realm.commitTransaction();
}
Also used : Action1(rx.functions.Action1) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AllTypes(io.realm.entities.AllTypes) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test)

Example 5 with AllTypes

use of io.realm.entities.AllTypes in project realm-java by realm.

the class RxJavaTests method realmResults_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void realmResults_closeInDoOnUnsubscribe() {
    Observable<RealmResults<AllTypes>> observable = realm.where(AllTypes.class).findAll().asObservable().doOnUnsubscribe(new Action0() {

        @Override
        public void call() {
            realm.close();
        }
    });
    subscription = observable.subscribe(new Action1<RealmResults<AllTypes>>() {

        @Override
        public void call(RealmResults<AllTypes> allTypes) {
        }
    });
    subscription.unsubscribe();
    assertTrue(realm.isClosed());
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1) AllTypes(io.realm.entities.AllTypes) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Aggregations

AllTypes (io.realm.entities.AllTypes)225 Test (org.junit.Test)210 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)70 UiThreadTest (androidx.test.annotation.UiThreadTest)54 Date (java.util.Date)36 DictionaryAllTypes (io.realm.entities.DictionaryAllTypes)32 Dog (io.realm.entities.Dog)27 JSONObject (org.json.JSONObject)26 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 RunInLooperThread (io.realm.rule.RunInLooperThread)20 InputStream (java.io.InputStream)19 Decimal128 (org.bson.types.Decimal128)19 ByteArrayInputStream (java.io.ByteArrayInputStream)17 ObjectId (org.bson.types.ObjectId)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 UiThreadTest (android.support.test.annotation.UiThreadTest)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 OsSharedRealm (io.realm.internal.OsSharedRealm)9 BigDecimal (java.math.BigDecimal)9 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)8