use of io.rx_cache2.internal.Record in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Save_Dynamic_Key_Group_And_Evict_One_Dynamic_Key_Group_Get_Others.
@Test
public void When_Save_Dynamic_Key_Group_And_Evict_One_Dynamic_Key_Group_Get_Others() {
twoLayersCacheUT = new io.rx_cache2.internal.cache.TwoLayersCache(evictRecord(memory), retrieveRecord(memory), saveRecord(memory));
twoLayersCacheUT.save(PROVIDER_KEY, "filer_1", "page_1", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
twoLayersCacheUT.save(PROVIDER_KEY, "filer_1", "page_2", new Mock(MOCK_VALUE + 1), DUMMY_LIFE_TIME, true, false);
twoLayersCacheUT.evictDynamicKeyGroup(PROVIDER_KEY, "filer_1", "page_2");
assertThat(twoLayersCacheUT.retrieve(PROVIDER_KEY, "filer_1", "page_2", false, ONE_SECOND_LIFE, false), is(nullValue()));
Record<Mock> record1 = twoLayersCacheUT.retrieve(PROVIDER_KEY, "filer_1", "page_1", false, ONE_SECOND_LIFE, false);
assertThat(record1.getData().getMessage(), is(MOCK_VALUE));
}
use of io.rx_cache2.internal.Record in project RxCache by VictorAlbertos.
the class TwoLayersCacheTest method When_Expiration_Date_Has_Been_Modified_Then_Reflect_This_Change.
@Test
public void When_Expiration_Date_Has_Been_Modified_Then_Reflect_This_Change() {
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, THREE_SECOND_LIFE, false);
assertThat(record.getData().getMessage(), is(MOCK_VALUE));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "", false, ONE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
twoLayersCacheUT.save(PROVIDER_KEY, "1", "", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
waitTime(MORE_THAN_ONE_SECOND_LIFE);
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "", false, THREE_SECOND_LIFE, false);
assertThat(record.getData().getMessage(), is(MOCK_VALUE));
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "", false, ONE_SECOND_LIFE, false);
assertThat(record, is(nullValue()));
twoLayersCacheUT.save(PROVIDER_KEY, "1", "", new Mock(MOCK_VALUE), DUMMY_LIFE_TIME, true, false);
waitTime(MORE_THAN_ONE_SECOND_LIFE);
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "1", "", false, null, 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_Date_Do_Not_Get_Null.
@Test
public void When_Save_And_Record_Has_Not_Expired_Date_Do_Not_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, null, false);
assertThat(record.getData().getMessage(), is(MOCK_VALUE));
assertThat(record.getSource(), is(Source.MEMORY));
twoLayersCacheUT.mockMemoryDestroyed();
record = twoLayersCacheUT.retrieve(PROVIDER_KEY, "", "", false, null, false);
assertThat(record.getData().getMessage(), is(MOCK_VALUE));
assertThat(record.getSource(), is(Source.PERSISTENCE));
}
use of io.rx_cache2.internal.Record in project RxCache by VictorAlbertos.
the class DeleteRecordMatchingClassNameTest method When_Class_Matches_Delete_Record_2.
@Test
public void When_Class_Matches_Delete_Record_2() {
disk.saveRecord(Mock1.KEY, new Record(new Mock1(), true, 0l), false, null);
disk.saveRecord(Mock2.KEY, new Record(new Mock2(), true, 0l), false, null);
assertThat(disk.allKeys().size(), is(2));
deleteRecordMatchingClassNameUT.with(Arrays.<Class>asList(Mock1.class, Mock2.class)).react().test().awaitTerminalEvent();
assertThat(disk.allKeys().size(), is(0));
}
use of io.rx_cache2.internal.Record in project RxCache by VictorAlbertos.
the class DeleteRecordMatchingClassNameTest method When_Class_Matches_Delete_Record_1.
@Test
public void When_Class_Matches_Delete_Record_1() {
disk.saveRecord(Mock1.KEY, new Record(new Mock1(), true, 0l), false, null);
disk.saveRecord(Mock2.KEY, new Record(new Mock2(), true, 0l), false, null);
assertThat(disk.allKeys().size(), is(2));
deleteRecordMatchingClassNameUT.with(Arrays.<Class>asList(Mock1.class)).react().test().awaitTerminalEvent();
assertThat(disk.allKeys().size(), is(1));
}
Aggregations