Search in sources :

Example 6 with DynamicKey

use of io.rx_cache2.DynamicKey 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)

Example 7 with DynamicKey

use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.

the class ProvidersDynamicsKeysRxCacheTest method Pagination_With_Evict_Cache_By_Page.

@Test
public void Pagination_With_Evict_Cache_By_Page() {
    TestObserver<Reply<List<io.rx_cache2.internal.Mock>>> observer;
    observer = providersRxCache.getMocksDynamicKeyEvictPage(Observable.just(createMocks(SIZE)), new DynamicKey(1), new EvictDynamicKey(true)).test();
    observer.awaitTerminalEvent();
    observer = providersRxCache.getMocksDynamicKeyEvictPage(Observable.just(createMocks(SIZE)), new DynamicKey(2), new EvictDynamicKey(true)).test();
    observer.awaitTerminalEvent();
    observer = providersRxCache.getMocksDynamicKeyEvictPage(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader(), new DynamicKey(1), new EvictDynamicKey(true)).test();
    observer.awaitTerminalEvent();
    assertThat(observer.errors().size(), is(1));
    assertThat(observer.values().size(), is(0));
    observer = providersRxCache.getMocksDynamicKeyEvictPage(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader(), new DynamicKey(2), new EvictDynamicKey(false)).test();
    observer.awaitTerminalEvent();
    assertThat(observer.errors().size(), is(0));
    assertThat(observer.values().size(), is(1));
}
Also used : EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Reply(io.rx_cache2.Reply) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey) Test(org.junit.Test)

Example 8 with DynamicKey

use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.

the class SaveRecord method save.

void save(final String providerKey, final String dynamicKey, final String dynamicKeyGroup, final Object data, final Long lifeTime, final boolean isExpirable, final boolean isEncrypted) {
    String composedKey = composeKey(providerKey, dynamicKey, dynamicKeyGroup);
    Record record = new Record(data, isExpirable, lifeTime);
    memory.put(composedKey, record);
    if (persistence.storedMB() >= maxMgPersistenceCache) {
        System.out.println(Locale.RECORD_CAN_NOT_BE_PERSISTED_BECAUSE_WOULD_EXCEED_THRESHOLD_LIMIT);
    } else {
        persistence.saveRecord(composedKey, record, isEncrypted, encryptKey);
    }
    evictExpirableRecordsPersistence.startTaskIfNeeded(isEncrypted);
}
Also used : Record(io.rx_cache2.internal.Record)

Example 9 with DynamicKey

use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.

the class ProxyTranslatorTest method When_Multiple_Dynamic_Keys_Throw_Exception.

@Test(expected = IllegalArgumentException.class)
public void When_Multiple_Dynamic_Keys_Throw_Exception() throws NoSuchMethodException {
    Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMockMultipleDynamicKeys", Observable.class, DynamicKey.class, DynamicKey.class);
    Object[] data = { Observable.just(new Object[] {}), new DynamicKey(1), new DynamicKey(1) };
    proxyTranslatorUT.processMethod(mockMethod, data);
}
Also used : Method(java.lang.reflect.Method) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey) Test(org.junit.Test)

Aggregations

DynamicKey (io.rx_cache2.DynamicKey)8 EvictDynamicKey (io.rx_cache2.EvictDynamicKey)7 Test (org.junit.Test)6 Method (java.lang.reflect.Method)4 ConfigProvider (io.rx_cache2.ConfigProvider)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TestObserver (io.reactivex.observers.TestObserver)1 DynamicKeyGroup (io.rx_cache2.DynamicKeyGroup)1 EvictProvider (io.rx_cache2.EvictProvider)1 Reply (io.rx_cache2.Reply)1 Record (io.rx_cache2.internal.Record)1