Search in sources :

Example 21 with Record

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

Example 22 with Record

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

Example 23 with Record

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

Example 24 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_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));
}
Also used : Mock(io.rx_cache2.internal.Mock) 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