Search in sources :

Example 1 with Cluster

use of com.couchbase.client.java.Cluster in project tutorials by eugenp.

the class PersonServiceImplIntegrationTest method setupBeforeClass.

@BeforeClass
public static void setupBeforeClass() {
    final Cluster cluster = CouchbaseCluster.create(MultiBucketCouchbaseConfig.NODE_LIST);
    final Bucket bucket = cluster.openBucket(MultiBucketCouchbaseConfig.DEFAULT_BUCKET_NAME, MultiBucketCouchbaseConfig.DEFAULT_BUCKET_PASSWORD);
    bucket.upsert(JsonDocument.create(johnSmithId, jsonJohnSmith));
    bucket.upsert(JsonDocument.create(foobarId, jsonFooBar));
    bucket.close();
    cluster.disconnect();
}
Also used : Bucket(com.couchbase.client.java.Bucket) CouchbaseCluster(com.couchbase.client.java.CouchbaseCluster) Cluster(com.couchbase.client.java.Cluster) BeforeClass(org.junit.BeforeClass)

Example 2 with Cluster

use of com.couchbase.client.java.Cluster in project tutorials by eugenp.

the class StudentServiceImplIntegrationTest method setupBeforeClass.

@BeforeClass
public static void setupBeforeClass() {
    Cluster cluster = CouchbaseCluster.create(MultiBucketCouchbaseConfig.NODE_LIST);
    Bucket bucket = cluster.openBucket(MultiBucketCouchbaseConfig.DEFAULT_BUCKET_NAME, MultiBucketCouchbaseConfig.DEFAULT_BUCKET_PASSWORD);
    bucket.upsert(JsonDocument.create(joeCollegeId, jsonJoeCollege));
    bucket.upsert(JsonDocument.create(judyJetsonId, jsonJudyJetson));
    bucket.close();
    cluster.disconnect();
}
Also used : Bucket(com.couchbase.client.java.Bucket) CouchbaseCluster(com.couchbase.client.java.CouchbaseCluster) Cluster(com.couchbase.client.java.Cluster) BeforeClass(org.junit.BeforeClass)

Example 3 with Cluster

use of com.couchbase.client.java.Cluster in project samza by apache.

the class CouchbaseBucketRegistry method openCluster.

/**
 * Helper method to open a cluster given cluster nodes and environment configurations.
 */
private Cluster openCluster(List<String> clusterNodes, CouchbaseEnvironmentConfigs configs) {
    DefaultCouchbaseEnvironment.Builder envBuilder = new DefaultCouchbaseEnvironment.Builder();
    if (configs.sslEnabled != null) {
        envBuilder.sslEnabled(configs.sslEnabled);
    }
    if (configs.certAuthEnabled != null) {
        envBuilder.certAuthEnabled(configs.certAuthEnabled);
    }
    if (configs.sslKeystoreFile != null) {
        envBuilder.sslKeystoreFile(configs.sslKeystoreFile);
    }
    if (configs.sslKeystorePassword != null) {
        envBuilder.sslKeystorePassword(configs.sslKeystorePassword);
    }
    if (configs.sslTruststoreFile != null) {
        envBuilder.sslTruststoreFile(configs.sslTruststoreFile);
    }
    if (configs.sslTruststorePassword != null) {
        envBuilder.sslTruststorePassword(configs.sslTruststorePassword);
    }
    if (configs.bootstrapCarrierDirectPort != null) {
        envBuilder.bootstrapCarrierDirectPort(configs.bootstrapCarrierDirectPort);
    }
    if (configs.bootstrapCarrierSslPort != null) {
        envBuilder.bootstrapCarrierSslPort(configs.bootstrapCarrierSslPort);
    }
    if (configs.bootstrapHttpDirectPort != null) {
        envBuilder.bootstrapHttpDirectPort(configs.bootstrapHttpDirectPort);
    }
    if (configs.bootstrapHttpSslPort != null) {
        envBuilder.bootstrapHttpSslPort(configs.bootstrapHttpSslPort);
    }
    CouchbaseEnvironment env = envBuilder.build();
    Cluster cluster = CouchbaseCluster.create(env, clusterNodes);
    if (configs.sslEnabled != null && configs.sslEnabled) {
        cluster.authenticate(CertAuthenticator.INSTANCE);
    } else if (configs.username != null) {
        cluster.authenticate(configs.username, configs.password);
    } else {
        LOGGER.warn("No authentication is enabled for cluster: {}. This is not recommended except for test cases.", clusterNodes);
    }
    return cluster;
}
Also used : DefaultCouchbaseEnvironment(com.couchbase.client.java.env.DefaultCouchbaseEnvironment) CouchbaseCluster(com.couchbase.client.java.CouchbaseCluster) Cluster(com.couchbase.client.java.Cluster) DefaultCouchbaseEnvironment(com.couchbase.client.java.env.DefaultCouchbaseEnvironment) CouchbaseEnvironment(com.couchbase.client.java.env.CouchbaseEnvironment)

