@NonNull public Single<StreamInfo> getStream() { return ExtractorHelper.getStreamInfo(this.serviceId, this.url, false) .subscribeOn(Schedulers.io()) .doOnError(throwable -> error = throwable); }
@Test(expected = NullPointerException.class) public void doOnError() { error.doOnError(null); }
/** * Add issue filter to store * <p/> * This method may perform file I/O and should never be called on the * UI-thread * * @param filter */ public Single<IssueFilter> addIssueFilter(final IssueFilter filter) { return Single.fromCallable(() -> { final File cache = new File(root, "issue_filters.ser"); Collection<IssueFilter> filters = read(cache); if (filters == null) { filters = new HashSet<>(); } if (filters.add(filter)) { write(cache, filters); } return filter; }).doOnError(e -> Log.d(TAG, "Exception adding issue filter", e)); }
/** * Add issue filter from store * <p/> * This method may perform file I/O and should never be called on the * UI-thread * * @param filter */ public Single<IssueFilter> removeIssueFilter(IssueFilter filter) { return Single.fromCallable(() -> { final File cache = new File(root, "issue_filters.ser"); Collection<IssueFilter> filters = read(cache); if (filters != null && filters.remove(filter)) { write(cache, filters); } return filter; }).doOnError( e -> Log.d(TAG, "Exception removing issue filter", e)); } }
@Test public void testOnErrorCalledOnScheduler() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Thread> thread = new AtomicReference<Thread>(); Single.<String>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(); } }) .onErrorResumeNext(Single.just("")) .subscribe(); latch.await(); assertNotEquals(Thread.currentThread(), thread.get()); }
@Test public void doOnError() { final Object[] event = { null }; Single.error(new TestException()).doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable e) throws Exception { event[0] = e; } }) .test(); assertTrue(event[0].toString(), event[0] instanceof TestException); }
@Test public void onErrorSuccess() { final int[] call = { 0 }; Single.just(1) .doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable v) throws Exception { call[0]++; } }) .test() .assertResult(1); assertEquals(0, call[0]); }
public static <U> SingleTransformer<U, U> bindToLifecycle(Context context, CharSequence message) { return upstream -> { final MaterialDialog progressDialog = new MaterialDialog.Builder(context) .content(message) .progress(true, 0) .build(); return upstream .doOnSubscribe(disposable -> progressDialog.show()) .doOnSuccess(u -> progressDialog.dismiss()) .doOnError(throwable -> progressDialog.dismiss()); }; } }
@Test public void onErrorCrashes() { TestObserver<Object> to = Single.error(new TestException("Outer")) .doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable v) throws Exception { throw new TestException("Inner"); } }) .test() .assertFailure(CompositeException.class); List<Throwable> errors = TestHelper.compositeList(to.errors().get(0)); TestHelper.assertError(errors, 0, TestException.class, "Outer"); TestHelper.assertError(errors, 1, TestException.class, "Inner"); }
private void reset() { hasCachedResults = false; this.deviceServicesObservable = getListOfServicesFromGatt() .map(wrapIntoRxBleDeviceServices()) .switchIfEmpty(getTimeoutConfiguration().flatMap(scheduleActualDiscoveryWithTimeout())) .doOnSuccess(Functions.actionConsumer(new Action() { @Override public void run() throws Exception { hasCachedResults = true; } })) .doOnError(Functions.actionConsumer(new Action() { @Override public void run() { reset(); } })) .cache(); }
protected Single<Thread> createAndOpenThread (String name, List<User> users) { return ChatSDK.thread().createThread(name, users) .observeOn(AndroidSchedulers.mainThread()) .doOnSuccess(thread -> { if (thread != null) { ChatSDK.ui().startChatActivityForID(getApplicationContext(), thread.getEntityID()); } }).doOnError(throwable -> ToastHelper.show(getApplicationContext(), R.string.create_thread_with_users_fail_toast)); }
void refresh() throws IOException { Disposable disposable = // Observable.just(ytApi.playlistItems() .list(YOUTUBE_PLAYLIST_PART) .setPlaylistId(YOUTUBE_PLAYLIST_ID) .setPageToken(null) .setFields(YOUTUBE_PLAYLIST_FIELDS) .setMaxResults(YOUTUBE_PLAYLIST_MAX_RESULTS) .setKey(API_KEY) // ) .map(AbstractGoogleClientRequest::execute) .map(PlaylistItemListResponse::getItems) .flatMap(playlistItems -> Observable.fromIterable(playlistItems) .map(item -> item.getSnippet().getResourceId().getVideoId())) .toList() .map(ids -> ytApi.videos().list(YOUTUBE_VIDEOS_PART).setFields(YOUTUBE_VIDEOS_FIELDS) // .setKey(API_KEY).setId(TextUtils.join(",", ids)).execute()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnError( throwable -> Log.e(TAG, "accept() called with: throwable = [" + throwable + "]")) .doOnSuccess( response -> Log.d(TAG, "accept() called with: response = [" + response + "]")) .onErrorReturnItem(new VideoListResponse()) // Bad work around .doOnSuccess(liveData::setValue) .subscribe(); disposables.add(disposable); } }
@Override public Single<Integer> getVersion() throws ElasticsearchException { return httpClient .get(URL_ROOT) .rxSend() .doOnError(throwable -> logger.error("Unable to get a connection to Elasticsearch", throwable)) .map(response -> mapper.readTree(response.bodyAsString()).path("version").path("number").asText()) .map(sVersion -> { float result = Float.valueOf(sVersion.substring(0, 3)); int version = Integer.valueOf(sVersion.substring(0, 1)); if (result < 2) { logger.warn("Please upgrade to Elasticsearch 2 or later. version={}", version); } return version; }); }
/** * @param url 提交的URL * @param paramsMap parameter map * @return 响应 */ public static Single<String> post(String url, Map<String, String> paramsMap) { String applicationXwwwformUrlEncodedString = HttpUtil.xwwwformEncode(paramsMap); return HttpUtil.post(url, applicationXwwwformUrlEncodedString, new HashMap<String, String>() {{ put("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); put("Accept", "application/json;charset=utf-8"); }}).doOnError(LOG::error); } }
@Override public Publisher<?> persistFramedEntries(Flowable<Map<String, Object>> framedEntries) { return framedEntries .flatMapIterable(BdioDocument::toGraphNodes) .reduce(new NodeAccumulator(), NodeAccumulator::addNode) .doOnSuccess(NodeAccumulator::addEdges) .doAfterSuccess(NodeAccumulator::commitTx) .doOnError(this::handleError) .toFlowable(); }
@Override public Single<Certificate> update(Certificate certificate) { // update date certificate.setUpdatedAt(new Date()); return certificateRepository.update(certificate) .flatMap(certificate1 -> { // Reload domain to take care about certificate update Event event = new Event(Type.CERTIFICATE, new Payload(certificate1.getId(), certificate1.getDomain(), Action.UPDATE)); return domainService.reload(certificate1.getDomain(), event).flatMap(domain1 -> Single.just(certificate1)); }) .doOnError(ex -> { LOGGER.error("An error occurs while trying to update a certificate", ex); throw new TechnicalManagementException("An error occurs while trying to update a certificate", ex); }); }
@Override public Single<JsonObject> getDocument(String index, String uuid) { String fullIndex = installationPrefix() + index; return client.getDocument(fullIndex, DEFAULT_TYPE, uuid).async() .map(response -> { if (log.isDebugEnabled()) { log.debug("Get object {" + uuid + "} from index {" + fullIndex + "}"); } return response; }).timeout(getOptions().getTimeout(), TimeUnit.MILLISECONDS).doOnError(error -> { log.error("Could not get object {" + uuid + "} from index {" + fullIndex + "}", error); }); }
private Observable<ModuleDescriptor> deployVerticle(final JsonObject config, final ModuleDescriptor module) { return vertx .rxDeployVerticle(module.getName(), getModuleOptions(config, module.getAlias())) .map(deployId -> new ModuleDescriptor(module) .setDeploymentId(deployId) .setState(DeploymentState.SUCCESS)) .doOnError(error -> LOGGER.error("Can't deploy {}: {}", module.toDescriptorLine(), error)) .onErrorResumeNext((err) -> Single.just(new ModuleDescriptor(module).setState(DeploymentState.FAILED))) .toObservable(); }
private Observable<ModuleDescriptor> deployVerticle(final JsonObject config, final ModuleDescriptor module) { return vertx .rxDeployVerticle(module.getName(), getModuleOptions(config, module.getAlias())) .map(deployId -> new ModuleDescriptor(module) .setDeploymentId(deployId) .setState(DeploymentState.SUCCESS)) .doOnError(error -> LOGGER.error("Can't deploy {}: {}", module.toDescriptorLine(), error)) .onErrorResumeNext((err) -> Single.just(new ModuleDescriptor(module).setState(DeploymentState.FAILED))) .toObservable(); }
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(); }