use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpPubSubAutoConfigurationTests method flowControlSettings_globalAndDifferentSelectiveConfigurationSet_pickGlobal.
@Test
void flowControlSettings_globalAndDifferentSelectiveConfigurationSet_pickGlobal() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.flow-control.max-outstanding-element-Count=11", "spring.cloud.gcp.pubsub.subscriber.flow-control.max-outstanding-request-Bytes=12", "spring.cloud.gcp.pubsub.subscriber.flow-control.limit-exceeded-behavior=Ignore", "spring.cloud.gcp.pubsub.subscription.subscription-name.parallel-pull-count=2").withUserConfiguration(TestConfig.class);
contextRunner.run(ctx -> {
GcpPubSubProperties gcpPubSubProperties = ctx.getBean(GcpPubSubProperties.class);
GcpProjectIdProvider projectIdProvider = ctx.getBean(GcpProjectIdProvider.class);
PubSubConfiguration.FlowControl flowControl = gcpPubSubProperties.computeSubscriberFlowControlSettings(ProjectSubscriptionName.of(projectIdProvider.getProjectId(), "subscription-name"));
assertThat(flowControl.getMaxOutstandingElementCount()).isEqualTo(11L);
assertThat(flowControl.getMaxOutstandingRequestBytes()).isEqualTo(12L);
assertThat(flowControl.getLimitExceededBehavior()).isEqualTo(FlowController.LimitExceededBehavior.Ignore);
assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).hasSize(1);
assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).containsKey(ProjectSubscriptionName.parse("projects/fake project/subscriptions/subscription-name"));
// Verify that bean for global flow control settings is created.
DefaultSubscriberFactory subscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
FlowControlSettings expectedFlowControlForSubscriptionName = FlowControlSettings.newBuilder().setMaxOutstandingElementCount(11L).setMaxOutstandingRequestBytes(12L).setLimitExceededBehavior(FlowController.LimitExceededBehavior.Ignore).build();
assertThat(subscriberFactory.getFlowControlSettings("subscription-name")).isEqualTo(expectedFlowControlForSubscriptionName);
assertThat(ctx.getBean("globalSubscriberFlowControlSettings", FlowControlSettings.class)).isEqualTo(expectedFlowControlForSubscriptionName);
});
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpPubSubAutoConfigurationTests method retrySettings_globalAndDifferentSelectiveConfigurationSet_pickGlobal.
@Test
void retrySettings_globalAndDifferentSelectiveConfigurationSet_pickGlobal() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.retry.total-timeout-seconds=10", "spring.cloud.gcp.pubsub.subscriber.retry.initial-retry-delay-seconds=10", "spring.cloud.gcp.pubsub.subscriber.retry.retry-delay-multiplier=10", "spring.cloud.gcp.pubsub.subscriber.retry.max-retry-delay-seconds=10", "spring.cloud.gcp.pubsub.subscriber.retry.max-attempts=10", "spring.cloud.gcp.pubsub.subscriber.retry.initial-rpc-timeout-seconds=10", "spring.cloud.gcp.pubsub.subscriber.retry.rpc-timeout-multiplier=10", "spring.cloud.gcp.pubsub.subscriber.retry.max-rpc-timeout-seconds=10", "spring.cloud.gcp.pubsub.subscription.subscription-name.executor-threads=2").withUserConfiguration(TestConfig.class);
contextRunner.run(ctx -> {
GcpPubSubProperties gcpPubSubProperties = ctx.getBean(GcpPubSubProperties.class);
GcpProjectIdProvider projectIdProvider = ctx.getBean(GcpProjectIdProvider.class);
PubSubConfiguration.Retry retrySettings = gcpPubSubProperties.computeSubscriberRetrySettings("subscription-name", projectIdProvider.getProjectId());
assertThat(retrySettings.getTotalTimeoutSeconds()).isEqualTo(10L);
assertThat(retrySettings.getInitialRetryDelaySeconds()).isEqualTo(10L);
assertThat(retrySettings.getRetryDelayMultiplier()).isEqualTo(10);
assertThat(retrySettings.getMaxRetryDelaySeconds()).isEqualTo(10);
assertThat(retrySettings.getMaxAttempts()).isEqualTo(10);
assertThat(retrySettings.getInitialRpcTimeoutSeconds()).isEqualTo(10);
assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(10);
assertThat(retrySettings.getMaxRpcTimeoutSeconds()).isEqualTo(10);
// Verify that bean for global retry settings is created.
RetrySettings expectedRetrySettings = RetrySettings.newBuilder().setTotalTimeout(Duration.ofSeconds(10L)).setInitialRetryDelay(Duration.ofSeconds(10L)).setRetryDelayMultiplier(10).setMaxRetryDelay(Duration.ofSeconds(10L)).setMaxAttempts(10).setInitialRpcTimeout(Duration.ofSeconds(10L)).setRpcTimeoutMultiplier(10).setMaxRpcTimeout(Duration.ofSeconds(10)).build();
DefaultSubscriberFactory subscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
assertThat(subscriberFactory.getRetrySettings("subscription-name")).isEqualTo(expectedRetrySettings);
assertThat(ctx.getBean("globalSubscriberRetrySettings", RetrySettings.class)).isEqualTo(expectedRetrySettings);
});
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpPubSubAutoConfigurationTests method retryableCodes_empty.
@Test
void retryableCodes_empty() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withUserConfiguration(TestConfig.class).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.retryableCodes=");
contextRunner.run(ctx -> {
GcpPubSubProperties properties = ctx.getBean(GcpPubSubProperties.class);
GcpProjectIdProvider projectIdProvider = ctx.getBean(GcpProjectIdProvider.class);
DefaultSubscriberFactory defaultSubscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
assertThat(properties.getSubscriber().getRetryableCodes()).isEqualTo(new Code[] {});
assertThat(properties.computeRetryableCodes("subscription-name", projectIdProvider.getProjectId())).isEqualTo(new Code[] {});
assertThat(defaultSubscriberFactory.getRetryableCodes("subscription-name")).isEqualTo(new Code[] {});
});
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpPubSubAutoConfigurationTests method retryableCodes_Internal.
@Test
void retryableCodes_Internal() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withUserConfiguration(TestConfig.class).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.retryableCodes=INTERNAL");
contextRunner.run(ctx -> {
GcpPubSubProperties properties = ctx.getBean(GcpPubSubProperties.class);
GcpProjectIdProvider projectIdProvider = ctx.getBean(GcpProjectIdProvider.class);
DefaultSubscriberFactory defaultSubscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
assertThat(properties.getSubscriber().getRetryableCodes()).isEqualTo(new Code[] { Code.INTERNAL });
assertThat(properties.computeRetryableCodes("subscription-name", projectIdProvider.getProjectId())).isEqualTo(new Code[] { Code.INTERNAL });
assertThat(defaultSubscriberFactory.getRetryableCodes("subscription-name")).isEqualTo(new Code[] { Code.INTERNAL });
});
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpPubSubAutoConfigurationTests method pullConfig_globalAndDifferentSelectiveConfigurationSet_pickGlobal.
@Test
void pullConfig_globalAndDifferentSelectiveConfigurationSet_pickGlobal() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.max-ack-extension-period=5", "spring.cloud.gcp.pubsub.subscriber.parallel-pull-count=10", "spring.cloud.gcp.pubsub.subscriber.pull-endpoint=other-endpoint", "spring.cloud.gcp.pubsub.subscription.subscription-name.executor-threads=4").withUserConfiguration(TestConfig.class);
contextRunner.run(ctx -> {
GcpPubSubProperties gcpPubSubProperties = ctx.getBean(GcpPubSubProperties.class);
GcpProjectIdProvider projectIdProvider = ctx.getBean(GcpProjectIdProvider.class);
assertThat(gcpPubSubProperties.computeMaxAckExtensionPeriod("subscription-name", projectIdProvider.getProjectId())).isEqualTo(5);
assertThat(gcpPubSubProperties.computeParallelPullCount("subscription-name", projectIdProvider.getProjectId())).isEqualTo(10);
assertThat(gcpPubSubProperties.computePullEndpoint("subscription-name", projectIdProvider.getProjectId())).isEqualTo("other-endpoint");
assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).containsKey(ProjectSubscriptionName.parse("projects/fake project/subscriptions/subscription-name"));
});
}
Aggregations