Java Code Examples for com.couchbase.client.java.env.CouchbaseEnvironment

The following examples show how to use com.couchbase.client.java.env.CouchbaseEnvironment. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@BeforeAll
public static void startCouchbase () {
    container = new CouchbaseContainer().withBucket(new BucketDefinition(BUCKET_NAME));
    container.start();

    CouchbaseEnvironment environment = DefaultCouchbaseEnvironment
        .builder()
        .bootstrapCarrierDirectPort(container.getBootstrapCarrierDirectPort())
        .bootstrapHttpDirectPort(container.getBootstrapHttpDirectPort())
        .build();

    cluster = CouchbaseCluster.create(
        environment,
        container.getContainerIpAddress()
    );

    cluster.authenticate(container.getUsername(), container.getPassword());

    bucket = cluster.openBucket(BUCKET_NAME);
}
 
Example 2
Source Project: samza   Source File: TestCouchbaseBucketRegistry.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This unit test uses CouchbaseBucketRegistry to register two mocked buckets. It tests:
 * 1. Calling registry.getBucket with same bucketName and clusterNodes should return same Bucket instance
 * 2. Calling registry.getBucket with different bucketNames should return different Bucket instances
 */
@Test
public void testOpenBuckets() {
  String bucketName1 = "bucket1";
  String bucketName2 = "bucket2";
  List<String> clusterNodes = Arrays.asList("cluster");
  CouchbaseEnvironmentConfigs configs = new CouchbaseEnvironmentConfigs();
  CouchbaseCluster cluster = mock(CouchbaseCluster.class);
  when(cluster.openBucket(bucketName1)).thenReturn(mock(Bucket.class));
  when(cluster.openBucket(bucketName2)).thenReturn(mock(Bucket.class));
  mockStatic(CouchbaseCluster.class);
  when(CouchbaseCluster.create(any(CouchbaseEnvironment.class), anyListOf(String.class))).thenReturn(cluster);
  CouchbaseBucketRegistry registry = new CouchbaseBucketRegistry();
  Bucket bucket1 = registry.getBucket(bucketName1, clusterNodes, configs);
  Bucket bucket1Copy = registry.getBucket(bucketName1, clusterNodes, configs);
  Bucket bucket2 = registry.getBucket(bucketName2, clusterNodes, configs);
  assertEquals(bucket1, bucket1Copy);
  assertNotEquals(bucket1, bucket2);
}
 
Example 3
Source Project: samza   Source File: TestCouchbaseBucketRegistry.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This unit test uses CouchbaseBucketRegistry to register two mocked buckets with same name but in different clusters.
 * Calling registry.getBucket with same bucketName but different clusterNodes should return different Bucket instances.
 */
@Test
public void testOpenSameBucketNameFromDifferentClusters() {
  String bucketName = "bucket";
  List<String> clusterNodes1 = Arrays.asList("cluster1");
  List<String> clusterNodes2 = Arrays.asList("cluster2");
  CouchbaseEnvironmentConfigs configs = new CouchbaseEnvironmentConfigs();
  CouchbaseCluster cluster1 = mock(CouchbaseCluster.class);
  CouchbaseCluster cluster2 = mock(CouchbaseCluster.class);
  when(cluster1.openBucket(bucketName)).thenReturn(mock(Bucket.class));
  when(cluster2.openBucket(bucketName)).thenReturn(mock(Bucket.class));
  mockStatic(CouchbaseCluster.class);
  when(CouchbaseCluster.create(any(CouchbaseEnvironment.class), eq(clusterNodes1))).thenReturn(cluster1);
  when(CouchbaseCluster.create(any(CouchbaseEnvironment.class), eq(clusterNodes2))).thenReturn(cluster2);
  CouchbaseBucketRegistry registry = new CouchbaseBucketRegistry();
  Bucket bucketInCluster1 = registry.getBucket(bucketName, clusterNodes1, configs);
  Bucket bucketInCluster2 = registry.getBucket(bucketName, clusterNodes2, configs);
  assertNotEquals(bucketInCluster1, bucketInCluster2);
}
 
Example 4
Source Project: samza   Source File: TestCouchbaseBucketRegistry.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This unit test simulates 10 tasks using the same bucket. Each task will call registry.getBucket once. Then
 * each task will also call registry.closeBucket once. After that, registry.closeBucket should return false if we
 * close the bucket one more time. And the bucket should have already been closed.
 */
