Search in sources :

Example 6 with AnyRepositoryKey

use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.

the class RosieRepositoryTest method shouldReturnValueFromReadableDataSourceIfCacheDataSourceValueIsNull.

@Test
public void shouldReturnValueFromReadableDataSourceIfCacheDataSourceValueIsNull() throws Exception {
    givenCacheDataSourceReturnsNull();
    AnyRepositoryValue readableValue = givenReadableDataSourceReturnsValidValueWithKey(ANY_KEY);
    RosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAReadableAndCacheRepository();
    AnyRepositoryValue value = repository.getByKey(ANY_KEY);
    Assert.assertEquals(readableValue, value);
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 7 with AnyRepositoryKey

use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.

the class RosieRepositoryTest method shouldPopulateCacheDataSourceWithValueIfCacheDataSourceIsNotValid.

@Test
public void shouldPopulateCacheDataSourceWithValueIfCacheDataSourceIsNotValid() throws Exception {
    givenCacheDataSourceReturnsNonValidValueWithKey(ANY_KEY);
    AnyRepositoryValue readableValue = givenReadableDataSourceReturnsValidValueWithKey(ANY_KEY);
    RosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAReadableAndCacheRepository();
    repository.getByKey(ANY_KEY);
    verify(cacheDataSource).addOrUpdate(readableValue);
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 8 with AnyRepositoryKey

use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.

the class InMemoryCacheDataSourceTest method shouldReturnInvalidValuesIfTheTTLHasExpired.

@Test
public void shouldReturnInvalidValuesIfTheTTLHasExpired() throws Exception {
    CacheDataSource<AnyRepositoryKey, AnyRepositoryValue> cache = givenAnInMemoryCacheDataSource();
    List<AnyRepositoryValue> values = givenSomeValues(ANY_ITEMS_COUNT);
    cache.addOrUpdateAll(values);
    advanceTime(ANY_TTL + 1);
    AnyRepositoryValue value = cache.getByKey(ANY_KEY);
    assertFalse(cache.isValid(value));
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 9 with AnyRepositoryKey

use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.

the class InMemoryCacheDataSourceTest method givenSomeValues.

private List<AnyRepositoryValue> givenSomeValues(int itemsCount) {
    List<AnyRepositoryValue> values = new LinkedList<>();
    for (int i = 0; i < itemsCount; i++) {
        AnyRepositoryValue value = new AnyRepositoryValue(new AnyRepositoryKey(i));
        values.add(value);
    }
    return values;
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) LinkedList(java.util.LinkedList)

Example 10 with AnyRepositoryKey

use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.

the class InMemoryPaginatedCacheDataSourceTest method shouldReturnHasMoreIfThereAreMoreItemsToLoad.

@Test
public void shouldReturnHasMoreIfThereAreMoreItemsToLoad() throws Exception {
    Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT);
    Collection<AnyRepositoryValue> values = givenSomeItems(ANY_OFFSET + ANY_LIMIT);
    PaginatedCacheDataSource<AnyRepositoryKey, AnyRepositoryValue> cache = givenAnInMemoryPaginatedCacheDataSource();
    cache.addOrUpdatePage(page, values, ANY_HAS_MORE);
    PaginatedCollection<AnyRepositoryValue> paginatedCollection = cache.getPage(page);
    assertEquals(ANY_HAS_MORE, paginatedCollection.hasMore());
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) Page(com.karumi.rosie.repository.datasource.paginated.Page) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Aggregations

AnyRepositoryKey (com.karumi.rosie.doubles.AnyRepositoryKey)21 AnyRepositoryValue (com.karumi.rosie.doubles.AnyRepositoryValue)21 Test (org.junit.Test)18 Page (com.karumi.rosie.repository.datasource.paginated.Page)12 LinkedList (java.util.LinkedList)3