Search in sources :

Example 21 with GcpProjectIdProvider

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);
    });
}
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 22 with GcpProjectIdProvider

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);
    });
}
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 23 with GcpProjectIdProvider

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[] {});
    });
}
Also used : DefaultSubscriberFactory(com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 24 with GcpProjectIdProvider

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 });
    });
}
Also used : DefaultSubscriberFactory(com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 25 with GcpProjectIdProvider

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"));
    });
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) 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