io.vertx.rx.java.ObservableFuture Java Examples

The following examples show how to use io.vertx.rx.java.ObservableFuture. 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: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailTwice() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  subscribe(o, subscriber);
  Throwable failure = new Throwable();
  o.toHandler().handle(Future.failedFuture(failure));
  o.toHandler().handle(Future.failedFuture(new Throwable()));
  subscriber.assertError(failure).assertEmpty();
}
 
Example #2
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompleteTwice() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  subscribe(o, subscriber);
  o.toHandler().handle(Future.succeededFuture("abc"));
  o.toHandler().handle(Future.succeededFuture("def"));
  subscriber.assertItem("abc").assertCompleted().assertEmpty();
}
 
Example #3
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsubscribeBeforeResolve() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  subscribe(o, subscriber);
  subscriber.unsubscribe();
  assertTrue(subscriber.isUnsubscribed());
  subscriber.assertEmpty();
}
 
Example #4
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompleteWithFailureAfterSubscribe() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  subscribe(o, subscriber);
  subscriber.assertEmpty();
  Throwable failure = new Throwable();
  o.toHandler().handle(Future.failedFuture(failure));
  subscriber.assertError(failure).assertEmpty();
}
 
Example #5
Source File: DefaultRxElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<BulkResponse> bulk(List<BulkIndexOptions> bulkIndexOptions,
                                     List<BulkUpdateOptions> bulkUpdateOptions,
                                     List<BulkDeleteOptions> bulkDeleteOptions,
                                     BulkOptions bulkOptions) {
    final ObservableFuture<BulkResponse> observableFuture = RxHelper.observableFuture();
    elasticSearchService.bulk(bulkIndexOptions, bulkUpdateOptions, bulkDeleteOptions, bulkOptions, observableFuture.toHandler());
    return observableFuture;
}
 
Example #6
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompleteWithFailureBeforeSubscribe() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  Throwable failure = new Throwable();
  o.toHandler().handle(Future.failedFuture(failure));
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  subscribe(o, subscriber);
  subscriber.assertError(failure).assertEmpty();
}
 
Example #7
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompleteWithSuccessAfterSubscribe() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  subscribe(o, subscriber);
  subscriber.assertEmpty();
  o.toHandler().handle(Future.succeededFuture("abc"));
  subscriber.assertItem("abc").assertCompleted().assertEmpty();
}
 
Example #8
Source File: AsyncResultHandlerTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompleteWithSuccessBeforeSubscribe() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  o.toHandler().handle(Future.succeededFuture("abc"));
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  subscribe(o, subscriber);
  subscriber.assertItem("abc").assertCompleted().assertEmpty();
}
 
Example #9
Source File: NativeExamples.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
public void observableFuture(Vertx vertx) {
  ObservableFuture<HttpServer> observable = RxHelper.observableFuture();
  observable.subscribe(
      server -> {
        // Server is listening
      },
      failure -> {
        // Server could not start
      }
  );
  vertx.createHttpServer(new HttpServerOptions().
      setPort(1234).
      setHost("localhost")
  ).listen(observable.toHandler());
}
 
Example #10
Source File: IntegrationTestBase.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteRx(TestContext testContext) throws Exception {
    final Async async = testContext.async();
    final JsonObject source = new JsonObject()
            .put("user", source_user)
            .put("message", source_message)
            .put("obj", new JsonObject()
                    .put("array", new JsonArray()
                            .add("1")
                            .add("2")));

    final UUID documentId = UUID.randomUUID();
    final IndexOptions indexOptions = new IndexOptions().setId(documentId.toString());

    rxService.index(index, type, source, indexOptions)
            .flatMap(indexResponse -> {
                final ObservableFuture<Void> observableFuture = RxHelper.observableFuture();
                vertx.setTimer(2000l, event -> observableFuture.toHandler().handle(Future.succeededFuture()));
                return observableFuture;
            })
            .flatMap(indexResponse -> rxService.delete(index, type, documentId.toString(), new DeleteOptions().setRefresh(RefreshPolicy.IMMEDIATE)))
            .subscribe(
                    deleteResponse -> {
                        assertDelete(testContext, deleteResponse, documentId);
                        async.complete();
                    },
                    error -> testContext.fail(error)
            );
}
 
