use of com.couchbase.client.core.util.ConnectionString in project couchbase-jvm-clients by couchbase.
the class AsyncCluster method extractClusterEnvironment.
/**
* Helper method to extract the cluster environment from the connection string and options.
*
* @param connectionString the connection string which is used to populate settings into it.
* @param opts the cluster options.
* @return the cluster environment, created if not passed in or the one supplied from the user.
*/
static Supplier<ClusterEnvironment> extractClusterEnvironment(final String connectionString, final ClusterOptions.Built opts) {
ConnectionString connStr = ConnectionString.create(connectionString);
Supplier<ClusterEnvironment> envSupplier;
if (opts.environment() == null) {
ClusterEnvironment.Builder builder = ClusterEnvironment.builder();
if (opts.environmentCustomizer() != null) {
opts.environmentCustomizer().accept(builder);
}
builder.load(new ConnectionStringPropertyLoader(connStr));
envSupplier = new OwnedSupplier<>(builder.build());
} else {
envSupplier = opts::environment;
}
boolean ownsEnvironment = envSupplier instanceof OwnedSupplier;
checkConnectionString(envSupplier.get(), ownsEnvironment, connStr);
return envSupplier;
}
use of com.couchbase.client.core.util.ConnectionString in project couchbase-jvm-clients by couchbase.
the class ConnectionStringTest method shouldAcceptIPv6WithPortType.
@Test
void shouldAcceptIPv6WithPortType() {
ConnectionString parsed = ConnectionString.create("couchbases://[::1]:8091=http,[::1]:11210=kv");
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(ConnectionString.PortType.MANAGER, parsed.hosts().get(0).portType().get());
assertEquals("::1", parsed.hosts().get(1).hostname());
assertEquals(11210, parsed.hosts().get(1).port());
assertEquals(ConnectionString.PortType.KV, parsed.hosts().get(1).portType().get());
assertTrue(parsed.params().isEmpty());
}
use of com.couchbase.client.core.util.ConnectionString in project couchbase-jvm-clients by couchbase.
the class ConnectionStringTest method shouldParseUsername.
@Test
void shouldParseUsername() {
ConnectionString parsed = ConnectionString.create("couchbase://user@localhost?foo=bar");
assertEquals(ConnectionString.Scheme.COUCHBASE, parsed.scheme());
assertEquals("user", parsed.username());
assertEquals("localhost", parsed.hosts().get(0).hostname());
assertEquals(0, parsed.hosts().get(0).port());
assertEquals(1, parsed.params().size());
assertEquals("bar", parsed.params().get("foo"));
parsed = ConnectionString.create("couchbase://user123@host1,host2?foo=bar&setting=true");
assertEquals(ConnectionString.Scheme.COUCHBASE, parsed.scheme());
assertEquals("user123", parsed.username());
assertEquals("host1", parsed.hosts().get(0).hostname());
assertEquals("host2", parsed.hosts().get(1).hostname());
assertEquals(2, parsed.params().size());
assertEquals("bar", parsed.params().get("foo"));
assertEquals("true", parsed.params().get("setting"));
}
use of com.couchbase.client.core.util.ConnectionString in project couchbase-jvm-clients by couchbase.
the class ConnectionStringTest method shouldParseHostList.
@Test
void shouldParseHostList() {
ConnectionString parsed = ConnectionString.create("couchbase://localhost");
assertEquals(ConnectionString.Scheme.COUCHBASE, parsed.scheme());
assertTrue(parsed.params().isEmpty());
assertEquals(1, parsed.hosts().size());
assertEquals("localhost", parsed.hosts().get(0).hostname());
assertEquals(0, parsed.hosts().get(0).port());
assertNull(parsed.username());
parsed = ConnectionString.create("couchbase://localhost:1234");
assertEquals(ConnectionString.Scheme.COUCHBASE, parsed.scheme());
assertTrue(parsed.params().isEmpty());
assertEquals(1, parsed.hosts().size());
assertEquals("localhost", parsed.hosts().get(0).hostname());
assertEquals(1234, parsed.hosts().get(0).port());
assertNull(parsed.username());
parsed = ConnectionString.create("couchbase://foo:1234,bar:5678");
assertEquals(ConnectionString.Scheme.COUCHBASE, parsed.scheme());
assertTrue(parsed.params().isEmpty());
assertEquals(2, parsed.hosts().size());
assertEquals("foo", parsed.hosts().get(0).hostname());
assertEquals(1234, parsed.hosts().get(0).port());
assertEquals("bar", parsed.hosts().get(1).hostname());
assertEquals(5678, parsed.hosts().get(1).port());
assertNull(parsed.username());
parsed = ConnectionString.create("couchbase://foo,bar:5678,baz");
assertEquals(ConnectionString.Scheme.COUCHBASE, parsed.scheme());
assertTrue(parsed.params().isEmpty());
assertEquals(3, parsed.hosts().size());
assertEquals("foo", parsed.hosts().get(0).hostname());
assertEquals(0, parsed.hosts().get(0).port());
assertEquals("bar", parsed.hosts().get(1).hostname());
assertEquals(5678, parsed.hosts().get(1).port());
assertEquals("baz", parsed.hosts().get(2).hostname());
assertEquals(0, parsed.hosts().get(2).port());
assertNull(parsed.username());
}
use of com.couchbase.client.core.util.ConnectionString in project couchbase-jvm-clients by couchbase.
the class ConnectionStringTest method shouldParseValidSchemes.
@Test
void shouldParseValidSchemes() {
ConnectionString parsed = ConnectionString.create("couchbase://");
assertEquals(ConnectionString.Scheme.COUCHBASE, parsed.scheme());
assertTrue(parsed.hosts().isEmpty());
assertTrue(parsed.params().isEmpty());
parsed = ConnectionString.create("couchbases://");
assertEquals(ConnectionString.Scheme.COUCHBASES, parsed.scheme());
assertTrue(parsed.hosts().isEmpty());
assertTrue(parsed.params().isEmpty());
}
Aggregations