use of com.apollographql.apollo.internal.cache.normalized.WriteableStore in project apollo-android by apollographql.
the class ApolloWatcherTest method testQueryWatcherUpdated_Store_write.
@Test
public void testQueryWatcherUpdated_Store_write() throws IOException, InterruptedException, TimeoutException, ApolloException {
final List<String> heroNameList = new ArrayList<>();
EpisodeHeroNameQuery query = EpisodeHeroNameQuery.builder().episode(Episode.EMPIRE).build();
server.enqueue(mockResponse("EpisodeHeroNameResponseWithId.json"));
ApolloQueryWatcher<EpisodeHeroNameQuery.Data> watcher = apolloClient.query(query).watcher();
watcher.enqueueAndWatch(new ApolloCall.Callback<EpisodeHeroNameQuery.Data>() {
@Override
public void onResponse(@Nonnull Response<EpisodeHeroNameQuery.Data> response) {
heroNameList.add(response.data().hero().name());
}
@Override
public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
}
});
assertThat(heroNameList.get(0)).isEqualTo("R2-D2");
// Someone writes to the store directly
Set<String> changedKeys = apolloClient.apolloStore().writeTransaction(new Transaction<WriteableStore, Set<String>>() {
@Nullable
@Override
public Set<String> execute(WriteableStore cache) {
Record record = Record.builder("2001").addField("name", "Artoo").build();
return cache.merge(Collections.singletonList(record), CacheHeaders.NONE);
}
});
apolloClient.apolloStore().publish(changedKeys);
assertThat(heroNameList.get(1)).isEqualTo("Artoo");
watcher.cancel();
}
Aggregations