Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for Optimistic update store #584

Merged
merged 8 commits into from
Jul 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Optional<Record> selectRecordForKey(String key) {
Record cursorToRecord(Cursor cursor) throws IOException {
String key = cursor.getString(1);
String jsonOfFields = cursor.getString(2);
return new Record(key, recordAdapter().from(jsonOfFields));
return Record.builder(key).addFields(recordAdapter().from(jsonOfFields)).build();
}

public void close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

import android.support.annotation.NonNull;

import com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery;
import com.apollographql.apollo.integration.normalizer.type.Episode;
import com.apollographql.apollo.api.Operation;
import com.apollographql.apollo.api.Response;
import com.apollographql.apollo.cache.normalized.Record;
import com.apollographql.apollo.exception.ApolloException;
import com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery;
import com.apollographql.apollo.integration.normalizer.type.Episode;
import com.apollographql.apollo.interceptor.ApolloInterceptor;
import com.apollographql.apollo.interceptor.ApolloInterceptorChain;
import com.apollographql.apollo.interceptor.FetchOptions;
Expand Down Expand Up @@ -55,15 +54,15 @@ public void onProceedCalled_chainPassesControlToInterceptor() throws ApolloExcep

ApolloInterceptor interceptor = new ApolloInterceptor() {
@Nonnull @Override
public InterceptorResponse intercept(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull FetchOptions fetchOptions) throws ApolloException {
public InterceptorResponse intercept(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain)
throws ApolloException {
counter.decrementAndGet();
return null;
}

@Override
public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull FetchOptions fetchOptions, @Nonnull CallBack callBack) {
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull CallBack callBack) {

}

Expand All @@ -73,9 +72,8 @@ public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloIntercep
};

List<ApolloInterceptor> interceptors = Collections.singletonList(interceptor);
chain = new RealApolloInterceptorChain(query, interceptors);

chain.proceed(FetchOptions.NETWORK_ONLY);
chain = new RealApolloInterceptorChain(interceptors);
chain.proceed(new ApolloInterceptor.InterceptorRequest(query, FetchOptions.NETWORK_ONLY));

if (counter.get() != 0) {
Assert.fail("Control not passed to the interceptor");
Expand All @@ -90,15 +88,14 @@ public void onProceedAsyncCalled_chainPassesControlToInterceptor() throws Timeou

ApolloInterceptor interceptor = new ApolloInterceptor() {
@Nonnull @Override
public InterceptorResponse intercept(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull FetchOptions options)
public InterceptorResponse intercept(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain)
throws ApolloException {
return null;
}

@Override
public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull FetchOptions options, @Nonnull CallBack callBack) {
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull CallBack callBack) {
counter.decrementAndGet();
}

Expand All @@ -108,21 +105,21 @@ public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloIntercep
};

List<ApolloInterceptor> interceptors = Collections.singletonList(interceptor);
chain = new RealApolloInterceptorChain(query, interceptors);

chain.proceedAsync(Utils.immediateExecutorService(), FetchOptions.NETWORK_ONLY, new CallBack() {
@Override public void onResponse(@Nonnull InterceptorResponse response) {
chain = new RealApolloInterceptorChain(interceptors);
chain.proceedAsync(new ApolloInterceptor.InterceptorRequest(query, FetchOptions.NETWORK_ONLY),
Utils.immediateExecutorService(), new CallBack() {
@Override public void onResponse(@Nonnull InterceptorResponse response) {

}
}

@Override public void onFailure(@Nonnull ApolloException e) {
@Override public void onFailure(@Nonnull ApolloException e) {

}
}

@Override public void onCompleted() {
@Override public void onCompleted() {

}
});
}
});

//If counter's count doesn't go down to zero, it means interceptor's interceptAsync wasn't called
//which means the test should fail.
Expand All @@ -140,14 +137,14 @@ public void onProceedCalled_correctInterceptorResponseIsReceived() throws Apollo

ApolloInterceptor interceptor = new ApolloInterceptor() {
@Nonnull @Override
public InterceptorResponse intercept(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull FetchOptions options) throws ApolloException {
public InterceptorResponse intercept(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain)
throws ApolloException {
return expectedResponse;
}

@Override
public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull FetchOptions options, @Nonnull CallBack callBack) {
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull CallBack callBack) {

}

Expand All @@ -157,9 +154,10 @@ public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloIntercep
};

List<ApolloInterceptor> interceptors = Collections.singletonList(interceptor);
chain = new RealApolloInterceptorChain(query, interceptors);
chain = new RealApolloInterceptorChain(interceptors);

InterceptorResponse actualResponse = chain.proceed(FetchOptions.NETWORK_ONLY);
InterceptorResponse actualResponse = chain.proceed(new ApolloInterceptor.InterceptorRequest(query,
FetchOptions.NETWORK_ONLY));

assertThat(actualResponse).isEqualTo(expectedResponse);
}
Expand All @@ -173,13 +171,14 @@ public void onProceedAsyncCalled_correctInterceptorResponseIsReceived() throws T

