Search in sources :

Example 16 with AnyRepositoryKey

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

the class RosieRepositoryTest method shouldReturnItemFromReadableDataSourceIfCacheDataSourceValueIsNotValid.

@Test
public void shouldReturnItemFromReadableDataSourceIfCacheDataSourceValueIsNotValid() throws Exception {
    givenCacheDataSourceReturnsNonValidValueWithKey(ANY_KEY);
    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 17 with AnyRepositoryKey

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

the class InMemoryCacheDataSourceTest method shouldReturnInvalidValuesIfTheTTLNoHasExpired.

@Test
public void shouldReturnInvalidValuesIfTheTTLNoHasExpired() 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);
    assertTrue(cache.isValid(value));
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 18 with AnyRepositoryKey

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

the class InMemoryPaginatedCacheDataSourceTest method givenSomeItems.

private Collection<AnyRepositoryValue> givenSomeItems(int numberOfItems) {
    List<AnyRepositoryValue> values = new LinkedList<>();
    for (int i = 0; i < numberOfItems; 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 19 with AnyRepositoryKey

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

the class InMemoryPaginatedCacheDataSourceTest method shouldAddValuesBasedOnTheOffsetAndLimit.

@Test
public void shouldAddValuesBasedOnTheOffsetAndLimit() 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(values, paginatedCollection.getItems());
}
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)

Example 20 with AnyRepositoryKey

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

the class InMemoryPaginatedCacheDataSourceTest method shouldReturnRequestedLimit.

@Test
public void shouldReturnRequestedLimit() 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_LIMIT, paginatedCollection.getPage().getLimit());
}
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