Search in sources :

Example 31 with GcpProjectIdProvider

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

the class GcpPubSubAutoConfigurationTests method retryableCodes_many.

@Test
void retryableCodes_many() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withUserConfiguration(TestConfig.class).withPropertyValues("spring.cloud.gcp.pubsub.subscriber.retryableCodes=UNKNOWN,ABORTED,UNAVAILABLE,INTERNAL");
    contextRunner.run(ctx -> {
        GcpPubSubProperties properties = ctx.getBean(GcpPubSubProperties.class);
        GcpProjectIdProvider projectIdProvider = ctx.getBean(GcpProjectIdProvider.class);
        DefaultSubscriberFactory defaultSubscriberFactory = ctx.getBean("defaultSubscriberFactory", DefaultSubscriberFactory.class);
        Code[] expectedRetryableCodes = new Code[] { Code.UNKNOWN, Code.ABORTED, Code.UNAVAILABLE, Code.INTERNAL };
        assertThat(properties.getSubscriber().getRetryableCodes()).isEqualTo(expectedRetryableCodes);
        assertThat(properties.computeRetryableCodes("subscription-name", projectIdProvider.getProjectId())).isEqualTo(expectedRetryableCodes);
        assertThat(defaultSubscriberFactory.getRetryableCodes("subscription-name")).isEqualTo(expectedRetryableCodes);
    });
}
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) Code(com.google.api.gax.rpc.StatusCode.Code) Test(org.junit.jupiter.api.Test)

Example 32 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testGetRetrySettings_presentInMap_pickSelective.

@Test
void testGetRetrySettings_presentInMap_pickSelective() {
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, mockPubSubConfiguration);
    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();
    ConcurrentHashMap<ProjectSubscriptionName, RetrySettings> settingsMap = new ConcurrentHashMap<>();
    settingsMap.put(ProjectSubscriptionName.parse("projects/project/subscriptions/mySubscription"), expectedRetrySettings);
    factory.setRetrySettingsMap(settingsMap);
    RetrySettings actualRetrySettings = factory.getRetrySettings("mySubscription");
    assertThat(actualRetrySettings.getTotalTimeout()).isEqualTo(Duration.ofSeconds(10));
    assertThat(actualRetrySettings.getInitialRetryDelay()).isEqualTo(Duration.ofSeconds(10));
    assertThat(actualRetrySettings.getRetryDelayMultiplier()).isEqualTo(10.0);
    assertThat(actualRetrySettings.getInitialRpcTimeout()).isEqualTo(Duration.ofSeconds(10));
    assertThat(actualRetrySettings.getMaxRetryDelay()).isEqualTo(Duration.ofSeconds(10));
    assertThat(actualRetrySettings.getMaxAttempts()).isEqualTo(10);
    assertThat(actualRetrySettings.getRpcTimeoutMultiplier()).isEqualTo(10.0);
    assertThat(actualRetrySettings.getMaxRpcTimeout()).isEqualTo(Duration.ofSeconds(10));
}
Also used : ProjectSubscriptionName(com.google.pubsub.v1.ProjectSubscriptionName) RetrySettings(com.google.api.gax.retrying.RetrySettings) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 33 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testBuildSubscriberStubSettings_retryableCodes_pickConfiguration.

@Test
void testBuildSubscriberStubSettings_retryableCodes_pickConfiguration() throws IllegalAccessException, IOException {
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, mockPubSubConfiguration);
    when(mockPubSubConfiguration.computeRetryableCodes("someSubscription", projectIdProvider.getProjectId())).thenReturn(new Code[] { Code.INTERNAL });
    assertThat(FieldUtils.readField(factory, "retryableCodes", true)).isNull();
    SubscriberStubSettings settings = factory.buildSubscriberStubSettings("someSubscription");
    assertThat(settings.pullSettings().getRetryableCodes()).containsExactly(Code.INTERNAL);
}
Also used : GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) SubscriberStubSettings(com.google.cloud.pubsub.v1.stub.SubscriberStubSettings) Test(org.junit.jupiter.api.Test)

Example 34 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testBuildSubscriberStubSettings_retryableCodes_pickUserProvidedValue.

@Test
void testBuildSubscriberStubSettings_retryableCodes_pickUserProvidedValue() throws IllegalAccessException, IOException {
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, this.pubSubConfig);
    factory.setRetryableCodes(new Code[] { Code.INTERNAL });
    assertThat(FieldUtils.readField(factory, "retryableCodes", true)).isEqualTo(new Code[] { Code.INTERNAL });
    SubscriberStubSettings settings = factory.buildSubscriberStubSettings("someSubscription");
    assertThat(settings.pullSettings().getRetryableCodes()).containsExactly(Code.INTERNAL);
}
Also used : GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) SubscriberStubSettings(com.google.cloud.pubsub.v1.stub.SubscriberStubSettings) Test(org.junit.jupiter.api.Test)

Example 35 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method createSubscriberStubSucceeds_noSubscriptionNameAndNewConfiguration.

@Test
void createSubscriberStubSucceeds_noSubscriptionNameAndNewConfiguration() {
    when(this.mockTransportChannel.getEmptyCallContext()).thenReturn(this.mockApiCallContext);
    when(this.mockApiCallContext.withCredentials(any())).thenReturn(this.mockApiCallContext);
    when(this.mockApiCallContext.withTransportChannel(any())).thenReturn(this.mockApiCallContext);
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, this.pubSubConfig);
    factory.setChannelProvider(FixedTransportChannelProvider.create(this.mockTransportChannel));
    factory.setCredentialsProvider(() -> NoCredentials.getInstance());
    SubscriberStub stub = factory.createSubscriberStub();
    assertThat(stub.isShutdown()).isFalse();
}
Also used : SubscriberStub(com.google.cloud.pubsub.v1.stub.SubscriberStub) 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