@Test
public void testCloseBucket() {
  String bucketName = "bucket";
  List<String> clusterNodes = Arrays.asList("cluster");
  CouchbaseEnvironmentConfigs configs = new CouchbaseEnvironmentConfigs();
  CouchbaseCluster cluster = mock(CouchbaseCluster.class);
  Bucket bucket = mock(Bucket.class);
  when(bucket.close()).thenReturn(true).thenReturn(false);
  when(cluster.openBucket(bucketName)).thenReturn(bucket);
  when(cluster.disconnect()).thenReturn(true).thenReturn(false);
  mockStatic(CouchbaseCluster.class);
  when(CouchbaseCluster.create(any(CouchbaseEnvironment.class), eq(clusterNodes))).thenReturn(cluster);
  CouchbaseBucketRegistry registry = new CouchbaseBucketRegistry();
  int numOfThreads = 10;
  for (int i = 0; i < numOfThreads; i++) {
    registry.getBucket(bucketName, clusterNodes, configs);
  }
  for (int i = 0; i < numOfThreads; i++) {
    assertTrue(registry.closeBucket(bucketName, clusterNodes));
  }
  // Close one more time. Should return false.
  assertFalse(registry.closeBucket(bucketName, clusterNodes));
  // Bucket should has been closed
  assertFalse(bucket.close());
}
 
Example 5
Source Project: components   Source File: CouchbaseInputTestIT.java    License: Apache License 2.0 6 votes vote down vote up
private void populateBucket() {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment
            .builder()
            .socketConnectTimeout(60000)
            .connectTimeout(60000)
            .keepAliveInterval(60000)
            .keyValueServiceConfig(KeyValueServiceConfig.create(60)) // If skip this config, we may get TimeoutException https://forums.couchbase.com/t/kv-upsert-throwing-timeoutexception-couchbase-4-5/9399
            .build();
    CouchbaseCluster cluster = CouchbaseCluster.create(env, bootstrapNodes);
    Bucket bucket = cluster.openBucket(bucketName, password);
    LOGGER.info("Connected to bucket - " + bucketName);
    assertTrue(bucket.bucketManager().flush());
    JsonDocument document = JsonDocument.create("foo", JsonObject.create().put("bar", 42));
    bucket.upsert(document, PersistTo.MASTER);
    bucket.close();
    LOGGER.info("Bucket is closed after upserting data");
    if (cluster != null) {
        cluster.disconnect();
    }
}
 
Example 6
@Override
protected CouchbaseEnvironment getEnvironment() {
    return DefaultCouchbaseEnvironment.builder()
        .connectTimeout(10000)
        .kvTimeout(10000)
        .queryTimeout(10000)
        .viewTimeout(10000)
        .build();
}
 
Example 7
Source Project: samza   Source File: TestCouchbaseBucketRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This unit test simulates closing two buckets within one cluster. The cluster should only be disconnected when all
 * buckets has been closed.
 */
@Test
public void testCloseTwoBucketsInSameCluster() {
  String bucketName1 = "bucket1";
  String bucketName2 = "bucket2";
  List<String> clusterNodes = Arrays.asList("cluster");
  CouchbaseEnvironmentConfigs configs = new CouchbaseEnvironmentConfigs();
  CouchbaseCluster cluster = mock(CouchbaseCluster.class);
  Bucket bucket1 = mock(Bucket.class);
  Bucket bucket2 = mock(Bucket.class);
  when(bucket1.close()).thenReturn(true).thenReturn(false);
  when(bucket2.close()).thenReturn(true).thenReturn(false);
  when(cluster.openBucket(bucketName1)).thenReturn(bucket1);
  when(cluster.openBucket(bucketName2)).thenReturn(bucket2);
  when(cluster.disconnect()).thenReturn(true).thenReturn(false);
  mockStatic(CouchbaseCluster.class);
  when(CouchbaseCluster.create(any(CouchbaseEnvironment.class), eq(clusterNodes))).thenReturn(cluster);
  CouchbaseBucketRegistry registry = new CouchbaseBucketRegistry();
  registry.getBucket(bucketName1, clusterNodes, configs);
  registry.getBucket(bucketName2, clusterNodes, configs);
  assertTrue(registry.closeBucket(bucketName1, clusterNodes));
  assertTrue(registry.closeBucket(bucketName2, clusterNodes));
  // Cluster should have been disconnected. Should return false.
  assertFalse(cluster.disconnect());
  // Buckets should have been closed. Should return false.
  assertFalse(cluster.disconnect());
}
 
