aboutsummaryrefslogtreecommitdiff
path: root/auth
diff options
context:
space:
mode:
authorKun Zhang <zhangkun@google.com>2015-06-25 20:24:01 -0700
committerKun Zhang <zhangkun@google.com>2015-07-07 14:28:38 -0700
commitd3c5b00827a8a1c1677ebabd256123d213593322 (patch)
tree855007dd33c39a570d7873b6c850559c21368adc /auth
parent12d57974c07144e91c436fd43214b7c9149235de (diff)
downloadgrpc-grpc-java-d3c5b00827a8a1c1677ebabd256123d213593322.tar.gz
Add CallOptions.
- Pass CallOptions to Channel.newCall() and ClientInterceptor.interceptCall(). - Remove timeout from AbstractStub.StubConfigBuilder and add deadline, which is stored in a CallOptions inside the stub. - Deadline is in nanoseconds in the clock defined by System.nanoTime(). It is converted to timeout before transmitting on the wire. Fail the call with DEADLINE_EXCEEDED if it's already expired.
Diffstat (limited to 'auth')
-rw-r--r--auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java5
-rw-r--r--auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java14
2 files changed, 13 insertions, 6 deletions
diff --git a/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java b/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java
index ef5d46a06..b64cc0d77 100644
--- a/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java
+++ b/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java
@@ -34,6 +34,7 @@ package io.grpc.auth;
import com.google.auth.Credentials;
import com.google.common.base.Preconditions;
+import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
import io.grpc.ClientInterceptor;
@@ -68,10 +69,10 @@ public class ClientAuthInterceptor implements ClientInterceptor {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method,
- Channel next) {
+ CallOptions callOptions, Channel next) {
// TODO(ejona86): If the call fails for Auth reasons, this does not properly propagate info that
// would be in WWW-Authenticate, because it does not yet have access to the header.
- return new CheckedForwardingClientCall<ReqT, RespT>(next.newCall(method)) {
+ return new CheckedForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
protected void checkedStart(Listener<RespT> responseListener, Metadata.Headers headers)
throws Exception {
diff --git a/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java b/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java
index 8fe7f84c8..42f3ac843 100644
--- a/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java
+++ b/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java
@@ -31,8 +31,10 @@
package io.grpc.auth;
+import static org.mockito.Mockito.any;
import static org.mockito.Mockito.isA;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.same;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -44,6 +46,7 @@ import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
+import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
import io.grpc.Metadata;
@@ -96,7 +99,7 @@ public class ClientAuthInterceptorTests {
@Before
public void startUp() throws IOException {
MockitoAnnotations.initMocks(this);
- when(channel.newCall(descriptor)).thenReturn(call);
+ when(channel.newCall(same(descriptor), any(CallOptions.class))).thenReturn(call);
interceptor = new ClientAuthInterceptor(credentials,
Executors.newSingleThreadExecutor());
}
@@ -109,7 +112,8 @@ public class ClientAuthInterceptorTests {
values.put("Extra-Authorization", "token3");
values.put("Extra-Authorization", "token4");
when(credentials.getRequestMetadata()).thenReturn(Multimaps.asMap(values));
- ClientCall<String, Integer> interceptedCall = interceptor.interceptCall(descriptor, channel);
+ ClientCall<String, Integer> interceptedCall =
+ interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
Metadata.Headers headers = new Metadata.Headers();
interceptedCall.start(listener, headers);
verify(call).start(listener, headers);
@@ -125,7 +129,8 @@ public class ClientAuthInterceptorTests {
@Test
public void testCredentialsThrows() throws IOException {
when(credentials.getRequestMetadata()).thenThrow(new IOException("Broken"));
- ClientCall<String, Integer> interceptedCall = interceptor.interceptCall(descriptor, channel);
+ ClientCall<String, Integer> interceptedCall =
+ interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
Metadata.Headers headers = new Metadata.Headers();
interceptedCall.start(listener, headers);
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
@@ -146,7 +151,8 @@ public class ClientAuthInterceptorTests {
}
};
interceptor = new ClientAuthInterceptor(oAuth2Credentials, Executors.newSingleThreadExecutor());
- ClientCall<String, Integer> interceptedCall = interceptor.interceptCall(descriptor, channel);
+ ClientCall<String, Integer> interceptedCall =
+ interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
Metadata.Headers headers = new Metadata.Headers();
interceptedCall.start(listener, headers);
verify(call).start(listener, headers);