Search in sources :

Example 1 with OperationStashCallable

use of com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable in project gax-java by googleapis.

the class OperationCallableImplTest method callResume.

@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()).isSameInstanceAs(defaultCallContext);
}
Also used : OperationStashCallable(com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable) Test(org.junit.Test)

Example 2 with OperationStashCallable

use of com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable in project gax-java by googleapis.

the class OperationCallableImplTest method callResumeWithContext.

@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()).isSameInstanceAs(channel);
    Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) OperationStashCallable(com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 3 with OperationStashCallable

use of com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable in project gax-java by googleapis.

the class OperationCallableImplTest method callWithContext.

@Test
public void callWithContext() {
    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()).isSameInstanceAs(channel);
    Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) OperationStashCallable(com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 4 with OperationStashCallable

use of com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable in project gax-java by googleapis.

the class OperationCallableImplTest method callCancelWithContext.

@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()).isSameInstanceAs(channel);
    Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) OperationStashCallable(com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 5 with OperationStashCallable

use of com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable in project gax-java by googleapis.

the class OperationCallableImplTest method call.

@Test
public void call() {
    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()).isSameInstanceAs(defaultCallContext);
}
Also used : OperationStashCallable(com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable) Test(org.junit.Test)

Aggregations

OperationStashCallable (com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable)6 Test (org.junit.Test)6 FakeCallContext (com.google.api.gax.rpc.testing.FakeCallContext)3 FakeChannel (com.google.api.gax.rpc.testing.FakeChannel)3 Credentials (com.google.auth.Credentials)3