Example #11
Source File: IntegrationTestBase.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiSearchRx(TestContext testContext) throws Exception {

    final Async async = testContext.async();
    final JsonObject source = new JsonObject()
            .put("user", source_user)
            .put("message", source_message)
            .put("obj", new JsonObject()
                    .put("array", new JsonArray()
                            .add("1")
                            .add("2")));

    final SearchOptions searchOptions = new SearchOptions()
            .setTimeoutInMillis(1000l)
            .setSize(10)
            .setSourceIncludes(Arrays.asList("user", "message"))
            .addFieldSort("user", SortOrder.DESC)
            .addScripSort("doc['message'].value", "painless", ScriptSortOption.Type.STRING, new JsonObject().put("param1", ImmutableList.of("1", "2", "3")), SortOrder.ASC)
            .addScriptField("script_field", "doc['message'].value", "painless", new JsonObject().put("param1", ImmutableList.of("1", "2", "3")))
            .setQuery(new JsonObject().put("match_all", new JsonObject()));

    final IndexOptions indexOptions = new IndexOptions().setId(id);
    rxService.index(index, type, source, indexOptions)
            .flatMap(indexResponse -> {
                final ObservableFuture<IndexResponse> observableFuture = RxHelper.observableFuture();
                vertx.setTimer(2000l, event -> observableFuture.toHandler().handle(Future.succeededFuture(indexResponse)));
                return observableFuture;
            })
            .flatMap(indexResponse -> rxService.multiSearch(ImmutableList.of(new MultiSearchQueryOptions().addIndex(index).setSearchOptions(searchOptions))))
            .subscribe(
                    multiSearchResponse -> {
                        assertMultiSearch(testContext, multiSearchResponse);
                        async.complete();
                    },
                    error -> testContext.fail(error)
            );
}
 
Example #12
Source File: IntegrationTestBase.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteByQuerySimpleRx(TestContext testContext) throws Exception {

    final Async async = testContext.async();
    final JsonObject source = new JsonObject()
            .put("user", source_user)
            .put("message", source_message)
            .put("obj", new JsonObject()
                    .put("array", new JsonArray()
                            .add("1")
                            .add("2")));

    final UUID documentId = UUID.randomUUID();
    final IndexOptions indexOptions = new IndexOptions().setId(documentId.toString());

    rxService.index(index, type, source, indexOptions)
            .flatMap(result -> {
                final ObservableFuture<Void> observableFuture = RxHelper.observableFuture();
                vertx.setTimer(2000, id -> observableFuture.toHandler().handle(Future.succeededFuture()));
                return observableFuture;
            })
            .flatMap(aVoid -> {
                final DeleteByQueryOptions deleteByQueryOptions = new DeleteByQueryOptions().setTimeoutInMillis(1000l);
                return rxService.deleteByQuery(index, deleteByQueryOptions.setQuery(new JsonObject().put("ids", new JsonObject().put("values", new JsonArray().add(documentId.toString())))));
            })
            .subscribe(
                    deleteByQueryResponse -> {
                        assertDeleteByQuerySimple(testContext, deleteByQueryResponse);
                        async.complete();
                    },
                    error -> testContext.fail(error)
            );
}
 
