use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpContextAutoConfigurationTests method testGetProjectIdProvider_withGcpProperties.
@Test
void testGetProjectIdProvider_withGcpProperties() {
this.contextRunner.withPropertyValues("spring.cloud.gcp.projectId=tonberry").run(context -> {
GcpProjectIdProvider projectIdProvider = context.getBean(GcpProjectIdProvider.class);
assertThat(projectIdProvider.getProjectId()).isEqualTo("tonberry");
});
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpContextAutoConfigurationTests method testGetProjectIdProvider_withoutGcpProperties.
@Test
void testGetProjectIdProvider_withoutGcpProperties() {
this.contextRunner.run(context -> {
GcpProjectIdProvider projectIdProvider = context.getBean(GcpProjectIdProvider.class);
assertThat(projectIdProvider).isInstanceOf(DefaultGcpProjectIdProvider.class);
});
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class GcpDatastoreEmulatorIntegrationTests method testDatastoreEmulatorConfiguration.
@Test
void testDatastoreEmulatorConfiguration() {
DatastoreOptions.Builder builder = DatastoreOptions.newBuilder();
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpDatastoreAutoConfiguration.class, GcpContextAutoConfiguration.class, DatastoreTransactionManagerAutoConfiguration.class, DatastoreRepositoriesAutoConfiguration.class, GcpDatastoreEmulatorAutoConfiguration.class)).withUserConfiguration(TestConfiguration.class).withPropertyValues("spring.cloud.gcp.project-id=test-project", "spring.cloud.gcp.datastore.namespace=test-namespace", "spring.cloud.gcp.datastore.emulator.port=8181", "spring.cloud.gcp.datastore.emulator.enabled=true", "spring.cloud.gcp.datastore.emulator.consistency=0.9").run(context -> {
DatastoreTemplate datastore = context.getBean(DatastoreTemplate.class);
Datastore datastoreClient = (Datastore) ((Supplier) context.getBean(context.getBeanNamesForType(ResolvableType.forClassWithGenerics(Supplier.class, Datastore.class))[0])).get();
GcpProjectIdProvider projectIdProvider = context.getBean(GcpProjectIdProvider.class);
builder.setServiceFactory(datastoreOptions -> datastoreClient).setProjectId(projectIdProvider.getProjectId());
EmulatorEntityTest entity = new EmulatorEntityTest();
entity.setProperty("property-test");
datastore.save(entity);
assertThat(entity.getId()).isNotNull();
assertThat(datastore.findById(entity.getId(), EmulatorEntityTest.class).getProperty()).isEqualTo("property-test");
});
Datastore datastore = builder.build().getService();
EntityQuery query = Query.newEntityQueryBuilder().setKind("RandomKind").setFilter(StructuredQuery.PropertyFilter.eq("key", "value")).build();
assertThatExceptionOfType(DatastoreException.class).isThrownBy(() -> datastore.run(query));
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class StackdriverJsonLayout method start.
@Override
public void start() {
super.start();
// If no Project ID set, then attempt to resolve it with the default project ID provider
if (!StringUtils.hasText(this.projectId) || this.projectId.endsWith("_IS_UNDEFINED")) {
GcpProjectIdProvider projectIdProvider = new DefaultGcpProjectIdProvider();
this.projectId = projectIdProvider.getProjectId();
}
this.filteredMdcFields = new HashSet<>(Arrays.asList(traceIdMdcField, spanIdMdcField, StackdriverTraceConstants.MDC_FIELD_SPAN_EXPORT));
}
use of com.google.cloud.spring.core.GcpProjectIdProvider in project spring-cloud-gcp by GoogleCloudPlatform.
the class DefaultSubscriberFactoryTests method testGetRetrySettings_notPresentInMap_pickGlobal.
@Test
void testGetRetrySettings_notPresentInMap_pickGlobal() {
GcpProjectIdProvider projectIdProvider = () -> "project";
DefaultSubscriberFactory factory = new DefaultSubscriberFactory(projectIdProvider, this.pubSubConfig);
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(10L)).build();
factory.setGlobalRetrySettings(expectedRetrySettings);
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));
}
Aggregations