use of io.rx_cache2.internal.Mock 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.internal.Mock in project RxCache by VictorAlbertos.
the class EvictExpiredRecordsPersistenceTest method Evict_Just_Expired_Records.
@Test
public void Evict_Just_Expired_Records() {
int recordsCount = 100;
for (int i = 0; i < recordsCount / 2; i++) {
twoLayersCache.save(i + "_expired", "", "", new Mock(i + "_expired"), ONE_SECOND_LIFE, true, false);
twoLayersCache.save(i + "_live", "", "", new Mock(i + "_live"), THIRTY_SECOND_LIFE, true, false);
}
waitTime(MORE_THAN_ONE_SECOND_LIFE);
assertThat(disk.allKeys().size(), is(recordsCount));
TestObserver<Integer> testObserver = evictExpiredRecordsPersistenceUT.startEvictingExpiredRecords().test();
testObserver.awaitTerminalEvent();
testObserver.assertNoErrors();
List<String> allKeys = disk.allKeys();
assertThat(allKeys.size(), is(recordsCount / 2));
for (String key : allKeys) {
key = key.substring(0, key.indexOf("$"));
Record<Mock> record = twoLayersCache.retrieve(key, "", "", false, THIRTY_SECOND_LIFE, false);
assert (record.getData().getMessage().contains("live"));
assert (!record.getData().getMessage().contains("expired"));
}
}
use of io.rx_cache2.internal.Mock in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Expired_Date_And_Not_Use_ExpiredDataIfLoaderNotAvailable_Then_Get_Null.
@Test
public void When_Expired_Date_And_Not_Use_ExpiredDataIfLoaderNotAvailable_Then_Get_Null() {
twoLayersCacheUT = new io.rx_cache2.internal.cache.TwoLayersCache(evictRecord(memory), retrieveRecord(memory), saveRecord(memory));
twoLayersCacheUT.save(PROVIDER_KEY, "1", "", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
waitTime(MORE_THAN_ONE_SECOND_LIFE);
Record<Mock> record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "", false, ONE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
}
use of io.rx_cache2.internal.Mock in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Save_And_Dynamic_Key_Record_Has_Expired_Only_Get_Null_For_Dynamic_Key.
@Test
public void When_Save_And_Dynamic_Key_Record_Has_Expired_Only_Get_Null_For_Dynamic_Key() {
twoLayersCacheUT = new io.rx_cache2.internal.cache.TwoLayersCache(evictRecord(memory), retrieveRecord(memory), saveRecord(memory));
twoLayersCacheUT.save(PROVIDER_KEY, "1", "", new Mock(MOCK_VALUE), ONE_SECOND_LIFE, true, false);
twoLayersCacheUT.save(PROVIDER_KEY, "2", "", new Mock(MOCK_VALUE), ONE_SECOND_LIFE, true, false);
waitTime(MORE_THAN_ONE_SECOND_LIFE);
Record<Mock> record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "", false, ONE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "", false, THREE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "2", "", false, THREE_SECOND_LIFE, false);
assertNotNull(record);
}
use of io.rx_cache2.internal.Mock in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Save_And_Dynamic_Key_Group_Record_Has_Expired_Only_Get_Null_For_Dynamic_Key.
@Test
public void When_Save_And_Dynamic_Key_Group_Record_Has_Expired_Only_Get_Null_For_Dynamic_Key() {
twoLayersCacheUT = new io.rx_cache2.internal.cache.TwoLayersCache(evictRecord(memory), retrieveRecord(memory), saveRecord(memory));
twoLayersCacheUT.save(PROVIDER_KEY, "1", "1", new Mock(MOCK_VALUE), ONE_SECOND_LIFE, true, false);
twoLayersCacheUT.save(PROVIDER_KEY, "1", "2", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
twoLayersCacheUT.save(PROVIDER_KEY, "2", "1", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
twoLayersCacheUT.save(PROVIDER_KEY, "2", "2", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
waitTime(MORE_THAN_ONE_SECOND_LIFE);
Record<Mock> record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "1", false, ONE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "1", false, THREE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "2", false, THREE_SECOND_LIFE, false);
assertNotNull(record);
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "2", "1", false, THREE_SECOND_LIFE, false);
assertNotNull(record);
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "2", "2", false, THREE_SECOND_LIFE, false);
assertNotNull(record);
}
Aggregations