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());
}
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());
}
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);
}
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));
}
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());
}
Aggregations