Java Code Examples for io.vertx.rx.java.RxHelper#toFuture()

The following examples show how to use io.vertx.rx.java.RxHelper#toFuture() . 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: NativeExamples.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
public void observableToHandler() {
  Observer<HttpServer> observer = new Observer<HttpServer>() {
    @Override
    public void onNext(HttpServer o) {
    }
    @Override
    public void onError(Throwable e) {
    }
    @Override
    public void onCompleted() {
    }
  };
  Handler<AsyncResult<HttpServer>> handler = RxHelper.toFuture(observer);
}
 
Example 2
Source File: NativeExamples.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
public void actionsToHandler() {
  Action1<HttpServer> onNext = httpServer -> {};
  Action1<Throwable> onError = httpServer -> {};
  Action0 onComplete = () -> {};

  Handler<AsyncResult<HttpServer>> handler1 = RxHelper.toFuture(onNext);
  Handler<AsyncResult<HttpServer>> handler2 = RxHelper.toFuture(onNext, onError);
  Handler<AsyncResult<HttpServer>> handler3 = RxHelper.toFuture(onNext, onError, onComplete);
}
 
Example 3
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testFulfillAdaptedSubscriber() {
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  Handler<AsyncResult<String>> o = RxHelper.toFuture(TestUtils.toObserver(subscriber));
  o.handle(Future.succeededFuture("abc"));
  subscriber.assertItem("abc").assertCompleted().assertEmpty();
}
 
Example 4
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testRejectAdaptedSubscriber() {
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  Handler<AsyncResult<String>> o = RxHelper.toFuture(TestUtils.toObserver(subscriber));
  Exception e = new Exception();
  o.handle(Future.failedFuture(e));
  subscriber.assertError(e).assertEmpty();
}
 
Example 5
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testFulfillAdaptedFunctions1() {
  List<String> items = new ArrayList<>();
  Handler<AsyncResult<String>> o = RxHelper.toFuture(items::add);
  o.handle(Future.succeededFuture("abc"));
  assertEquals(Collections.singletonList("abc"), items);
}
 
Example 6
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testFulfillAdaptedFunctions2() {
  List<String> items = new ArrayList<>();
  List<Throwable> errors = new ArrayList<>();
  Handler<AsyncResult<String>> o = RxHelper.toFuture(items::add, errors::add);
  o.handle(Future.succeededFuture("abc"));
  assertEquals(Collections.singletonList("abc"), items);
  assertEquals(Collections.emptyList(), errors);
}
 
Example 7
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testFulfillAdaptedFunctions3() {
  List<String> items = new ArrayList<>();
  List<Throwable> errors = new ArrayList<>();
  AtomicInteger completions = new AtomicInteger();
  Handler<AsyncResult<String>> o = RxHelper.toFuture(items::add, errors::add, completions::incrementAndGet);
  o.handle(Future.succeededFuture("abc"));
  assertEquals(Collections.singletonList("abc"), items);
  assertEquals(Collections.emptyList(), errors);
  assertEquals(1, completions.get());
}
 
Example 8
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testRejectAdaptedFunctions1() {
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  Handler<AsyncResult<String>> o = RxHelper.toFuture(subscriber::onNext);
  Exception cause = new Exception();
  try {
    o.handle(Future.failedFuture(cause));
  } catch (OnErrorNotImplementedException e) {
    assertSame(cause, e.getCause());
  }
  subscriber.assertEmpty();
}
 
Example 9
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testRejectAdaptedFunctions2() {
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  Handler<AsyncResult<String>> o = RxHelper.toFuture(subscriber::onNext, subscriber::onError);
  Exception cause = new Exception();
  o.handle(Future.failedFuture(cause));
  subscriber.assertError(cause).assertEmpty();
}
 
Example 10
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testRejectAdaptedFunctions3() {
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  Handler<AsyncResult<String>> o = RxHelper.toFuture(subscriber::onNext, subscriber::onError, subscriber::onCompleted);
  Exception cause = new Exception();
  o.handle(Future.failedFuture(cause));
  subscriber.assertError(cause).assertEmpty();
}