本文整理匯總了Java中io.reactivex.subscribers.TestSubscriber.assertTerminated方法的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber.assertTerminated方法的具體用法?Java TestSubscriber.assertTerminated怎麽用?Java TestSubscriber.assertTerminated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.reactivex.subscribers.TestSubscriber
的用法示例。
在下文中一共展示了TestSubscriber.assertTerminated方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: clientCanCancelServerStreamImplicitly
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void clientCanCancelServerStreamImplicitly() throws InterruptedException {
RxNumbersGrpc.RxNumbersStub stub = RxNumbersGrpc.newRxStub(channel);
TestSubscriber<NumberProto.Number> subscription = stub
.responsePressure(Single.just(Empty.getDefaultInstance()))
.doOnNext(number -> System.out.println(number.getNumber(0)))
.doOnError(throwable -> System.out.println(throwable.getMessage()))
.doOnComplete(() -> System.out.println("Completed"))
.doOnCancel(() -> System.out.println("Client canceled"))
.take(10)
.test();
// Consume some work
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
subscription.dispose();
subscription.awaitTerminalEvent(3, TimeUnit.SECONDS);
subscription.assertValueCount(10);
subscription.assertTerminated();
assertThat(svc.wasCanceled()).isTrue();
}
示例2: serverCanCancelClientStreamImplicitlyBidi
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void serverCanCancelClientStreamImplicitlyBidi() {
RxNumbersGrpc.RxNumbersStub stub = RxNumbersGrpc.newRxStub(channel);
svc.setExplicitCancel(false);
AtomicBoolean requestWasCanceled = new AtomicBoolean(false);
AtomicBoolean requestDidProduce = new AtomicBoolean(false);
Flowable<NumberProto.Number> request = Flowable
.fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator)
.delay(10, TimeUnit.MILLISECONDS)
.map(CancellationPropagationIntegrationTest::protoNum)
.doOnNext(x -> {
requestDidProduce.set(true);
System.out.println("Produced: " + x.getNumber(0));
})
.doOnCancel(() -> {
requestWasCanceled.set(true);
System.out.println("Client canceled");
});
TestSubscriber<NumberProto.Number> observer = stub
.twoWayPressure(request)
.doOnNext(number -> System.out.println(number.getNumber(0)))
.doOnError(throwable -> System.out.println(throwable.getMessage()))
.test();
observer.awaitTerminalEvent(3, TimeUnit.SECONDS);
observer.assertTerminated();
assertThat(requestWasCanceled.get()).isTrue();
assertThat(requestDidProduce.get()).isTrue();
}
示例3: serverCanCancelClientStreamExplicitlyBidi
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void serverCanCancelClientStreamExplicitlyBidi() {
RxNumbersGrpc.RxNumbersStub stub = RxNumbersGrpc.newRxStub(channel);
svc.setExplicitCancel(true);
AtomicBoolean requestWasCanceled = new AtomicBoolean(false);
AtomicBoolean requestDidProduce = new AtomicBoolean(false);
Flowable<NumberProto.Number> request = Flowable
.fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator)
.delay(10, TimeUnit.MILLISECONDS)
.map(CancellationPropagationIntegrationTest::protoNum)
.doOnNext(n -> {
requestDidProduce.set(true);
System.out.println("P: " + n.getNumber(0));
})
.doOnCancel(() -> {
requestWasCanceled.set(true);
System.out.println("Client canceled");
});
TestSubscriber<NumberProto.Number> observer = stub
.twoWayPressure(request)
.doOnNext(number -> System.out.println(number.getNumber(0)))
.doOnError(throwable -> System.out.println(throwable.getMessage()))
.test();
observer.awaitTerminalEvent();
observer.assertTerminated();
assertThat(requestWasCanceled.get()).isTrue();
assertThat(requestDidProduce.get()).isTrue();
}