Search in sources :

Example 6 with AsyncBucket

use of com.couchbase.client.java.AsyncBucket in project samza by apache.

the class TestCouchbaseTableWriteFunction method testPutAsyncJsonObjectValue.

@Test
public void testPutAsyncJsonObjectValue() throws Exception {
    String key = "key";
    JsonObject value = JsonObject.fromJson("{\"id\": 1}");
    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.just(null));
    assertNull(writeFunction.putAsync(key, value).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) Document(com.couchbase.client.java.document.Document) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with AsyncBucket

use of com.couchbase.client.java.AsyncBucket in project samza by apache.

the class TestCouchbaseTableWriteFunction method testDeleteAsyncStringValue.

@Test
public void testDeleteAsyncStringValue() throws Exception {
    String key = "key";
    Bucket bucket = mock(Bucket.class);
    AsyncBucket asyncBucket = mock(AsyncBucket.class);
    CouchbaseTableWriteFunction<String> writeFunction = createAndInit(String.class, new StringSerde(), bucket, asyncBucket);
    when(asyncBucket.remove(eq(key), anyLong(), any(TimeUnit.class))).thenReturn(Observable.just(null));
    assertNull(writeFunction.deleteAsync(key).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) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with AsyncBucket

use of com.couchbase.client.java.AsyncBucket in project samza by apache.

the class TestCouchbaseTableReadFunction method testGetAsyncStringValue.

@Test
public void testGetAsyncStringValue() throws Exception {
    String key = "key";
    String value = "value";
    StringSerde stringSerde = new StringSerde();
    Bucket bucket = mock(Bucket.class);
    AsyncBucket asyncBucket = mock(AsyncBucket.class);
    CouchbaseTableReadFunction readFunction = createAndInit(String.class, stringSerde, bucket, asyncBucket);
    when(asyncBucket.get(eq(key), anyObject(), anyLong(), any(TimeUnit.class))).thenReturn(Observable.just(BinaryDocument.create(key, Unpooled.wrappedBuffer(stringSerde.toBytes(value)))));
    assertEquals(value, readFunction.getAsync(key).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) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with AsyncBucket

use of com.couchbase.client.java.AsyncBucket 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());
}
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 10 with AsyncBucket

use of com.couchbase.client.java.AsyncBucket 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());
}
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) 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