Java Code Examples for com.couchbase.client.core.BackpressureException

The following examples show how to use com.couchbase.client.core.BackpressureException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCouchbaseTempClusterError() throws Exception {
    String docIdExp = "doc-c";

    Bucket bucket = mock(Bucket.class);
    CouchbaseException exception = new BackpressureException();
    when(bucket.get(docIdExp, RawJsonDocument.class))
        .thenThrow(exception);
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);

    String inputFileDataStr = "input FlowFile data";
    byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    testRunner.run();

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 1);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0);
    orgFile.assertContentEquals(inputFileDataStr);
    orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName());
}
 
Example 2
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCouchbaseTempClusterError() throws Exception {
    String docIdExp = "doc-c";

    Bucket bucket = mock(Bucket.class);
    CouchbaseException exception = new BackpressureException();
    when(bucket.get(docIdExp, RawJsonDocument.class))
        .thenThrow(exception);
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);

    String inputFileDataStr = "input FlowFile data";
    byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    testRunner.run();

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 1);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0);
    orgFile.assertContentEquals(inputFileDataStr);
    orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName());
}
 
Example 3
Source Project: tutorials   Source File: AbstractCrudService.java    License: MIT License 5 votes vote down vote up
@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();
}
 
Example 4
Source Project: tutorials   Source File: AbstractCrudService.java    License: MIT License 5 votes vote down vote up
@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();
}
 
Example 5
Source Project: tutorials   Source File: AbstractCrudService.java    License: MIT License 5 votes vote down vote up
@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();
}
 
Example 6
Source Project: couchbase-jvm-core   Source File: RingBufferMonitor.java    License: Apache License 2.0 4 votes vote down vote up
public BackpressureException createException() {
    return new BackpressureException(diagnostics());
}