Search in sources :

Example 11 with Mock

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

Example 12 with Mock

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

Example 13 with Mock

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));
}
Also used : Type(java.lang.reflect.Type) EvictProvider(io.rx_cache2.EvictProvider) Test(org.junit.Test)

Example 14 with Mock

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);
}
Also used : ArrayList(java.util.ArrayList) Mock(io.rx_cache2.internal.Mock)

Example 15 with Mock

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);
    }
}
Also used : ArrayList(java.util.ArrayList) Record(io.rx_cache2.internal.Record) ArrayList(java.util.ArrayList) List(java.util.List) DataPoint(org.junit.experimental.theories.DataPoint) Mock(io.rx_cache2.internal.Mock)

Aggregations

Test (org.junit.Test)22 BaseTest (io.rx_cache2.internal.common.BaseTest)21 Mock (io.rx_cache2.internal.Mock)20 TestObserver (io.reactivex.observers.TestObserver)5 Reply (io.rx_cache2.Reply)3 ArrayList (java.util.ArrayList)3 EvictProvider (io.rx_cache2.EvictProvider)2 Observable (io.reactivex.Observable)1 ObservableEmitter (io.reactivex.ObservableEmitter)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 ConfigProvider (io.rx_cache2.ConfigProvider)1 Record (io.rx_cache2.internal.Record)1 Type (java.lang.reflect.Type)1 List (java.util.List)1 DataPoint (org.junit.experimental.theories.DataPoint)1