com.couchbase.client.core.ServiceNotAvailableException Java Examples

The following examples show how to use com.couchbase.client.core.ServiceNotAvailableException. 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 File: TestGetCouchbaseKey.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testCouchbaseFailure() throws Exception {

    Bucket bucket = mock(Bucket.class);
    String inFileDataStr = "doc-in";
    when(bucket.get(inFileDataStr, RawJsonDocument.class))
        .thenThrow(new ServiceNotAvailableException());
    setupMockBucket(bucket);


    byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    try {
        testRunner.run();
        fail("ProcessException should be thrown.");
    } catch (AssertionError e) {
        Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
    }

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}
 
Example #2
Source File: ViewLocatorTest.java    From couchbase-jvm-core with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFailWhenUsedAgainstMemcacheBucket() {
    Locator locator = new ViewLocator(0);

    ClusterConfig config = mock(ClusterConfig.class);
    when(config.bucketConfig("default")).thenReturn(mock(MemcachedBucketConfig.class));

    CouchbaseRequest request = mock(ViewQueryRequest.class);
    Subject<CouchbaseResponse, CouchbaseResponse> response = AsyncSubject.create();
    when(request.bucket()).thenReturn("default");
    when(request.observable()).thenReturn(response);

    TestSubscriber<CouchbaseResponse> subscriber = new TestSubscriber<CouchbaseResponse>();
    response.subscribe(subscriber);

    locator.locateAndDispatch(request, Collections.<Node>emptyList(), config, null, null);

    subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    List<Throwable> errors = subscriber.getOnErrorEvents();
    assertEquals(1, errors.size());
    assertTrue(errors.get(0) instanceof ServiceNotAvailableException);
}
 
Example #3
Source File: TestGetCouchbaseKey.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testCouchbaseFailure() throws Exception {

    Bucket bucket = mock(Bucket.class);
    String inFileDataStr = "doc-in";
    when(bucket.get(inFileDataStr, RawJsonDocument.class))
        .thenThrow(new ServiceNotAvailableException());
    setupMockBucket(bucket);


    byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    try {
        testRunner.run();
        fail("ProcessException should be thrown.");
    } catch (AssertionError e) {
        Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
    }

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}
 
Example #4
Source File: TestPutCouchbaseKey.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCouchbaseFailure() throws Exception {

    String docId = "doc-a";

    String inFileData = "{\"key\":\"value\"}";
    byte[] inFileDataBytes = inFileData.getBytes(StandardCharsets.UTF_8);

    Bucket bucket = mock(Bucket.class);
    when(bucket.upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE)))
        .thenThrow(new ServiceNotAvailableException());
    setupMockBucket(bucket);

    testRunner.enqueue(inFileDataBytes);
    testRunner.setProperty(DOC_ID, docId);
    testRunner.setProperty(PutCouchbaseKey.REPLICATE_TO, ReplicateTo.ONE.toString());
    try {
        testRunner.run();
        fail("ProcessException should be thrown.");
    } catch (AssertionError e){
        Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
    }

    verify(bucket, times(1)).upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE));

    testRunner.assertAllFlowFilesTransferred(REL_FAILURE);
    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}
 
Example #5
Source File: TestPutCouchbaseKey.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCouchbaseFailure() throws Exception {

    String docId = "doc-a";

    String inFileData = "{\"key\":\"value\"}";
    byte[] inFileDataBytes = inFileData.getBytes(StandardCharsets.UTF_8);

    Bucket bucket = mock(Bucket.class);
    when(bucket.upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE)))
        .thenThrow(new ServiceNotAvailableException());
    setupMockBucket(bucket);

    testRunner.enqueue(inFileDataBytes);
    testRunner.setProperty(DOC_ID, docId);
    testRunner.setProperty(PutCouchbaseKey.REPLICATE_TO, ReplicateTo.ONE.toString());
    try {
        testRunner.run();
        fail("ProcessException should be thrown.");
    } catch (AssertionError e){
        Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
    }

    verify(bucket, times(1)).upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE));

    testRunner.assertAllFlowFilesTransferred(REL_FAILURE);
    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}