Example #13
Source File: IntegrationTestBase.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testSearchRx(TestContext testContext) throws Exception {

    final Async async = testContext.async();
    final JsonObject source = new JsonObject()
            .put("user", source_user)
            .put("message", source_message)
            .put("obj", new JsonObject()
                    .put("array", new JsonArray()
                            .add("1")
                            .add("2")));

    final SearchOptions searchOptions = new SearchOptions()
            .setTimeoutInMillis(1000l)
            .setSize(10)
            .setSourceIncludes(Arrays.asList("user", "message"))
            .addFieldSort("user", SortOrder.DESC)
            .addScripSort("doc['message'].value", "painless", ScriptSortOption.Type.STRING, new JsonObject().put("param1", ImmutableList.of("1", "2", "3")), SortOrder.ASC)
            .addScriptField("script_field", "doc['message'].value", "painless", new JsonObject().put("param1", ImmutableList.of("1", "2", "3")))
            .setQuery(new JsonObject().put("match_all", new JsonObject()));

    final IndexOptions indexOptions = new IndexOptions().setId(id);
    rxService.index(index, type, source, indexOptions)
            .flatMap(indexResponse -> {
                final ObservableFuture<IndexResponse> observableFuture = RxHelper.observableFuture();
                vertx.setTimer(2000l, event -> observableFuture.toHandler().handle(Future.succeededFuture(indexResponse)));
                return observableFuture;
            })
            .flatMap(indexResponse -> rxService.search(index, searchOptions))
            .subscribe(
                    searchResponse -> {
                        assertSearch(testContext, searchResponse);
                        async.complete();
                    },
                    error -> testContext.fail(error)
            );
}
 
Example #14
Source File: IntegrationTestBase.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testSearch_SuggestRx(TestContext testContext) throws Exception {

    final Async async = testContext.async();
    final JsonObject source = new JsonObject()
            .put("user", source_user)
            .put("message", source_message)
            .put("message_suggest", source_message);

    rxService.index(index, type, source)
            .flatMap(result -> {
                final ObservableFuture<Void> observableFuture = RxHelper.observableFuture();
                vertx.setTimer(1000, id -> observableFuture.toHandler().handle(Future.succeededFuture()));
                return observableFuture;
            })
            .flatMap(aVoid -> {
                final SearchOptions options = new SearchOptions();
                final CompletionSuggestOption completionSuggestOption = new CompletionSuggestOption()
                        .setText("v")
                        .setField("message_suggest");
                options.addSuggestion("test-suggest", completionSuggestOption);

                return rxService.search(index, options);
            })
            .subscribe(
                    searchResponse -> {
                        assertSuggest(testContext, searchResponse);
                        async.complete();
                    },
                    error -> testContext.fail(error)
            );
}
 
Example #15
Source File: IntegrationTestBase.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Test
public void testScrollRx(TestContext testContext) throws Exception {

    final Async async = testContext.async();
    final SearchOptions options = new SearchOptions()
            .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
            .setScroll("5m")
            .setQuery(new JsonObject().put("match_all", new JsonObject()));

    final JsonObject source = new JsonObject()
            .put("user", source_user)
            .put("message", source_message)
            .put("obj", new JsonObject()
                    .put("array", new JsonArray()
                            .add("1")
                            .add("2")));

    final UUID documentId = UUID.randomUUID();
    final IndexOptions indexOptions = new IndexOptions().setId(documentId.toString());

    rxService.index(index, type, source, indexOptions)
            .flatMap(indexResponse -> {
                final ObservableFuture<Void> observableFuture = RxHelper.observableFuture();
                vertx.setTimer(2000l, event -> observableFuture.toHandler().handle(Future.succeededFuture()));
                return observableFuture;
            })
            .flatMap(aVoid -> rxService.search(index, options))
            .flatMap(searchResponse -> {
                String scrollId = searchResponse.getScrollId();
                assertScroll(testContext, searchResponse);
                SearchScrollOptions scrollOptions = new SearchScrollOptions().setScroll("5m");
                return rxService.searchScroll(scrollId, scrollOptions);
            })
            .subscribe(
                    searchResponse -> {
                        assertThat(testContext, searchResponse.getHits().getTotal(), greaterThan(0l));
                        async.complete();
                    },
                    error -> testContext.fail(error)
            );
}
 
Example #16
Source File: RxMicroServiceVerticle.java    From vertx-microservices-workshop with Apache License 2.0 4 votes vote down vote up
private Single<Void> rxPublish(Record record) {
  ObservableFuture<Void> adapter = RxHelper.observableFuture();
  publish(record, adapter.toHandler());
  return adapter.toSingle();
}
 