Example 8
Source Project: components   Source File: CouchbaseConnectionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    PowerMockito.mockStatic(CouchbaseCluster.class);
    cluster = Mockito.mock(CouchbaseCluster.class);
    Mockito.when(CouchbaseCluster.create(Mockito.any(CouchbaseEnvironment.class), Mockito.eq("testNode"))).thenReturn(cluster);
    connection = new CouchbaseConnection("testNode", "testBucket", "defaultPassword");
    bucket = Mockito.mock(Bucket.class);
    Mockito.when(cluster.openBucket(Mockito.anyString(), Mockito.anyString())).thenReturn(bucket);
}
 
Example 9
/**
 * Currently hands out a singleton DefaultCouchbaseEnvironment.
 * This is done because it is recommended to use a single couchbase environment instance per JVM.
 * TODO: Determine if we need to use the config to tweak certain parameters
 * @param config
 * @return
 */
public static synchronized CouchbaseEnvironment getInstance(Config config)
{
  Boolean sslEnabled = ConfigUtils.getBoolean(config, CouchbaseWriterConfigurationKeys.SSL_ENABLED, false);
  String sslKeystoreFile = ConfigUtils.getString(config, CouchbaseWriterConfigurationKeys.SSL_KEYSTORE_FILE, "");
  String sslKeystorePassword = ConfigUtils.getString(config, CouchbaseWriterConfigurationKeys.SSL_KEYSTORE_PASSWORD, "");
  String sslTruststoreFile = ConfigUtils.getString(config, CouchbaseWriterConfigurationKeys.SSL_TRUSTSTORE_FILE, "");
  String sslTruststorePassword = ConfigUtils.getString(config, CouchbaseWriterConfigurationKeys.SSL_TRUSTSTORE_PASSWORD, "");
  Boolean certAuthEnabled = ConfigUtils.getBoolean(config, CouchbaseWriterConfigurationKeys.CERT_AUTH_ENABLED, false);
  Boolean dnsSrvEnabled = ConfigUtils.getBoolean(config, CouchbaseWriterConfigurationKeys.DNS_SRV_ENABLED, false);
  Integer socketConnectTimeout = ConfigUtils.getInt(config, CouchbaseWriterConfigurationKeys.SOCKET_CONNECT_TIMEOUT,
      DefaultCouchbaseEnvironment.SOCKET_CONNECT_TIMEOUT);

  DefaultCouchbaseEnvironment.Builder builder = DefaultCouchbaseEnvironment.builder()
      .sslEnabled(sslEnabled)
      .sslKeystoreFile(sslKeystoreFile)
      .sslKeystorePassword(sslKeystorePassword)
      .sslTruststoreFile(sslTruststoreFile)
      .sslTruststorePassword(sslTruststorePassword)
      .certAuthEnabled(certAuthEnabled)
      .dnsSrvEnabled(dnsSrvEnabled)
      .socketConnectTimeout(socketConnectTimeout);

  if (couchbaseEnvironment == null)
  {
    couchbaseEnvironment = builder.build();
  }
  return couchbaseEnvironment;
}
 
