use of com.couchbase.client.java.AsyncBucket in project tutorials by eugenp.
the class AbstractCrudService method readBulk.
@Override
public List<T> readBulk(Iterable<String> ids) {
final AsyncBucket asyncBucket = bucket.async();
Observable<JsonDocument> asyncOperation = Observable.from(ids).flatMap(new Func1<String, Observable<JsonDocument>>() {
public Observable<JsonDocument> call(String key) {
return asyncBucket.get(key);
}
});
final List<T> items = new ArrayList<T>();
try {
asyncOperation.toBlocking().forEach(new Action1<JsonDocument>() {
public void call(JsonDocument doc) {
T item = converter.fromDocument(doc);
items.add(item);
}
});
} catch (Exception e) {
logger.error("Error during bulk get", e);
}
return items;
}
use of com.couchbase.client.java.AsyncBucket in project samza by apache.
the class TestCouchbaseTableWriteFunction method testDeleteAsyncException.
@Test
public void testDeleteAsyncException() {
String key = "throwExceptionKey";
Bucket bucket = mock(Bucket.class);
AsyncBucket asyncBucket = mock(AsyncBucket.class);
CouchbaseTableWriteFunction<JsonObject> writeFunction = createAndInit(bucket, asyncBucket);
when(asyncBucket.remove(eq(key), anyLong(), any(TimeUnit.class))).thenReturn(Observable.error(new CouchbaseException()));
assertTrue(writeFunction.deleteAsync(key).isCompletedExceptionally());
}
use of com.couchbase.client.java.AsyncBucket in project samza by apache.
the class TestCouchbaseTableWriteFunction method testPutAsyncException.
@Test
public void testPutAsyncException() {
String key = "throwExceptionKey";
JsonObject value = JsonObject.create();
Bucket bucket = mock(Bucket.class);
AsyncBucket asyncBucket = mock(AsyncBucket.class);
CouchbaseTableWriteFunction<JsonObject> writeFunction = createAndInit(bucket, asyncBucket);
when(asyncBucket.upsert(any(Document.class), anyLong(), any(TimeUnit.class))).thenReturn(Observable.error(new CouchbaseException()));
assertTrue(writeFunction.putAsync(key, value).isCompletedExceptionally());
}
use of com.couchbase.client.java.AsyncBucket in project samza by apache.
the class TestCouchbaseTableReadFunction method testGetAsyncException.
@Test
public void testGetAsyncException() {
String key = "throwExceptionKey";
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.error(new CouchbaseException()));
assertTrue(readFunction.getAsync(key).isCompletedExceptionally());
}
use of com.couchbase.client.java.AsyncBucket in project samza by apache.
the class TestCouchbaseTableReadFunction method testGetAsyncFailedToDeserialize.
@Test
public void testGetAsyncFailedToDeserialize() {
String key = "key";
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.just(BinaryDocument.create(key, null)));
assertTrue(readFunction.getAsync(key).isCompletedExceptionally());
}
Aggregations