Search in sources :

Example 26 with AllTypes

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

the class RxJavaTests method findAllAsync_emittedOnSubscribe.

@Test
@UiThreadTest
public void findAllAsync_emittedOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<AllTypes> results = realm.where(AllTypes.class).findAllAsync();
    subscription = results.asObservable().subscribe(new Action1<RealmResults<AllTypes>>() {

        @Override
        public void call(RealmResults<AllTypes> rxResults) {
            assertTrue(rxResults == results);
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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)

Example 27 with AllTypes

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

the class RxJavaTests method realmResults_emittedOnSubscribe.

@Test
@UiThreadTest
public void realmResults_emittedOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<AllTypes> results = realm.where(AllTypes.class).findAll();
    subscription = results.asObservable().subscribe(new Action1<RealmResults<AllTypes>>() {

        @Override
        public void call(RealmResults<AllTypes> rxResults) {
            assertTrue(rxResults == results);
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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)

Example 28 with AllTypes

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

the class RxJavaTests method findFirst_emittedOnSubscribe.

@Test
@UiThreadTest
public void findFirst_emittedOnSubscribe() {
    realm.beginTransaction();
    realm.createObject(AllTypes.class).setColumnLong(42);
    realm.commitTransaction();
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = realm.where(AllTypes.class).equalTo(AllTypes.FIELD_LONG, 42).findFirst().<AllTypes>asObservable().subscribe(new Action1<AllTypes>() {

        @Override
        public void call(AllTypes rxObject) {
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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)

Example 29 with AllTypes

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

the class RxJavaTests method wrongGenericClassThrows.

@Test
@UiThreadTest
public void wrongGenericClassThrows() {
    realm.beginTransaction();
    final AllTypes obj = realm.createObject(AllTypes.class);
    realm.commitTransaction();
    Observable<CyclicType> obs = obj.asObservable();
    obs.subscribe(new Action1<CyclicType>() {

        @Override
        public void call(CyclicType cyclicType) {
            fail();
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable ignored) {
        }
    });
}
Also used : AllTypes(io.realm.entities.AllTypes) CyclicType(io.realm.entities.CyclicType) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 30 with AllTypes

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

the class RxJavaTests method findFirstAsync_emittedOnDelete.

@Test
@RunTestInLooperThread
public void findFirstAsync_emittedOnDelete() {
    final AtomicInteger subscriberCalled = new AtomicInteger(0);
    final Realm realm = looperThread.realm;
    realm.beginTransaction();
    final AllTypes obj = realm.createObject(AllTypes.class);
    realm.commitTransaction();
    subscription = realm.where(AllTypes.class).findFirstAsync().<AllTypes>asObservable().subscribe(new Action1<AllTypes>() {

        @Override
        public void call(final AllTypes rxObject) {
            switch(subscriberCalled.incrementAndGet()) {
                case 1:
                    assertFalse(rxObject.isLoaded());
                    break;
                case 2:
                    assertTrue(rxObject.isLoaded());
                    assertTrue(rxObject.isValid());
                    realm.executeTransactionAsync(new Realm.Transaction() {

                        @Override
                        public void execute(Realm realm) {
                            realm.delete(AllTypes.class);
                        }
                    });
                    break;
                case 3:
                    assertTrue(rxObject.isLoaded());
                    assertFalse(rxObject.isValid());
                    looperThread.testComplete();
                    break;
                default:
                    fail();
            }
        }
    });
}
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)

Aggregations

AllTypes (io.realm.entities.AllTypes)134 Test (org.junit.Test)122 UiThreadTest (android.support.test.annotation.UiThreadTest)40 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)33 Date (java.util.Date)27 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 Action1 (rx.functions.Action1)12 JSONObject (org.json.JSONObject)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 Dog (io.realm.entities.Dog)8 InputStream (java.io.InputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)5 SharedRealm (io.realm.internal.SharedRealm)5 RealmException (io.realm.exceptions.RealmException)4 RunInLooperThread (io.realm.rule.RunInLooperThread)3 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutionException (java.util.concurrent.ExecutionException)3 JSONException (org.json.JSONException)3