use of io.rx_cache2.internal.Mock in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Save_Dynamic_Key_And_Re_Save_Dynamic_Key_Get_Last_Value.
@Test
public void When_Save_Dynamic_Key_And_Re_Save_Dynamic_Key_Get_Last_Value() {
twoLayersCacheUT = new io.rx_cache2.internal.cache.TwoLayersCache(evictRecord(memory), retrieveRecord(memory), saveRecord(memory));
twoLayersCacheUT.save(PROVIDER_KEY, "1", "", new Mock(MOCK_VALUE + 1), DUMMY_LIFE_TIME, true, false);
twoLayersCacheUT.save(PROVIDER_KEY, "1", "", new Mock(MOCK_VALUE + 2), DUMMY_LIFE_TIME, true, false);
Record<Mock> record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "", false, ONE_SECOND_LIFE, false);
assertThat(record.getData().getMessage(), is(MOCK_VALUE + 2));
}
use of io.rx_cache2.internal.Mock in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Save_And_Provider_Record_Has_Expired_Get_Null.
@Test
public void When_Save_And_Provider_Record_Has_Expired_Get_Null() {
twoLayersCacheUT = new io.rx_cache2.internal.cache.TwoLayersCache(evictRecord(memory), retrieveRecord(memory), saveRecord(memory));
twoLayersCacheUT.save(PROVIDER_KEY, "", "", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
waitTime(MORE_THAN_ONE_SECOND_LIFE);
Record<Mock> record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "", "", false, ONE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "", "", false, THREE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
}
use of io.rx_cache2.internal.Mock 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.internal.Mock in project RxCache by VictorAlbertos.
the class ProvidersRxCacheEncryptedTest method createObservableMocks.
private Observable<List<Mock>> createObservableMocks(int size) {
long currentTime = System.currentTimeMillis();
List<Mock> mocks = new ArrayList(size);
for (int i = 0; i < size; i++) {
mocks.add(new Mock("mock" + currentTime));
}
return Observable.just(mocks);
}
use of io.rx_cache2.internal.Mock in project RxCache by VictorAlbertos.
the class EvictExpirableRecordsPersistenceTest method populate.
//7 mb
private void populate(boolean expirable) {
for (int i = 0; i < mocksCount(); i++) {
List<Mock> mocks = new ArrayList(mocksCount());
for (int z = 0; z < mocksCount(); z++) {
Mock mock = new Mock("Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC," + "making it over 2000 years old.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, " + "making it over 2000 years old. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, " + "making it over 2000 years old. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC.");
mocks.add(mock);
}
Record<List<Mock>> record = new Record<>(mocks, expirable, 1l);
disk.saveRecord(String.valueOf(i), record, false, null);
}
}
Aggregations