Refine search
@Test public void voidReturnType() throws Exception { testVoid(null, on(TestController.class).resolveReturnType(void.class)); testVoid(Mono.empty(), on(TestController.class).resolveReturnType(Mono.class, Void.class)); testVoid(Flux.empty(), on(TestController.class).resolveReturnType(Flux.class, Void.class)); testVoid(Completable.complete(), on(TestController.class).resolveReturnType(Completable.class)); testVoid(Observable.empty(), on(TestController.class).resolveReturnType(Observable.class, Void.class)); MethodParameter type = on(TestController.class).resolveReturnType(io.reactivex.Completable.class); testVoid(io.reactivex.Completable.complete(), type); type = on(TestController.class).resolveReturnType(io.reactivex.Observable.class, Void.class); testVoid(io.reactivex.Observable.empty(), type); type = on(TestController.class).resolveReturnType(Flowable.class, Void.class); testVoid(Flowable.empty(), type); }
if (v instanceof Observable) { return new Deferred( deferred -> observable.apply((Observable) v).subscribe(new DeferredSubscriber(deferred))); } else if (v instanceof Single) { return new Deferred( } else if (v instanceof Completable) { return new Deferred(deferred -> completable.apply((Completable) v) .subscribe(new DeferredSubscriber(deferred)));
@Test public void testGetCompletableUserWithRxFallback() { Completable completable = userService.getCompletableUserWithRxFallback(null, "name: "); completable.<User>toObservable().subscribe(new Action1<User>() { @Override public void call(User user) { assertEquals("default_id", user.getId()); } }); com.netflix.hystrix.HystrixInvokableInfo getUserCommand = getHystrixCommandByKey("getCompletableUserWithRxFallback"); assertTrue(getUserCommand.getExecutionEvents().contains(HystrixEventType.FAILURE)); assertTrue(getUserCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS)); }
@Override protected Observable<Integer> construct() { return Completable.complete().toObservable(); } }
@Override public Completable removeDownload(String md5) { return downloadsRepository.getDownload(md5) .first() .flatMap(download -> getAppDownloader(download.getMd5()).flatMap( appDownloader -> appDownloader.removeAppDownload() .andThen(downloadsRepository.remove(md5)) .andThen(Observable.just(download)))) .doOnNext(download -> removeDownloadFiles(download)) .toCompletable(); }
@Override public void restart() { restartAsync().toObservable().toBlocking().subscribe(); }
@Test public void dispatch_completable() { SimpleStore<String> store = new SimpleStore<>("test1"); CompletableDispatcher dispatcher = new CompletableDispatcher(); TestSubscriber<String> testSubscriber = new TestSubscriber<>(); ObservableAdapter.observable(store).subscribe(testSubscriber); final boolean[] completableCalled = new boolean[1]; dispatcher.dispatch(rx.Completable.fromAction(new Action0() { @Override public void call() { completableCalled[0] = true; } })); testSubscriber.assertValues("test1"); assertTrue(completableCalled[0]); } }
public void truncateTables(String keyspace) { //TODO: The filtering below for static data tables is prone to error. Find a better way to avoid //truncating those tables. session.execute("select table_name from system_schema.tables where keyspace_name = '" + keyspace + "'") .flatMap(Observable::from) .filter(row -> !row.getString(0).equals("cassalog") && !row.getString(0).equals("sys_config")) .flatMap(row -> session.execute("truncate " + row.getString(0))) .toCompletable() .await(10, TimeUnit.SECONDS); }
@Override public Observable<T> call(Observable<T> upstream) { return sqlConnection.rxSetAutoCommit(false).toCompletable() .andThen(upstream) .concatWith(sqlConnection.rxCommit().toCompletable().toObservable()) .onErrorResumeNext(throwable -> { return sqlConnection.rxRollback().toCompletable().onErrorComplete() .andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete()) .andThen(Observable.error(throwable)); }).concatWith(sqlConnection.rxSetAutoCommit(true).toCompletable().toObservable()); } }
@Test public void test() throws Exception { System.out.println("Testing Completable.concat"); System.out.println(); Completable.concat( Observable.range(1, 5).map(integer -> Completable.fromAction(() -> { try { System.out.println("Processing " + integer + "..."); Thread.sleep(100); System.out.println("Processing " + integer + " finished"); } catch (InterruptedException e) { e.printStackTrace(); } }) .doOnUnsubscribe(() -> System.out.println("Unsubscribed from " + integer)) .subscribeOn(Schedulers.io()).observeOn(Schedulers.computation()) ) .doOnUnsubscribe(() -> System.out.println("Unsubscribed from parent observable")) ).subscribe(() -> { System.out.println("Finished Completable.concat"); }, Throwable::printStackTrace ); Thread.sleep(2000); } }
private void unscheduleDeleteExpiredMetrics() { String jobName = "DELETE_EXPIRED_METRICS"; String configId = "org.hawkular.metrics.jobs.DELETE_EXPIRED_METRICS"; // We load the configuration first so that delete is done only if it exists in order to avoid generating // tombstones. Completable deleteConfig = configurationService.load(configId) .map(config -> configurationService.delete(configId)) .toCompletable(); // unscheduleJobByTypeAndName will not generate unnecessary tombstones as it does reads before writes Completable unscheduleJob = scheduler.unscheduleJobByTypeAndName(jobName, jobName); Completable.merge(deleteConfig, unscheduleJob).await(); }
private Observable<String> inTransaction(Exception e) throws Exception { return client.rxGetConnection().flatMapObservable(conn -> { return rxInsertExtraFolks(conn) .andThen(uniqueNames(conn)) .compose(upstream -> e == null ? upstream : upstream.concatWith(Observable.error(e))) .compose(SQLClientHelper.txObservableTransformer(conn)) .concatWith(rxAssertAutoCommit(conn).toObservable()) .doAfterTerminate(conn::close); }); } }
public Observable<String> deleteByNameAsync(List<String> names) { List<Observable<String>> items = new ArrayList<>(); for (final String name : names) { items.add(this.deleteByNameAsync(name).<String>toObservable().map(new Func1<String, String>() { @Override public String call(String s) { return name; } })); } return Observable.mergeDelayError(items); }
return ((Single) res).toObservable(); } else if (res instanceof Completable) { return ((Completable) res).toObservable(); } else { return Observable.just(res);
@Override public Observable<Indexable> call(Context context) { return manager().eventHubs() .deleteByNameAsync(resourceGroupName(), name(), eventHubName) .<Indexable>toObservable() .concatWith(context.voidObservable()); } });
@Override public Completable afterPostRunAsync(boolean isGroupFaulted) { this.virtualMachineExtensions.clear(); if (isGroupFaulted) { return Completable.complete(); } else { return this.refreshAsync().toCompletable(); } }
private Single<List<String>> inTransaction(Exception e) throws Exception { return client.rxGetConnection().flatMap(conn -> { return rxInsertExtraFolks(conn) .andThen(uniqueNames(conn)) .<List<String>>collect(ArrayList::new, List::add).toSingle() .compose(upstream -> e == null ? upstream : upstream.flatMap(names -> Single.error(e))) .compose(SQLClientHelper.txSingleTransformer(conn)) .flatMap(names -> rxAssertAutoCommit(conn).andThen(Single.just(names))) .doAfterTerminate(conn::close); }); } }
@Test public void testInterrupt() throws InterruptedException { final int count = 1000; CountDownLatch latch = new CountDownLatch(count); for (int i = 0; i < count; i++) { Completable.complete() .subscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) // The problem does not occur if you comment out this line .andThen(Completable.fromAction(() -> { try { Thread.sleep(3000); } catch (InterruptedException e) { System.out.println("Interrupted!"); // This is output periodically } })) .subscribe(() -> latch.countDown()); } latch.await(); //testInterrupt(); } }
@Override public void deleteById(String id, String eTagValue) { deleteByIdAsync(id, eTagValue).await(); } }