use of io.rx_cache2.internal.Record in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Save_And_Evict_All_Get_Null.
@Test
public void When_Save_And_Evict_All_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);
twoLayersCacheUT.save(PROVIDER_KEY, "" + 1, "", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
twoLayersCacheUT.save(PROVIDER_KEY + 1, "", "", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
twoLayersCacheUT.save(PROVIDER_KEY + 1, "" + 1, "", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
twoLayersCacheUT.evictAll();
Record<Mock> record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "", "", false, ONE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "", "", false, ONE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY + 1, "", "", false, ONE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY + 1, "", "", false, ONE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
}
use of io.rx_cache2.internal.Record in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Save_And_Object_Not_Expired_And_Memory_Not_Destroyed_Retrieve_It_From_Memory.
@Test
public void When_Save_And_Object_Not_Expired_And_Memory_Not_Destroyed_Retrieve_It_From_Memory() {
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);
Record<Mock> record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "", "", false, ONE_SECOND_LIFE + 1000, false);
Mock mock = record.getData();
assertThat(mock.getMessage(), is(MOCK_VALUE));
assertThat(record.getSource(), is(Source.MEMORY));
}
use of io.rx_cache2.internal.Record in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Expired_Date_But_Use_ExpiredDataIfLoaderNotAvailable_Then_GetMock.
@Test
public void When_Expired_Date_But_Use_ExpiredDataIfLoaderNotAvailable_Then_GetMock() {
twoLayersCacheUT = new 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", "", true, ONE_SECOND_LIFE, false);
assertThat(record.getData().getMessage(), is(MOCK_VALUE));
}
use of io.rx_cache2.internal.Record in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Save_And_Record_Has_Not_Expired_And_Memory_Destroyed_Retrieve_It_From_Disk.
@Test
public void When_Save_And_Record_Has_Not_Expired_And_Memory_Destroyed_Retrieve_It_From_Disk() {
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);
twoLayersCacheUT.mockMemoryDestroyed();
Record<Mock> record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "", "", false, ONE_SECOND_LIFE, false);
Mock mock = record.getData();
assertThat(mock.getMessage(), is(MOCK_VALUE));
assertThat(record.getSource(), is(Source.PERSISTENCE));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "", "", false, ONE_SECOND_LIFE, false);
assertThat(mock.getMessage(), is(MOCK_VALUE));
assertThat(record.getSource(), is(Source.MEMORY));
}
Aggregations