Search in sources :

Example 6 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testCreateSubscriber_validateSetProperties.

@Test
void testCreateSubscriber_validateSetProperties() {
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, mockPubSubConfiguration);
    factory.setCredentialsProvider(this.credentialsProvider);
    FlowControlSettings flowControlSettings = FlowControlSettings.newBuilder().setLimitExceededBehavior(FlowController.LimitExceededBehavior.Ignore).build();
    factory.setGlobalFlowControlSettings(flowControlSettings);
    when(mockPubSubConfiguration.computeMaxAckExtensionPeriod("defaultSubscription", projectIdProvider.getProjectId())).thenReturn(2L);
    when(mockPubSubConfiguration.computeParallelPullCount("defaultSubscription", projectIdProvider.getProjectId())).thenReturn(2);
    Subscriber expectedSubscriber = factory.createSubscriber("defaultSubscription", (message, consumer) -> {
    });
    assertThat(expectedSubscriber.getFlowControlSettings().getLimitExceededBehavior()).isEqualTo(FlowController.LimitExceededBehavior.Ignore);
    assertThat(expectedSubscriber).hasFieldOrPropertyWithValue("maxAckExtensionPeriod", Duration.ofSeconds(2L)).hasFieldOrPropertyWithValue("numPullers", 2);
}
Also used : FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) Subscriber(com.google.cloud.pubsub.v1.Subscriber) GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 7 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testGetPullEndpoint_userSetValue.

@Test
void testGetPullEndpoint_userSetValue() {
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, mockPubSubConfiguration);
    factory.setPullEndpoint("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 8 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testGetMaxAckExtensionPeriod_configurationIsPresent.

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

Example 9 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testGetMaxAckExtensionPeriod_userSetValue.

@Test
void testGetMaxAckExtensionPeriod_userSetValue() {
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, mockPubSubConfiguration);
    factory.setMaxAckExtensionPeriod(Duration.ofSeconds(1));
    assertThat(factory.getMaxAckExtensionPeriod("subscription-name")).isEqualTo(Duration.ofSeconds(1));
}
Also used : GcpProjectIdProvider(com.google.cloud.spring.core.GcpProjectIdProvider) Test(org.junit.jupiter.api.Test)

Example 10 with GcpProjectIdProvider

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

the class DefaultSubscriberFactoryTests method testGetParallelPullCount_userSetValue.

@Test
void testGetParallelPullCount_userSetValue() {
    GcpProjectIdProvider projectIdProvider = () -> "project";
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, mockPubSubConfiguration);
    factory.setParallelPullCount(1);
    assertThat(factory.getPullCount("subscription-name")).isEqualTo(1);
}
Also used : 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