Search in sources :

Example 1 with EvictProvider

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;
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ConfigProvider(io.rx_cache2.ConfigProvider) EvictProvider(io.rx_cache2.EvictProvider) Observable(io.reactivex.Observable) ObservableEmitter(io.reactivex.ObservableEmitter) TestObserver(io.reactivex.observers.TestObserver)

Example 2 with EvictProvider

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;
}
Also used : ConfigProvider(io.rx_cache2.ConfigProvider)

Example 3 with EvictProvider

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));
}
Also used : Type(java.lang.reflect.Type) EvictProvider(io.rx_cache2.EvictProvider) Test(org.junit.Test)

Example 4 with EvictProvider

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));
}
Also used : ConfigProvider(io.rx_cache2.ConfigProvider) Method(java.lang.reflect.Method) EvictProvider(io.rx_cache2.EvictProvider) Test(org.junit.Test)

Example 5 with EvictProvider

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));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) EvictProvider(io.rx_cache2.EvictProvider) TestObserver(io.reactivex.observers.TestObserver) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey)

Aggregations

EvictProvider (io.rx_cache2.EvictProvider)5 ConfigProvider (io.rx_cache2.ConfigProvider)3 Test (org.junit.Test)3 TestObserver (io.reactivex.observers.TestObserver)2 Method (java.lang.reflect.Method)2 Observable (io.reactivex.Observable)1 ObservableEmitter (io.reactivex.ObservableEmitter)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 DynamicKey (io.rx_cache2.DynamicKey)1 EvictDynamicKey (io.rx_cache2.EvictDynamicKey)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1