Search in sources :

Example 1 with AsyncBucket

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();
}
Also used : AsyncBucket(com.couchbase.client.java.AsyncBucket) Func1(rx.functions.Func1) JsonDocument(com.couchbase.client.java.document.JsonDocument)

Example 2 with AsyncBucket

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();
}
Also used : AsyncBucket(com.couchbase.client.java.AsyncBucket) Func1(rx.functions.Func1) JsonDocument(com.couchbase.client.java.document.JsonDocument)

Example 3 with AsyncBucket

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();
}
Also used : AsyncBucket(com.couchbase.client.java.AsyncBucket) Func1(rx.functions.Func1) JsonDocument(com.couchbase.client.java.document.JsonDocument)

Example 4 with AsyncBucket

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());
}
Also used : AsyncBucket(com.couchbase.client.java.AsyncBucket) Bucket(com.couchbase.client.java.Bucket) AsyncBucket(com.couchbase.client.java.AsyncBucket) JsonObject(com.couchbase.client.java.document.json.JsonObject) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with AsyncBucket

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());
}
Also used : StringSerde(org.apache.samza.serializers.StringSerde) AsyncBucket(com.couchbase.client.java.AsyncBucket) Bucket(com.couchbase.client.java.Bucket) AsyncBucket(com.couchbase.client.java.AsyncBucket) TimeUnit(java.util.concurrent.TimeUnit) Document(com.couchbase.client.java.document.Document) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

AsyncBucket (com.couchbase.client.java.AsyncBucket)16 Bucket (com.couchbase.client.java.Bucket)12 TimeUnit (java.util.concurrent.TimeUnit)12 Test (org.junit.Test)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 StringSerde (org.apache.samza.serializers.StringSerde)6 JsonObject (com.couchbase.client.java.document.json.JsonObject)5 JsonDocument (com.couchbase.client.java.document.JsonDocument)4 CouchbaseException (com.couchbase.client.core.CouchbaseException)3 Document (com.couchbase.client.java.document.Document)3 Func1 (rx.functions.Func1)3 BackpressureException (com.couchbase.client.core.BackpressureException)1 ArrayList (java.util.ArrayList)1 Observable (rx.Observable)1