use of io.rx_cache2.EvictProvider 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.EvictProvider 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.EvictProvider in project RxCache by VictorAlbertos.
the class ProvidersRxCacheTest method _13_When_Retrieve_Cached_Data_After_Modified_Object_Then_Object_Preserves_Initial_State.
@Test
public void _13_When_Retrieve_Cached_Data_After_Modified_Object_Then_Object_Preserves_Initial_State() {
initProviders(false);
TestObserver<io.rx_cache2.internal.Mock> subscriber;
subscriber = new TestObserver<>();
providersRxCache.getLoggedMock(Observable.<io.rx_cache2.internal.Mock>just(createMocks(SIZE).get(0)), new EvictProvider(true)).subscribe(subscriber);
subscriber.awaitTerminalEvent();
io.rx_cache2.internal.Mock mock = subscriber.values().get(0);
Type type = new TypeToken<io.rx_cache2.internal.Mock>() {
}.getType();
io.rx_cache2.internal.Mock mockOriginal = (io.rx_cache2.internal.Mock) deepCopy(mock, type);
assertThat(compare(mock, mockOriginal, type), is(true));
mock.setMessage("modified");
assertThat(compare(mock, mockOriginal, type), is(false));
subscriber = new TestObserver<>();
providersRxCache.getLoggedMock(ProviderHelper.<io.rx_cache2.internal.Mock>withoutLoader(), new EvictProvider(false)).subscribe(subscriber);
subscriber.awaitTerminalEvent();
assertThat(subscriber.errors().size(), is(0));
assertThat(subscriber.values().size(), is(1));
mock = subscriber.values().get(0);
assertThat(compare(mock, mockOriginal, type), is(true));
}
use of io.rx_cache2.EvictProvider in project RxCache by VictorAlbertos.
the class ProxyTranslatorTest method When_Evict_Cache_Evict.
@Test
public void When_Evict_Cache_Evict() throws NoSuchMethodException {
Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMocksEvictProvider", Observable.class, EvictProvider.class);
Object[] dataMethodEvict = { Observable.just(new Object[] {}), new EvictProvider(true) };
ConfigProvider configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodEvict);
assertThat(configProvider.evictProvider().evict(), is(true));
Object[] dataMethodNoEvict = { Observable.just(new Object[] {}), new EvictProvider(false) };
configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodNoEvict);
assertThat(configProvider.evictProvider().evict(), is(false));
}
use of io.rx_cache2.EvictProvider in project RxCache by VictorAlbertos.
the class ProvidersDynamicsKeysRxCacheTest method paginationEvictAll.
private void paginationEvictAll() {
TestObserver<List<io.rx_cache2.internal.Mock>> observer = new TestObserver<>();
EvictProvider evictProviderFalse = new EvictProvider(false);
EvictProvider evictProviderTrue = new EvictProvider(true);
providersRxCache.getMocksPaginateEvictProvider(Observable.just(createMocks(SIZE)), new DynamicKey(1), evictProviderFalse).subscribe(observer);
observer.awaitTerminalEvent();
assertThat(observer.errors().size(), is(0));
assertThat(observer.values().size(), is(1));
observer = providersRxCache.getMocksPaginateEvictProvider(Observable.just(createMocks(SIZE)), new DynamicKey(2), evictProviderFalse).test();
observer.awaitTerminalEvent();
assertThat(observer.errors().size(), is(0));
assertThat(observer.values().size(), is(1));
Observable<List<io.rx_cache2.internal.Mock>> oMocks = Observable.<List<io.rx_cache2.internal.Mock>>just(new ArrayList<io.rx_cache2.internal.Mock>());
observer = new TestObserver<>();
providersRxCache.getMocksPaginateEvictProvider(oMocks, new DynamicKey(1), evictProviderTrue).subscribe(observer);
observer.awaitTerminalEvent();
observer = providersRxCache.getMocksPaginateEvictProvider(oMocks, new DynamicKey(1), evictProviderFalse).test();
observer.awaitTerminalEvent();
assertThat(observer.values().size(), is(1));
assertThat(observer.values().get(0).size(), is(0));
observer = providersRxCache.getMocksPaginateEvictProvider(oMocks, new DynamicKey(2), evictProviderFalse).test();
observer.awaitTerminalEvent();
assertThat(observer.values().size(), is(1));
assertThat(observer.values().get(0).size(), is(0));
}
Aggregations