@Test @SuppressWarnings("deprecation") public void informationPropagatedToNewStreamAndCallCredentials() { createChannel(); CallOptions callOptions = CallOptions.DEFAULT.withCallCredentials(creds); final Context.Key<String> testKey = Context.key("testing"); Context ctx = Context.current().withValue(testKey, "testValue"); final LinkedList<Context> credsApplyContexts = new LinkedList<Context>(); final LinkedList<Context> newStreamContexts = new LinkedList<Context>(); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock in) throws Throwable { credsApplyContexts.add(Context.current()); return null; } }).when(creds).applyRequestMetadata( any(MethodDescriptor.class), any(Attributes.class), any(Executor.class), any(CallCredentials.MetadataApplier.class)); Context origCtx = ctx.attach(); assertEquals("testValue", testKey.get()); ClientCall<String, Integer> call = channel.newCall(method, callOptions); ctx.detach(origCtx); assertNull(testKey.get()); call.start(mockCallListener, new Metadata()); EquivalentAddressGroup addressGroup = new EquivalentAddressGroup(socketAddress); Subchannel subchannel = createSubchannelSafely(helper, addressGroup, Attributes.EMPTY); subchannel.requestConnection(); verify(mockTransportFactory) .newClientTransport(same(socketAddress), eq(clientTransportOptions)); MockClientTransportInfo transportInfo = transports.poll(); final ConnectionClientTransport transport = transportInfo.transport; when(transport.getAttributes()).thenReturn(Attributes.EMPTY); doAnswer(new Answer<ClientStream>() { @Override public ClientStream answer(InvocationOnMock in) throws Throwable { newStreamContexts.add(Context.current()); return mock(ClientStream.class); } }).when(transport).newStream( any(MethodDescriptor.class), any(Metadata.class), any(CallOptions.class)); verify(creds, never()).applyRequestMetadata( any(MethodDescriptor.class), any(Attributes.class), any(Executor.class), any(CallCredentials.MetadataApplier.class)); transportInfo.listener.transportReady(); when(mockPicker.pickSubchannel(any(PickSubchannelArgs.class))) .thenReturn(PickResult.withSubchannel(subchannel)); helper.updateBalancingState(READY, mockPicker); executor.runDueTasks(); ArgumentCaptor<Attributes> attrsCaptor = ArgumentCaptor.forClass(Attributes.class); ArgumentCaptor<CallCredentials.MetadataApplier> applierCaptor = ArgumentCaptor.forClass(CallCredentials.MetadataApplier.class); verify(creds).applyRequestMetadata(same(method), attrsCaptor.capture(), same(executor.getScheduledExecutorService()), applierCaptor.capture()); assertEquals("testValue", testKey.get(credsApplyContexts.poll())); assertEquals(AUTHORITY, attrsCaptor.getValue().get(CallCredentials.ATTR_AUTHORITY)); assertEquals(SecurityLevel.NONE, attrsCaptor.getValue().get(CallCredentials.ATTR_SECURITY_LEVEL)); verify(transport, never()).newStream( any(MethodDescriptor.class), any(Metadata.class), any(CallOptions.class)); applierCaptor.getValue().apply(new Metadata()); verify(transport).newStream(same(method), any(Metadata.class), same(callOptions)); assertEquals("testValue", testKey.get(newStreamContexts.poll())); assertNull(testKey.get()); origCtx = ctx.attach(); call = channel.newCall(method, callOptions); ctx.detach(origCtx); call.start(mockCallListener, new Metadata()); verify(creds, times(2)).applyRequestMetadata(same(method), attrsCaptor.capture(), same(executor.getScheduledExecutorService()), applierCaptor.capture()); assertEquals("testValue", testKey.get(credsApplyContexts.poll())); assertEquals(AUTHORITY, attrsCaptor.getValue().get(CallCredentials.ATTR_AUTHORITY)); assertEquals(SecurityLevel.NONE, attrsCaptor.getValue().get(CallCredentials.ATTR_SECURITY_LEVEL)); verify(transport).newStream( any(MethodDescriptor.class), any(Metadata.class), any(CallOptions.class)); applierCaptor.getValue().apply(new Metadata()); verify(transport, times(2)).newStream(same(method), any(Metadata.class), same(callOptions)); assertEquals("testValue", testKey.get(newStreamContexts.poll())); assertNull(testKey.get()); }
@Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) { return interceptorChannel.newCall(method, callOptions); }
ManagedChannelImpl extends ManagedChannel implements
    InternalInstrumented<ChannelStats> { @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) { return interceptorChannel.newCall(method, callOptions); } }
