Java Code Examples for io.reactivex.Completable#blockingAwait()

The following examples show how to use io.reactivex.Completable#blockingAwait() . 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: BlockingOperators.java    From Learn-Java-12-Programming with MIT License 6 votes vote down vote up
private static void completableBlocking(){
    Completable obs = Completable.fromRunnable(() -> {
        System.out.println("Running...");
        try {
            TimeUnit.MILLISECONDS.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }); //prints: Run

    Throwable ex = obs.blockingGet();
    System.out.println(ex);   //prints: null

    //ex = obs.blockingGet(15, TimeUnit.MILLISECONDS);
    //java.util.concurrent.TimeoutException: The source did not signal an event for 15 milliseconds and has been terminated.

    ex = obs.blockingGet(150, TimeUnit.MILLISECONDS);
    System.out.println(ex);   //prints: null

    obs.blockingAwait();

    obs.blockingAwait(15, TimeUnit.MILLISECONDS);
}
 
Example 2
Source File: PahoObservableMqttClientITCase.java    From rxmqtt with Apache License 2.0 6 votes vote down vote up
@Test(expected = MqttException.class)
public void itCanClose() throws Throwable {
    Assert.assertFalse(this.asyncClient.isConnected());
    Assert.assertFalse(this.observableClient.isConnected());

    final Completable obs1 = this.observableClient.connect();
    obs1.blockingAwait();
    final Completable obs2 = this.observableClient.disconnect();
    obs2.blockingAwait();
    final Completable obs3 = this.observableClient.close();
    obs3.blockingAwait();

    // Should error
    AsyncPahoUtils.connect(this.asyncClient);

}
 
Example 3
Source File: UnsubscribeFactoryTest.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 IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.unsubscribe(Matchers.any(String[].class),
            Matchers.isNull(),
            Matchers.any(
                    UnsubscribeFactory.UnsubscribeActionListener.class)))
            .thenThrow(new MqttException(
                    MqttException.REASON_CODE_CLIENT_CONNECTED));
    final UnsubscribeFactory factory = new UnsubscribeFactory(client);
    final Completable obs = factory
            .create(new String[] { "topic1", "topic2" });
    obs.blockingAwait();
}
 
Example 4
Source File: CompletableFromRSPublisherTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Override
protected Exception getFailure(Completable instance) {
    AtomicReference<Exception> reference = new AtomicReference<>();
    try {
        instance.blockingAwait();
    } catch (Exception e) {
        reference.set(e);
    }
    return reference.get();
}
 
Example 5
Source File: CompletableFromCompletionStageTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Override
protected Exception getFailure(Completable instance) {
    AtomicReference<Exception> reference = new AtomicReference<>();
    try {
        instance.blockingAwait();
    } catch (Exception e) {
        reference.set(e);
    }
    return reference.get();
}
 
Example 6
Source File: ConnectFactoryTest.java    From rxmqtt with Apache License 2.0 5 votes vote down vote up
@Test
public void whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled()
        throws Throwable {
    this.expectedException.expectCause(isA(MqttException.class));
    final MqttConnectOptions options = Mockito
            .mock(MqttConnectOptions.class);
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.connect(Matchers.same(options), Matchers.isNull(),
            Matchers.any(ConnectFactory.ConnectActionListener.class)))
            .thenThrow(new MqttException(
                    MqttException.REASON_CODE_CLIENT_CONNECTED));
    final ConnectFactory factory = new ConnectFactory(client, options);
    final Completable obs = factory.create();
    obs.blockingAwait();
}
 
Example 7
Source File: PahoObservableMqttClientITCase.java    From rxmqtt with Apache License 2.0 5 votes vote down vote up
@Test
public void itCanConnect() throws Throwable {
    Assert.assertFalse(this.asyncClient.isConnected());
    Assert.assertFalse(this.observableClient.isConnected());

    final Completable obs = this.observableClient.connect();
    obs.blockingAwait();

    Assert.assertTrue(this.asyncClient.isConnected());
    Assert.assertTrue(this.observableClient.isConnected());
}
 
Example 8
Source File: PahoObservableMqttClientITCase.java    From rxmqtt with Apache License 2.0 5 votes vote down vote up
@Test
public void itCanDisconnect() throws Throwable {

    AsyncPahoUtils.connect(this.asyncClient);
    Assert.assertTrue(this.asyncClient.isConnected());
    Assert.assertTrue(this.observableClient.isConnected());

    final Completable obs1 = this.observableClient.disconnect();
    obs1.blockingAwait();

    Assert.assertFalse(this.asyncClient.isConnected());
    Assert.assertFalse(this.observableClient.isConnected());

}
 
Example 9
Source File: CloseFactoryTest.java    From rxmqtt with Apache License 2.0 5 votes vote down vote up
@Test
public void whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled()
        throws Throwable {
    this.expectedException.expectCause(isA(MqttException.class));
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.doThrow(
            new MqttException(MqttException.REASON_CODE_CLIENT_CONNECTED))
            .when(client).close();
    final CloseFactory factory = new CloseFactory(client);
    final Completable obs = factory.create();
    obs.blockingAwait();
}
 
Example 10
Source File: DisconnectFactoryTest.java    From rxmqtt with Apache License 2.0 5 votes vote down vote up
@Test
public void whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled()
        throws Throwable {
    this.expectedException.expectCause(isA(MqttException.class));
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.disconnect(Matchers.isNull(),
            Matchers.any(DisconnectFactory.DisconnectActionListener.class)))
            .thenThrow(new MqttException(
                    MqttException.REASON_CODE_CLIENT_CONNECTED));
    final DisconnectFactory factory = new DisconnectFactory(client);
    final Completable obs = factory.create();
    obs.blockingAwait();
}
 
Example 11
Source File: CompletableFromRSPublisherTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected String getOne(Completable instance) {
    instance.blockingAwait();
    return null;
}
 
Example 12
Source File: CompletableFromRSPublisherTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@Override
protected List<String> getAll(Completable instance) {
    instance.blockingAwait();
    return Collections.emptyList();
}
 
Example 13
Source File: CompletableFromRSPublisherTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@Override
protected void consume(Completable instance) {
    instance.blockingAwait();
}
 
Example 14
Source File: CompletableFromCompletionStageTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected String getOne(Completable instance) {
    instance.blockingAwait();
    return null;
}