Search in sources :

Example 1 with Record

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));
}
Also used : Mock(io.rx_cache2.internal.Mock) BaseTest(io.rx_cache2.internal.common.BaseTest) Test(org.junit.Test)

Example 2 with Record

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));
}
Also used : Mock(io.rx_cache2.internal.Mock) BaseTest(io.rx_cache2.internal.common.BaseTest) Test(org.junit.Test)

Example 3 with Record

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));
}
Also used : Mock(io.rx_cache2.internal.Mock) BaseTest(io.rx_cache2.internal.common.BaseTest) Test(org.junit.Test)

Example 4 with Record

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));
}
Also used : Record(io.rx_cache2.internal.Record) BaseTest(io.rx_cache2.internal.common.BaseTest) Test(org.junit.Test)

Example 5 with Record

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));
}
Also used : Record(io.rx_cache2.internal.Record) BaseTest(io.rx_cache2.internal.common.BaseTest) Test(org.junit.Test)

Aggregations

BaseTest (io.rx_cache2.internal.common.BaseTest)20 Test (org.junit.Test)20 Mock (io.rx_cache2.internal.Mock)17 Record (io.rx_cache2.internal.Record)7 ObservableEmitter (io.reactivex.ObservableEmitter)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 Function (io.reactivex.functions.Function)1 Reply (io.rx_cache2.Reply)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DataPoint (org.junit.experimental.theories.DataPoint)1