@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 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 callCancelWithContext() 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); callable.cancel(operationFuture.getName(), context).get(); Truth.assertThat(stashCallable.wasCancelCalled()).isTrue(); FakeCallContext actualContext = (FakeCallContext) stashCallable.getCancelContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); }
@Test public void call() throws Exception { ApiCallContext defaultCallContext = FakeCallContext.createDefault(); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(defaultCallContext); String response = callable.call(1); Truth.assertThat(response).isEqualTo("1"); Truth.assertThat(stashCallable.getContext()).isSameAs(defaultCallContext); }
@Test public void callCancel() throws Exception { ApiCallContext defaultCallContext = FakeCallContext.createDefault(); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(defaultCallContext); OperationFuture<String, Long> operationFuture = callable.futureCall(45); callable.cancel(operationFuture.getName()).get(); Truth.assertThat(stashCallable.wasCancelCalled()).isTrue(); Truth.assertThat(stashCallable.getCancelContext()).isSameAs(defaultCallContext); }
@Test public void callResume() throws Exception { ApiCallContext defaultCallContext = FakeCallContext.createDefault(); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(defaultCallContext); OperationFuture<String, Long> operationFuture = callable.futureCall(45); String response = callable.resumeFutureCall(operationFuture.getName()).get(); Truth.assertThat(response).isEqualTo("45"); Truth.assertThat(stashCallable.getResumeContext()).isSameAs(defaultCallContext); }