本文整理匯總了Java中io.reactivex.subscribers.TestSubscriber.awaitTerminalEvent方法的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber.awaitTerminalEvent方法的具體用法?Java TestSubscriber.awaitTerminalEvent怎麽用?Java TestSubscriber.awaitTerminalEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.reactivex.subscribers.TestSubscriber
的用法示例。
在下文中一共展示了TestSubscriber.awaitTerminalEvent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testGetOneObject
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testGetOneObject(){
models.clear();
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(10));
list.add(new TestModel(20));
list.add(new TestModel(30));
memoryStore.insertOrUpdate(list);
TestModel toFind = new TestModel(20);
TestSubscriber<Optional<TestModel>> observer = new TestSubscriber<>();
disposables.add(testStore.getOne(toFind)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(5, SECONDS);
observer.assertComplete();
observer.assertNoErrors();
Assert.assertEquals(3, models.size());
TestModel tm = observer.values().get(0).get();
Assert.assertEquals(20, tm.getId());
}
示例2: testDeleteAllWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testDeleteAllWithError(){
testStore.shouldThrowError(true);
models.clear();
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(1));
list.add(new TestModel(2));
list.add(new TestModel(3));
memoryStore.insertOrUpdate(list);
TestSubscriber<Integer> observer = new TestSubscriber<>();
disposables.add(testStore.deleteAll()
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(5, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("deleteAll.error");
testStore.shouldThrowError(false); // disable error
Assert.assertEquals(3, models.size());
}
示例3: 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();
}
示例4: testInsertWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testInsertWithError(){
models.clear();
testStore.shouldThrowError(true); // enable error
TestModel model = new TestModel(99);
TestSubscriber<Optional<TestModel>> observer = new TestSubscriber<>();
disposables.add(testStore.insert(model)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(2, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("insertSingle.error");
testStore.shouldThrowError(false); // disable error
Assert.assertEquals(0, models.size());
}
示例5: testGetOneAscending
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testGetOneAscending(){
models.clear();
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(10));
list.add(new TestModel(30));
memoryStore.insertOrUpdate(list);
TestSubscriber<Optional<TestModel>> observer = new TestSubscriber<>();
disposables.add(testStore.getOne()
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(5, SECONDS);
observer.assertComplete();
observer.assertNoErrors();
Assert.assertEquals(2, models.size());
TestModel tm = observer.values().get(0).get();
Assert.assertEquals(10, tm.getId());
}
示例6: onNextDelegates
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void onNextDelegates() {
ClientCallStreamObserver<Object> obs = mock(ClientCallStreamObserver.class);
RxConsumerStreamObserver rxObs = new RxConsumerStreamObserver();
Subscriber<Object> sub = mock(Subscriber.class);
rxObs.beforeStart(obs);
rxObs.getRxConsumer().subscribe(sub);
TestSubscriber<Object> testSubscriber = ((Flowable<Object>)rxObs.getRxConsumer()).test();
Object obj = new Object();
rxObs.onNext(obj);
rxObs.onCompleted();
testSubscriber.awaitTerminalEvent(3, TimeUnit.SECONDS);
testSubscriber.assertValues(obj);
}
示例7: onErrorDelegates
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void onErrorDelegates() {
ClientCallStreamObserver<Object> obs = mock(ClientCallStreamObserver.class);
RxConsumerStreamObserver rxObs = new RxConsumerStreamObserver();
Subscriber<Object> sub = mock(Subscriber.class);
rxObs.beforeStart(obs);
rxObs.getRxConsumer().subscribe(sub);
TestSubscriber<Object> testSubscriber = ((Flowable<Object>)rxObs.getRxConsumer()).test();
Throwable obj = new Exception();
rxObs.onError(obj);
testSubscriber.awaitTerminalEvent(3, TimeUnit.SECONDS);
testSubscriber.assertError(obj);
}
示例8: oneToMany
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void oneToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<HelloResponse> resp = stub.sayHelloRespStream(Single.just(HelloRequest.getDefaultInstance()));
TestSubscriber<HelloResponse> test = resp
.doOnNext(msg -> System.out.println(msg))
.doOnError(throwable -> System.out.println(throwable.getMessage()))
.doOnComplete(() -> System.out.println("Completed"))
.doOnCancel(() -> System.out.println("Client canceled"))
.test();
test.awaitTerminalEvent(3, TimeUnit.SECONDS);
test.assertError(t -> t instanceof StatusRuntimeException);
test.assertError(t -> ((StatusRuntimeException)t).getStatus() == Status.INTERNAL);
}
示例9: manyToMany
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void manyToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<HelloRequest> req = Flowable.just(HelloRequest.getDefaultInstance());
Flowable<HelloResponse> resp = stub.sayHelloBothStream(req);
TestSubscriber<HelloResponse> test = resp.test();
test.awaitTerminalEvent(3, TimeUnit.SECONDS);
test.assertError(t -> t instanceof StatusRuntimeException);
test.assertError(t -> ((StatusRuntimeException)t).getStatus().getCode() == Status.Code.CANCELLED);
}
示例10: testUpdateListWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUpdateListWithError(){
models.clear();
testStore.shouldThrowError(true); // enable error
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(1));
list.add(new TestModel(2));
list.add(new TestModel(3));
memoryStore.insertOrUpdate(list);
List<TestModel> updateList = new ArrayList<>();
TestModel testModel = new TestModel(1);
testModel.setAvailable(true);
updateList.add(testModel);
testModel = new TestModel(3);
testModel.setAvailable(true);
updateList.add(testModel);
TestSubscriber<Optional<List<TestModel>>> observer = new TestSubscriber<>();
disposables.add(testStore.update(updateList)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(4, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("update.error");
testStore.shouldThrowError(false); // disable error
Assert.assertEquals(3, models.size()); // should have been cleared
for(TestModel tm : models){
Assert.assertFalse(tm.isAvailable());
}
}
示例11: 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();
}
示例12: manyToMany
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void manyToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<String> rxRequest = Flowable.just("A", "B", "C", "D");
Flowable<String> rxResponse = stub.sayHelloBothStream(rxRequest.map(this::toRequest)).map(this::fromResponse);
TestSubscriber<String> test = rxResponse.test();
test.awaitTerminalEvent(1, TimeUnit.SECONDS);
test.assertNoErrors();
test.assertValues("Hello A and B", "Hello C and D");
}
示例13: testUpdate
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUpdate(){
models.clear();
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(1));
list.add(new TestModel(2));
list.add(new TestModel(3));
memoryStore.insertOrUpdate(list);
TestModel testModel = new TestModel(1);
testModel.setAvailable(true);
TestSubscriber<Optional<TestModel>> observer = new TestSubscriber<>();
disposables.add(testStore.update(testModel)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(4, SECONDS);
observer.assertComplete();
observer.assertNoErrors();
Optional<TestModel> results = observer.values().get(0);
Optional<TestModel> resultsAfter = observer.values().get(1);
Assert.assertNotNull(results.get());
Assert.assertNotNull(resultsAfter.get());
Assert.assertTrue(results.get().isAvailable());
Assert.assertTrue(resultsAfter.get().isAvailable());
Assert.assertEquals(3, models.size());
for(TestModel tm : models){
if(tm.getId() == 1){
Assert.assertTrue(tm.isAvailable());
}
}
}
示例14: testDeleteSingle
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testDeleteSingle(){
models.clear();
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(1));
list.add(new TestModel(2));
list.add(new TestModel(3));
memoryStore.insertOrUpdate(list);
TestModel model = new TestModel(2);
TestSubscriber<Integer> observer = new TestSubscriber<>();
disposables.add(testStore.delete(model)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(2, SECONDS);
observer.assertComplete();
observer.assertNoErrors();
int sum = 0;
for(TestModel tm : models){
sum += tm.getId();
}
Integer numberOfDeletions = observer.values().get(0);
Assert.assertEquals(2, models.size());
Assert.assertEquals(1, (int) numberOfDeletions);
Assert.assertEquals(4, sum);
}
示例15: oneToMany
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void oneToMany() throws IOException {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Single<HelloRequest> req = Single.just(HelloRequest.newBuilder().setName("rxjava").build());
Flowable<HelloResponse> resp = stub.sayHelloRespStream(req);
TestSubscriber<String> testSubscriber = resp.map(HelloResponse::getMessage).test();
testSubscriber.awaitTerminalEvent(3, TimeUnit.SECONDS);
testSubscriber.assertValues("Hello rxjava", "Hi rxjava", "Greetings rxjava");
}