use of com.couchbase.client.java.env.CouchbaseEnvironment in project incubator-gobblin by apache.
the class CouchbaseTestServer method testServer.
@Test
public static void testServer() throws InterruptedException, IOException {
CouchbaseTestServer couchbaseTestServer = new CouchbaseTestServer(TestUtils.findFreePort());
couchbaseTestServer.start();
int port = couchbaseTestServer.getPort();
int serverPort = couchbaseTestServer.getServerPort();
try {
CouchbaseEnvironment cbEnv = DefaultCouchbaseEnvironment.builder().bootstrapHttpEnabled(true).bootstrapHttpDirectPort(port).bootstrapCarrierDirectPort(serverPort).connectTimeout(TimeUnit.SECONDS.toMillis(15)).bootstrapCarrierEnabled(true).build();
CouchbaseCluster cbCluster = CouchbaseCluster.create(cbEnv, "localhost");
Bucket bucket = cbCluster.openBucket("default", "");
try {
JsonObject content = JsonObject.empty().put("name", "Michael");
JsonDocument doc = JsonDocument.create("docId", content);
JsonDocument inserted = bucket.insert(doc);
} catch (Exception e) {
Assert.fail("Should not throw exception on insert", e);
}
} finally {
couchbaseTestServer.stop();
}
}
use of com.couchbase.client.java.env.CouchbaseEnvironment in project components by Talend.
the class CouchbaseInputTestIT method populateBucket.
private void populateBucket() {
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().socketConnectTimeout(60000).connectTimeout(60000).keepAliveInterval(60000).build();
CouchbaseCluster cluster = CouchbaseCluster.create(env, bootstrapNodes);
Bucket bucket = cluster.openBucket(bucketName, password);
assertTrue(bucket.bucketManager().flush());
JsonDocument document = JsonDocument.create("foo", JsonObject.create().put("bar", 42));
bucket.upsert(document, PersistTo.MASTER);
bucket.close();
cluster.disconnect();
}
use of com.couchbase.client.java.env.CouchbaseEnvironment in project tutorials by eugenp.
the class ClusterServiceImpl method init.
@PostConstruct
private void init() {
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.create();
cluster = CouchbaseCluster.create(env, "localhost");
}
use of com.couchbase.client.java.env.CouchbaseEnvironment 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;
}
use of com.couchbase.client.java.env.CouchbaseEnvironment in project teiid by teiid.
the class CouchbaseManagedConnectionFactory method createConnectionFactory.
@SuppressWarnings("serial")
@Override
public BasicConnectionFactory<CouchbaseConnectionImpl> createConnectionFactory() throws ResourceException {
final CouchbaseEnvironment environment = DefaultCouchbaseEnvironment.builder().managementTimeout(managementTimeout).queryTimeout(queryTimeout).viewTimeout(viewTimeout).kvTimeout(kvTimeout).searchTimeout(searchTimeout).connectTimeout(connectTimeout).dnsSrvEnabled(dnsSrvEnabled).build();
if (this.connectionString == null) {
// $NON-NLS-1$
throw new InvalidPropertyException(UTIL.getString("no_server"));
}
if (this.keyspace == null) {
// $NON-NLS-1$
throw new InvalidPropertyException(UTIL.getString("no_keyspace"));
}
if (this.namespace == null) {
// $NON-NLS-1$
throw new InvalidPropertyException(UTIL.getString("no_namespace"));
}
final ScanConsistency consistency = ScanConsistency.valueOf(scanConsistency);
TimeUnit unit = TimeUnit.MILLISECONDS;
if (this.timeUnit != null) {
try {
unit = TimeUnit.valueOf(timeUnit);
} catch (IllegalArgumentException e) {
// $NON-NLS-1$
throw new InvalidPropertyException(UTIL.getString("invalid_timeUnit", timeUnit));
}
}
final TimeUnit timeoutUnit = unit;
return new BasicConnectionFactory<CouchbaseConnectionImpl>() {
@Override
public CouchbaseConnectionImpl getConnection() throws ResourceException {
return new CouchbaseConnectionImpl(environment, connectionString, keyspace, password, timeoutUnit, namespace, consistency);
}
};
}
Aggregations