Example 4 with Cluster

use of com.couchbase.client.java.Cluster in project spring-boot by spring-projects.

the class CouchbaseAutoConfigurationIntegrationTests method defaultConfiguration.

@Test
void defaultConfiguration() {
    this.contextRunner.run((context) -> {
        assertThat(context).hasSingleBean(Cluster.class).hasSingleBean(ClusterEnvironment.class);
        Cluster cluster = context.getBean(Cluster.class);
        Bucket bucket = cluster.bucket(BUCKET_NAME);
        bucket.waitUntilReady(Duration.ofMinutes(5));
        DiagnosticsResult diagnostics = cluster.diagnostics();
        assertThat(diagnostics.state()).isEqualTo(ClusterState.ONLINE);
    });
}
Also used : Bucket(com.couchbase.client.java.Bucket) DiagnosticsResult(com.couchbase.client.core.diagnostics.DiagnosticsResult) Cluster(com.couchbase.client.java.Cluster) Test(org.junit.jupiter.api.Test)

Example 5 with Cluster

use of com.couchbase.client.java.Cluster in project spring-boot by spring-projects.

the class CouchbaseAutoConfigurationIntegrationTests method whenCouchbaseIsUsingCustomObjectMapperThenJsonCanBeRoundTripped.

@Test
void whenCouchbaseIsUsingCustomObjectMapperThenJsonCanBeRoundTripped() {
    this.contextRunner.withBean(ObjectMapper.class, ObjectMapper::new).run((context) -> {
        Cluster cluster = context.getBean(Cluster.class);
        Bucket bucket = cluster.bucket(BUCKET_NAME);
        bucket.waitUntilReady(Duration.ofMinutes(5));
        Collection collection = bucket.defaultCollection();
        collection.insert("test-document", JsonObject.create().put("a", "alpha"));
        assertThat(collection.get("test-document").contentAsObject().get("a")).isEqualTo("alpha");
    });
}
Also used : Bucket(com.couchbase.client.java.Bucket) Cluster(com.couchbase.client.java.Cluster) Collection(com.couchbase.client.java.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

Cluster (com.couchbase.client.java.Cluster)11 Bucket (com.couchbase.client.java.Bucket)6 Test (org.junit.jupiter.api.Test)6 DiagnosticsResult (com.couchbase.client.core.diagnostics.DiagnosticsResult)5 CouchbaseCluster (com.couchbase.client.java.CouchbaseCluster)5 EndpointDiagnostics (com.couchbase.client.core.diagnostics.EndpointDiagnostics)4 ServiceType (com.couchbase.client.core.service.ServiceType)4 List (java.util.List)4 BeforeClass (org.junit.BeforeClass)4 Health (org.springframework.boot.actuate.health.Health)4 Collection (com.couchbase.client.java.Collection)1 CouchbaseEnvironment (com.couchbase.client.java.env.CouchbaseEnvironment)1 DefaultCouchbaseEnvironment (com.couchbase.client.java.env.DefaultCouchbaseEnvironment)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1