private <T> Single<T> getData(EVCacheClient client, String canonicalKey, Transcoder<T> tc, boolean throwException, boolean hasZF, Scheduler scheduler) { if (client == null) return Single.error(new IllegalArgumentException("Client cannot be null")); if(hashKey.get()) { return Single.error(new IllegalArgumentException("Not supported")); } else { if(tc == null && _transcoder != null) tc = (Transcoder<T>)_transcoder; return client.get(canonicalKey, tc, throwException, hasZF, scheduler).onErrorReturn(ex -> { if (ex instanceof EVCacheReadQueueException) { if (log.isDebugEnabled() && shouldLog()) log.debug("EVCacheReadQueueException while getting data for APP " + _appName + ", key : " + canonicalKey + "; hasZF : " + hasZF, ex); if (!throwException || hasZF) return null; throw sneakyThrow(ex); } else if (ex instanceof EVCacheException) { if (log.isDebugEnabled() && shouldLog()) log.debug("EVCacheException while getting data for APP " + _appName + ", key : " + canonicalKey + "; hasZF : " + hasZF, ex); if (!throwException || hasZF) return null; throw sneakyThrow(ex); } else { if (log.isDebugEnabled() && shouldLog()) log.debug("Exception while getting data for APP " + _appName + ", key : " + canonicalKey, ex); if (!throwException || hasZF) return null; throw sneakyThrow(ex); } }); } }
return Single.error(e);
public <T> Single<T> getAndTouch(String key, int timeToLive, Transcoder<T> tc, Scheduler scheduler) { if (null == key) return Single.error(new IllegalArgumentException("Key cannot be null")); if(hashKey.get()) { return Single.error(new IllegalArgumentException("Not supported")); if (client == null) { increment("NULL_CLIENT"); return Single.error(new EVCacheException("Could not find a client to get and touch the data for APP " + _appName)); if (shouldThrottle(event)) { increment("THROTTLED"); return Single.error(new EVCacheException("Request Throttled for app " + _appName + " & key " + key));
public <T> Single<T> get(String key, Transcoder<T> tc, Scheduler scheduler) { if (null == key) return Single.error(new IllegalArgumentException("Key cannot be null")); if (client == null) { increment("NULL_CLIENT"); return Single.error(new EVCacheException("Could not find a client to get the data APP " + _appName)); if (shouldThrottle(event)) { increment("THROTTLED"); return Single.error(new EVCacheException("Request Throttled for app " + _appName + " & key " + key));
public <T> Single<T> get(String key, Transcoder<T> tc, boolean _throwException, boolean hasZF, Scheduler scheduler) { try { if (!validateNode(key, _throwException)) { if(ignoreInactiveNodes.get()) { EVCacheMetricsFactory.increment(appName, null, serverGroup.getName(), appName + "-IGNORE_INACTIVE_NODES"); return pool.getEVCacheClientForReadExclude(serverGroup).get(key, tc, _throwException, hasZF, enableChunking.get(), scheduler); } else { return Single.just(null); } } return get(key, tc, _throwException, hasZF, enableChunking.get(), scheduler); } catch (Throwable e) { return Single.error(e); } }
return Single.error(e);
@Test public void s1s2Error() { toV2Single(rx.Single.error(new RuntimeException("Forced failure"))).test() .assertFailureAndMessage(RuntimeException.class, "Forced failure"); }
@Test public void s1m2Error() { toV2Maybe(rx.Single.error(new RuntimeException("Forced failure"))).test() .assertFailureAndMessage(RuntimeException.class, "Forced failure"); }
@Override public Single<Void> delete(Long id) { // This service is an append-only service, so delete is not allowed. return Single.error(new RuntimeException("Delete is not allowed")); }
public static <T> Func1<Throwable, Single<T>> ifStatusCodeException(Function<HttpStatusCodeException, T> func) { return throwable -> { if (throwable instanceof HttpStatusCodeException) { return Single.just(func.apply((HttpStatusCodeException) throwable)); } else { return Single.error(throwable); } }; } }
private Single<DatabaseAccount> getDatabaseAccountAsync(URL serviceEndpoint) { try { return this.owner.getDatabaseAccountFromEndpoint(serviceEndpoint.toURI()) .doOnNext(i -> logger.debug("account retrieved: {}", i)).toSingle(); } catch (URISyntaxException e) { return Single.error(e); } }
@Override public Single<Boolean> delete(T obj){ try { genericDao.delete(obj); return Single.just(true); } catch (DataAccessException de) { return Single.error(de); } }
@Override public Single<T> edit(T obj){ try { genericDao.modify(obj); return Single.just(obj); } catch (DataAccessException de) { return Single.error(de); } }
@Override public Single<T> add(T obj){ try { genericDao.add(obj); return Single.just(obj); } catch (DataAccessException de) { return Single.error(de); } }
@Override public Single<T> getById(String id){ try { return Single.just(genericDao.getById(id)).map(o->{ if(o == null) throw Exceptions.propagate(new ResourceNotFoundException(type.getSimpleName() + " : " + id)); return o; }); } catch (DataAccessException de) { return Single.error(de); } }
@Test public void getTagsFails() { List<Cat> cats = TestDataFactory.makeCats(10); stubDataManagerGetCats(Single.just(cats)); stubDataManagerGetCats(Single.<List<Cat>>error(new RuntimeException())); mSearchContentPresenter.searchCats(cats); verify(mMockSearchContentMvpView).showCatsError(); verify(mMockSearchContentMvpView, never()).showCats(anyListOf(Cat.class)); }
@Test public void getTagsFails() { List<Cat> cats = TestDataFactory.makeCats(10); stubDataManagerGetCats(Single.just(cats)); stubDataManagerGetCats(Single.<List<Cat>>error(new RuntimeException())); mContentPresenter.getCats(cats); verify(mMockContentMvpView).showCatsError(); verify(mMockContentMvpView, never()).showCats(anyListOf(Cat.class)); }
@Override public Single<T> call(Single<T> upstream) { return sqlConnection.rxSetAutoCommit(false).toCompletable() .andThen(upstream) .flatMap(item -> sqlConnection.rxCommit().toCompletable().andThen(Single.just(item))) .onErrorResumeNext(throwable -> { return sqlConnection.rxRollback().toCompletable().onErrorComplete() .andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete()) .andThen(Single.error(throwable)); }).flatMap(item -> sqlConnection.rxSetAutoCommit(true).toCompletable().andThen(Single.just(item))); } }
@Override public Single<T> call(Single<T> upstream) { return sqlConnection.rxSetAutoCommit(false).toCompletable() .andThen(upstream) .flatMap(item -> sqlConnection.rxCommit().toCompletable().andThen(Single.just(item))) .onErrorResumeNext(throwable -> { return sqlConnection.rxRollback().toCompletable().onErrorComplete() .andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete()) .andThen(Single.error(throwable)); }).flatMap(item -> sqlConnection.rxSetAutoCommit(true).toCompletable().andThen(Single.just(item))); } }
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); }); } }