Example 10
Source Project: incubator-gobblin   Source File: CouchbaseWriter.java    License: Apache License 2.0 5 votes vote down vote up
public CouchbaseWriter(CouchbaseEnvironment couchbaseEnvironment, Config config) {

    List<String> hosts = ConfigUtils.getStringList(config, CouchbaseWriterConfigurationKeys.BOOTSTRAP_SERVERS);
    boolean usesCertAuth = ConfigUtils.getBoolean(config, CouchbaseWriterConfigurationKeys.CERT_AUTH_ENABLED, false);
    String password = ConfigUtils.getString(config, CouchbaseWriterConfigurationKeys.PASSWORD, "");

    log.info("Using hosts hosts: {}", hosts.stream().collect(Collectors.joining(",")));

    _documentTTL = ConfigUtils.getInt(config, CouchbaseWriterConfigurationKeys.DOCUMENT_TTL, 0);
    _documentTTLTimeUnits =
        ConfigUtils.getTimeUnit(config, CouchbaseWriterConfigurationKeys.DOCUMENT_TTL_UNIT, CouchbaseWriterConfigurationKeys.DOCUMENT_TTL_UNIT_DEFAULT);
    _documentTTLOriginField =
        ConfigUtils.getString(config, CouchbaseWriterConfigurationKeys.DOCUMENT_TTL_ORIGIN_FIELD, null);
    _documentTTLOriginUnits =
        ConfigUtils.getTimeUnit(config, CouchbaseWriterConfigurationKeys.DOCUMENT_TTL_ORIGIN_FIELD_UNITS,
            CouchbaseWriterConfigurationKeys.DOCUMENT_TTL_ORIGIN_FIELD_UNITS_DEFAULT);

    String bucketName = ConfigUtils.getString(config, CouchbaseWriterConfigurationKeys.BUCKET,
        CouchbaseWriterConfigurationKeys.BUCKET_DEFAULT);

    _cluster = CouchbaseCluster.create(couchbaseEnvironment, hosts);

    if (usesCertAuth) {
      _cluster.authenticate(CertAuthenticator.INSTANCE);
      _bucket = _cluster.openBucket(bucketName, Collections.singletonList(_tupleDocumentTranscoder));
    } else if (password.isEmpty()) {
      _bucket = _cluster.openBucket(bucketName, Collections.singletonList(_tupleDocumentTranscoder));
    } else {
      _bucket = _cluster.openBucket(bucketName, password, Collections.singletonList(_tupleDocumentTranscoder));
    }
    _operationTimeout = ConfigUtils.getLong(config, CouchbaseWriterConfigurationKeys.OPERATION_TIMEOUT_MILLIS,
        CouchbaseWriterConfigurationKeys.OPERATION_TIMEOUT_DEFAULT);
    _operationTimeunit = TimeUnit.MILLISECONDS;

    _defaultWriteResponseMapper = new GenericWriteResponseWrapper<>();

    log.info("Couchbase writer configured with: hosts: {}, bucketName: {}, operationTimeoutInMillis: {}", hosts,
        bucketName, _operationTimeout);
  }
 
Example 11
Source Project: incubator-gobblin   Source File: CouchbaseWriterBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public DataWriter build(Config config) throws IOException {
  Assert.assertNotNull("Config cannot be null", config);
  config.entrySet().stream().forEach(x -> String.format("Config passed to factory builder '%s':'%s'", x.getKey(), x.getValue().toString()));
  CouchbaseEnvironment couchbaseEnvironment = CouchbaseEnvironmentFactory.getInstance(config);

  //TODO: Read config to decide whether to build a blocking writer or an async writer

  double failureAllowance =
      ConfigUtils.getDouble(config, CouchbaseWriterConfigurationKeys.FAILURE_ALLOWANCE_PCT_CONFIG,
          CouchbaseWriterConfigurationKeys.FAILURE_ALLOWANCE_PCT_DEFAULT) / 100.0;

  boolean retriesEnabled = ConfigUtils.getBoolean(config, CouchbaseWriterConfigurationKeys.RETRIES_ENABLED,
      CouchbaseWriterConfigurationKeys.RETRIES_ENABLED_DEFAULT);

  int maxRetries = ConfigUtils.getInt(config, CouchbaseWriterConfigurationKeys.MAX_RETRIES,
      CouchbaseWriterConfigurationKeys.MAX_RETRIES_DEFAULT);

  // build an async couchbase writer
  AsyncDataWriter couchbaseWriter = new CouchbaseWriter(couchbaseEnvironment, config);
  return AsyncWriterManager.builder()
      .asyncDataWriter(couchbaseWriter)
      .failureAllowanceRatio(failureAllowance)
      .retriesEnabled(retriesEnabled)
      .numRetries(maxRetries)
      .config(config)
      .build();
}
 
Example 12
Source Project: incubator-gobblin   Source File: CouchbaseTestServer.java    License: Apache License 2.0 5 votes vote down vote up
@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();
  }
}
 
Example 13
Source Project: incubator-pinot   Source File: CouchbaseCacheDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Initialize connection to Couchbase and open bucket where data is stored.
 */
