Search in sources :

Example 16 with GcpProjectIdProvider

use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.

the class GcpPubSubAutoConfigurationTests method retrySettings_globalConfigurationSet.

@Test
void retrySettings_globalConfigurationSet() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.retry.total-timeout-seconds=1", "spring.cloud.gcp.pubsub.subscriber.retry.initial-retry-delay-seconds=2", "spring.cloud.gcp.pubsub.subscriber.retry.retry-delay-multiplier=3", "spring.cloud.gcp.pubsub.subscriber.retry.max-retry-delay-seconds=4", "spring.cloud.gcp.pubsub.subscriber.retry.max-attempts=5", "spring.cloud.gcp.pubsub.subscriber.retry.jittered=true", "spring.cloud.gcp.pubsub.subscriber.retry.initial-rpc-timeout-seconds=6", "spring.cloud.gcp.pubsub.subscriber.retry.rpc-timeout-multiplier=7", "spring.cloud.gcp.pubsub.subscriber.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);
        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(8)).build();
        assertThat(subscriberFactory.getRetrySettings("name")).isEqualTo(expectedRetrySettings);
        assertThat(ctx.getBean("globalSubscriberRetrySettings", RetrySettings.class)).isEqualTo(expectedRetrySettings);
    });
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) DefaultSubscriberFactory(com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) PubSubConfiguration(com.google.cloud.spring.pubsub.core.PubSubConfiguration) Test(org.junit.jupiter.api.Test)

Example 17 with GcpProjectIdProvider

use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.

the class GcpPubSubAutoConfigurationTests method flowControlSettings_selectiveConfigurationSet.

@Test
void flowControlSettings_selectiveConfigurationSet() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("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);
        PubSubConfiguration.FlowControl flowControl = gcpPubSubProperties.getSubscriber("subscription-name", projectIdProvider.getProjectId()).getFlowControl();
        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"));
        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("subscriberFlowControlSettings-projects/fake project/subscriptions/subscription-name", FlowControlSettings.class)).isEqualTo(expectedFlowControlForSubscriptionName);
    });
}
Also used : FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) DefaultSubscriberFactory(com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) PubSubConfiguration(com.google.cloud.spring.pubsub.core.PubSubConfiguration) Test(org.junit.jupiter.api.Test)

Example 18 with GcpProjectIdProvider

use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.

the class GcpPubSubAutoConfigurationTests method pullConfig_globalAndSelectiveConfigurationSet_selectiveTakesPrecedence.

@Test
void pullConfig_globalAndSelectiveConfigurationSet_selectiveTakesPrecedence() {
    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.max-ack-extension-period=7", "spring.cloud.gcp.pubsub.subscription.subscription-name.parallel-pull-count=12", "spring.cloud.gcp.pubsub.subscription.subscription-name.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.computeMaxAckExtensionPeriod("other", projectIdProvider.getProjectId())).isEqualTo(5L);
        assertThat(gcpPubSubProperties.computeParallelPullCount("other", projectIdProvider.getProjectId())).isEqualTo(10);
        assertThat(gcpPubSubProperties.computePullEndpoint("other", projectIdProvider.getProjectId())).isEqualTo("other-endpoint");
        assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).hasSize(1);
        assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).containsKey(ProjectSubscriptionName.parse("projects/fake project/subscriptions/subscription-name"));
    });
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 19 with GcpProjectIdProvider

use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.

the class GcpPubSubAutoConfigurationTests method retrySettings_globalAndSelectiveConfigurationSet_selectiveTakesPrecedence.

@Test
void retrySettings_globalAndSelectiveConfigurationSet_selectiveTakesPrecedence() {
    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.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.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);
        // Validate settings for subscribers that have subscription-specific retry settings
        // property set
        PubSubConfiguration.Retry retrySettings = gcpPubSubProperties.computeSubscriberRetrySettings("subscription-name", projectIdProvider.getProjectId());
        assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).containsKey(ProjectSubscriptionName.parse("projects/fake project/subscriptions/subscription-name"));
        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.getInitialRpcTimeoutSeconds()).isEqualTo(6);
        assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(7);
        assertThat(retrySettings.getMaxRpcTimeoutSeconds()).isEqualTo(8);
        // Validate settings for subscribers that do **not** have subscription-specific retry
        // settings
        // property set
        PubSubConfiguration.Retry retrySettingsForOtherSubscriber = gcpPubSubProperties.getSubscriber("other", projectIdProvider.getProjectId()).getRetry();
        assertThat(retrySettingsForOtherSubscriber.getTotalTimeoutSeconds()).isEqualTo(10L);
        assertThat(retrySettingsForOtherSubscriber.getInitialRetryDelaySeconds()).isEqualTo(10L);
        assertThat(retrySettingsForOtherSubscriber.getRetryDelayMultiplier()).isEqualTo(10);
        assertThat(retrySettingsForOtherSubscriber.getMaxRetryDelaySeconds()).isEqualTo(10);
        assertThat(retrySettingsForOtherSubscriber.getMaxAttempts()).isEqualTo(10);
        assertThat(retrySettingsForOtherSubscriber.getInitialRpcTimeoutSeconds()).isEqualTo(10);
        assertThat(retrySettingsForOtherSubscriber.getRpcTimeoutMultiplier()).isEqualTo(10);
        assertThat(retrySettingsForOtherSubscriber.getMaxRpcTimeoutSeconds()).isEqualTo(10);
        assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).hasSize(1);
        assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).containsKey(ProjectSubscriptionName.parse("projects/fake project/subscriptions/subscription-name"));
        // Verify that beans for selective and global retry settings are created. Also
        // verify that selective retry setting takes precedence.
        DefaultSubscriberFactory subscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
        RetrySettings expectedRetrySettingsForSubscriptionName = 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(8)).build();
        RetrySettings expectedRetrySettingsForOther = 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();
        assertThat(subscriberFactory.getRetrySettings("subscription-name")).isEqualTo(expectedRetrySettingsForSubscriptionName);
        assertThat(ctx.getBean("subscriberRetrySettings-projects/fake project/subscriptions/subscription-name", RetrySettings.class)).isEqualTo(expectedRetrySettingsForSubscriptionName);
        assertThat(subscriberFactory.getRetrySettings("other")).isEqualTo(expectedRetrySettingsForOther);
        assertThat(ctx.getBean("globalSubscriberRetrySettings", RetrySettings.class)).isEqualTo(expectedRetrySettingsForOther);
    });
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) DefaultSubscriberFactory(com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) PubSubConfiguration(com.google.cloud.spring.pubsub.core.PubSubConfiguration) Test(org.junit.jupiter.api.Test)

