use of com.couchbase.client.java.Bucket in project samza by apache.
the class TestCouchbaseTableReadFunction method testGetAsyncJsonObjectValue.
@Test
public void testGetAsyncJsonObjectValue() throws Exception {
String key = "key";
JsonObject value = JsonObject.fromJson("{\"id\": 1}");
Bucket bucket = mock(Bucket.class);
AsyncBucket asyncBucket = mock(AsyncBucket.class);
CouchbaseTableReadFunction readFunction = createAndInit(bucket, asyncBucket);
when(asyncBucket.get(eq(key), anyObject(), anyLong(), any(TimeUnit.class))).thenReturn(Observable.just(JsonDocument.create(key, value)));
assertEquals(value, readFunction.getAsync(key).get());
}
use of com.couchbase.client.java.Bucket in project samza by apache.
the class TestCouchbaseTableReadFunction method testGetAsyncNullValue.
@Test
public void testGetAsyncNullValue() throws Exception {
String key = "NonExistingKey";
Bucket bucket = mock(Bucket.class);
AsyncBucket asyncBucket = mock(AsyncBucket.class);
CouchbaseTableReadFunction readFunction = createAndInit(String.class, new StringSerde(), bucket, asyncBucket);
when(asyncBucket.get(eq(key), anyObject(), anyLong(), any(TimeUnit.class))).thenReturn(Observable.empty());
assertNull(readFunction.getAsync(key).get());
}
use of com.couchbase.client.java.Bucket in project samza by apache.
the class TestCouchbaseRemoteTableEndToEnd method testEndToEnd.
@Test
public void testEndToEnd() {
Bucket inputBucket = cluster.openBucket(inputBucketName);
inputBucket.upsert(ByteArrayDocument.create("Alice", "20".getBytes()));
inputBucket.upsert(ByteArrayDocument.create("Bob", "30".getBytes()));
inputBucket.upsert(ByteArrayDocument.create("Chris", "40".getBytes()));
inputBucket.upsert(ByteArrayDocument.create("David", "50".getBytes()));
inputBucket.close();
List<String> users = Arrays.asList("Alice", "Bob", "Chris", "David");
final StreamApplication app = appDesc -> {
DelegatingSystemDescriptor inputSystemDescriptor = new DelegatingSystemDescriptor("test");
GenericInputDescriptor<String> inputDescriptor = inputSystemDescriptor.getInputDescriptor("User", new NoOpSerde<>());
CouchbaseTableReadFunction<String> readFunction = new CouchbaseTableReadFunction<>(inputBucketName, String.class, "couchbase://127.0.0.1").withBootstrapCarrierDirectPort(couchbaseMock.getCarrierPort(inputBucketName)).withBootstrapHttpDirectPort(couchbaseMock.getHttpPort()).withSerde(new StringSerde());
CouchbaseTableWriteFunction<JsonObject> writeFunction = new CouchbaseTableWriteFunction<>(outputBucketName, JsonObject.class, "couchbase://127.0.0.1").withBootstrapCarrierDirectPort(couchbaseMock.getCarrierPort(outputBucketName)).withBootstrapHttpDirectPort(couchbaseMock.getHttpPort());
RemoteTableDescriptor inputTableDesc = new RemoteTableDescriptor<String, String, Void>("input-table").withReadFunction(readFunction).withRateLimiterDisabled();
Table<KV<String, String>> inputTable = appDesc.getTable(inputTableDesc);
RemoteTableDescriptor outputTableDesc = new RemoteTableDescriptor<String, JsonObject, Object>("output-table").withReadFunction(new NoOpTableReadFunction<>()).withWriteFunction(writeFunction).withRateLimiterDisabled();
Table<KV<String, JsonObject>> outputTable = appDesc.getTable(outputTableDesc);
appDesc.getInputStream(inputDescriptor).map(k -> KV.of(k, k)).join(inputTable, new JoinFunction()).sendTo(outputTable);
};
InMemorySystemDescriptor isd = new InMemorySystemDescriptor("test");
InMemoryInputDescriptor<TestTableData.PageView> inputDescriptor = isd.getInputDescriptor("User", new NoOpSerde<>());
TestRunner.of(app).addInputStream(inputDescriptor, users).run(Duration.ofSeconds(10));
Bucket outputBucket = cluster.openBucket(outputBucketName);
Assert.assertEquals("{\"name\":\"Alice\",\"age\":\"20\"}", outputBucket.get("Alice").content().toString());
Assert.assertEquals("{\"name\":\"Bob\",\"age\":\"30\"}", outputBucket.get("Bob").content().toString());
Assert.assertEquals("{\"name\":\"Chris\",\"age\":\"40\"}", outputBucket.get("Chris").content().toString());
Assert.assertEquals("{\"name\":\"David\",\"age\":\"50\"}", outputBucket.get("David").content().toString());
outputBucket.close();
}
use of com.couchbase.client.java.Bucket in project spring-boot by spring-projects.
the class CouchbaseAutoConfigurationIntegrationTests method defaultConfiguration.
@Test
void defaultConfiguration() {
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(Cluster.class).hasSingleBean(ClusterEnvironment.class);
Cluster cluster = context.getBean(Cluster.class);
Bucket bucket = cluster.bucket(BUCKET_NAME);
bucket.waitUntilReady(Duration.ofMinutes(5));
DiagnosticsResult diagnostics = cluster.diagnostics();
assertThat(diagnostics.state()).isEqualTo(ClusterState.ONLINE);
});
}
use of com.couchbase.client.java.Bucket in project spring-boot by spring-projects.
the class CouchbaseAutoConfigurationIntegrationTests method whenCouchbaseIsUsingCustomObjectMapperThenJsonCanBeRoundTripped.
@Test
void whenCouchbaseIsUsingCustomObjectMapperThenJsonCanBeRoundTripped() {
this.contextRunner.withBean(ObjectMapper.class, ObjectMapper::new).run((context) -> {
Cluster cluster = context.getBean(Cluster.class);
Bucket bucket = cluster.bucket(BUCKET_NAME);
bucket.waitUntilReady(Duration.ofMinutes(5));
Collection collection = bucket.defaultCollection();
collection.insert("test-document", JsonObject.create().put("a", "alpha"));
assertThat(collection.get("test-document").contentAsObject().get("a")).isEqualTo("alpha");
});
}
Aggregations