ManagedChannelImpl extends ManagedChannel implements
    InternalInstrumented<ChannelStats> { @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) { return interceptorChannel.newCall(method, callOptions); } ManagedChannelImpl(
      AbstractManagedChannelImplBuilder<?> builder,
      ClientTransportFactory clientTransportFactory,
      BackoffPolicy.Provider backoffPolicyProvider,
      ObjectPool<? extends Executor> balancerRpcExecutorPool,
      Supplier<Stopwatch> stopwatchSupplier,
      List<ClientInterceptor> interceptors,
      final TimeProvider timeProvider); }
ManagedChannelImpl extends ManagedChannel implements
    InternalInstrumented<ChannelStats> { @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) { return interceptorChannel.newCall(method, callOptions); } ManagedChannelImpl(
      AbstractManagedChannelImplBuilder<?> builder,
      ClientTransportFactory clientTransportFactory,
      BackoffPolicy.Provider backoffPolicyProvider,
      ObjectPool<? extends Executor> balancerRpcExecutorPool,
      Supplier<Stopwatch> stopwatchSupplier,
      List<ClientInterceptor> interceptors,
      final TimeProvider timeProvider); @Override ListenableFuture<ChannelStats> getStats(); @Override InternalLogId getLogId(); @Override ManagedChannelImpl shutdown(); @Override ManagedChannelImpl shutdownNow(); @Override boolean isShutdown(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override boolean isTerminated(); @Override ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method,
      CallOptions callOptions); @Override String authority(); @Override ConnectivityState getState(boolean requestConnection); @Override void notifyWhenStateChanged(final ConnectivityState source, final Runnable callback); @Override void resetConnectBackoff(); @Override void enterIdle(); @Override String toString(); @Override Map<String, String> getLoadBalanceModeMap(); @Override void setLoadBalanceModeMap(Map<String, String> map); @Override NameResolver getNameResolver(); @Override LoadBalancer getLoadBalancer(); }
ManagedChannelImpl extends ManagedChannel implements
    InternalInstrumented<ChannelStats> { @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) { return interceptorChannel.newCall(method, callOptions); } ManagedChannelImpl(
      AbstractManagedChannelImplBuilder<?> builder,
      ClientTransportFactory clientTransportFactory,
      BackoffPolicy.Provider backoffPolicyProvider,
      ObjectPool<? extends Executor> balancerRpcExecutorPool,
      Supplier<Stopwatch> stopwatchSupplier,
      List<ClientInterceptor> interceptors,
      final TimeProvider timeProvider); @Override ListenableFuture<ChannelStats> getStats(); @Override InternalLogId getLogId(); @Override ManagedChannelImpl shutdown(); @Override ManagedChannelImpl shutdownNow(); @Override boolean isShutdown(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override boolean isTerminated(); @Override ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method,
      CallOptions callOptions); @Override String authority(); @Override ConnectivityState getState(boolean requestConnection); @Override void notifyWhenStateChanged(final ConnectivityState source, final Runnable callback); @Override void resetConnectBackoff(); @Override void enterIdle(); @Override String toString(); @Override Map<String, String> getLoadBalanceModeMap(); @Override void setLoadBalanceModeMap(Map<String, String> map); @Override NameResolver getNameResolver(); @Override LoadBalancer getLoadBalancer();  }