@Test public void testNoRpcTimeout() { parentFuture.timedAttemptSettings = parentFuture.timedAttemptSettings.toBuilder().setRpcTimeout(Duration.ZERO).build(); MutateRowsRequest request = MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).build(); innerCallable.response.add( MutateRowsResponse.newBuilder() .addEntries( MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)) .build()); MutateRowsAttemptCallable attemptCallable = new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes); attemptCallable.setExternalFuture(parentFuture); attemptCallable.call(); assertThat(innerCallable.lastContext.getTimeout()).isNull(); }
@Test public void testMergeWithNullTimeout() { Duration timeout = Duration.ofSeconds(10); GrpcCallContext baseContext = GrpcCallContext.createDefault().withTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getTimeout()).isEqualTo(timeout); GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withTimeout(null); Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeout()).isEqualTo(timeout); }
@Test public void testFutureCallContextPropagation() throws Exception { String opName = "testFutureCallContextPropagation"; Color resp = getColor(0.5f); Currency meta1 = Currency.getInstance("UAH"); Currency meta2 = Currency.getInstance("USD"); OperationSnapshot initialOperation = getOperation(opName, null, null, null, false); OperationSnapshot resultOperation = getOperation(opName, resp, null, meta2, true); UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation); LongRunningClient longRunningClient = Mockito.mock(LongRunningClient.class); @SuppressWarnings("unchecked") UnaryCallable<String, OperationSnapshot> getOpCallable = Mockito.mock(UnaryCallable.class); ArgumentCaptor<ApiCallContext> callContextCaptor = ArgumentCaptor.forClass(ApiCallContext.class); Mockito.when(longRunningClient.getOperationCallable()).thenReturn(getOpCallable); Mockito.when(getOpCallable.futureCall(Mockito.<String>any(), callContextCaptor.capture())) .thenReturn(ApiFutures.immediateFuture(resultOperation)); OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable( initialCallable, callSettings, initialContext, longRunningClient); ApiCallContext callContext = FakeCallContext.createDefault().withTimeout(Duration.ofMillis(10)); callable.futureCall(2, callContext).get(10, TimeUnit.SECONDS); assertThat(callContextCaptor.getValue().getTimeout()).isEqualTo(Duration.ofMillis(10)); }
@Test public void testRpcTimeoutIsNotErased() { Duration callerTimeout = Duration.ofMillis(10); ApiCallContext callerCallContext = FakeCallContext.createDefault().withTimeout(callerTimeout); AttemptCallable<String, String> callable = new AttemptCallable<>(mockInnerCallable, "fake-request", callerCallContext); callable.setExternalFuture(mockExternalFuture); callable.call(); assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(callerTimeout); } }
@Test public void testMergeWithTimeout() { Duration timeout = Duration.ofSeconds(19); GrpcCallContext ctx1 = GrpcCallContext.createDefault(); GrpcCallContext ctx2 = GrpcCallContext.createDefault().withTimeout(timeout); Truth.assertThat(ctx1.merge(ctx2).getTimeout()).isEqualTo(timeout); }
@Test public void testRpcTimeout() { AttemptCallable<String, String> callable = new AttemptCallable<>(mockInnerCallable, "fake-request", FakeCallContext.createDefault()); callable.setExternalFuture(mockExternalFuture); // Make sure that the rpc timeout is set Duration timeout = Duration.ofSeconds(10); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build(); callable.call(); assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(timeout); // Make sure that subsequent attempts can extend the time out Duration longerTimeout = Duration.ofSeconds(20); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(longerTimeout).build(); callable.call(); assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(longerTimeout); }
@Test public void testRpcTimeout() { CheckingAttemptCallable<String, String> callable = new CheckingAttemptCallable<>(mockInnerCallable, FakeCallContext.createDefault()); callable.setExternalFuture(mockExternalFuture); // Make sure that the rpc timeout is set Duration timeout = Duration.ofSeconds(10); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build(); callable.call(); assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(timeout); // Make sure that subsequent attempts can extend the time out Duration longerTimeout = Duration.ofSeconds(20); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(longerTimeout).build(); callable.call(); assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(longerTimeout); } }
actualTimeouts.add(callContext.getTimeout());