Search in sources :

Example 36 with GcpProjectIdProvider

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));
}
Also used : GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 37 with GcpProjectIdProvider

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);
}
Also used : GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) SubscriberStubSettings(com.google.cloud.pubsub.v1.stub.SubscriberStubSettings) Test(org.junit.jupiter.api.Test)

Example 38 with GcpProjectIdProvider

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);
}
Also used : GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) SubscriberStubSettings(com.google.cloud.pubsub.v1.stub.SubscriberStubSettings) Test(org.junit.jupiter.api.Test)

Example 39 with GcpProjectIdProvider

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();
}
Also used : SubscriberStub(com.google.cloud.pubsub.v1.stub.SubscriberStub) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 40 with GcpProjectIdProvider

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");
}
Also used : PubSubException(com.google.cloud.spring.pubsub.core.PubSubException) CredentialsProvider(com.google.api.gax.core.CredentialsProvider) IOException(java.io.IOException) 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