Search in sources :

Example 1 with LruNormalizedCacheFactory

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

the class ApolloWatcherTest method setUp.

@Before
public void setUp() throws IOException {
    OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(Utils.immediateExecutorService())).build();
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).dispatcher(immediateExecutor()).okHttpClient(okHttpClient).logger(new Logger() {

        @Override
        public void log(int priority, @Nonnull String message, @Nonnull Optional<Throwable> t, @Nonnull Object... args) {
            String throwableTrace = "";
            if (t.isPresent()) {
                throwableTrace = t.get().getMessage();
            }
            System.out.println(String.format(message, args) + " " + throwableTrace);
        }
    }).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Optional(com.apollographql.apollo.api.internal.Optional) LruNormalizedCacheFactory(com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory) Nonnull(javax.annotation.Nonnull) Dispatcher(okhttp3.Dispatcher) Before(org.junit.Before)

Example 2 with LruNormalizedCacheFactory

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

the class IntegrationTest method setUp.

@Before
public void setUp() {
    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));
        }
    };
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(new OkHttpClient.Builder().dispatcher(new Dispatcher(Utils.immediateExecutorService())).build()).addCustomTypeAdapter(CustomType.DATE, dateCustomTypeAdapter).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).defaultResponseFetcher(ApolloResponseFetchers.NETWORK_ONLY).dispatcher(Utils.immediateExecutor()).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) LruNormalizedCacheFactory(com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory) CustomTypeValue(com.apollographql.apollo.response.CustomTypeValue) ParseException(java.text.ParseException) Dispatcher(okhttp3.Dispatcher) Date(java.util.Date) Before(org.junit.Before)

Example 3 with LruNormalizedCacheFactory

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

the class OptimisticCacheTestCase method setUp.

@Before
public void setUp() {
    OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(Utils.immediateExecutorService())).build();
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).dispatcher(Utils.immediateExecutor()).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) LruNormalizedCacheFactory(com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory) Dispatcher(okhttp3.Dispatcher) Before(org.junit.Before)

Example 4 with LruNormalizedCacheFactory

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

the class ResponseWriteTestCase method setUp.

@Before
public void setUp() {
    OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(Utils.immediateExecutorService())).build();
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).dispatcher(Utils.immediateExecutor()).addCustomTypeAdapter(CustomType.DATE, new CustomTypeAdapter<Date>() {

        @Override
        public Date decode(CustomTypeValue value) {
            try {
                return DATE_TIME_FORMAT.parse(value.value.toString());
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public CustomTypeValue encode(Date value) {
            return new CustomTypeValue.GraphQLString(DATE_TIME_FORMAT.format(value));
        }
    }).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) LruNormalizedCacheFactory(com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory) CustomTypeValue(com.apollographql.apollo.response.CustomTypeValue) ParseException(java.text.ParseException) Dispatcher(okhttp3.Dispatcher) Date(java.util.Date) Before(org.junit.Before)

Example 5 with LruNormalizedCacheFactory

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

the class RxApolloTest method setup.

@Before
public void setup() {
    OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(Utils.immediateExecutorService())).build();
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).dispatcher(Utils.immediateExecutor()).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) LruNormalizedCacheFactory(com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory) Dispatcher(okhttp3.Dispatcher) Before(org.junit.Before)

Aggregations

LruNormalizedCacheFactory (com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory)12 OkHttpClient (okhttp3.OkHttpClient)12 Before (org.junit.Before)11 Dispatcher (okhttp3.Dispatcher)10 IdFieldCacheKeyResolver (com.apollographql.apollo.IdFieldCacheKeyResolver)2 CustomTypeValue (com.apollographql.apollo.response.CustomTypeValue)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 Nonnull (javax.annotation.Nonnull)2 MockWebServer (okhttp3.mockwebserver.MockWebServer)2 ResponseField (com.apollographql.apollo.api.ResponseField)1 Optional (com.apollographql.apollo.api.internal.Optional)1 CacheKeyResolver (com.apollographql.apollo.cache.normalized.CacheKeyResolver)1 NormalizedCacheFactory (com.apollographql.apollo.cache.normalized.NormalizedCacheFactory)1 ApolloSqlHelper (com.apollographql.apollo.cache.normalized.sql.ApolloSqlHelper)1 SqlNormalizedCacheFactory (com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCacheFactory)1 WebSocketSubscriptionTransport (com.apollographql.apollo.subscription.WebSocketSubscriptionTransport)1 Map (java.util.Map)1