@Override public Completable apply(Completable f) throws Exception { return f.doFinally(CompletableDoFinallyTest.this); } });
@Test(expected = NullPointerException.class) public void nullAction() { Completable.complete().doFinally(null); }
mIsLoading.set(true); }).doFinally(new Action() { @Override public void run() throws Exception { mIsLoading.set(false);
@Test public void disposed() { TestHelper.checkDisposed(PublishSubject.create().ignoreElements().doFinally(this)); } }
@Test public void normalEmpty() { Completable.complete() .doFinally(this) .test() .assertResult(); assertEquals(1, calls); }
@Test public void normalError() { Completable.error(new TestException()) .doFinally(this) .test() .assertFailure(TestException.class); assertEquals(1, calls); }
@Test public void actionThrows() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { Completable.complete() .doFinally(new Action() { @Override public void run() throws Exception { throw new TestException(); } }) .test() .assertResult() .cancel(); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { RxJavaPlugins.reset(); } }
protected void authenticateWithCachedToken () { showProgressDialog(getString(R.string.authenticating)); signInButton.setEnabled(false); ChatSDK.auth().authenticateWithCachedToken() .observeOn(AndroidSchedulers.mainThread()) .doFinally(() -> { signInButton.setEnabled(true); dismissProgressDialog(); }) .subscribe(() -> { ChatSDK.ui().startMainActivity(SplashScreenActivity.this); }, throwable -> { // startAuthenticationActivity(); }); }
@Override protected void onResume() { super.onResume(); initListeners(); // If the logged out flag isn't set... if (getIntent() == null || getIntent().getExtras() == null || getIntent().getExtras().get(InterfaceManager.ATTEMPT_CACHED_LOGIN) == null || (boolean) getIntent().getExtras().get(InterfaceManager.ATTEMPT_CACHED_LOGIN)) { showProgressDialog(getString(R.string.authenticating)); ChatSDK.auth().authenticateWithCachedToken() .observeOn(AndroidSchedulers.mainThread()) .doFinally(this::dismissProgressDialog) .subscribe(this::afterLogin, throwable -> { // ChatSDK.logError(throwable); dismissProgressDialog(); }); } }
public void authenticateWithDetails (AccountDetails details) { if(authenticating) { return; } authenticating = true; showProgressDialog(getString(R.string.connecting)); ChatSDK.auth().authenticate(details) .observeOn(AndroidSchedulers.mainThread()) .doFinally(() -> { authenticating = false; dismissProgressDialog(); }) .subscribe(this::afterLogin, e -> { toastErrorMessage(e, false); ChatSDK.logError(e); }); }
ChatSDK.socialLogin().loginWithTwitter(this).doOnError(error) .observeOn(AndroidSchedulers.mainThread()) .doFinally(doFinally) .subscribe(completion, error); ChatSDK.socialLogin().loginWithFacebook(this).doOnError(error) .observeOn(AndroidSchedulers.mainThread()) .doFinally(doFinally) .subscribe(completion, error); ChatSDK.socialLogin().loginWithGoogle(this).doOnError(error) .observeOn(AndroidSchedulers.mainThread()) .doFinally(doFinally) .subscribe(completion, error);
private Completable update(SQLConnection connection, String id, Article article) { String sql = "UPDATE articles SET title = ?, url = ? WHERE id = ?"; JsonArray params = new JsonArray().add(article.getTitle()) .add(article.getUrl()) .add(Integer.valueOf(id)); return connection.rxUpdateWithParams(sql, params) .flatMapCompletable(ur -> ur.getUpdated() == 0 ? Completable .error(new NoSuchElementException("No article with id " + id)) : Completable.complete() ) .doFinally(connection::close); }
private Completable buildComponentInternal() throws Throwable { if (getParentWeaverComponent() == null) return (Completable) getJoinPoint().proceed(); if (getParentWeaverComponent().getComponentInfo().subscribeOnScheduler() == null) { getParentWeaverComponent().getComponentInfo().setSubscribeOnScheduler(getSchedulerName()); } return ((Completable) getJoinPoint().proceed()) .doFinally(() -> { if (getParentWeaverComponent().getComponentInfo().subscribeOnThread() == null) getParentWeaverComponent().getComponentInfo().setSubscribeOnThread(Thread.currentThread().getName()); }); } }
protected Completable rxAssertAutoCommit(SQLConnection conn) { String testName = UUID.randomUUID().toString(); return conn.rxExecute(String.format(INSERT_FOLK_SQL, testName)) .andThen(client.rxGetConnection().flatMapCompletable(other -> { return uniqueNames(other).contains(testName) .flatMapCompletable(contains -> { if (contains) { return Completable.complete(); } return Completable.error(new AssertionError("Connection should be back in autocommit mode")); }) .doFinally(other::close); })); }
@Override public void execute(UnitRequest msg, Handler<UnitResponse> handler) { XianTransaction transaction = BaseLocalTransaction.getExistedLocalTrans(MsgIdHolder.get()); if (transaction == null) { handler.handle(UnitResponse.createError(DaoGroup.CODE_UNKNOWN_ERROR, MsgIdHolder.get(), String.format("Transaction with id=%s does not exist.", MsgIdHolder.get()))); } else { transaction .rollback() //close the transaction asynchronously is ok and better .doFinally(() -> transaction.close().subscribe()) .subscribe(() -> handler.handle(UnitResponse.createSuccess("Rollback transaction OK! transId= " + MsgIdHolder.get()))); } }
@Override public void execute(UnitRequest msg, Handler<UnitResponse> handler) { XianTransaction transaction = BaseLocalTransaction.getExistedLocalTrans(MsgIdHolder.get()); if (transaction == null) { handler.handle(UnitResponse.createError(DaoGroup.CODE_UNKNOWN_ERROR, MsgIdHolder.get(), String.format("Transaction with id=%s does not exist.", MsgIdHolder.get()))); } else { transaction .rollback() //close the transaction asynchronously is ok and better .doFinally(() -> transaction.close().subscribe()) .subscribe(() -> handler.handle(UnitResponse.createSuccess("Rollback transaction OK! transId= " + MsgIdHolder.get()))); } }
@Override public void execute(UnitRequest msg, Handler<UnitResponse> handler) { XianTransaction transaction = BaseLocalTransaction.getExistedLocalTrans(MsgIdHolder.get()); if (transaction == null) { handler.handle(UnitResponse.createError(DaoGroup.CODE_TRANSACTION_ALREADY_ENDS, MsgIdHolder.get(), String.format("Transaction with id=%s does not exist.", MsgIdHolder.get()))); } else { transaction .commit() //close the transaction asynchronously is ok and better .doFinally(() -> transaction.close().subscribe()) .subscribe(() -> handler.handle(UnitResponse.createSuccess("Commit Transaction OK! transId= " + MsgIdHolder.get()))); } }
@Override public void execute(UnitRequest msg, Handler<UnitResponse> handler) { XianTransaction transaction = BaseLocalTransaction.getExistedLocalTrans(MsgIdHolder.get()); if (transaction == null) { handler.handle(UnitResponse.createError(DaoGroup.CODE_TRANSACTION_ALREADY_ENDS, MsgIdHolder.get(), String.format("Transaction with id=%s does not exist.", MsgIdHolder.get()))); } else { transaction .commit() //close the transaction asynchronously is ok and better .doFinally(() -> transaction.close().subscribe()) .subscribe(() -> handler.handle(UnitResponse.createSuccess("Commit Transaction OK! transId= " + MsgIdHolder.get()))); } }
@Override public void setUp() throws Exception { super.setUp(); client = new JDBCClient(io.vertx.ext.jdbc.JDBCClient.createNonShared(vertx, config)); client.rxGetConnection().flatMapCompletable(conn -> { Completable setup = conn.rxExecute("drop table folks if exists") .andThen(conn.rxExecute("create table folks (firstname varchar(255) not null)")); for (String name : NAMES) { setup = setup.andThen(conn.rxExecute(String.format(INSERT_FOLK_SQL, name))); } return setup.doFinally(conn::close); }).blockingAwait(); }
private Completable inTransaction(Exception e) throws Exception { return client.rxGetConnection().flatMapCompletable(conn -> { return rxInsertExtraFolks(conn) .andThen(uniqueNames(conn)) .<List<String>>collect(ArrayList::new, List::add) .flatMapCompletable(names -> rxAssertEquals(namesWithExtraFolks(), names)) .compose(upstream -> e == null ? upstream : upstream.andThen(Completable.error(e))) .compose(SQLClientHelper.txCompletableTransformer(conn)) .andThen(rxAssertAutoCommit(conn)) .doFinally(conn::close); }); } }