Example 20 with GcpProjectIdProvider

use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.

the class GcpPubSubAutoConfigurationTests method retrySettings_subsetOfProperties_pickGlobalWhenSelectiveNotSpecified.

@Test
void retrySettings_subsetOfProperties_pickGlobalWhenSelectiveNotSpecified() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.retry.total-timeout-seconds=10", "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.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 retry = gcpPubSubProperties.computeSubscriberRetrySettings("subscription-name", projectIdProvider.getProjectId());
        assertThat(retry.getTotalTimeoutSeconds()).isEqualTo(10L);
        assertThat(retry.getInitialRetryDelaySeconds()).isEqualTo(2L);
        assertThat(retry.getRetryDelayMultiplier()).isEqualTo(3);
        assertThat(retry.getMaxRetryDelaySeconds()).isEqualTo(4L);
        assertThat(retry.getMaxAttempts()).isEqualTo(5);
        assertThat(retry.getInitialRpcTimeoutSeconds()).isEqualTo(6L);
        assertThat(retry.getRpcTimeoutMultiplier()).isEqualTo(7);
        assertThat(retry.getMaxRpcTimeoutSeconds()).isEqualTo(8L);
        // Verify that beans for selective and global retry settings are created.
        DefaultSubscriberFactory subscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
        RetrySettings expectedRetrySettingsForSubscriptionName = RetrySettings.newBuilder().setTotalTimeout(Duration.ofSeconds(10L)).setInitialRetryDelay(Duration.ofSeconds(2L)).setRetryDelayMultiplier(3).setMaxRetryDelay(Duration.ofSeconds(4L)).setMaxAttempts(5).setInitialRpcTimeout(Duration.ofSeconds(6L)).setRpcTimeoutMultiplier(7).setMaxRpcTimeout(Duration.ofSeconds(8L)).build();
        RetrySettings expectedGlobalRetrySettings = RetrySettings.newBuilder().setTotalTimeout(Duration.ofSeconds(10L)).build();
        assertThat(subscriberFactory.getRetrySettings("subscription-name")).isEqualTo(expectedRetrySettingsForSubscriptionName);
        assertThat(ctx.getBean("subscriberRetrySettings-projects/fake project/subscriptions/subscription-name", RetrySettings.class)).isEqualTo(expectedRetrySettingsForSubscriptionName);
        assertThat(ctx.getBean("globalSubscriberRetrySettings", RetrySettings.class)).isEqualTo(expectedGlobalRetrySettings);
    });
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) DefaultSubscriberFactory(com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) PubSubConfiguration(com.google.cloud.spring.pubsub.core.PubSubConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

GcpProjectIdProvider (com.google.cloud.spring.core.GcpProjectIdProvider)40 Test (org.junit.jupiter.api.Test)39 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)18 DefaultSubscriberFactory (com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory)12 PubSubConfiguration (com.google.cloud.spring.pubsub.core.PubSubConfiguration)10 RetrySettings (com.google.api.gax.retrying.RetrySettings)7 FlowControlSettings (com.google.api.gax.batching.FlowControlSettings)5 SubscriberStubSettings (com.google.cloud.pubsub.v1.stub.SubscriberStubSettings)4 DefaultGcpProjectIdProvider (com.google.cloud.spring.core.DefaultGcpProjectIdProvider)3 CredentialsProvider (com.google.api.gax.core.CredentialsProvider)2 Subscriber (com.google.cloud.pubsub.v1.Subscriber)2 SubscriberStub (com.google.cloud.pubsub.v1.stub.SubscriberStub)2 ProjectSubscriptionName (com.google.pubsub.v1.ProjectSubscriptionName)2 Code (com.google.api.gax.rpc.StatusCode.Code)1 Credentials (com.google.auth.Credentials)1 Datastore (com.google.cloud.datastore.Datastore)1 DatastoreException (com.google.cloud.datastore.DatastoreException)1 DatastoreOptions (com.google.cloud.datastore.DatastoreOptions)1 EntityQuery (com.google.cloud.datastore.EntityQuery)1 Query (com.google.cloud.datastore.Query)1