Search in sources :

Example 11 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testGetParallelPullCount_newConfiguration.

@Test
void testGetParallelPullCount_newConfiguration() {
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, this.pubSubConfig);
    assertThat(factory.getPullCount("subscription-name")).isNull();
}
Also used : GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 12 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testGetParallelPullCount_configurationIsPresent.

@Test
void testGetParallelPullCount_configurationIsPresent() {
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, mockPubSubConfiguration);
    when(mockPubSubConfiguration.computeParallelPullCount("subscription-name", projectIdProvider.getProjectId())).thenReturn(1);
    assertThat(factory.getPullCount("subscription-name")).isEqualTo(1);
}
Also used : GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 13 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testNewSubscriber_constructorWithPubSubConfiguration.

@Test
void testNewSubscriber_constructorWithPubSubConfiguration() {
    GcpProjectIdProvider projectIdProvider = () -> "angeldust";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, this.pubSubConfig);
    factory.setCredentialsProvider(this.credentialsProvider);
    Subscriber subscriber = factory.createSubscriber("midnight cowboy", (message, consumer) -> {
    });
    assertThat(subscriber.getSubscriptionNameString()).isEqualTo("projects/angeldust/subscriptions/midnight cowboy");
}
Also used : Subscriber(com.google.cloud.pubsub.v1.Subscriber) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 14 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testGetPullEndpoint_configurationIsPresent.

@Test
void testGetPullEndpoint_configurationIsPresent() {
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(() -> "project", mockPubSubConfiguration);
    when(mockPubSubConfiguration.computePullEndpoint("subscription-name", projectIdProvider.getProjectId())).thenReturn("my-endpoint");
    assertThat(factory.getPullEndpoint("subscription-name")).isEqualTo("my-endpoint");
}
Also used : GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 15 with GcpProjectIdProvider

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

the class GcpPubSubAutoConfigurationTests method pullConfig_selectiveConfigurationSet.

@Test
void pullConfig_selectiveConfigurationSet() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)).withPropertyValues("spring.cloud.gcp.pubsub.subscription.subscription-name.max-ack-extension-period=7", "spring.cloud.gcp.pubsub.subscription.subscription-name.parallel-pull-count=12", "spring.cloud.gcp.pubsub.subscription.subscription-name.pull-endpoint=my-endpoint").withUserConfiguration(TestConfig.class);
    contextRunner.run(ctx -> {
        GcpPubSubProperties gcpPubSubProperties = ctx.getBean(GcpPubSubProperties.class);
        GcpProjectIdProvider projectIdProvider = ctx.getBean(GcpProjectIdProvider.class);
        assertThat(gcpPubSubProperties.computeMaxAckExtensionPeriod("subscription-name", projectIdProvider.getProjectId())).isEqualTo(7L);
        assertThat(gcpPubSubProperties.computeParallelPullCount("subscription-name", projectIdProvider.getProjectId())).isEqualTo(12);
        assertThat(gcpPubSubProperties.computePullEndpoint("subscription-name", projectIdProvider.getProjectId())).isEqualTo("my-endpoint");
        assertThat(gcpPubSubProperties.getFullyQualifiedSubscriberProperties()).containsKey(ProjectSubscriptionName.parse("projects/fake project/subscriptions/subscription-name"));
    });
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) 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