@Test
public void testAffinity() throws IOException {

  MethodDescriptor<Color, Money> descriptor = FakeServiceGrpc.METHOD_RECOGNIZE;
  @SuppressWarnings("unchecked")
  ClientCall<Color, Money> clientCall0 = Mockito.mock(ClientCall.class);
  @SuppressWarnings("unchecked")
  ClientCall<Color, Money> clientCall1 = Mockito.mock(ClientCall.class);
  ManagedChannel channel0 = Mockito.mock(ManagedChannel.class);
  ManagedChannel channel1 = Mockito.mock(ManagedChannel.class);
  Mockito.when(channel0.newCall(Mockito.eq(descriptor), Mockito.<CallOptions>any()))
      .thenReturn(clientCall0);
  Mockito.when(channel1.newCall(Mockito.eq(descriptor), Mockito.<CallOptions>any()))
      .thenReturn(clientCall1);
  Channel pool = ChannelPool.create(2, new FakeChannelFactory(Arrays.asList(channel0, channel1)));
  GrpcCallContext context = GrpcCallContext.createDefault().withChannel(pool);
  ClientCall<Color, Money> gotCallA =
      GrpcClientCalls.newCall(descriptor, context.withChannelAffinity(0));
  ClientCall<Color, Money> gotCallB =
      GrpcClientCalls.newCall(descriptor, context.withChannelAffinity(0));
  ClientCall<Color, Money> gotCallC =
      GrpcClientCalls.newCall(descriptor, context.withChannelAffinity(1));
  assertThat(gotCallA).isSameInstanceAs(gotCallB);
  assertThat(gotCallA).isNotSameInstanceAs(gotCallC);
}