ApolloInterceptor interceptor = new ApolloInterceptor() {
@Nonnull @Override
public InterceptorResponse intercept(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain, @Nonnull FetchOptions options) throws ApolloException {
public InterceptorResponse intercept(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain)
throws ApolloException {
return null;
}

@Override
public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull FetchOptions options, @Nonnull final CallBack callBack) {
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull final CallBack callBack) {
dispatcher.execute(new Runnable() {
@Override public void run() {
callBack.onResponse(expectedResponse);
Expand All @@ -193,22 +192,23 @@ public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloIntercep
};

List<ApolloInterceptor> interceptors = Collections.singletonList(interceptor);
chain = new RealApolloInterceptorChain(query, interceptors);
chain = new RealApolloInterceptorChain(interceptors);

chain.proceedAsync(Utils.immediateExecutorService(), FetchOptions.NETWORK_ONLY, new CallBack() {
@Override public void onResponse(@Nonnull InterceptorResponse response) {
assertThat(response).isEqualTo(expectedResponse);
counter.decrementAndGet();
}
chain.proceedAsync(new ApolloInterceptor.InterceptorRequest(query, FetchOptions.NETWORK_ONLY),
Utils.immediateExecutorService(), new CallBack() {
@Override public void onResponse(@Nonnull InterceptorResponse response) {
assertThat(response).isEqualTo(expectedResponse);
counter.decrementAndGet();
}

@Override public void onFailure(@Nonnull ApolloException e) {
@Override public void onFailure(@Nonnull ApolloException e) {

}
}

@Override public void onCompleted() {
@Override public void onCompleted() {

}
});
}
});

if (counter.get() != 0) {
Assert.fail("Interceptor's response not received");
Expand All @@ -223,14 +223,14 @@ public void onProceedCalled_correctExceptionIsCaught() {

ApolloInterceptor Interceptor = new ApolloInterceptor() {
@Nonnull @Override
public InterceptorResponse intercept(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull FetchOptions options)
public InterceptorResponse intercept(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain)
throws ApolloException {
throw new ApolloException(message);
}

@Override
public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain, @Nonnull ExecutorService dispatcher, @Nonnull FetchOptions options, @Nonnull CallBack callBack) {
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull CallBack callBack) {

}

Expand All @@ -242,10 +242,10 @@ public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloIntercep
List<ApolloInterceptor> interceptors = new ArrayList<>();
interceptors.add(Interceptor);

chain = new RealApolloInterceptorChain(query, interceptors);
chain = new RealApolloInterceptorChain(interceptors);

try {
chain.proceed(FetchOptions.NETWORK_ONLY);
chain.proceed(new ApolloInterceptor.InterceptorRequest(query, FetchOptions.NETWORK_ONLY));
} catch (Exception e) {
assertThat(e.getMessage()).isEqualTo(message);
assertThat(e).isInstanceOf(ApolloException.class);
Expand All @@ -262,14 +262,14 @@ public void onProceedAsyncCalled_correctExceptionIsCaught() throws TimeoutExcept

ApolloInterceptor interceptor = new ApolloInterceptor() {
@Nonnull @Override
public InterceptorResponse intercept(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull FetchOptions fetchOptions) throws ApolloException {
public InterceptorResponse intercept(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain)
throws ApolloException {
return null;
}

@Override
public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull FetchOptions options, @Nonnull final CallBack callBack) {
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain,
@Nonnull ExecutorService dispatcher, @Nonnull final CallBack callBack) {
dispatcher.execute(new Runnable() {
@Override public void run() {
ApolloException apolloException = new ApolloException(message);
Expand All @@ -284,22 +284,23 @@ public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloIntercep
};

List<ApolloInterceptor> interceptors = Collections.singletonList(interceptor);
chain = new RealApolloInterceptorChain(query, interceptors);
chain = new RealApolloInterceptorChain(interceptors);

chain.proceedAsync(Utils.immediateExecutorService(), FetchOptions.NETWORK_ONLY, new CallBack() {
@Override public void onResponse(@Nonnull InterceptorResponse response) {
chain.proceedAsync(new ApolloInterceptor.InterceptorRequest(query, FetchOptions.NETWORK_ONLY),
Utils.immediateExecutorService(), new CallBack() {
@Override public void onResponse(@Nonnull InterceptorResponse response) {

}
}

@Override public void onFailure(@Nonnull ApolloException e) {
assertThat(e.getMessage()).isEqualTo(message);
counter.decrementAndGet();
}
@Override public void onFailure(@Nonnull ApolloException e) {
assertThat(e.getMessage()).isEqualTo(message);
counter.decrementAndGet();
}

@Override public void onCompleted() {
@Override public void onCompleted() {

}
});
}
});

if (counter.get() != 0) {
Assert.fail("Exception thrown by Interceptor not caught");
Expand All @@ -314,14 +315,14 @@ public void onDisposeCalled_interceptorIsDisposed() {

ApolloInterceptor interceptor = new ApolloInterceptor() {
@Nonnull @Override
public InterceptorResponse intercept(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain,
@Nonnull FetchOptions fetchOptions) throws ApolloException {
public InterceptorResponse intercept(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain)
throws ApolloException {
return null;
}

@Override
public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloInterceptorChain chain, @Nonnull
ExecutorService dispatcher, @Nonnull FetchOptions fetchOptions, @Nonnull CallBack callBack) {
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain, @Nonnull
ExecutorService dispatcher, @Nonnull CallBack callBack) {

}

Expand All @@ -331,7 +332,7 @@ public void interceptAsync(@Nonnull Operation operation, @Nonnull ApolloIntercep
};

List<ApolloInterceptor> interceptors = Collections.singletonList(interceptor);
chain = new RealApolloInterceptorChain(query, interceptors);
chain = new RealApolloInterceptorChain(interceptors);

chain.dispose();

Expand Down
Loading