Search in sources :

Example 1 with TransportChannelProvider

use of com.google.api.gax.rpc.TransportChannelProvider in project spring-cloud-gcp by spring-cloud.

the class GcpPubSubAutoConfigurationTests method maxInboundMessageSize_default.

@Test
public void maxInboundMessageSize_default() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withUserConfiguration(TestConfig.class);
    contextRunner.run(ctx -> {
        TransportChannelProvider subscriberTcp = ctx.getBean("subscriberTransportChannelProvider", TransportChannelProvider.class);
        assertThat(FieldUtils.readField(subscriberTcp, "maxInboundMessageSize", true)).isEqualTo(20 << 20);
        TransportChannelProvider publisherTcp = ctx.getBean("publisherTransportChannelProvider", TransportChannelProvider.class);
        assertThat(FieldUtils.readField(publisherTcp, "maxInboundMessageSize", true)).isEqualTo(Integer.MAX_VALUE);
    });
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) Test(org.junit.Test)

Example 2 with TransportChannelProvider

use of com.google.api.gax.rpc.TransportChannelProvider in project spring-cloud-gcp by spring-cloud.

the class GcpPubSubAutoConfigurationTests method keepAliveValue_default.

@Test
public void keepAliveValue_default() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withUserConfiguration(TestConfig.class);
    contextRunner.run(ctx -> {
        GcpPubSubProperties props = ctx.getBean(GcpPubSubProperties.class);
        assertThat(props.getKeepAliveIntervalMinutes()).isEqualTo(5);
        TransportChannelProvider subscriberTcp = ctx.getBean("subscriberTransportChannelProvider", TransportChannelProvider.class);
        TransportChannelProvider publisherTcp = ctx.getBean("publisherTransportChannelProvider", TransportChannelProvider.class);
        assertThat(((InstantiatingGrpcChannelProvider) subscriberTcp).getKeepAliveTime().toMinutes()).isEqualTo(5);
        assertThat(((InstantiatingGrpcChannelProvider) publisherTcp).getKeepAliveTime().toMinutes()).isEqualTo(5);
    });
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) Test(org.junit.Test)

Example 3 with TransportChannelProvider

use of com.google.api.gax.rpc.TransportChannelProvider in project spring-cloud-gcp by spring-cloud.

the class GcpPubSubAutoConfigurationTests method keepAliveValue_custom.

@Test
public void keepAliveValue_custom() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withUserConfiguration(TestConfig.class).withPropertyValues("spring.cloud.gcp.pubsub.keepAliveIntervalMinutes=2");
    contextRunner.run(ctx -> {
        GcpPubSubProperties props = ctx.getBean(GcpPubSubProperties.class);
        assertThat(props.getKeepAliveIntervalMinutes()).isEqualTo(2);
        TransportChannelProvider subscriberTcp = ctx.getBean("subscriberTransportChannelProvider", TransportChannelProvider.class);
        TransportChannelProvider publisherTcp = ctx.getBean("publisherTransportChannelProvider", TransportChannelProvider.class);
        assertThat(((InstantiatingGrpcChannelProvider) subscriberTcp).getKeepAliveTime().toMinutes()).isEqualTo(2);
        assertThat(((InstantiatingGrpcChannelProvider) publisherTcp).getKeepAliveTime().toMinutes()).isEqualTo(2);
    });
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) Test(org.junit.Test)

Example 4 with TransportChannelProvider

use of com.google.api.gax.rpc.TransportChannelProvider in project spring-cloud-gcp by spring-cloud.

the class GcpPubSubEmulatorConfigurationTests method testEmulatorConfig.

@Test
public void testEmulatorConfig() {
    this.contextRunner.run(context -> {
        CredentialsProvider credentialsProvider = context.getBean(CredentialsProvider.class);
        Assert.assertTrue("CredentialsProvider is not correct", credentialsProvider instanceof NoCredentialsProvider);
        TransportChannelProvider transportChannelProvider = context.getBean(TransportChannelProvider.class);
        Assert.assertTrue("TransportChannelProvider is not correct", transportChannelProvider instanceof FixedTransportChannelProvider);
    });
}
Also used : NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) FixedTransportChannelProvider(com.google.api.gax.rpc.FixedTransportChannelProvider) CredentialsProvider(com.google.api.gax.core.CredentialsProvider) NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) FixedTransportChannelProvider(com.google.api.gax.rpc.FixedTransportChannelProvider) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) Test(org.junit.Test)

Example 5 with TransportChannelProvider

use of com.google.api.gax.rpc.TransportChannelProvider in project google-cloud-java by GoogleCloudPlatform.

the class UsePubSubEmulatorSnippet method main.

public static void main(String... args) throws IOException {
    // [START pubsub_use_emulator]
    String hostport = System.getenv("PUBSUB_EMULATOR_HOST");
    ManagedChannel channel = ManagedChannelBuilder.forTarget(hostport).usePlaintext().build();
    try {
        TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
        CredentialsProvider credentialsProvider = NoCredentialsProvider.create();
        // Set the channel and credentials provider when creating a `TopicAdminClient`.
        // Similarly for SubscriptionAdminClient
        TopicAdminClient topicClient = TopicAdminClient.create(TopicAdminSettings.newBuilder().setTransportChannelProvider(channelProvider).setCredentialsProvider(credentialsProvider).build());
        TopicName topicName = TopicName.of("my-project-id", "my-topic-id");
        // Set the channel and credentials provider when creating a `Publisher`.
        // Similarly for Subscriber
        Publisher publisher = Publisher.newBuilder(topicName).setChannelProvider(channelProvider).setCredentialsProvider(credentialsProvider).build();
    } finally {
        channel.shutdown();
    }
// [END pubsub_use_emulator]
}
Also used : TopicAdminClient(com.google.cloud.pubsub.v1.TopicAdminClient) ManagedChannel(io.grpc.ManagedChannel) CredentialsProvider(com.google.api.gax.core.CredentialsProvider) NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) Publisher(com.google.cloud.pubsub.v1.Publisher) FixedTransportChannelProvider(com.google.api.gax.rpc.FixedTransportChannelProvider) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) TopicName(com.google.pubsub.v1.TopicName)

Aggregations

TransportChannelProvider (com.google.api.gax.rpc.TransportChannelProvider)6 Test (org.junit.Test)5 CredentialsProvider (com.google.api.gax.core.CredentialsProvider)3 NoCredentialsProvider (com.google.api.gax.core.NoCredentialsProvider)3 FixedTransportChannelProvider (com.google.api.gax.rpc.FixedTransportChannelProvider)3 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)3 Publisher (com.google.cloud.pubsub.v1.Publisher)1 TopicAdminClient (com.google.cloud.pubsub.v1.TopicAdminClient)1 TopicAdminSettings (com.google.cloud.pubsub.v1.TopicAdminSettings)1 TopicName (com.google.pubsub.v1.TopicName)1 ManagedChannel (io.grpc.ManagedChannel)1