use of com.apollographql.apollo.cache.http.DiskLruHttpCacheStore in project apollo-android by apollographql.
the class ApolloPrefetchTest method setup.
@Before
public void setup() {
cacheStore = new MockHttpCacheStore();
cacheStore.delegate = new DiskLruHttpCacheStore(inMemoryFileSystem, new File("/cache/"), Integer.MAX_VALUE);
okHttpClient = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
lastHttRequest = chain.request();
lastHttResponse = chain.proceed(lastHttRequest);
return lastHttResponse;
}
}).dispatcher(new Dispatcher(Utils.immediateExecutorService())).build();
apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).dispatcher(Utils.immediateExecutor()).httpCache(new ApolloHttpCache(cacheStore, null)).build();
}
use of com.apollographql.apollo.cache.http.DiskLruHttpCacheStore in project apollo-android by apollographql.
the class HttpCacheTest method setUp.
@Before
public void setUp() {
CustomTypeAdapter<Date> dateCustomTypeAdapter = new CustomTypeAdapter<Date>() {
@Override
public Date decode(CustomTypeValue value) {
try {
return DATE_FORMAT.parse(value.value.toString());
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
@Override
public CustomTypeValue encode(Date value) {
return new CustomTypeValue.GraphQLString(DATE_FORMAT.format(value));
}
};
cacheStore = new MockHttpCacheStore();
cacheStore.delegate = new DiskLruHttpCacheStore(inMemoryFileSystem, new File("/cache/"), Integer.MAX_VALUE);
HttpCache cache = new ApolloHttpCache(cacheStore, null);
okHttpClient = new OkHttpClient.Builder().addInterceptor(new TrackingInterceptor()).addInterceptor(cache.interceptor()).dispatcher(new Dispatcher(Utils.immediateExecutorService())).readTimeout(2, TimeUnit.SECONDS).writeTimeout(2, TimeUnit.SECONDS).build();
apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).dispatcher(Utils.immediateExecutor()).addCustomTypeAdapter(CustomType.DATE, dateCustomTypeAdapter).httpCache(cache).build();
}
use of com.apollographql.apollo.cache.http.DiskLruHttpCacheStore 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();
}
Aggregations