use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class OperationCallableImplTest method testCancelOperation.
@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();
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class FixedTransportChannelProviderTest method testBasic.
@Test
public void testBasic() throws Exception {
TransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel());
FixedTransportChannelProvider provider = FixedTransportChannelProvider.create(transportChannel);
Truth.assertThat(provider.shouldAutoClose()).isFalse();
Truth.assertThat(provider.needsExecutor()).isFalse();
Exception thrownException = null;
try {
provider.withExecutor(new ScheduledThreadPoolExecutor(0));
} catch (Exception e) {
thrownException = e;
}
Truth.assertThat(thrownException).isInstanceOf(UnsupportedOperationException.class);
Truth.assertThat(provider.needsHeaders()).isFalse();
thrownException = null;
try {
provider.withHeaders(Collections.<String, String>emptyMap());
} catch (Exception e) {
thrownException = e;
}
Truth.assertThat(thrownException).isInstanceOf(UnsupportedOperationException.class);
Truth.assertThat(provider.needsEndpoint()).isFalse();
thrownException = null;
try {
provider.withEndpoint("localhost:8080");
} catch (Exception e) {
thrownException = e;
}
Truth.assertThat(thrownException).isInstanceOf(UnsupportedOperationException.class);
Truth.assertThat(provider.needsCredentials()).isFalse();
thrownException = null;
try {
provider.withCredentials(ComputeEngineCredentials.create());
} catch (Exception e) {
thrownException = e;
}
Truth.assertThat(thrownException).isInstanceOf(UnsupportedOperationException.class);
Truth.assertThat(provider.acceptsPoolSize()).isFalse();
thrownException = null;
try {
provider.withPoolSize(1);
} catch (Exception e) {
thrownException = e;
}
Truth.assertThat(thrownException).isInstanceOf(UnsupportedOperationException.class);
Truth.assertThat(provider.getTransportChannel()).isSameInstanceAs(transportChannel);
Truth.assertThat(provider.getTransportName()).isEqualTo(FakeTransportChannel.getFakeTransportName());
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class ServerStreamingCallableTest method testServerStreamingCallWithContext.
@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()).isSameInstanceAs(observer);
Truth.assertThat(stashCallable.getActualRequest()).isSameInstanceAs(request);
FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
Truth.assertThat(actualContext.getChannel()).isSameInstanceAs(channel);
Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class ServerStreamingCallableTest method testAllElementCallWithContext.
@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()).isSameInstanceAs(request);
FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
Truth.assertThat(actualContext.getChannel()).isSameInstanceAs(channel);
Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class ServerStreamingCallableTest method testFirstElementCallWithContext.
@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()).isSameInstanceAs(request);
FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
Truth.assertThat(actualContext.getChannel()).isSameInstanceAs(channel);
Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
Aggregations