@Override public void sendsTimeoutHeader() { long configuredTimeoutMinutes = 100; TestServiceGrpc.TestServiceBlockingStub stub = blockingStub.withDeadlineAfter(configuredTimeoutMinutes, TimeUnit.MINUTES); stub.emptyCall(EMPTY); long transferredTimeoutMinutes = TimeUnit.MILLISECONDS.toMinutes( ctxCapture.get().requestTimeoutMillis()); Assert.assertTrue( "configuredTimeoutMinutes=" + configuredTimeoutMinutes + ", transferredTimeoutMinutes=" + transferredTimeoutMinutes, configuredTimeoutMinutes - transferredTimeoutMinutes >= 0 && configuredTimeoutMinutes - transferredTimeoutMinutes <= 1); }
@Test public void testConfigureDeadline() { Deadline deadline = Deadline.after(2, NANOSECONDS); // Create a default stub TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel); assertNull(stub.getCallOptions().getDeadline()); // Reconfigure it TestServiceGrpc.TestServiceBlockingStub reconfiguredStub = stub.withDeadline(deadline); // New altered config assertEquals(deadline, reconfiguredStub.getCallOptions().getDeadline()); // Default config unchanged assertNull(stub.getCallOptions().getDeadline()); }
@Test public void testStubCallOptionsPopulatedToNewCall() { TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel); CallOptions options1 = stub.getCallOptions(); SimpleRequest request = SimpleRequest.getDefaultInstance(); stub.unaryCall(request, responseObserver); verify(channel).newCall(same(TestServiceGrpc.getUnaryCallMethod()), same(options1)); stub = stub.withDeadlineAfter(2, NANOSECONDS); CallOptions options2 = stub.getCallOptions(); assertNotSame(options1, options2); stub.unaryCall(request, responseObserver); verify(channel).newCall(same(TestServiceGrpc.getUnaryCallMethod()), same(options2)); }