Search in sources :

Example 1 with PingResult

use of com.couchbase.client.core.diagnostics.PingResult in project couchbase-jvm-clients by couchbase.

the class JavaIntegrationTest method waitForService.

/**
 * Improve test stability by waiting for a given service to report itself ready.
 */
protected static void waitForService(final Bucket bucket, final ServiceType serviceType) {
    bucket.waitUntilReady(Duration.ofSeconds(30));
    Util.waitUntilCondition(() -> {
        PingResult pingResult = bucket.ping(PingOptions.pingOptions().serviceTypes(Collections.singleton(serviceType)));
        return pingResult.endpoints().containsKey(serviceType) && pingResult.endpoints().get(serviceType).size() > 0 && pingResult.endpoints().get(serviceType).get(0).state() == PingState.OK;
    });
}
Also used : PingResult(com.couchbase.client.core.diagnostics.PingResult)

Example 2 with PingResult

use of com.couchbase.client.core.diagnostics.PingResult in project spring-data-couchbase by spring-projects.

the class JavaIntegrationTests method waitForService.

/**
 * Improve test stability by waiting for a given service to report itself ready.
 */
protected static void waitForService(final Bucket bucket, final ServiceType serviceType) {
    bucket.waitUntilReady(Duration.ofSeconds(30));
    Util.waitUntilCondition(() -> {
        PingResult pingResult = bucket.ping(PingOptions.pingOptions().serviceTypes(Collections.singleton(serviceType)));
        return pingResult.endpoints().containsKey(serviceType) && pingResult.endpoints().get(serviceType).size() > 0 && pingResult.endpoints().get(serviceType).get(0).state() == PingState.OK;
    });
}
Also used : PingResult(com.couchbase.client.core.diagnostics.PingResult)

Example 3 with PingResult

use of com.couchbase.client.core.diagnostics.PingResult 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;
}
Also used : ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) PingResult(com.couchbase.client.core.diagnostics.PingResult) Builder(com.couchbase.client.core.env.TimeoutConfig.Builder) ComponentException(org.talend.sdk.component.api.exception.ComponentException) Cluster(com.couchbase.client.java.Cluster) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException)

Example 4 with PingResult

use of com.couchbase.client.core.diagnostics.PingResult in project camel-kafka-connector by apache.

the class CamelSinkCouchbaseITCase method setUp.

@BeforeEach
public void setUp() {
    bucketName = "testBucket" + TestUtils.randomWithRange(0, 100);
    cluster = Cluster.connect(service.getConnectionString(), service.getUsername(), service.getPassword());
    cluster.ping().endpoints().entrySet().forEach(this::checkEndpoints);
    LOG.debug("Creating a new bucket named {}", bucketName);
    cluster.buckets().createBucket(BucketSettings.create(bucketName));
    PingResult pingResult = cluster.bucket(bucketName).ping();
    pingResult.endpoints().entrySet().forEach(this::checkEndpoints);
    LOG.debug("Bucket created");
    topic = getTopicForTest(this);
    try {
        String startDelay = System.getProperty("couchbase.test.start.delay", "1000");
        int delay = Integer.parseInt(startDelay);
        Thread.sleep(delay);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupted();
    }
}
Also used : PingResult(com.couchbase.client.core.diagnostics.PingResult) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

PingResult (com.couchbase.client.core.diagnostics.PingResult)4 Builder (com.couchbase.client.core.env.TimeoutConfig.Builder)1 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)1 Cluster (com.couchbase.client.java.Cluster)1 ClusterEnvironment (com.couchbase.client.java.env.ClusterEnvironment)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ComponentException (org.talend.sdk.component.api.exception.ComponentException)1