Search in sources :

Example 16 with Record

use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.

the class LruNormalizedCacheTest method testClearAll.

@Test
public void testClearAll() {
    LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION);
    NormalizedCache primaryCacheStore = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION).chain(secondaryCacheFactory).createChain(basicFieldAdapter);
    Record record = Record.builder("key").build();
    primaryCacheStore.merge(record, CacheHeaders.NONE);
    primaryCacheStore.clearAll();
    assertThat(primaryCacheStore.loadRecord("key", CacheHeaders.NONE)).isNull();
}
Also used : NormalizedCache(com.apollographql.apollo.cache.normalized.NormalizedCache) Record(com.apollographql.apollo.cache.normalized.Record) Test(org.junit.Test)

Example 17 with Record

use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.

the class LruNormalizedCacheTest method assertTestRecordPresentAndAccurate.

private void assertTestRecordPresentAndAccurate(Record testRecord, NormalizedCache store) {
    final Record cacheRecord1 = store.loadRecord(testRecord.key(), CacheHeaders.NONE);
    assertThat(cacheRecord1.key()).isEqualTo(testRecord.key());
    assertThat(cacheRecord1.field("a")).isEqualTo(testRecord.field("a"));
    assertThat(cacheRecord1.field("b")).isEqualTo(testRecord.field("b"));
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record)

Example 18 with Record

use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.

the class LruNormalizedCacheTest method testClearSecondaryCache.

@Test
public void testClearSecondaryCache() {
    LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION);
    NormalizedCache primaryCache = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION).chain(secondaryCacheFactory).createChain(basicFieldAdapter);
    Record record = Record.builder("key").build();
    primaryCache.merge(record, CacheHeaders.NONE);
    primaryCache.nextCache().get().clearAll();
    assertThat(primaryCache.nextCache().get().loadRecord("key", CacheHeaders.NONE)).isNull();
}
Also used : NormalizedCache(com.apollographql.apollo.cache.normalized.NormalizedCache) Record(com.apollographql.apollo.cache.normalized.Record) Test(org.junit.Test)

Example 19 with Record

use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.

the class LruNormalizedCacheTest method testSaveAndLoad_multipleRecord_readSingle.

@Test
public void testSaveAndLoad_multipleRecord_readSingle() {
    LruNormalizedCache lruCache = new LruNormalizedCacheFactory(EvictionPolicy.builder().maxSizeBytes(10 * 1024).build()).create(basicFieldAdapter);
    Record testRecord1 = createTestRecord("1");
    Record testRecord2 = createTestRecord("2");
    Record testRecord3 = createTestRecord("3");
    List<Record> records = Arrays.asList(testRecord1, testRecord2, testRecord3);
    lruCache.merge(records, CacheHeaders.NONE);
    assertTestRecordPresentAndAccurate(testRecord1, lruCache);
    assertTestRecordPresentAndAccurate(testRecord2, lruCache);
    assertTestRecordPresentAndAccurate(testRecord3, lruCache);
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record) Test(org.junit.Test)

Example 20 with Record

use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.

the class SqlNormalizedCacheTest method testHeader_noCache.

@Test
public void testHeader_noCache() {
    sqlStore.merge(Record.builder(STANDARD_KEY).build(), CacheHeaders.builder().addHeader(ApolloCacheHeaders.DO_NOT_STORE, "true").build());
    final Record record = sqlStore.loadRecord(STANDARD_KEY, CacheHeaders.NONE);
    assertThat(record).isNull();
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record) Test(org.junit.Test)

Aggregations

Record (com.apollographql.apollo.cache.normalized.Record)42 Test (org.junit.Test)35 CacheReference (com.apollographql.apollo.cache.normalized.CacheReference)15 NormalizedCache (com.apollographql.apollo.cache.normalized.NormalizedCache)7 Nonnull (javax.annotation.Nonnull)5 CacheKey (com.apollographql.apollo.cache.normalized.CacheKey)4 CacheHeaders (com.apollographql.apollo.cache.CacheHeaders)3 EpisodeHeroNameQuery (com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery)3 HeroAndFriendsNamesQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesQuery)3 HeroTypeDependentAliasedFieldQuery (com.apollographql.apollo.integration.normalizer.HeroTypeDependentAliasedFieldQuery)3 NonNull (android.support.annotation.NonNull)2 ApolloCacheHeaders (com.apollographql.apollo.cache.ApolloCacheHeaders)2 NormalizedCacheFactory (com.apollographql.apollo.cache.normalized.NormalizedCacheFactory)2 RecordFieldJsonAdapter (com.apollographql.apollo.cache.normalized.RecordFieldJsonAdapter)2 ApolloException (com.apollographql.apollo.exception.ApolloException)2 HeroParentTypeDependentFieldQuery (com.apollographql.apollo.integration.normalizer.HeroParentTypeDependentFieldQuery)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2