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);
});
}
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);
});
}
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);
});
}
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);
});
}
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]
}
Aggregations