Search in sources :

Example 6 with NormalizedCache

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

the class ApolloStoreTest method storeClearAllCallsNormalizedCacheClearAll.

@Test
public void storeClearAllCallsNormalizedCacheClearAll() throws Exception {
    final NamedCountDownLatch latch = new NamedCountDownLatch("storeClearAllCallsNormalizedCacheClearAll", 1);
    final RealApolloStore realApolloStore = new RealApolloStore(new NormalizedCache() {

        @Nullable
        @Override
        public Record loadRecord(@Nonnull String key, @Nonnull CacheHeaders cacheHeaders) {
            return null;
        }

        @Nonnull
        @Override
        public Set<String> merge(@Nonnull Record record, @Nonnull CacheHeaders cacheHeaders) {
            return emptySet();
        }

        @Override
        public void clearAll() {
            latch.countDown();
        }

        @Override
        public boolean remove(@Nonnull CacheKey cacheKey) {
            return false;
        }

        @Nonnull
        @Override
        protected Set<String> performMerge(@Nonnull Record apolloRecord, @Nonnull CacheHeaders cacheHeaders) {
            return emptySet();
        }
    }, CacheKeyResolver.DEFAULT, new ScalarTypeAdapters(Collections.EMPTY_MAP), Executors.newSingleThreadExecutor(), new ApolloLogger(Optional.<Logger>absent()));
    realApolloStore.clearAll().execute();
    latch.awaitOrThrowWithTimeout(3, TimeUnit.SECONDS);
}
Also used : Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) Nonnull(javax.annotation.Nonnull) NamedCountDownLatch(com.apollographql.apollo.NamedCountDownLatch) ApolloLogger(com.apollographql.apollo.internal.ApolloLogger) Logger(com.apollographql.apollo.Logger) ApolloLogger(com.apollographql.apollo.internal.ApolloLogger) ScalarTypeAdapters(com.apollographql.apollo.response.ScalarTypeAdapters) CacheHeaders(com.apollographql.apollo.cache.CacheHeaders) NormalizedCache(com.apollographql.apollo.cache.normalized.NormalizedCache) Record(com.apollographql.apollo.cache.normalized.Record) Nullable(javax.annotation.Nullable) CacheKey(com.apollographql.apollo.cache.normalized.CacheKey) Test(org.junit.Test)

Example 7 with NormalizedCache

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

the class LruNormalizedCacheTest method testDualCache_recordNotPresent.

@Test
public void testDualCache_recordNotPresent() {
    LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION);
    NormalizedCache primaryCacheStore = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION).chain(secondaryCacheFactory).createChain(basicFieldAdapter);
    assertThat(primaryCacheStore.loadRecord("not_present_id", CacheHeaders.NONE)).isNull();
}
Also used : NormalizedCache(com.apollographql.apollo.cache.normalized.NormalizedCache) Test(org.junit.Test)

Example 8 with NormalizedCache

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

the class LruNormalizedCacheTest method testDualCacheSingleRecord.

@Test
public void testDualCacheSingleRecord() {
    LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION);
    NormalizedCache primaryCache = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION).chain(secondaryCacheFactory).createChain(basicFieldAdapter);
    Record.Builder recordBuilder = Record.builder("root");
    recordBuilder.addField("bar", "bar");
    final Record record = recordBuilder.build();
    primaryCache.merge(record, CacheHeaders.NONE);
    // verify write through behavior
    assertThat(primaryCache.loadRecord("root", CacheHeaders.NONE).field("bar")).isEqualTo("bar");
    assertThat(primaryCache.nextCache().get().loadRecord("root", CacheHeaders.NONE).field("bar")).isEqualTo("bar");
}
Also used : NormalizedCache(com.apollographql.apollo.cache.normalized.NormalizedCache) Record(com.apollographql.apollo.cache.normalized.Record) Test(org.junit.Test)

Aggregations

NormalizedCache (com.apollographql.apollo.cache.normalized.NormalizedCache)8 Test (org.junit.Test)8 Record (com.apollographql.apollo.cache.normalized.Record)7 CacheHeaders (com.apollographql.apollo.cache.CacheHeaders)3 CacheKey (com.apollographql.apollo.cache.normalized.CacheKey)3 Nonnull (javax.annotation.Nonnull)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 HeroAndFriendsNamesQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesQuery)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Dispatcher (okhttp3.Dispatcher)2 Logger (com.apollographql.apollo.Logger)1 NamedCountDownLatch (com.apollographql.apollo.NamedCountDownLatch)1 ApolloLogger (com.apollographql.apollo.internal.ApolloLogger)1 ScalarTypeAdapters (com.apollographql.apollo.response.ScalarTypeAdapters)1 Collections.emptySet (java.util.Collections.emptySet)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1