@Test public void testWithTransportChannelWrongType() { thrown.expect(IllegalArgumentException.class); FakeChannel channel = new FakeChannel(); HttpJsonCallContext.createDefault().withTransportChannel(FakeTransportChannel.create(channel)); }
@Test public void testWithTransportChannelWrongType() { thrown.expect(IllegalArgumentException.class); FakeChannel channel = new FakeChannel(); GrpcCallContext.createDefault().withTransportChannel(FakeTransportChannel.create(channel)); }
@Test public void testCancelOperation() throws Exception { String opName = "testCancelOperation"; LongRunningClient longRunningClient = mockCancelOperation(StatusCode.Code.OK); ClientContext mockContext = getClientContext(new FakeChannel(), executor); OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable( getUnexpectedStartCallable(), callSettings, mockContext, longRunningClient); ApiFuture<Void> future = callable.cancel(opName); assertThat(future.get()).isNull(); }
@Before public void setUp() { batchingExecutor = new ScheduledThreadPoolExecutor(1); clientContext = ClientContext.newBuilder() .setExecutor(batchingExecutor) .setDefaultCallContext(FakeCallContext.createDefault()) .setTransportChannel(FakeTransportChannel.create(new FakeChannel())) .build(); }
@Test public void callWithContext() throws Exception { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); StashCallable<Integer, Integer> stashCallable = new StashCallable<>(1); UnaryCallable<Integer, Integer> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault()); Integer response = callable.call(2, context); Truth.assertThat(response).isEqualTo(Integer.valueOf(1)); FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); } }
@Test public void callWithContext() throws Exception { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault()); String response = callable.call(2, context); Truth.assertThat(response).isEqualTo("2"); FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); }
@Test public void testBasic() throws Exception { TransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel()); FixedTransportChannelProvider provider = FixedTransportChannelProvider.create(transportChannel);
@Test @SuppressWarnings("unchecked") public void testClientStreamingCallWithContext() { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); ClientStreamingStashCallable<Integer, Integer> stashCallable = new ClientStreamingStashCallable<>(); ApiStreamObserver<Integer> observer = Mockito.mock(ApiStreamObserver.class); ClientStreamingCallable<Integer, Integer> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault()); callable.clientStreamingCall(observer, context); Truth.assertThat(stashCallable.getActualObserver()).isSameAs(observer); FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); } }
@Test public void testServerStreamingCallWithContext() { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>(); ServerStreamingCallable<Integer, Integer> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault()); @SuppressWarnings("unchecked") ResponseObserver<Integer> observer = Mockito.mock(StateCheckingResponseObserver.class); Integer request = 1; callable.call(request, observer, context); Truth.assertThat(stashCallable.getActualObserver()).isSameAs(observer); Truth.assertThat(stashCallable.getActualRequest()).isSameAs(request); FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); }
@Test public void testResumeFutureCall() throws Exception { String opName = "testResumeFutureCall"; Color resp = getColor(0.5f); Currency meta = Currency.getInstance("UAH"); OperationSnapshot resultOperation = getOperation(opName, resp, null, meta, true); LongRunningClient longRunningClient = mockGetOperation(StatusCode.Code.OK, resultOperation); ClientContext mockContext = getClientContext(new FakeChannel(), executor); OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable( getUnexpectedStartCallable(), callSettings, mockContext, longRunningClient); OperationFuture<Color, Currency> future = callable.resumeFutureCall(opName); assertFutureSuccessMetaSuccess(opName, future, resp, meta); assertThat(executor.getIterationsCount()).isEqualTo(0); }
@Test public void callResumeWithContext() throws Exception { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault()); OperationFuture<String, Long> operationFuture = callable.futureCall(45); String response = callable.resumeFutureCall(operationFuture.getName(), context).get(); Truth.assertThat(response).isEqualTo("45"); FakeCallContext actualContext = (FakeCallContext) stashCallable.getResumeContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); }
@Test public void testIteratedServerStreamingCallWithContext() { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>(); ServerStreamingCallable<Integer, Integer> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault()); Integer request = 1; callable.call(request, context); Truth.assertThat(stashCallable.getActualRequest()).isSameAs(request); FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); }
@Before public void setUp() { clientContext = ClientContext.newBuilder() .setDefaultCallContext(FakeCallContext.createDefault()) .setTransportChannel(FakeTransportChannel.create(new FakeChannel())) .build(); }
@Before public void setUp() { clientContext = ClientContext.newBuilder() .setDefaultCallContext(FakeCallContext.createDefault()) .setTransportChannel(FakeTransportChannel.create(new FakeChannel())) .build(); }
@Before public void setUp() { clientContext = ClientContext.newBuilder() .setDefaultCallContext(FakeCallContext.createDefault()) .setTransportChannel(FakeTransportChannel.create(new FakeChannel())) .build(); }
@Before public void setUp() { clientContext = ClientContext.newBuilder() .setDefaultCallContext(FakeCallContext.createDefault()) .setTransportChannel(FakeTransportChannel.create(new FakeChannel())) .build(); }
@Test public void testFirstElementCallWithContext() { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>(); UnaryCallable<Integer, Integer> firstCallable = stashCallable.first().withDefaultCallContext(FakeCallContext.createDefault()); Integer request = 1; firstCallable.call(request, context); Truth.assertThat(stashCallable.getActualRequest()).isSameAs(request); FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); }
@Test public void testAllElementCallWithContext() { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>(); UnaryCallable<Integer, List<Integer>> firstCallable = stashCallable.all().withDefaultCallContext(FakeCallContext.createDefault()); Integer request = 1; firstCallable.call(request, context); Truth.assertThat(stashCallable.getActualRequest()).isSameAs(request); FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); } }
@Before public void resetClock() { fakeClock = new FakeApiClock(System.nanoTime()); executor = RecordingScheduler.create(fakeClock); clientContext = ClientContext.newBuilder() .setExecutor(executor) .setClock(fakeClock) .setDefaultCallContext(FakeCallContext.createDefault()) .setTransportChannel(FakeTransportChannel.create(new FakeChannel())) .build(); }
ExecutorProvider executorProvider = new FakeExecutorProvider(executor, shouldAutoClose); Map<String, String> headers = ImmutableMap.of("k1", "v1", "k2", "v2"); FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel()); FakeTransportProvider transportProvider = new FakeTransportProvider(