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);
});
}
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));
}
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);
}
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);
}
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();
}
Aggregations