use of com.couchbase.client.java.Bucket in project tutorials by eugenp.
the class N1QLIntegrationTest method givenDeleteStatement_whenQuery_thenDelete.
@Test
public void givenDeleteStatement_whenQuery_thenDelete() {
Bucket bucket = bucketFactory.getTravelSampleBucket();
String query4 = "DELETE FROM `travel-sample` USE KEYS \"cust_50\"";
N1qlQueryResult result4 = bucket.query(N1qlQuery.simple(query4));
}
use of com.couchbase.client.java.Bucket in project tutorials by eugenp.
the class N1QLIntegrationTest method givenDocuments_whenBatchInsert_thenResult.
@Test
public void givenDocuments_whenBatchInsert_thenResult() {
Bucket bucket = bucketFactory.getTravelSampleBucket();
List<JsonDocument> documents = IntStream.rangeClosed(0, 10).mapToObj(i -> {
JsonObject content = JsonObject.create().put("id", i).put("type", "airline").put("name", "Sample Airline " + i);
return JsonDocument.create("cust_" + i, content);
}).collect(Collectors.toList());
List<JsonDocument> r5 = Observable.from(documents).flatMap(doc -> bucket.async().insert(doc)).toList().last().toBlocking().single();
r5.forEach(System.out::println);
}
use of com.couchbase.client.java.Bucket in project tutorials by eugenp.
the class PersonServiceIntegrationTest method setupBeforeClass.
@BeforeClass
public static void setupBeforeClass() {
final Cluster cluster = CouchbaseCluster.create(MyCouchbaseConfig.NODE_LIST);
final Bucket bucket = cluster.openBucket(MyCouchbaseConfig.BUCKET_NAME, MyCouchbaseConfig.BUCKET_PASSWORD);
bucket.upsert(JsonDocument.create(johnSmithId, jsonJohnSmith));
bucket.upsert(JsonDocument.create(foobarId, jsonFooBar));
bucket.close();
cluster.disconnect();
}
use of com.couchbase.client.java.Bucket in project tutorials by eugenp.
the class StudentServiceIntegrationTest method setupBeforeClass.
@BeforeClass
public static void setupBeforeClass() {
Cluster cluster = CouchbaseCluster.create(MyCouchbaseConfig.NODE_LIST);
Bucket bucket = cluster.openBucket(MyCouchbaseConfig.BUCKET_NAME, MyCouchbaseConfig.BUCKET_PASSWORD);
bucket.upsert(JsonDocument.create(joeCollegeId, jsonJoeCollege));
bucket.upsert(JsonDocument.create(judyJetsonId, jsonJudyJetson));
bucket.close();
cluster.disconnect();
}
use of com.couchbase.client.java.Bucket in project samza by apache.
the class TestCouchbaseBucketRegistry method testCloseBucket.
/**
* 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());
}
Aggregations