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));
}
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));
}
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);
}
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);
}
Aggregations