use of com.couchbase.client.java.env.ClusterEnvironment in project spring-data-couchbase by spring-projects.
the class CollectionAwareIntegrationTests method beforeAll.
@BeforeAll
public static void beforeAll() {
callSuperBeforeAll(new Object() {
});
ClusterEnvironment environment = environment().build();
Cluster cluster = Cluster.connect(seedNodes(), ClusterOptions.clusterOptions(authenticator()).environment(environment));
Bucket bucket = cluster.bucket(config().bucketname());
bucket.waitUntilReady(Duration.ofSeconds(5));
waitForService(bucket, ServiceType.QUERY);
waitForQueryIndexerToHaveBucket(cluster, config().bucketname());
CollectionManager collectionManager = bucket.collections();
setupScopeCollection(cluster, scopeName, collectionName, collectionManager);
setupScopeCollection(cluster, scopeName, collectionName2, collectionManager);
if (otherScope != null || otherCollection != null) {
// afterAll should be undoing the creation of scope etc
setupScopeCollection(cluster, otherScope, otherCollection, collectionManager);
}
try {
// needs an index for this N1ql Join
// create index ix2 on my_bucket(parent_id) where `_class` = 'org.springframework.data.couchbase.domain.Address';
List<String> fieldList = new ArrayList<>();
fieldList.add("parentId");
cluster.query("CREATE INDEX `parent_idx` ON default:" + bucketName() + "." + scopeName + "." + collectionName2 + "(parentId)");
} catch (IndexExistsException ife) {
LOGGER.warn("IndexFailureException occurred - ignoring: ", ife.toString());
}
Config.setScopeName(scopeName);
ApplicationContext ac = new AnnotationConfigApplicationContext(Config.class);
// the Config class has been modified, these need to be loaded again
couchbaseTemplate = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE);
reactiveCouchbaseTemplate = (ReactiveCouchbaseTemplate) ac.getBean(REACTIVE_COUCHBASE_TEMPLATE);
}
use of com.couchbase.client.java.env.ClusterEnvironment in project connectors-se by Talend.
the class CouchbaseService method openConnection.
public Cluster openConnection(CouchbaseDataStore dataStore) {
String bootStrapNodes = dataStore.getBootstrapNodes();
String username = dataStore.getUsername();
String password = dataStore.getPassword();
String urls = Arrays.stream(resolveAddresses(bootStrapNodes)).collect(Collectors.joining(","));
ClusterHolder holder = clustersPool.computeIfAbsent(dataStore, ds -> {
ClusterEnvironment.Builder envBuilder = ClusterEnvironment.builder();
if (dataStore.isUseConnectionParameters()) {
Builder timeoutBuilder = TimeoutConfig.builder();
dataStore.getConnectionParametersList().forEach(conf -> setTimeout(timeoutBuilder, envBuilder, conf.getParameterName(), parseValue(conf.getParameterValue())));
envBuilder.timeoutConfig(timeoutBuilder);
}
ClusterEnvironment environment = envBuilder.build();
Cluster cluster = Cluster.connect(urls, ClusterOptions.clusterOptions(username, password).environment(environment));
try {
cluster.waitUntilReady(Duration.ofSeconds(3), WaitUntilReadyOptions.waitUntilReadyOptions().desiredState(ClusterState.ONLINE));
} catch (UnambiguousTimeoutException e) {
LOG.error(i18n.connectionKO());
throw new ComponentException(e);
}
return new ClusterHolder(environment, cluster);
});
holder.use();
Cluster cluster = holder.getCluster();
// connection is lazily initialized; need to send actual request to test it
cluster.buckets().getAllBuckets();
PingResult pingResult = cluster.ping();
LOG.debug(i18n.connectedToCluster(pingResult.id()));
return cluster;
}
use of com.couchbase.client.java.env.ClusterEnvironment in project connectors-se by Talend.
the class CouchbaseService method closeConnection.
public void closeConnection(CouchbaseDataStore ds) {
ClusterHolder holder = clustersPool.get(ds);
if (holder == null) {
return;
}
int stillUsed = holder.release();
if (stillUsed > 0) {
return;
}
clustersPool.remove(ds);
Cluster cluster = holder.getCluster();
ClusterEnvironment environment = holder.getEnv();
if (cluster != null) {
try {
cluster.disconnect();
log.debug(i18n.clusterWasClosed());
} catch (ComponentException e) {
log.debug(i18n.cannotCloseCluster());
}
}
if (environment != null) {
try {
environment.shutdown();
log.debug(i18n.couchbaseEnvWasClosed());
} catch (ComponentException e) {
log.debug(i18n.cannotCloseCouchbaseEnv());
}
}
}
use of com.couchbase.client.java.env.ClusterEnvironment in project spring-boot by spring-projects.
the class CouchbaseAutoConfigurationTests method customizeJsonSerializer.
@Test
void customizeJsonSerializer() {
JsonSerializer customJsonSerializer = mock(JsonSerializer.class);
this.contextRunner.withUserConfiguration(CouchbaseTestConfiguration.class).withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class)).withBean(ClusterEnvironmentBuilderCustomizer.class, () -> (builder) -> builder.jsonSerializer(customJsonSerializer)).withPropertyValues("spring.couchbase.connection-string=localhost").run((context) -> {
ClusterEnvironment env = context.getBean(ClusterEnvironment.class);
JsonSerializer serializer = env.jsonSerializer();
assertThat(serializer).extracting("wrapped").isSameAs(customJsonSerializer);
});
}
use of com.couchbase.client.java.env.ClusterEnvironment in project spring-boot by spring-projects.
the class CouchbaseAutoConfigurationTests method whenObjectMapperBeanIsDefinedThenClusterEnvironmentObjectMapperIsDerivedFromIt.
@Test
void whenObjectMapperBeanIsDefinedThenClusterEnvironmentObjectMapperIsDerivedFromIt() {
this.contextRunner.withUserConfiguration(CouchbaseTestConfiguration.class).withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class)).withPropertyValues("spring.couchbase.connection-string=localhost").run((context) -> {
ClusterEnvironment env = context.getBean(ClusterEnvironment.class);
Set<Object> expectedModuleIds = new HashSet<>(context.getBean(ObjectMapper.class).getRegisteredModuleIds());
expectedModuleIds.add(new JsonValueModule().getTypeId());
JsonSerializer serializer = env.jsonSerializer();
assertThat(serializer).extracting("wrapped").isInstanceOf(JacksonJsonSerializer.class).extracting("mapper", as(InstanceOfAssertFactories.type(ObjectMapper.class))).extracting(ObjectMapper::getRegisteredModuleIds).isEqualTo(expectedModuleIds);
});
}
Aggregations