Search in sources :

Example 1 with DurabilityException

use of com.couchbase.client.java.error.DurabilityException in project nifi by apache.

the class TestGetCouchbaseKey method testCouchbaseTempFlowFileError.

@Test
public void testCouchbaseTempFlowFileError() throws Exception {
    String docIdExp = "doc-c";
    Bucket bucket = mock(Bucket.class);
    // There is no suitable CouchbaseException for temp flowfile error, currently.
    CouchbaseException exception = new DurabilityException();
    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());
    Assert.assertEquals(true, orgFile.isPenalized());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) CouchbaseException(com.couchbase.client.core.CouchbaseException) Bucket(com.couchbase.client.java.Bucket) Matchers.anyString(org.mockito.Matchers.anyString) DurabilityException(com.couchbase.client.java.error.DurabilityException) Test(org.junit.Test)

Example 2 with DurabilityException

use of com.couchbase.client.java.error.DurabilityException in project nifi by apache.

the class TestPutCouchbaseKey method testCouchbaseTempFlowFileError.

@Test
public void testCouchbaseTempFlowFileError() throws Exception {
    String docId = "doc-a";
    String inFileData = "{\"key\":\"value\"}";
    byte[] inFileDataBytes = inFileData.getBytes(StandardCharsets.UTF_8);
    Bucket bucket = mock(Bucket.class);
    CouchbaseException exception = new DurabilityException();
    when(bucket.upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE))).thenThrow(exception);
    setupMockBucket(bucket);
    testRunner.enqueue(inFileDataBytes);
    testRunner.setProperty(DOC_ID, docId);
    testRunner.setProperty(PutCouchbaseKey.REPLICATE_TO, ReplicateTo.ONE.toString());
    testRunner.run();
    verify(bucket, times(1)).upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE));
    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_RETRY, 1);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0);
    orgFile.assertContentEquals(inFileData);
    orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) CouchbaseException(com.couchbase.client.core.CouchbaseException) Bucket(com.couchbase.client.java.Bucket) Matchers.anyString(org.mockito.Matchers.anyString) DurabilityException(com.couchbase.client.java.error.DurabilityException) RawJsonDocument(com.couchbase.client.java.document.RawJsonDocument) Test(org.junit.Test)

Aggregations

CouchbaseException (com.couchbase.client.core.CouchbaseException)2 Bucket (com.couchbase.client.java.Bucket)2 DurabilityException (com.couchbase.client.java.error.DurabilityException)2 MockFlowFile (org.apache.nifi.util.MockFlowFile)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 RawJsonDocument (com.couchbase.client.java.document.RawJsonDocument)1