Search in sources :

Example 6 with ConnectionString

use of com.couchbase.client.core.util.ConnectionString in project couchbase-jvm-clients by couchbase.

the class ConnectionStringTest method shouldParseParams.

@Test
void shouldParseParams() {
    ConnectionString parsed = ConnectionString.create("couchbase://localhost?foo=bar");
    assertEquals(ConnectionString.Scheme.COUCHBASE, parsed.scheme());
    assertEquals(1, parsed.hosts().size());
    assertEquals(1, parsed.params().size());
    assertEquals("bar", parsed.params().get("foo"));
    assertNull(parsed.username());
    parsed = ConnectionString.create("couchbase://localhost?foo=bar&setting=true");
    assertEquals(ConnectionString.Scheme.COUCHBASE, parsed.scheme());
    assertEquals(1, parsed.hosts().size());
    assertEquals(2, parsed.params().size());
    assertEquals("bar", parsed.params().get("foo"));
    assertEquals("true", parsed.params().get("setting"));
    assertNull(parsed.username());
}
Also used : ConnectionStringUtil.asConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString) ConnectionString(com.couchbase.client.core.util.ConnectionString) Test(org.junit.jupiter.api.Test)

Example 7 with ConnectionString

use of com.couchbase.client.core.util.ConnectionString in project couchbase-jvm-clients by couchbase.

the class ConnectionStringTest method shouldAcceptSingleIPv6WithPort.

@Test
void shouldAcceptSingleIPv6WithPort() {
    ConnectionString parsed = ConnectionString.create("couchbases://[::1]:8091, [::1]:11210");
    assertEquals(ConnectionString.Scheme.COUCHBASES, parsed.scheme());
    assertEquals(2, parsed.hosts().size());
    assertEquals("::1", parsed.hosts().get(0).hostname());
    assertEquals(8091, parsed.hosts().get(0).port());
    assertEquals("::1", parsed.hosts().get(1).hostname());
    assertEquals(11210, parsed.hosts().get(1).port());
    assertTrue(parsed.params().isEmpty());
    parsed = ConnectionString.create("couchbase://[::1/128]:1234, [::1/128]:11210,[::1/128]:1");
    assertEquals(ConnectionString.Scheme.COUCHBASE, parsed.scheme());
    assertEquals(3, parsed.hosts().size());
    assertEquals("::1/128", parsed.hosts().get(0).hostname());
    assertEquals(1234, parsed.hosts().get(0).port());
    assertEquals("::1/128", parsed.hosts().get(1).hostname());
    assertEquals(11210, parsed.hosts().get(1).port());
    assertEquals("::1/128", parsed.hosts().get(2).hostname());
    assertEquals(1, parsed.hosts().get(2).port());
    assertTrue(parsed.params().isEmpty());
}
Also used : ConnectionStringUtil.asConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString) ConnectionString(com.couchbase.client.core.util.ConnectionString) Test(org.junit.jupiter.api.Test)

Example 8 with ConnectionString

use of com.couchbase.client.core.util.ConnectionString in project couchbase-elasticsearch-connector by couchbase.

the class CouchbaseHelper method getKvNodes.

public static Set<SeedNode> getKvNodes(CouchbaseConfig config, Bucket bucket) {
    String connectionString = String.join(",", config.hosts());
    Duration timeout = Duration.ofSeconds(30);
    return SeedNodeHelper.getKvNodes(bucket, connectionString, config.secureConnection(), config.network(), timeout);
}
Also used : Duration(java.time.Duration) ConnectionString(com.couchbase.client.core.util.ConnectionString)

Example 9 with ConnectionString

use of com.couchbase.client.core.util.ConnectionString in project couchbase-elasticsearch-connector by couchbase.

the class CouchbaseHelper method createCluster.

public static Cluster createCluster(CouchbaseConfig config, ClusterEnvironment env) {
    List<String> hosts = config.hosts();
    // For compatibility with previous 4.2.x versions of the connector,
    // interpret unqualified ports as MANAGER ports instead of KV ports.
    hosts = qualifyPorts(hosts, ConnectionString.PortType.MANAGER);
    String connectionString = String.join(",", hosts);
    Authenticator authenticator = authenticator(config);
    return Cluster.connect(connectionString, clusterOptions(authenticator).environment(env));
}
Also used : ConnectionString(com.couchbase.client.core.util.ConnectionString) PasswordAuthenticator(com.couchbase.client.core.env.PasswordAuthenticator) CertificateAuthenticator(com.couchbase.client.core.env.CertificateAuthenticator) Authenticator(com.couchbase.client.core.env.Authenticator)

Example 10 with ConnectionString

use of com.couchbase.client.core.util.ConnectionString in project couchbase-jvm-clients by couchbase.

the class ConnectionStringTest method canCreateFromSeedNodes.

@Test
void canCreateFromSeedNodes() {
    ConnectionString connectionString = ConnectionString.create(asConnectionString(listOf(SeedNode.create("neither"), SeedNode.create("onlyKvPort", Optional.of(123), Optional.empty()), SeedNode.create("onlyManagerPort", Optional.empty(), Optional.of(456)), SeedNode.create("both", Optional.of(123), Optional.of(456)))));
    System.out.println(connectionString);
    assertEquals("neither,onlyKvPort:123=kv,onlyManagerPort:456=manager,both:123=kv", connectionString.original());
}
Also used : ConnectionStringUtil.asConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString) ConnectionString(com.couchbase.client.core.util.ConnectionString) Test(org.junit.jupiter.api.Test)

Aggregations

ConnectionString (com.couchbase.client.core.util.ConnectionString)14 ConnectionStringUtil.asConnectionString (com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString)12 Test (org.junit.jupiter.api.Test)11 Authenticator (com.couchbase.client.core.env.Authenticator)1 CertificateAuthenticator (com.couchbase.client.core.env.CertificateAuthenticator)1 ConnectionStringPropertyLoader (com.couchbase.client.core.env.ConnectionStringPropertyLoader)1 OwnedSupplier (com.couchbase.client.core.env.OwnedSupplier)1 PasswordAuthenticator (com.couchbase.client.core.env.PasswordAuthenticator)1 ConnectionStringUtil.checkConnectionString (com.couchbase.client.core.util.ConnectionStringUtil.checkConnectionString)1 ClusterEnvironment (com.couchbase.client.java.env.ClusterEnvironment)1 Duration (java.time.Duration)1