private void createDataStoreConnection() {
  CacheDataSource dataSource = CacheConfig.getInstance().getCentralizedCacheSettings().getDataSourceConfig();
  Map<String, Object> config = dataSource.getConfig();
  List<String> hosts = ConfigUtils.getList(config.get(HOSTS));

  Cluster cluster;
  if (MapUtils.getBoolean(config, USE_CERT_BASED_AUTH)) {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment
        .builder()
        .sslEnabled(true)
        .certAuthEnabled(true)
        .dnsSrvEnabled(MapUtils.getBoolean(config, ENABLE_DNS_SRV))
        .sslKeystoreFile(MapUtils.getString(config, KEY_STORE_FILE_PATH))
        .sslKeystorePassword(MapUtils.getString(config, KEY_STORE_PASSWORD))
        .sslTruststoreFile(MapUtils.getString(config, TRUST_STORE_FILE_PATH))
        .sslTruststorePassword(MapUtils.getString(config, TRUST_STORE_PASSWORD))
        .build();

    cluster = CouchbaseCluster.create(env, CacheUtils.getBootstrapHosts(hosts));
    cluster.authenticate(CertAuthenticator.INSTANCE);
  } else {
    cluster = CouchbaseCluster.create(hosts);
    cluster.authenticate(MapUtils.getString(config, AUTH_USERNAME), MapUtils.getString(config, AUTH_PASSWORD));
  }

  this.bucket = cluster.openBucket(CacheUtils.getBucketName());
}
 
Example 14
Source Project: tutorials   Source File: ReactiveCouchbaseConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
public CouchbaseEnvironment couchbaseEnvironment() {
    return DefaultCouchbaseEnvironment
      .builder()
      .bootstrapHttpDirectPort(couchbaseProperties.getPort())
      .build();
}
 
Example 15
Source Project: tutorials   Source File: IntegrationTestConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public Cluster cluster() {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
      .connectTimeout(60000)
      .build();
    return CouchbaseCluster.create(env, "127.0.0.1");
}
 
Example 16
Source Project: tutorials   Source File: PersonCrudServiceIntegrationTestConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public Cluster cluster() {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
      .connectTimeout(60000)
      .build();
    return CouchbaseCluster.create(env, "127.0.0.1");
}
 
Example 17
Source Project: samza   Source File: CouchbaseBucketRegistry.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source Project: testcontainers-java   Source File: CouchbaseContainerTest.java    License: MIT License 4 votes vote down vote up
@Test
public void testBasicContainerUsage() {
    // bucket_definition {
    BucketDefinition bucketDefinition = new BucketDefinition("mybucket");
    // }

    try (
        // container_definition {
        CouchbaseContainer container = new CouchbaseContainer()
            .withBucket(bucketDefinition)
        // }
    ) {
        container.start();

        // cluster_creation {
        CouchbaseEnvironment environment = DefaultCouchbaseEnvironment
            .builder()
            .bootstrapCarrierDirectPort(container.getBootstrapCarrierDirectPort())
            .bootstrapHttpDirectPort(container.getBootstrapHttpDirectPort())
            .build();

        Cluster cluster = CouchbaseCluster.create(
            environment,
            container.getHost()
        );
        // }

        try {
            // auth {
            cluster.authenticate(container.getUsername(), container.getPassword());
            // }

            Bucket bucket = cluster.openBucket(bucketDefinition.getName());

            bucket.upsert(JsonDocument.create("foo", JsonObject.empty()));

            assertTrue(bucket.exists("foo"));
            assertNotNull(cluster.clusterManager().getBucket(bucketDefinition.getName()));
        } finally {
            cluster.disconnect();
            environment.shutdown();
        }
    }
}
 
Example 19
Source Project: components   Source File: CouchbaseConnection.java    License: Apache License 2.0 4 votes vote down vote up
public CouchbaseConnection(String bootstrapNodes, String bucket, String password) {
    CouchbaseEnvironment environment = new DefaultCouchbaseEnvironment.Builder().connectTimeout(20000L).build();
    this.cluster = CouchbaseCluster.create(environment, bootstrapNodes);
    this.bucketName = bucket;
    this.password = password;
}
 
Example 20
Source Project: tutorials   Source File: ClusterServiceImpl.java    License: MIT License 4 votes vote down vote up
@PostConstruct
private void init() {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment.create();
    cluster = CouchbaseCluster.create(env, "localhost");
}
 
Example 21
Source Project: tutorials   Source File: CodeSnippets.java    License: MIT License 4 votes vote down vote up
static Cluster loadClusterWithCustomEnvironment() {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().connectTimeout(10000).kvTimeout(3000).build();
    return CouchbaseCluster.create(env, "localhost");
}
 
Example 22
Source Project: tutorials   Source File: ClusterServiceImpl.java    License: MIT License 4 votes vote down vote up
@PostConstruct
private void init() {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment.create();
    cluster = CouchbaseCluster.create(env, "localhost");
}