Search in sources :

Example 11 with DefaultSubscriberFactory

use of com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory 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 12 with DefaultSubscriberFactory

use of com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory in project spring-cloud-gcp by GoogleCloudPlatform.

the class GcpPubSubAutoConfigurationTests method flowControlSettings_globalConfigurationSet.

@Test
void flowControlSettings_globalConfigurationSet() {
    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").withUserConfiguration(TestConfig.class);
    contextRunner.run(ctx -> {
        GcpPubSubProperties gcpPubSubProperties = ctx.getBean(GcpPubSubProperties.class);
        DefaultSubscriberFactory subscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
        PubSubConfiguration.FlowControl flowControlFromConfiguration = gcpPubSubProperties.getSubscriber().getFlowControl();
        FlowControlSettings expectedFlowControlSettings = FlowControlSettings.newBuilder().setMaxOutstandingElementCount(11L).setMaxOutstandingRequestBytes(12L).setLimitExceededBehavior(FlowController.LimitExceededBehavior.Ignore).build();
        assertThat(flowControlFromConfiguration.getMaxOutstandingElementCount()).isEqualTo(11L);
        assertThat(flowControlFromConfiguration.getMaxOutstandingRequestBytes()).isEqualTo(12L);
        assertThat(flowControlFromConfiguration.getLimitExceededBehavior()).isEqualTo(FlowController.LimitExceededBehavior.Ignore);
        assertThat(subscriberFactory.getFlowControlSettings("name")).isEqualTo(expectedFlowControlSettings);
        assertThat(ctx.getBean("globalSubscriberFlowControlSettings", FlowControlSettings.class)).isEqualTo(expectedFlowControlSettings);
    });
}
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) PubSubConfiguration(com.google.cloud.spring.pubsub.core.PubSubConfiguration) Test(org.junit.jupiter.api.Test)

Example 13 with DefaultSubscriberFactory

use of com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory in project spring-cloud-gcp by GoogleCloudPlatform.

the class GcpPubSubAutoConfigurationTests method subscriberExecutorProvider_globalAndSelectiveConfigurationSet_selectiveTakesPrecedence.

@Test
void subscriberExecutorProvider_globalAndSelectiveConfigurationSet_selectiveTakesPrecedence() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.executor-threads=5", "spring.cloud.gcp.pubsub.subscription.subscription-name.executor-threads=3").withUserConfiguration(TestConfig.class);
    contextRunner.run(ctx -> {
        DefaultSubscriberFactory factory = (DefaultSubscriberFactory) ctx.getBean("defaultSubscriberFactory");
        ExecutorProvider selectiveExecutorProvider = (ExecutorProvider) ctx.getBean("subscriberExecutorProvider-projects/fake project/subscriptions/subscription-name");
        ExecutorProvider globalExecutorProvider = (ExecutorProvider) ctx.getBean("globalSubscriberExecutorProvider");
        assertThat(selectiveExecutorProvider).isNotNull();
        assertThat(globalExecutorProvider).isNotNull();
        assertThat(factory.getGlobalExecutorProvider()).isNotNull();
        assertThat(factory.getExecutorProvider("subscription-name")).isSameAs(selectiveExecutorProvider);
    });
}
Also used : DefaultSubscriberFactory(com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) ExecutorProvider(com.google.api.gax.core.ExecutorProvider) Test(org.junit.jupiter.api.Test)

Example 14 with DefaultSubscriberFactory

use of com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory 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 15 with DefaultSubscriberFactory

use of com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory 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)

Aggregations

DefaultSubscriberFactory (com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory)26 Test (org.junit.jupiter.api.Test)25 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)25 GcpProjectIdProvider (com.google.cloud.spring.core.GcpProjectIdProvider)12 PubSubConfiguration (com.google.cloud.spring.pubsub.core.PubSubConfiguration)10 FlowControlSettings (com.google.api.gax.batching.FlowControlSettings)6 RetrySettings (com.google.api.gax.retrying.RetrySettings)6 ExecutorProvider (com.google.api.gax.core.ExecutorProvider)5 Code (com.google.api.gax.rpc.StatusCode.Code)1 Subscriber (com.google.cloud.pubsub.v1.Subscriber)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1