Java Code Examples for io.reactivex.Flowable#blockingFirst()

The following examples show how to use io.reactivex.Flowable#blockingFirst() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChatStorageTest.java    From adamant-android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void concurrentTwoProducerOneConsumer() throws InterruptedException {
    ChatsStorage chatsStorage = new ChatsStorage();

    Flowable<AdamantBasicMessage> producer1 = provideProducer(chatsStorage);
    Flowable<AdamantBasicMessage> producer2 = provideProducer(chatsStorage);
    Flowable<Integer> consumer = provideConsumer(chatsStorage, CHAT_COUNT * 2);

    Disposable producerSubscription1 = producer1.subscribe();
    subscriptions.add(producerSubscription1);
    Disposable producerSubscription2 = producer2.subscribe();
    subscriptions.add(producerSubscription2);
    Integer size = consumer.blockingFirst();

    Assert.assertEquals(CHAT_COUNT * 2, (int) size);
}
 
Example 2
Source File: SubscribeFactoryTest.java    From rxmqtt with Apache License 2.0 6 votes vote down vote up
@Test
public void whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled()
        throws Throwable {
    this.expectedException.expectCause(isA(MqttException.class));
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor
            .forClass(IMqttActionListener.class);
    final ArgumentCaptor<IMqttMessageListener[]> messageListener = ArgumentCaptor
            .forClass(IMqttMessageListener[].class);
    final String[] topics = new String[] { "topic1", "topic2" };
    final int[] qos = new int[] { 1, 2 };
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.subscribe(Matchers.same(topics), Matchers.same(qos),
            Matchers.isNull(), actionListener.capture(),
            messageListener.capture()))
            .thenThrow(new MqttException(
                    MqttException.REASON_CODE_CLIENT_CONNECTED));
    final SubscribeFactory factory = new SubscribeFactory(client);
    final Flowable<SubscribeMessage> obs = factory.create(topics, qos,
            BackpressureStrategy.ERROR);
    obs.blockingFirst();
}
 
Example 3
Source File: UniToPublisherTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testThatTwoSubscribersHaveTwoSubscriptions() {
    AtomicInteger count = new AtomicInteger(1);
    Publisher<Integer> publisher = Uni.createFrom().deferred(() -> Uni.createFrom()
            .item(count.getAndIncrement()))
            .convert().toPublisher();
    assertThat(publisher).isNotNull();
    Flowable<Integer> flow = Flowable.fromPublisher(publisher);
    int first = flow.blockingFirst();
    assertThat(first).isEqualTo(1);
    first = flow.blockingFirst();
    assertThat(first).isEqualTo(2);
}
 
Example 4
Source File: UniToPublisherTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testThatTwoSubscribersWithCache() {
    AtomicInteger count = new AtomicInteger(1);
    Publisher<Integer> publisher = Uni.createFrom()
            .deferred(() -> Uni.createFrom().item(count.getAndIncrement())).cache().convert().toPublisher();
    assertThat(publisher).isNotNull();
    Flowable<Integer> flow = Flowable.fromPublisher(publisher);
    int first = flow.blockingFirst();
    assertThat(first).isEqualTo(1);
    first = flow.blockingFirst();
    assertThat(first).isEqualTo(1);
}
 
Example 5
Source File: ChatStorageTest.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void concurrentOneProducerOneConsumer() {
    ChatsStorage chatsStorage = new ChatsStorage();

    Flowable<AdamantBasicMessage> producer = provideProducer(chatsStorage);
    Flowable<Integer> consumer = provideConsumer(chatsStorage, CHAT_COUNT);

    Disposable producerSubscription = producer.subscribe();
    subscriptions.add(producerSubscription);

    Integer size = consumer.blockingFirst();

    Assert.assertEquals(CHAT_COUNT, (int) size);
}
 
Example 6
Source File: CompletableToRSPublisherTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test
public void testToPublisherWithImmediateCompletion() {
    Completable completable = Completable.complete();
    Flowable<String> flowable = Flowable.fromPublisher(converter.toRSPublisher(completable));
    String res = flowable.blockingFirst("DEFAULT");
    assertThat(res).isEqualTo("DEFAULT");
}
 
Example 7
Source File: CompletableToRSPublisherTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test
public void testToPublisherWithDelayedCompletion() {
    Completable completable = Single.just("hello").delay(10, TimeUnit.MILLISECONDS).ignoreElement();
    Flowable<String> flowable = Flowable.fromPublisher(converter.toRSPublisher(completable));
    String res = flowable.blockingFirst("DEFAULT");
    assertThat(res).isEqualTo("DEFAULT");
}