Search in sources :

Example 76 with Action0

use of rx.functions.Action0 in project Hystrix by Netflix.

the class CumulativeCommandEventCounterStreamTest method testCancelled.

@Test
public void testCancelled() {
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-M");
    stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(5).subscribe(getSubscriber(latch));
    Command toCancel = Command.from(groupKey, key, HystrixEventType.SUCCESS, 500);
    System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " : about to observe and subscribe");
    Subscription s = toCancel.observe().doOnUnsubscribe(new Action0() {

        @Override
        public void call() {
            System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " : UnSubscribe from command.observe()");
        }
    }).subscribe(new Subscriber<Integer>() {

        @Override
        public void onCompleted() {
            System.out.println("Command OnCompleted");
        }

        @Override
        public void onError(Throwable e) {
            System.out.println("Command OnError : " + e);
        }

        @Override
        public void onNext(Integer i) {
            System.out.println("Command OnNext : " + i);
        }
    });
    System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " : about to unsubscribe");
    s.unsubscribe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertEquals(HystrixEventType.values().length, stream.getLatest().length);
    long[] expected = new long[HystrixEventType.values().length];
    expected[HystrixEventType.CANCELLED.ordinal()] = 1;
    assertArrayEquals(expected, stream.getLatest());
}
Also used : Action0(rx.functions.Action0) HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(rx.Subscription) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 77 with Action0

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

the class RxJavaTests method dynamicRealmResults_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void dynamicRealmResults_closeInDoOnUnsubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    Observable<RealmResults<DynamicRealmObject>> observable = dynamicRealm.where(AllTypes.CLASS_NAME).findAll().asObservable().doOnUnsubscribe(new Action0() {

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

        @Override
        public void call(RealmResults<DynamicRealmObject> allTypes) {
        }
    });
    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 78 with Action0

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

the class RxJavaTests method dynamicRealmObject_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void dynamicRealmObject_closeInDoOnUnsubscribe() {
    realm.beginTransaction();
    realm.createObject(AllTypes.class);
    realm.commitTransaction();
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    Observable<DynamicRealmObject> observable = dynamicRealm.where(AllTypes.CLASS_NAME).findFirst().<DynamicRealmObject>asObservable().doOnUnsubscribe(new Action0() {

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

        @Override
        public void call(DynamicRealmObject obj) {
        }
    });
    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 79 with Action0

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

the class RxJavaTests method realm_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void realm_closeInDoOnUnsubscribe() {
    Observable<Realm> observable = realm.asObservable().doOnUnsubscribe(new Action0() {

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

        @Override
        public void call(Realm rxRealm) {
        }
    });
    subscription.unsubscribe();
    assertTrue(realm.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 80 with Action0

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

the class RxJavaTests method realmObject_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void realmObject_closeInDoOnUnsubscribe() {
    realm.beginTransaction();
    realm.createObject(AllTypes.class);
    realm.commitTransaction();
    Observable<AllTypes> observable = realm.where(AllTypes.class).findFirst().<AllTypes>asObservable().doOnUnsubscribe(new Action0() {

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

        @Override
        public void call(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

Action0 (rx.functions.Action0)134 Subscription (rx.Subscription)58 Test (org.junit.Test)56 CountDownLatch (java.util.concurrent.CountDownLatch)50 Action1 (rx.functions.Action1)28 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 ArrayList (java.util.ArrayList)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 List (java.util.List)15 Func1 (rx.functions.Func1)13 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)12 Observable (rx.Observable)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 OnClick (butterknife.OnClick)10 IOException (java.io.IOException)9 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)8 UiThreadTest (android.support.test.annotation.UiThreadTest)7 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)7 TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)7 Method (java.lang.reflect.Method)7