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);
}
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();
}
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");
}
Aggregations