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