use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method fileSystemReadFailure.
@Test
public void fileSystemReadFailure() throws IOException, ApolloException {
FaultyHttpCacheStore faultyCacheStore = new FaultyHttpCacheStore(inMemoryFileSystem);
cacheStore.delegate = faultyCacheStore;
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
checkCachedResponse("/HttpCacheTestAllPlanets.json");
enqueueResponse("/HttpCacheTestAllPlanets.json");
faultyCacheStore.failStrategy(FaultyHttpCacheStore.FailStrategy.FAIL_HEADER_READ);
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_FIRST)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
assertThat(server.getRequestCount()).isEqualTo(2);
enqueueResponse("/HttpCacheTestAllPlanets.json");
faultyCacheStore.failStrategy(FaultyHttpCacheStore.FailStrategy.FAIL_BODY_READ);
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_FIRST)).test().assertError(Exception.class);
assertThat(server.getRequestCount()).isEqualTo(2);
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method cacheOnlyHit.
@Test
public void cacheOnlyHit() throws Exception {
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
assertThat(server.takeRequest()).isNotNull();
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_ONLY)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
assertThat(server.getRequestCount()).isEqualTo(1);
assertThat(lastHttResponse.networkResponse()).isNull();
assertThat(lastHttResponse.cacheResponse()).isNotNull();
checkCachedResponse("/HttpCacheTestAllPlanets.json");
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method fromCacheFlag.
@Test
public void fromCacheFlag() throws Exception {
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.NETWORK_FIRST)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors() && !response.fromCache();
}
});
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.NETWORK_ONLY)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors() && !response.fromCache();
}
});
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_ONLY)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors() && response.fromCache();
}
});
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_FIRST)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors() && response.fromCache();
}
});
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_FIRST)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors() && response.fromCache();
}
});
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.NETWORK_FIRST)).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors() && response.fromCache();
}
});
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method fileSystemUnavailable.
@Test
public void fileSystemUnavailable() throws IOException, ApolloException {
cacheStore.delegate = new DiskLruHttpCacheStore(new NoFileSystem(), new File("/cache/"), Integer.MAX_VALUE);
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
checkNoCachedResponse();
}
use of com.apollographql.apollo.integration.httpcache.AllPlanetsQuery in project apollo-android by apollographql.
the class HttpCacheTest method expireAfterRead.
@Test
public void expireAfterRead() throws IOException, ApolloException {
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
checkCachedResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_ONLY.expireAfterRead())).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
checkNoCachedResponse();
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery()).httpCachePolicy(HttpCachePolicy.CACHE_ONLY)).test().assertError(Exception.class);
enqueueResponse("/HttpCacheTestAllPlanets.json");
Rx2Apollo.from(apolloClient.query(new AllPlanetsQuery())).test().assertValue(new Predicate<Response<AllPlanetsQuery.Data>>() {
@Override
public boolean test(Response<AllPlanetsQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
checkCachedResponse("/HttpCacheTestAllPlanets.json");
}
Aggregations