Search in sources :

Example 21 with Action1

use of rx.functions.Action1 in project realm-java by realm.

the class RxJavaTests method dynamicRealmResults_emittedOnUpdate.

@Test
@RunTestInLooperThread
public void dynamicRealmResults_emittedOnUpdate() {
    final AtomicInteger subscriberCalled = new AtomicInteger(0);
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(looperThread.realmConfiguration);
    dynamicRealm.beginTransaction();
    RealmResults<DynamicRealmObject> results = dynamicRealm.where(AllTypes.CLASS_NAME).findAll();
    dynamicRealm.commitTransaction();
    subscription = results.asObservable().subscribe(new Action1<RealmResults<DynamicRealmObject>>() {

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

Example 22 with Action1

use of rx.functions.Action1 in project realm-java by realm.

the class RxJavaTests method dynamicRealm_emittedOnSubscribe.

@Test
@UiThreadTest
public void dynamicRealm_emittedOnSubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = dynamicRealm.asObservable().subscribe(new Action1<DynamicRealm>() {

        @Override
        public void call(DynamicRealm rxRealm) {
            assertTrue(rxRealm == dynamicRealm);
            subscribedNotified.set(true);
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            throwable.printStackTrace();
        }
    });
    assertTrue(subscribedNotified.get());
    dynamicRealm.close();
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 23 with Action1

use of rx.functions.Action1 in project realm-java by realm.

the class RxJavaTests method realm_emittedOnSubscribe.

@Test
@UiThreadTest
public void realm_emittedOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = realm.asObservable().subscribe(new Action1<Realm>() {

        @Override
        public void call(Realm rxRealm) {
            assertTrue(rxRealm == realm);
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 24 with Action1

use of rx.functions.Action1 in project realm-java by realm.

the class RxJavaTests method dynamicRealm_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void dynamicRealm_closeInDoOnUnsubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    Observable<DynamicRealm> observable = dynamicRealm.asObservable().doOnUnsubscribe(new Action0() {

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

        @Override
        public void call(DynamicRealm rxRealm) {
        }
    });
    subscription.unsubscribe();
    assertTrue(dynamicRealm.isClosed());
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 25 with Action1

use of rx.functions.Action1 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)

Aggregations

Action1 (rx.functions.Action1)108 Test (org.junit.Test)33 Action0 (rx.functions.Action0)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 UiThreadTest (android.support.test.annotation.UiThreadTest)20 Observable (rx.Observable)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)11 ArrayList (java.util.ArrayList)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 TestSubscriber (rx.observers.TestSubscriber)10 AllTypes (io.realm.entities.AllTypes)9 List (java.util.List)9 TestCircuitBreaker (com.netflix.hystrix.HystrixCircuitBreakerTest.TestCircuitBreaker)7 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)6 IOException (java.io.IOException)6 Func1 (rx.functions.Func1)6 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)5 Method (java.lang.reflect.Method)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5