use of io.rx_cache2.ConfigProvider in project RxCache by VictorAlbertos.
the class ProxyTranslator method loadConfigProviderMethod.
private ConfigProvider loadConfigProviderMethod(Method method) {
ConfigProvider result;
synchronized (configProviderMethodCache) {
result = configProviderMethodCache.get(method);
if (result == null) {
result = new ConfigProvider(getProviderKey(method), null, getLifeTimeCache(method), requiredDetailResponse(method), getExpirable(method), isEncrypted(method), null, null, null, null);
configProviderMethodCache.put(method, result);
}
}
return result;
}
use of io.rx_cache2.ConfigProvider in project RxCache by VictorAlbertos.
the class ProxyTranslator method processMethod.
ConfigProvider processMethod(Method method, Object[] objectsMethod) {
ConfigProvider prev = loadConfigProviderMethod(method);
ConfigProvider configProvider = new ConfigProvider(prev.getProviderKey(), null, prev.getLifeTimeMillis(), prev.requiredDetailedResponse(), prev.isExpirable(), prev.isEncrypted(), getDynamicKey(method, objectsMethod), getDynamicKeyGroup(method, objectsMethod), getLoaderObservable(method, objectsMethod), evictProvider(method, objectsMethod));
return configProvider;
}
use of io.rx_cache2.ConfigProvider in project RxCache by VictorAlbertos.
the class ProcessorProvidersBehaviour method getDataFromLoader.
private Observable<Reply> getDataFromLoader(final io.rx_cache2.ConfigProvider configProvider, final Record record) {
return configProvider.getLoaderObservable().map(new Function<Object, Reply>() {
@Override
public Reply apply(Object data) throws Exception {
boolean useExpiredData = configProvider.useExpiredDataIfNotLoaderAvailable() != null ? configProvider.useExpiredDataIfNotLoaderAvailable() : useExpiredDataIfLoaderNotAvailable;
if (data == null && useExpiredData && record != null) {
return new Reply(record.getData(), record.getSource(), configProvider.isEncrypted());
}
clearKeyIfNeeded(configProvider);
if (data == null) {
throw new io.rx_cache2.RxCacheException(io.rx_cache2.internal.Locale.NOT_DATA_RETURN_WHEN_CALLING_OBSERVABLE_LOADER + " " + configProvider.getProviderKey());
}
twoLayersCache.save(configProvider.getProviderKey(), configProvider.getDynamicKey(), configProvider.getDynamicKeyGroup(), data, configProvider.getLifeTimeMillis(), configProvider.isExpirable(), configProvider.isEncrypted());
return new Reply(data, Source.CLOUD, configProvider.isEncrypted());
}
}).onErrorReturn(new Function<Object, Object>() {
@Override
public Object apply(Object o) throws Exception {
clearKeyIfNeeded(configProvider);
boolean useExpiredData = configProvider.useExpiredDataIfNotLoaderAvailable() != null ? configProvider.useExpiredDataIfNotLoaderAvailable() : useExpiredDataIfLoaderNotAvailable;
if (useExpiredData && record != null) {
return new Reply(record.getData(), record.getSource(), configProvider.isEncrypted());
}
throw new io.rx_cache2.RxCacheException(io.rx_cache2.internal.Locale.NOT_DATA_RETURN_WHEN_CALLING_OBSERVABLE_LOADER + " " + configProvider.getProviderKey(), (Throwable) o);
}
});
}
use of io.rx_cache2.ConfigProvider in project RxCache by VictorAlbertos.
the class ProcessorProvidersTest method getSubscriberCompleted.
private TestObserver getSubscriberCompleted(boolean hasCache, final boolean evictCache, boolean detailResponse, Loader loader, boolean useExpiredDataIfLoaderNotAvailable) {
Observable observable;
switch(loader) {
case VALID:
observable = Observable.just(new Mock("message"));
break;
case NULL:
observable = Observable.error(new RuntimeException("No data"));
break;
default:
observable = Observable.create(new ObservableOnSubscribe<Object>() {
@Override
public void subscribe(ObservableEmitter<Object> e) throws Exception {
throw new RuntimeException("error");
}
});
break;
}
ConfigProvider configProvider = new ConfigProvider("mockKey", null, null, detailResponse, true, false, "", "", observable, new EvictProvider(evictCache));
if (hasCache)
twoLayersCacheMock.save("mockKey", "", "", new Mock("message"), configProvider.getLifeTimeMillis(), configProvider.isExpirable(), configProvider.isEncrypted());
processorProvidersUT = new ProcessorProvidersBehaviour(twoLayersCacheMock, useExpiredDataIfLoaderNotAvailable, evictExpiredRecordsPersistence, getDeepCopy, doMigrations);
TestObserver observerMock = processorProvidersUT.getData(configProvider).test();
observerMock.awaitTerminalEvent();
return observerMock;
}
use of io.rx_cache2.ConfigProvider in project RxCache by VictorAlbertos.
the class ProxyTranslatorTest method When_Get_Page_Get_Pages.
@Test
public void When_Get_Page_Get_Pages() throws NoSuchMethodException {
Object[] dataMethodPaginate = { Observable.just(new Object[] {}), new DynamicKey(1) };
Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMocksPaginate", Observable.class, DynamicKey.class);
ConfigProvider configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodPaginate);
assertThat(configProvider.getDynamicKey(), is("1"));
}
Aggregations