use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpPubSubAutoConfigurationTests method pullConfig_globalConfigurationSet.
@Test
void pullConfig_globalConfigurationSet() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.max-ack-extension-period=7", "spring.cloud.gcp.pubsub.subscriber.parallel-pull-count=12", "spring.cloud.gcp.pubsub.subscriber.pull-endpoint=my-endpoint").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(7L);
assertThat(gcpPubSubProperties.computeParallelPullCount("subscription-name", projectIdProvider.getProjectId())).isEqualTo(12);
assertThat(gcpPubSubProperties.computePullEndpoint("subscription-name", projectIdProvider.getProjectId())).isEqualTo("my-endpoint");
assertThat(gcpPubSubProperties.getSubscriber().getMaxAckExtensionPeriod()).isEqualTo(7L);
assertThat(gcpPubSubProperties.getSubscriber().getParallelPullCount()).isEqualTo(12);
assertThat(gcpPubSubProperties.getSubscriber().getPullEndpoint()).isEqualTo("my-endpoint");
});
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpPubSubAutoConfigurationTests method retrySettings_selectiveConfigurationSet.
@Test
void retrySettings_selectiveConfigurationSet() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscription.subscription-name.retry.total-timeout-seconds=1", "spring.cloud.gcp.pubsub.subscription.subscription-name.retry.initial-retry-delay-seconds=2", "spring.cloud.gcp.pubsub.subscription.subscription-name.retry.retry-delay-multiplier=3", "spring.cloud.gcp.pubsub.subscription.subscription-name.retry.max-retry-delay-seconds=4", "spring.cloud.gcp.pubsub.subscription.subscription-name.retry.max-attempts=5", "spring.cloud.gcp.pubsub.subscription.subscription-name.retry.jittered=true", "spring.cloud.gcp.pubsub.subscription.subscription-name.retry.initial-rpc-timeout-seconds=6", "spring.cloud.gcp.pubsub.subscription.subscription-name.retry.rpc-timeout-multiplier=7", "spring.cloud.gcp.pubsub.subscription.subscription-name.retry.max-rpc-timeout-seconds=8").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(1L);
assertThat(retrySettings.getInitialRetryDelaySeconds()).isEqualTo(2L);
assertThat(retrySettings.getRetryDelayMultiplier()).isEqualTo(3);
assertThat(retrySettings.getMaxRetryDelaySeconds()).isEqualTo(4);
assertThat(retrySettings.getMaxAttempts()).isEqualTo(5);
assertThat(retrySettings.getJittered()).isTrue();
assertThat(retrySettings.getInitialRpcTimeoutSeconds()).isEqualTo(6);
assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(7);
assertThat(retrySettings.getMaxRpcTimeoutSeconds()).isEqualTo(8);
assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).hasSize(1);
assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).containsKey(ProjectSubscriptionName.parse("projects/fake project/subscriptions/subscription-name"));
DefaultSubscriberFactory subscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
RetrySettings expectedRetrySettings = RetrySettings.newBuilder().setTotalTimeout(Duration.ofSeconds(1L)).setInitialRetryDelay(Duration.ofSeconds(2L)).setRetryDelayMultiplier(3).setMaxRetryDelay(Duration.ofSeconds(4L)).setMaxAttempts(5).setInitialRpcTimeout(Duration.ofSeconds(6L)).setRpcTimeoutMultiplier(7).setMaxRpcTimeout(Duration.ofSeconds(8L)).build();
assertThat(subscriberFactory.getRetrySettings("subscription-name")).isEqualTo(expectedRetrySettings);
assertThat(ctx.getBean("subscriberRetrySettings-projects/fake project/subscriptions/subscription-name", RetrySettings.class)).isEqualTo(expectedRetrySettings);
});
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpPubSubAutoConfigurationTests method flowControlSettings_globalAndSelectiveConfigurationSet_selectiveTakesPrecedence.
@Test
void flowControlSettings_globalAndSelectiveConfigurationSet_selectiveTakesPrecedence() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.flow-control.max-outstanding-element-Count=10", "spring.cloud.gcp.pubsub.subscriber.flow-control.max-outstanding-request-Bytes=10", "spring.cloud.gcp.pubsub.subscriber.flow-control.limit-exceeded-behavior=Block", "spring.cloud.gcp.pubsub.subscription.subscription-name.flow-control.max-outstanding-element-Count=11", "spring.cloud.gcp.pubsub.subscription.subscription-name.flow-control.max-outstanding-request-Bytes=12", "spring.cloud.gcp.pubsub.subscription.subscription-name.flow-control.limit-exceeded-behavior=Ignore").withUserConfiguration(TestConfig.class);
contextRunner.run(ctx -> {
GcpPubSubProperties gcpPubSubProperties = ctx.getBean(GcpPubSubProperties.class);
GcpProjectIdProvider projectIdProvider = ctx.getBean(GcpProjectIdProvider.class);
// Validate settings for subscribers that have subscription-specific flow control settings
// property set
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);
// Validate settings for subscribers that do not have subscription-specific flow control
// settings property set
PubSubConfiguration.FlowControl flowControlForOtherSubscriber = gcpPubSubProperties.computeSubscriberFlowControlSettings(ProjectSubscriptionName.of(projectIdProvider.getProjectId(), "other"));
assertThat(flowControlForOtherSubscriber.getMaxOutstandingElementCount()).isEqualTo(10L);
assertThat(flowControlForOtherSubscriber.getMaxOutstandingRequestBytes()).isEqualTo(10L);
assertThat(flowControlForOtherSubscriber.getLimitExceededBehavior()).isEqualTo(FlowController.LimitExceededBehavior.Block);
// Change in behavior: calculated properties don't get stored
assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).hasSize(1);
assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).containsKey(ProjectSubscriptionName.parse("projects/fake project/subscriptions/subscription-name"));
// Verify that beans for selective and global flow control settings are created.
DefaultSubscriberFactory subscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
FlowControlSettings expectedFlowControlForSubscriptionName = FlowControlSettings.newBuilder().setMaxOutstandingElementCount(11L).setMaxOutstandingRequestBytes(12L).setLimitExceededBehavior(FlowController.LimitExceededBehavior.Ignore).build();
FlowControlSettings expectedFlowControlForOther = FlowControlSettings.newBuilder().setMaxOutstandingElementCount(10L).setMaxOutstandingRequestBytes(10L).setLimitExceededBehavior(FlowController.LimitExceededBehavior.Block).build();
assertThat(subscriberFactory.getFlowControlSettings("subscription-name")).isEqualTo(expectedFlowControlForSubscriptionName);
assertThat(ctx.getBean("subscriberFlowControlSettings-projects/fake project/subscriptions/subscription-name", FlowControlSettings.class)).isEqualTo(expectedFlowControlForSubscriptionName);
assertThat(subscriberFactory.getFlowControlSettings("other")).isEqualTo(expectedFlowControlForOther);
assertThat(ctx.getBean("globalSubscriberFlowControlSettings", FlowControlSettings.class)).isEqualTo(expectedFlowControlForOther);
});
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpPubSubAutoConfigurationTests method flowControlSettings_subsetOfProperties_pickGlobalWhenSelectiveNotSpecified.
@Test
void flowControlSettings_subsetOfProperties_pickGlobalWhenSelectiveNotSpecified() {
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.subscription.subscription-name.flow-control.max-outstanding-request-Bytes=12", "spring.cloud.gcp.pubsub.subscription.subscription-name.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);
// Verify that beans for selective and global flow control settings are created.
DefaultSubscriberFactory subscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
FlowControlSettings expectedFlowControlForSubscriptionName = FlowControlSettings.newBuilder().setMaxOutstandingElementCount(11L).setMaxOutstandingRequestBytes(12L).setLimitExceededBehavior(FlowController.LimitExceededBehavior.Ignore).build();
FlowControlSettings expectedGlobalSettings = FlowControlSettings.newBuilder().setMaxOutstandingElementCount(11L).build();
assertThat(subscriberFactory.getFlowControlSettings("subscription-name")).isEqualTo(expectedFlowControlForSubscriptionName);
assertThat(ctx.getBean("subscriberFlowControlSettings-projects/fake project/subscriptions/subscription-name", FlowControlSettings.class)).isEqualTo(expectedFlowControlForSubscriptionName);
assertThat(ctx.getBean("globalSubscriberFlowControlSettings", FlowControlSettings.class)).isEqualTo(expectedGlobalSettings);
});
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpPubSubAutoConfigurationTests method flowControlSettings_multipleKeysForSameSubscription_firstOneUsed.
@Test
void flowControlSettings_multipleKeysForSameSubscription_firstOneUsed(CapturedOutput output) {
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscription.subscription-name.flow-control.max-outstanding-element-Count=100", "spring.cloud.gcp.pubsub.subscription.synthetic-sub-name.flow-control.max-outstanding-element-Count=200", "spring.cloud.gcp.pubsub.subscription.synthetic-sub-name.fully-qualified-name=projects/fake project/subscriptions/subscription-name").withUserConfiguration(TestConfig.class);
contextRunner.run(ctx -> {
GcpPubSubProperties gcpPubSubProperties = ctx.getBean(GcpPubSubProperties.class);
GcpProjectIdProvider projectIdProvider = ctx.getBean(GcpProjectIdProvider.class);
ProjectSubscriptionName projectSubscriptionName = ProjectSubscriptionName.of(projectIdProvider.getProjectId(), "subscription-name");
PubSubConfiguration.FlowControl flowControl = gcpPubSubProperties.getSubscriptionProperties(projectSubscriptionName).getFlowControl();
assertThat(flowControl.getMaxOutstandingElementCount()).isEqualTo(100L);
assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).hasSize(1).containsKey(projectSubscriptionName);
assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties().get(projectSubscriptionName).getFlowControl().getMaxOutstandingElementCount()).isEqualTo(100L);
assertThat(output).contains("Found multiple configurations for projects/fake project/subscriptions/subscription-name; ignoring properties with key synthetic-sub-name");
});
}
Aggregations