Search in sources :

Example 31 with MockFlowFile

use of org.apache.nifi.util.MockFlowFile in project nifi by apache.

the class ITPutKinesisStream method testIntegrationWithFixedPartitionSuccess.

@Test
public void testIntegrationWithFixedPartitionSuccess() throws Exception {
    runner.setProperty(PutKinesisStream.KINESIS_PARTITION_KEY, "pfixed");
    runner.assertValid();
    runner.enqueue("test".getBytes());
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PutKinesisStream.REL_SUCCESS, 1);
    final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(PutKinesisStream.REL_SUCCESS);
    final MockFlowFile out = ffs.iterator().next();
    out.assertContentEquals("test".getBytes());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Example 32 with MockFlowFile

use of org.apache.nifi.util.MockFlowFile in project nifi by apache.

the class ITPutKinesisStream method testThreeMessageWithBatch5MaxBufferSize1MBRunOnceTwoMessageSent.

@Test
public void testThreeMessageWithBatch5MaxBufferSize1MBRunOnceTwoMessageSent() {
    runner.setProperty(PutKinesisStream.BATCH_SIZE, "5");
    runner.setProperty(PutKinesisStream.MAX_MESSAGE_BUFFER_SIZE_MB, "1 MB");
    runner.assertValid();
    byte[] bytes = new byte[(PutKinesisStream.MAX_MESSAGE_SIZE)];
    for (int i = 0; i < bytes.length; i++) {
        bytes[i] = 'a';
    }
    runner.enqueue(bytes);
    runner.enqueue(bytes.clone());
    runner.enqueue(bytes.clone());
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(PutKinesisStream.REL_SUCCESS, 2);
    List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutKinesisStream.REL_SUCCESS);
    assertEquals(2, flowFiles.size());
    for (MockFlowFile flowFile : flowFiles) {
        flowFile.assertAttributeExists(PutKinesisStream.AWS_KINESIS_SEQUENCE_NUMBER);
        flowFile.assertAttributeExists(PutKinesisStream.AWS_KINESIS_SHARD_ID);
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Example 33 with MockFlowFile

use of org.apache.nifi.util.MockFlowFile in project nifi by apache.

the class ITPutKinesisStream method testTwoMessageBatch5WithMaxBufferSize1MBRunOnceTwoMessageSent.

@Test
public void testTwoMessageBatch5WithMaxBufferSize1MBRunOnceTwoMessageSent() {
    runner.setProperty(PutKinesisStream.BATCH_SIZE, "5");
    runner.setProperty(PutKinesisStream.MAX_MESSAGE_BUFFER_SIZE_MB, "2 MB");
    runner.assertValid();
    byte[] bytes = new byte[(PutKinesisStream.MAX_MESSAGE_SIZE)];
    for (int i = 0; i < bytes.length; i++) {
        bytes[i] = 'a';
    }
    runner.enqueue(bytes);
    runner.enqueue(bytes.clone());
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PutKinesisStream.REL_SUCCESS, 2);
    List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutKinesisStream.REL_SUCCESS);
    assertEquals(2, flowFiles.size());
    for (MockFlowFile flowFile : flowFiles) {
        flowFile.assertAttributeExists(PutKinesisStream.AWS_KINESIS_SEQUENCE_NUMBER);
        flowFile.assertAttributeExists(PutKinesisStream.AWS_KINESIS_SHARD_ID);
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Example 34 with MockFlowFile

use of org.apache.nifi.util.MockFlowFile in project nifi by apache.

the class ITPutLambda method testIntegrationSuccess.

/**
 * Comment out ignore for integration tests (requires creds files)
 */
@Test
@Ignore
public void testIntegrationSuccess() throws Exception {
    runner = TestRunners.newTestRunner(PutLambda.class);
    runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "hello");
    runner.assertValid();
    runner.enqueue("{\"test\":\"hi\"}".getBytes());
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PutLambda.REL_SUCCESS, 1);
    final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(PutLambda.REL_SUCCESS);
    final MockFlowFile out = ffs.iterator().next();
    assertNull("Function error should be null " + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR));
    assertNotNull("log should not be null", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG));
    assertEquals("Status should be equal", "200", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with MockFlowFile

use of org.apache.nifi.util.MockFlowFile in project nifi by apache.

the class TestPutLambda method testPutLambdaTooManyRequestsException.

@Test
public void testPutLambdaTooManyRequestsException() {
    runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "test-function");
    runner.enqueue("TestContent");
    Mockito.when(mockLambdaClient.invoke(Mockito.any(InvokeRequest.class))).thenThrow(new TooManyRequestsException("TestFail"));
    runner.assertValid();
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PutLambda.REL_FAILURE, 1);
    final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutLambda.REL_FAILURE);
    final MockFlowFile ff0 = flowFiles.get(0);
    assertTrue(ff0.isPenalized());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TooManyRequestsException(com.amazonaws.services.lambda.model.TooManyRequestsException) InvokeRequest(com.amazonaws.services.lambda.model.InvokeRequest) Test(org.junit.Test)

Aggregations

MockFlowFile (org.apache.nifi.util.MockFlowFile)1228 Test (org.junit.Test)1198 TestRunner (org.apache.nifi.util.TestRunner)725 HashMap (java.util.HashMap)279 File (java.io.File)155 Matchers.anyString (org.mockito.Matchers.anyString)59 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)48 FlowFile (org.apache.nifi.flowfile.FlowFile)42 ByteArrayInputStream (java.io.ByteArrayInputStream)41 ProcessContext (org.apache.nifi.processor.ProcessContext)37 InputStream (java.io.InputStream)34 Connection (java.sql.Connection)31 GenericRecord (org.apache.avro.generic.GenericRecord)31 Statement (java.sql.Statement)30 Schema (org.apache.avro.Schema)30 ArrayList (java.util.ArrayList)29 Map (java.util.Map)27 SQLException (java.sql.SQLException)25 DBCPService (org.apache.nifi.dbcp.DBCPService)25 GenericDatumWriter (org.apache.avro.generic.GenericDatumWriter)24