use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class DefaultSubscriberFactoryTests method testGetMaxAckExtensionPeriod_newConfiguration.
@Test
void testGetMaxAckExtensionPeriod_newConfiguration() {
GcpProjectIdProvider projectIdProvider = () -> "project";
DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, this.pubSubConfig);
assertThat(factory.getMaxAckExtensionPeriod("subscription-name")).isEqualTo(Duration.ofSeconds(0L));
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class DefaultSubscriberFactoryTests method testBuildGlobalSubscriberStubSettings_retryableCodes_pickConfiguration.
@Test
void testBuildGlobalSubscriberStubSettings_retryableCodes_pickConfiguration() throws IOException {
GcpProjectIdProvider projectIdProvider = () -> "project";
DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, mockPubSubConfiguration);
when(mockPubSubConfiguration.getSubscriber()).thenReturn(mockSubscriber);
when(mockSubscriber.getRetryableCodes()).thenReturn(new Code[] { Code.INTERNAL });
SubscriberStubSettings settings = factory.buildGlobalSubscriberStubSettings();
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 testBuildGlobalSubscriberStubSettings_retryableCodes_userProvidedValue.
@Test
void testBuildGlobalSubscriberStubSettings_retryableCodes_userProvidedValue() throws IOException, IllegalAccessException {
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.buildGlobalSubscriberStubSettings();
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.
@Test
void createSubscriberStubSucceeds() {
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("unusedSubscription");
assertThat(stub.isShutdown()).isFalse();
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class DefaultSubscriberFactoryTests method createSubscriberStubFailsOnBadCredentials.
@Test
void createSubscriberStubFailsOnBadCredentials() throws IOException {
GcpProjectIdProvider projectIdProvider = () -> "project";
DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, this.pubSubConfig);
factory.setChannelProvider(FixedTransportChannelProvider.create(this.mockTransportChannel));
CredentialsProvider mockCredentialsProvider = mock(CredentialsProvider.class);
factory.setCredentialsProvider(mockCredentialsProvider);
when(mockCredentialsProvider.getCredentials()).thenThrow(new IOException("boom"));
assertThatThrownBy(() -> factory.createSubscriberStub("unusedSubscription")).isInstanceOf(PubSubException.class).hasMessageContaining("Error creating the SubscriberStub");
}
Aggregations