Example #17
Source File: DefaultRxElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<UpdateResponse> update(String index, String type, String id, UpdateOptions options) {
    final ObservableFuture<UpdateResponse> observableFuture = RxHelper.observableFuture();
    elasticSearchService.update(index, type, id, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #18
Source File: DefaultRxElasticSearchAdminService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Void> deleteTemplate(String name, TemplateOptions options) {
    final ObservableFuture<Void> observableFuture = RxHelper.observableFuture();
    elasticSearchAdminService.deleteTemplate(name, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #19
Source File: DefaultRxElasticSearchAdminService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Void> putTemplate(String name, JsonObject source, TemplateOptions options) {
    final ObservableFuture<Void> observableFuture = RxHelper.observableFuture();
    elasticSearchAdminService.putTemplate(name, source, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #20
Source File: DefaultRxElasticSearchAdminService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Void> deleteIndex(List<String> indices, DeleteIndexOptions options) {
    final ObservableFuture<Void> observableFuture = RxHelper.observableFuture();
    elasticSearchAdminService.deleteIndex(indices, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #21
Source File: DefaultRxElasticSearchAdminService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Void> createIndex(String index, JsonObject source, CreateIndexOptions options) {
    final ObservableFuture<Void> observableFuture = RxHelper.observableFuture();
    elasticSearchAdminService.createIndex(index, source, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #22
Source File: DefaultRxElasticSearchAdminService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Void> putMapping(List<String> indices, String type, JsonObject source, MappingOptions options) {
    final ObservableFuture<Void> observableFuture = RxHelper.observableFuture();
    elasticSearchAdminService.putMapping(indices, type, source, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #23
Source File: DefaultRxElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<DeleteByQueryResponse> deleteByQuery(List<String> indices, DeleteByQueryOptions options) {
    final ObservableFuture<DeleteByQueryResponse> observableFuture = RxHelper.observableFuture();
    elasticSearchService.deleteByQuery(indices, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #24
Source File: DefaultRxElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<MultiGetResponse> multiGet(List<MultiGetQueryOptions> multiGetQueryOptions, MultiGetOptions options) {
    final ObservableFuture<MultiGetResponse> observableFuture = RxHelper.observableFuture();
    elasticSearchService.multiGet(multiGetQueryOptions, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #25
Source File: DefaultRxElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<MultiSearchResponse> multiSearch(final List<MultiSearchQueryOptions> multiSearchQueryOptions, MultiSearchOptions options) {
    final ObservableFuture<MultiSearchResponse> observableFuture = RxHelper.observableFuture();
    elasticSearchService.multiSearch(multiSearchQueryOptions, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #26
Source File: DefaultRxElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<DeleteResponse> delete(String index, String type, String id, DeleteOptions options) {
    final ObservableFuture<DeleteResponse> observableFuture = RxHelper.observableFuture();
    elasticSearchService.delete(index, type, id, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #27
Source File: DefaultRxElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<SearchResponse> searchScroll(String scrollId, SearchScrollOptions options) {
    final ObservableFuture<SearchResponse> observableFuture = RxHelper.observableFuture();
    elasticSearchService.searchScroll(scrollId, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #28
Source File: DefaultRxElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<SearchResponse> search(List<String> indices, SearchOptions options) {
    final ObservableFuture<SearchResponse> observableFuture = RxHelper.observableFuture();
    elasticSearchService.search(indices, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #29
Source File: DefaultRxElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<GetResponse> get(String index, String type, String id, GetOptions options) {
    final ObservableFuture<GetResponse> observableFuture = RxHelper.observableFuture();
    elasticSearchService.get(index, type, id, options, observableFuture.toHandler());
    return observableFuture;
}
 
Example #30
Source File: RxHelper.java    From vertx-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Like {@link #deployVerticle(Vertx, Verticle)}, but {@link io.vertx.core.DeploymentOptions} are provided to configure the
 * deployment.
 *
 * @param vertx the vertx instance
 * @param verticle the verticle instance to deploy
 * @param options the deployment options.
 * @return the response observable
 */
public static Observable<String> deployVerticle(Vertx vertx, Verticle verticle, DeploymentOptions options) {
  ObservableFuture<String> completionHandler = io.vertx.rx.java.RxHelper.observableFuture();
  vertx.getDelegate().deployVerticle(verticle, options, completionHandler.toHandler());
  return completionHandler;
}