This commit is contained in:
Carl Mastrangelo 2016-02-10 10:40:16 -08:00
parent ad301c7e4d
commit 544cd3a33b
5 changed files with 17 additions and 17 deletions

View File

@ -64,12 +64,11 @@ public final class ClientAuthInterceptor implements ClientInterceptor {
private Metadata cached;
private Map<String, List<String>> lastMetadata;
// TODO(louiscryan): refresh token asynchronously with this executor.
private Executor executor;
public ClientAuthInterceptor(Credentials credentials, Executor executor) {
public ClientAuthInterceptor(
Credentials credentials, @SuppressWarnings("unused") Executor executor) {
this.credentials = Preconditions.checkNotNull(credentials);
this.executor = Preconditions.checkNotNull(executor);
// TODO(louiscryan): refresh token asynchronously with this executor.
}
@Override

View File

@ -46,6 +46,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
import com.google.common.util.concurrent.MoreExecutors;
import io.grpc.CallOptions;
import io.grpc.Channel;
@ -68,7 +69,7 @@ import org.mockito.MockitoAnnotations;
import java.io.IOException;
import java.net.URI;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.Executor;
/**
* Tests for {@link ClientAuthInterceptor}.
@ -76,11 +77,13 @@ import java.util.concurrent.Executors;
@RunWith(JUnit4.class)
public class ClientAuthInterceptorTests {
public static final Metadata.Key<String> AUTHORIZATION = Metadata.Key.of("Authorization",
private static final Metadata.Key<String> AUTHORIZATION = Metadata.Key.of("Authorization",
Metadata.ASCII_STRING_MARSHALLER);
public static final Metadata.Key<String> EXTRA_AUTHORIZATION = Metadata.Key.of(
private static final Metadata.Key<String> EXTRA_AUTHORIZATION = Metadata.Key.of(
"Extra-Authorization", Metadata.ASCII_STRING_MARSHALLER);
private final Executor executor = MoreExecutors.directExecutor();
@Mock
Credentials credentials;
@ -105,14 +108,13 @@ public class ClientAuthInterceptorTests {
/** Set up for test. */
@Before
public void startUp() throws IOException {
public void startUp() {
MockitoAnnotations.initMocks(this);
descriptor = MethodDescriptor.create(
MethodDescriptor.MethodType.UNKNOWN, "a.service/method", stringMarshaller, intMarshaller);
when(channel.newCall(same(descriptor), any(CallOptions.class))).thenReturn(call);
doReturn("localhost:443").when(channel).authority();
interceptor = new ClientAuthInterceptor(credentials,
Executors.newSingleThreadExecutor());
interceptor = new ClientAuthInterceptor(credentials, executor);
}
@Test
@ -161,7 +163,7 @@ public class ClientAuthInterceptorTests {
return token;
}
};
interceptor = new ClientAuthInterceptor(oAuth2Credentials, Executors.newSingleThreadExecutor());
interceptor = new ClientAuthInterceptor(oAuth2Credentials, executor);
ClientCall<String, Integer> interceptedCall =
interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
Metadata headers = new Metadata();

View File

@ -85,8 +85,8 @@ public class TransportBenchmark {
@Setup
public void setUp() throws Exception {
AbstractServerImplBuilder serverBuilder;
AbstractManagedChannelImplBuilder channelBuilder;
AbstractServerImplBuilder<?> serverBuilder;
AbstractManagedChannelImplBuilder<?> channelBuilder;
switch (transport) {
case INPROCESS:
{

View File

@ -221,7 +221,7 @@ public class OpenLoopClient {
});
}
private void waitForRpcsToComplete(int duration) throws InterruptedException {
private void waitForRpcsToComplete(int duration) {
long now = System.nanoTime();
long end = now + duration * 1000 * 1000 * 1000;
while (histogram.getTotalCount() < numRpcs && now < end) {

View File

@ -46,7 +46,6 @@ import com.google.common.base.Throwables;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import io.grpc.CallOptions;
import io.grpc.ClientCall;
@ -98,7 +97,7 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT>
// If we know that the executor is a direct executor, we don't need to wrap it with a
// SerializingExecutor. This is purely for performance reasons.
// See https://github.com/grpc/grpc-java/issues/368
this.callExecutor = executor == MoreExecutors.directExecutor()
this.callExecutor = executor == directExecutor()
? new SerializeReentrantCallsDirectExecutor()
: new SerializingExecutor(executor);
// Propagate the context from the thread which initiated the call to all callbacks.
@ -254,7 +253,7 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT>
}
}
// Propagate later Context cancellation to the remote side.
this.context.addListener(this, MoreExecutors.directExecutor());
this.context.addListener(this, directExecutor());
}
/**