use of com.couchbase.client.java.AsyncBucket in project tutorials by eugenp.
the class AbstractCrudService method createBulk.
@Override
public void createBulk(Iterable<T> items) {
final AsyncBucket asyncBucket = bucket.async();
Observable.from(items).flatMap(new Func1<T, Observable<JsonDocument>>() {
@SuppressWarnings("unchecked")
@Override
public Observable<JsonDocument> call(final T t) {
if (t.getId() == null) {
t.setId(UUID.randomUUID().toString());
}
JsonDocument doc = converter.toDocument(t);
return asyncBucket.insert(doc).retryWhen(RetryBuilder.anyOf(BackpressureException.class).delay(Delay.exponential(TimeUnit.MILLISECONDS, 100)).max(10).build());
}
}).last().toBlocking().single();
}
use of com.couchbase.client.java.AsyncBucket in project tutorials by eugenp.
the class AbstractCrudService method updateBulk.
@Override
public void updateBulk(Iterable<T> items) {
final AsyncBucket asyncBucket = bucket.async();
Observable.from(items).flatMap(new Func1<T, Observable<JsonDocument>>() {
@SuppressWarnings("unchecked")
@Override
public Observable<JsonDocument> call(final T t) {
JsonDocument doc = converter.toDocument(t);
return asyncBucket.upsert(doc).retryWhen(RetryBuilder.anyOf(BackpressureException.class).delay(Delay.exponential(TimeUnit.MILLISECONDS, 100)).max(10).build());
}
}).last().toBlocking().single();
}
use of com.couchbase.client.java.AsyncBucket in project tutorials by eugenp.
the class AbstractCrudService method deleteBulk.
@Override
public void deleteBulk(Iterable<String> ids) {
final AsyncBucket asyncBucket = bucket.async();
Observable.from(ids).flatMap(new Func1<String, Observable<JsonDocument>>() {
@SuppressWarnings("unchecked")
@Override
public Observable<JsonDocument> call(String key) {
return asyncBucket.remove(key).retryWhen(RetryBuilder.anyOf(BackpressureException.class).delay(Delay.exponential(TimeUnit.MILLISECONDS, 100)).max(10).build());
}
}).last().toBlocking().single();
}
use of com.couchbase.client.java.AsyncBucket in project samza by apache.
the class TestCouchbaseTableWriteFunction method testDeleteAsyncJsonObjectValue.
@Test
public void testDeleteAsyncJsonObjectValue() throws Exception {
String key = "key";
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.just(null));
assertNull(writeFunction.deleteAsync(key).get());
}
use of com.couchbase.client.java.AsyncBucket in project samza by apache.
the class TestCouchbaseTableWriteFunction method testPutAsyncStringValue.
@Test
public void testPutAsyncStringValue() throws Exception {
String key = "key";
String value = "value";
Bucket bucket = mock(Bucket.class);
AsyncBucket asyncBucket = mock(AsyncBucket.class);
CouchbaseTableWriteFunction<String> writeFunction = createAndInit(String.class, new StringSerde(), bucket, asyncBucket);
when(asyncBucket.upsert(any(Document.class), anyLong(), any(TimeUnit.class))).thenReturn(Observable.just(null));
assertNull(writeFunction.putAsync(key, value).get());
}
Aggregations