Search in sources :

Example 36 with Record

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

the class ResponseNormalizationTest method list_of_objects_with_null_object.

@Test
public void list_of_objects_with_null_object() throws Exception {
    assertHasNoErrors("AllPlanetsListOfObjectWithNullObject.json", new AllPlanetsQuery());
    String fieldKey = "allPlanets({\"first\":\"300.0\"})";
    Record record = normalizedCache.loadRecord(fieldKey + ".planets.0", CacheHeaders.NONE);
    assertThat(record.field("filmConnection")).isNull();
    record = normalizedCache.loadRecord(fieldKey + ".planets.0.filmConnection", CacheHeaders.NONE);
    assertThat(record).isNull();
    record = normalizedCache.loadRecord(fieldKey + ".planets.1.filmConnection", CacheHeaders.NONE);
    assertThat(record).isNotNull();
}
Also used : AllPlanetsQuery(com.apollographql.apollo.integration.httpcache.AllPlanetsQuery) Record(com.apollographql.apollo.cache.normalized.Record) Test(org.junit.Test)

Example 37 with Record

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

the class RecordWeigherTest method testRecordWeigher.

@Test
public void testRecordWeigher() {
    Record.Builder recordBuilder = Record.builder("root");
    BigDecimal expectedBigDecimal = new BigDecimal(1.23);
    String expectedStringValue = "StringValue";
    Boolean expectedBooleanValue = true;
    CacheReference expectedCacheReference = new CacheReference("foo");
    List<CacheReference> expectedCacheReferenceList = Arrays.asList(new CacheReference("bar"), new CacheReference("baz"));
    List<Object> expectedScalarList = Arrays.<Object>asList("scalarOne", "scalarTwo");
    recordBuilder.addField("bigDecimal", expectedBigDecimal);
    recordBuilder.addField("string", expectedStringValue);
    recordBuilder.addField("boolean", expectedBooleanValue);
    recordBuilder.addField("cacheReference", expectedCacheReference);
    recordBuilder.addField("scalarList", expectedScalarList);
    recordBuilder.addField("referenceList", expectedCacheReferenceList);
    Record record = recordBuilder.build();
    record.sizeEstimateBytes();
    // It's difficult to say what the "right" size estimate is, so just checking it is has been calculate at all.
    assertThat(record.sizeEstimateBytes()).isNotEqualTo(-1);
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 38 with Record

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

the class LruNormalizedCacheTest method testHeader_evictAfterRead.

// Tests for StandardCacheHeader compliance.
@Test
public void testHeader_evictAfterRead() {
    LruNormalizedCache lruCache = new LruNormalizedCacheFactory(EvictionPolicy.builder().maxSizeBytes(10 * 1024).build()).create(basicFieldAdapter);
    Record testRecord = createTestRecord("1");
    lruCache.merge(testRecord, CacheHeaders.NONE);
    final Record record = lruCache.loadRecord("key1", CacheHeaders.builder().addHeader(ApolloCacheHeaders.EVICT_AFTER_READ, "true").build());
    assertThat(record).isNotNull();
    final Record nullRecord = lruCache.loadRecord("key1", CacheHeaders.builder().addHeader(ApolloCacheHeaders.EVICT_AFTER_READ, "true").build());
    assertThat(nullRecord).isNull();
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record) Test(org.junit.Test)

Example 39 with Record

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

the class LruNormalizedCacheTest method testSaveAndLoad_singleRecord.

@Test
public void testSaveAndLoad_singleRecord() {
    LruNormalizedCache lruCache = new LruNormalizedCacheFactory(EvictionPolicy.builder().maxSizeBytes(10 * 1024).build()).create(basicFieldAdapter);
    Record testRecord = createTestRecord("1");
    lruCache.merge(testRecord, CacheHeaders.NONE);
    assertTestRecordPresentAndAccurate(testRecord, lruCache);
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record) Test(org.junit.Test)

Example 40 with Record

use of com.apollographql.apollo.cache.normalized.Record 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

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