CouchbaseTableWriteFunction extends BaseCouchbaseTableFunction<V> implements TableWriteFunction<String, V> { @Override public CompletableFuture<Void> deleteAsync(String key) { Preconditions.checkArgument(StringUtils.isNotBlank(key), "key must not be null, empty or blank"); return asyncWriteHelper( bucket.async().remove(key, timeout.toMillis(), TimeUnit.MILLISECONDS), String.format("Failed to delete key %s from bucket %s.", key, bucketName)); } CouchbaseTableWriteFunction(String bucketName, Class<V> valueClass, String... clusterNodes); @Override void init(Context context, AsyncReadWriteTable table); @Override CompletableFuture<Void> putAsync(String key, V record); @Override CompletableFuture<Void> deleteAsync(String key);  }
@Test(expected = IllegalArgumentException.class) public void testDeleteAsyncNullKey() { CouchbaseTableWriteFunction<JsonObject> writeFunction = createAndInit(); writeFunction.deleteAsync(null); }
@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()); }
@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()); }
@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()); }