3939import com .google .api .gax .grpc .GaxGrpcProperties ;
4040import com .google .api .gax .grpc .GrpcCallContext ;
4141import com .google .api .gax .grpc .GrpcTransportChannel ;
42+ import com .google .api .gax .retrying .RetrySettings ;
4243import com .google .api .gax .rpc .FailedPreconditionException ;
4344import com .google .api .gax .rpc .FixedTransportChannelProvider ;
4445import com .google .api .gax .rpc .InstantiatingWatchdogProvider ;
110111import io .grpc .ManagedChannelBuilder ;
111112import io .grpc .Metadata ;
112113import io .grpc .Metadata .Key ;
114+ import io .grpc .MethodDescriptor ;
113115import io .grpc .Server ;
114116import io .grpc .ServerCall ;
115117import io .grpc .ServerCall .Listener ;
@@ -708,7 +710,14 @@ public void testCallContextPropagatedInMutationBatcher()
708710
709711 // Override the timeout
710712 GrpcCallContext clientCtx =
711- GrpcCallContext .createDefault ().withTimeout (Duration .ofMinutes (10 ));
713+ GrpcCallContext .createDefault ()
714+ .withTimeout (Duration .ofMinutes (10 ))
715+ .withRetrySettings (
716+ RetrySettings .newBuilder ()
717+ .setTotalTimeout (Duration .ofMinutes (10 ))
718+ .build ()
719+
720+ );
712721
713722 // Send a batch
714723 try (Batcher <RowMutationEntry , Void > batcher =
@@ -717,7 +726,7 @@ public void testCallContextPropagatedInMutationBatcher()
717726 }
718727
719728 // Ensure that the server got the overriden deadline
720- Context serverCtx = contextInterceptor .contexts . poll ( );
729+ Context serverCtx = contextInterceptor .pollContext ( BigtableGrpc . getMutateRowsMethod () );
721730 assertThat (serverCtx ).isNotNull ();
722731 assertThat (serverCtx .getDeadline ()).isAtLeast (Deadline .after (8 , TimeUnit .MINUTES ));
723732 }
@@ -738,7 +747,14 @@ public void testCallContextPropagatedInReadBatcher()
738747
739748 // Override the timeout
740749 GrpcCallContext clientCtx =
741- GrpcCallContext .createDefault ().withTimeout (Duration .ofMinutes (10 ));
750+ GrpcCallContext .createDefault ()
751+ .withTimeout (Duration .ofMinutes (10 ))
752+ .withRetrySettings (
753+ RetrySettings .newBuilder ()
754+ .setTotalTimeout (Duration .ofMinutes (10 ))
755+ .build ()
756+
757+ );
742758
743759 // Send a batch
744760 try (Batcher <ByteString , Row > batcher =
@@ -747,7 +763,7 @@ public void testCallContextPropagatedInReadBatcher()
747763 }
748764
749765 // Ensure that the server got the overriden deadline
750- Context serverCtx = contextInterceptor .contexts . poll ( );
766+ Context serverCtx = contextInterceptor .pollContext ( BigtableGrpc . getReadRowsMethod () );
751767 assertThat (serverCtx ).isNotNull ();
752768 assertThat (serverCtx .getDeadline ()).isAtLeast (Deadline .after (8 , TimeUnit .MINUTES ));
753769 }
@@ -970,16 +986,37 @@ public <ReqT, RespT> Listener<ReqT> interceptCall(
970986 }
971987
972988 private static class ContextInterceptor implements ServerInterceptor {
973- final BlockingQueue <Context > contexts = Queues .newLinkedBlockingDeque ();
989+ final BlockingQueue <MethodContext > contexts = Queues .newLinkedBlockingDeque ();
990+
991+ static class MethodContext {
992+ final MethodDescriptor <?,?> method ;
993+ final Context context ;
994+
995+ MethodContext (MethodDescriptor <?, ?> method , Context context ) {
996+ this .method = method ;
997+ this .context = context ;
998+ }
999+ }
9741000
9751001 @ Override
9761002 public <ReqT , RespT > Listener <ReqT > interceptCall (
9771003 ServerCall <ReqT , RespT > serverCall ,
9781004 Metadata metadata ,
9791005 ServerCallHandler <ReqT , RespT > serverCallHandler ) {
980- contexts .add (Context .current ());
1006+ contexts .add (new MethodContext ( serverCall . getMethodDescriptor (), Context .current () ));
9811007 return serverCallHandler .startCall (serverCall , metadata );
9821008 }
1009+
1010+ Context pollContext (MethodDescriptor <?, ?> method ) {
1011+ ContextInterceptor .MethodContext methodContext = contexts .poll ();
1012+ while (methodContext != null ) {
1013+ if (method .equals (methodContext .method )) {
1014+ return methodContext .context ;
1015+ }
1016+ methodContext = contexts .poll ();
1017+ }
1018+ return null ;
1019+ }
9831020 }
9841021
9851022 private static class FakeDataService extends BigtableGrpc .BigtableImplBase {
0 commit comments