@Test(expected = NullPointerException.class) public void doOnErrorNull() { normal.completable.doOnError(null); }
@Test(timeout = 5000) public void doOnErrorNoError() { final AtomicReference<Throwable> error = new AtomicReference<Throwable>(); Completable c = normal.completable.doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable e) { error.set(e); } }); c.blockingAwait(); Assert.assertNull(error.get()); }
@Test(expected = NullPointerException.class) public void doOnErrorNullValue() { Completable.complete().doOnError(null); }
@Test(timeout = 5000) public void doOnErrorHasError() { final AtomicReference<Throwable> err = new AtomicReference<Throwable>(); Completable c = error.completable.doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable e) { err.set(e); } }); try { c.blockingAwait(); Assert.fail("Did not throw exception"); } catch (Throwable e) { // expected } Assert.assertTrue(err.get() instanceof TestException); }
@Test public void testOnErrorCalledOnScheduler() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Thread> thread = new AtomicReference<Thread>(); Completable.error(new Exception()) .delay(0, TimeUnit.MILLISECONDS, Schedulers.newThread()) .doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { thread.set(Thread.currentThread()); latch.countDown(); } }) .onErrorComplete() .subscribe(); latch.await(); assertNotEquals(Thread.currentThread(), thread.get()); }
@Test(timeout = 5000) public void doOnErrorThrows() { Completable c = error.completable.doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable e) { throw new IllegalStateException(); } }); try { c.blockingAwait(); } catch (CompositeException ex) { List<Throwable> a = ex.getExceptions(); Assert.assertEquals(2, a.size()); Assert.assertTrue(a.get(0) instanceof TestException); Assert.assertTrue(a.get(1) instanceof IllegalStateException); } }
e.onComplete(); }).doOnError(throwable -> ChatSDK.logError(throwable));
ChatSDK.socialLogin().loginWithTwitter(this).doOnError(error) .observeOn(AndroidSchedulers.mainThread()) .doFinally(doFinally) ChatSDK.socialLogin().loginWithFacebook(this).doOnError(error) .observeOn(AndroidSchedulers.mainThread()) .doFinally(doFinally) ChatSDK.socialLogin().loginWithGoogle(this).doOnError(error) .observeOn(AndroidSchedulers.mainThread()) .doFinally(doFinally)
wrapper.push().doOnError(throwable -> { DaoCore.deleteEntity(thread); e.onError(throwable);
public static void uploadFile(BlockBlobURL blob, File sourceFile) throws IOException { logInfo("Start uploading file %s...", sourceFile); final AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(sourceFile.toPath()); TransferManager.uploadFileToBlockBlob(fileChannel, blob, 8 * 1024 * 1024, null) .toCompletable() .doOnComplete(() -> logInfo("File %s is uploaded.", sourceFile.toPath())) .doOnError(error -> logError("Failed to upload file %s with error %s.", sourceFile.toPath(), error.getMessage())) .blockingAwait(); }
public void makePaymentButtonClicked(View view) { if (!checkChannelAvailable()) { return; } Completable.defer(() -> bdsChannel.makePayment(BigInteger.ONE, receiverAddress, receiverAddress, receiverAddress) .toCompletable()) .doOnSubscribe(disposable -> runOnUiThread( () -> Toast.makeText(this, "Making payment", Toast.LENGTH_SHORT) .show())) .observeOn(AndroidSchedulers.mainThread()) .doOnError(throwable -> Toast.makeText(this, "Payment Failed!", Toast.LENGTH_SHORT) .show()) .doOnComplete(() -> Toast.makeText(this, "Payment Success", Toast.LENGTH_SHORT) .show()) .subscribeOn(Schedulers.io()) .subscribe(); }
handleError(completable, throwable); }).doOnError(t -> { if (t instanceof WebSocketHandshakeException) { LOG.warn("Problem with connection: {} - {}", t.getClass(), t.getMessage());
public static void downloadBlob(BlockBlobURL blockBlobURL, File downloadToFile) { logInfo("Start downloading file %s to %s...", blockBlobURL.toURL(), downloadToFile); FileUtils.deleteQuietly(downloadToFile); blockBlobURL.download(new BlobRange().withOffset(0).withCount(4 * 1024 * 1024L), null, false, null) .flatMapCompletable( response -> { final AsynchronousFileChannel channel = AsynchronousFileChannel .open(Paths.get(downloadToFile.getAbsolutePath()), StandardOpenOption.CREATE, StandardOpenOption.WRITE); return FlowableUtil.writeFile(response.body(null), channel); }) .doOnComplete(() -> logInfo("File is downloaded to %s.", downloadToFile)) .doOnError(error -> logError("Failed to download file from blob %s with error %s.", blockBlobURL.toURL(), error.getMessage())) .blockingAwait(); }
/** * Execute the index sync job. */ public Completable executeJob(Message<Object> message) { return Completable.fromAction(() -> { log.info("Processing index sync job."); SyncMetric.reset(); }) .andThen(purgeOldIndices()) .andThen(syncIndices()) .andThen(provider.refreshIndex()).doOnComplete(() -> { log.info("Sync completed"); vertx.eventBus().publish(Events.INDEX_SYNC_EVENT, new JsonObject().put("status", "completed")); }).doOnError(error -> { log.error("Sync failed", error); vertx.eventBus().publish(Events.INDEX_SYNC_EVENT, new JsonObject().put("status", "failed")); }); }
public static void deleteBlob(BlockBlobURL blockBlobURL) { logInfo("Start deleting file %s...", blockBlobURL.toURL()); blockBlobURL.delete(null, null, null) .toCompletable() .doOnComplete(() -> logInfo("Blob %s is deleted.", blockBlobURL.toURL())) .doOnError(error -> logError("Failed to delete blob %s with error %s.", blockBlobURL.toURL(), error.getMessage())) .blockingAwait(); }
/** * Modify the given completable and add the configured timeout, error logging and retry handler. * * @param msg * Message to be shown on timeout * @param ignoreError * Whether to ignore any encountered errors * @return */ private CompletableTransformer withTimeoutAndLog(String msg, boolean ignoreError) { Long timeout = getOptions().getTimeout(); return c -> { Completable t = c // Retry the operation if an conflict error was returned .retry((nTry, error) -> nTry < MAX_RETRY_ON_ERROR && isConflictError(error)) .timeout(timeout, TimeUnit.MILLISECONDS) .doOnError(error -> { if (error instanceof TimeoutException) { log.error("The operation failed since the timeout of {" + timeout + "} ms has been reached. Action: " + msg); } else { log.error("Request failed {" + msg + "}", error.toString()); log.error(error); } }); return ignoreError ? t.onErrorComplete() : t; }; }
@Override public Completable store(Flowable<Buffer> stream, String uuid) { return Completable.defer(() -> { FileSystem fileSystem = FileSystem.newInstance(Mesh.vertx().fileSystem()); String path = getFilePath(uuid); log.debug("Saving data for field to path {" + path + "}"); MeshUploadOptions uploadOptions = Mesh.mesh().getOptions().getUploadOptions(); File uploadFolder = new File(uploadOptions.getDirectory(), getSegmentedPath(uuid)); if (!uploadFolder.exists()) { if (!uploadFolder.mkdirs()) { log.error("Failed to create target folder {" + uploadFolder.getAbsolutePath() + "}"); throw error(BAD_REQUEST, "node_error_upload_failed"); } if (log.isDebugEnabled()) { log.debug("Created folder {" + uploadFolder.getAbsolutePath() + "}"); } } File targetFile = new File(uploadFolder, uuid + ".bin"); return fileSystem.rxOpen(targetFile.getAbsolutePath(), new OpenOptions()).flatMapCompletable(file -> stream .map(io.vertx.reactivex.core.buffer.Buffer::new) .doOnNext(file::write) .ignoreElements() .andThen(file.rxFlush()) .andThen(file.rxClose()) .doOnError(err -> file.close()) ); }); }
public Session(Process process, Disposable processDisposable) { this.process = process; this.destroy = Completable .create(e -> { processDisposable.dispose(); e.onComplete(); }) .subscribeOn(Schedulers.io()) .doOnComplete(() -> { if (RXSDebug.isDebug()) Timber.tag(TAG).v("destroy():doOnComplete");}) .doOnError(t -> { if (RXSDebug.isDebug()) Timber.tag(TAG).v(t, "destroy():doOnError");}) .cache(); this.waitFor = Single .create((SingleOnSubscribe<Integer>) e -> { if (RXSDebug.isDebug()) Timber.tag(TAG).d("Waiting for %s to exit.", process); int exitCode = process.waitFor(); if (RXSDebug.isDebug()) Timber.tag(TAG).d("Exitcode: %d, Process: %s", exitCode, process); e.onSuccess(exitCode); }) .subscribeOn(Schedulers.io()) .doOnSuccess(s -> { if (RXSDebug.isDebug()) Timber.tag(TAG).v("waitFor():doOnSuccess %s", s);}) .doOnError(t -> { if (RXSDebug.isDebug()) Timber.tag(TAG).v(t, "waitFor():doOnError");}) .cache(); }
.doOnError(t -> { if (RXSDebug.isDebug()) Timber.tag(TAG).v(t, "cancel():doOnError");}) .cache(); this.waitFor = processSession.waitFor()
public Session(RxShell.Session session, CmdProcessor cmdProcessor) { this.session = session; this.cmdProcessor = cmdProcessor; this.waitFor = session.waitFor().cache(); this.cancel = session.cancel() .doOnComplete(() -> { if (RXSDebug.isDebug()) Timber.tag(TAG).v("cancel():doOnComplete");}) .doOnError(t -> { if (RXSDebug.isDebug()) Timber.tag(TAG).v(t, "cancel():doOnError");}) .cache(); this.close = cmdProcessor.isIdle() .filter(i -> i) .first(true) .flatMap(i -> session.close()) .doOnSuccess(s -> { if (RXSDebug.isDebug()) Timber.tag(TAG).v("close():doOnSuccess %s", s);}) .doOnError(t -> { if (RXSDebug.isDebug()) Timber.tag(TAG).v(t, "close():doOnError");}) .cache(); }