Search in sources :

Example 21 with FakeChannel

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();
}
Also used : Color(java.awt.Color) Currency(java.util.Currency) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 22 with FakeChannel

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());
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) FakeTransportChannel(com.google.api.gax.rpc.testing.FakeTransportChannel) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 23 with FakeChannel

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);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) ServerStreamingStashCallable(com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 24 with FakeChannel

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);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) ServerStreamingStashCallable(com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 25 with FakeChannel

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);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) ServerStreamingStashCallable(com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Aggregations

FakeChannel (com.google.api.gax.rpc.testing.FakeChannel)28 Test (org.junit.Test)24 FakeTransportChannel (com.google.api.gax.rpc.testing.FakeTransportChannel)12 Credentials (com.google.auth.Credentials)12 FakeClientSettings (com.google.api.gax.rpc.testing.FakeClientSettings)11 FakeCallContext (com.google.api.gax.rpc.testing.FakeCallContext)9 BackgroundResource (com.google.api.gax.core.BackgroundResource)5 ServerStreamingStashCallable (com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable)4 OperationStashCallable (com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable)3 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)3 List (java.util.List)3 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)3 Before (org.junit.Before)3 ApiClock (com.google.api.core.ApiClock)2 CredentialsProvider (com.google.api.gax.core.CredentialsProvider)2 ExecutorProvider (com.google.api.gax.core.ExecutorProvider)2 FakeApiClock (com.google.api.gax.core.FakeApiClock)2 FixedCredentialsProvider (com.google.api.gax.core.FixedCredentialsProvider)2 FixedExecutorProvider (com.google.api.gax.core.FixedExecutorProvider)2 RetrySettings (com.google.api.gax.retrying.RetrySettings)2