Search in sources :

Example 56 with TestRunner

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

the class TestSplitAvro method testRecordSplitDatafileOutputWithSplitSizeLarger.

@Test
public void testRecordSplitDatafileOutputWithSplitSizeLarger() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new SplitAvro());
    runner.setProperty(SplitAvro.OUTPUT_SIZE, "200");
    runner.enqueue(users.toByteArray());
    runner.run();
    runner.assertTransferCount(SplitAvro.REL_SPLIT, 1);
    runner.assertTransferCount(SplitAvro.REL_ORIGINAL, 1);
    runner.assertTransferCount(SplitAvro.REL_FAILURE, 0);
    runner.getFlowFilesForRelationship(SplitAvro.REL_ORIGINAL).get(0).assertAttributeEquals(FRAGMENT_COUNT.key(), "1");
    final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(SplitAvro.REL_SPLIT);
    checkDataFileSplitSize(flowFiles, 100, true);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 57 with TestRunner

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

the class TestSplitAvro method testRecordSplitWithNoIncomingRecords.

@Test
public void testRecordSplitWithNoIncomingRecords() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new SplitAvro());
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    createUsers(0, out);
    runner.enqueue(out.toByteArray());
    runner.run();
    runner.assertTransferCount(SplitAvro.REL_SPLIT, 0);
    runner.assertTransferCount(SplitAvro.REL_ORIGINAL, 1);
    runner.assertTransferCount(SplitAvro.REL_FAILURE, 0);
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) ByteArrayOutputStream(org.apache.nifi.stream.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 58 with TestRunner

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

the class ITDeleteElasticsearch5Test method testDeleteIntegrationTestDocumentNotFound.

@Test
public void testDeleteIntegrationTestDocumentNotFound() {
    final TestRunner runnerDelete = TestRunners.newTestRunner(new DeleteElasticsearch5());
    runnerDelete.setValidateExpressionUsage(false);
    runnerDelete.setProperty(AbstractElasticsearch5TransportClientProcessor.CLUSTER_NAME, clusterName);
    runnerDelete.setProperty(AbstractElasticsearch5TransportClientProcessor.HOSTS, "127.0.0.1:9300");
    runnerDelete.setProperty(AbstractElasticsearch5TransportClientProcessor.PING_TIMEOUT, "5s");
    runnerDelete.setProperty(AbstractElasticsearch5TransportClientProcessor.SAMPLER_INTERVAL, "5s");
    runnerDelete.setProperty(DeleteElasticsearch5.INDEX, INDEX1);
    runnerDelete.setProperty(DeleteElasticsearch5.TYPE, TYPE1);
    runnerDelete.setProperty(DeleteElasticsearch5.DOCUMENT_ID, "${documentId}");
    runnerDelete.assertValid();
    runnerDelete.enqueue(new byte[] {}, new HashMap<String, String>() {

        {
            put("documentId", documentId);
        }
    });
    runnerDelete.enqueue(new byte[] {});
    runnerDelete.run(1, true, true);
    runnerDelete.assertAllFlowFilesTransferred(DeleteElasticsearch5.REL_NOT_FOUND, 1);
    final MockFlowFile out = runnerDelete.getFlowFilesForRelationship(DeleteElasticsearch5.REL_NOT_FOUND).get(0);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_FILENAME, documentId);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_INDEX, INDEX1);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_TYPE, TYPE1);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 59 with TestRunner

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

the class ITDeleteElasticsearch5Test method testDeleteIntegrationTestBadType.

@Test
public void testDeleteIntegrationTestBadType() {
    final TestRunner runnerDelete = TestRunners.newTestRunner(new DeleteElasticsearch5());
    runnerDelete.setValidateExpressionUsage(false);
    runnerDelete.setProperty(AbstractElasticsearch5TransportClientProcessor.CLUSTER_NAME, clusterName);
    runnerDelete.setProperty(AbstractElasticsearch5TransportClientProcessor.HOSTS, "127.0.0.1:9300");
    runnerDelete.setProperty(AbstractElasticsearch5TransportClientProcessor.PING_TIMEOUT, "5s");
    runnerDelete.setProperty(AbstractElasticsearch5TransportClientProcessor.SAMPLER_INTERVAL, "5s");
    runnerDelete.setProperty(DeleteElasticsearch5.INDEX, INDEX1);
    String type = String.valueOf(System.currentTimeMillis());
    runnerDelete.setProperty(DeleteElasticsearch5.TYPE, type);
    runnerDelete.setProperty(DeleteElasticsearch5.DOCUMENT_ID, "${documentId}");
    runnerDelete.assertValid();
    runnerDelete.enqueue(new byte[] {}, new HashMap<String, String>() {

        {
            put("documentId", documentId);
        }
    });
    runnerDelete.enqueue(new byte[] {});
    runnerDelete.run(1, true, true);
    runnerDelete.assertAllFlowFilesTransferred(DeleteElasticsearch5.REL_NOT_FOUND, 1);
    final MockFlowFile out = runnerDelete.getFlowFilesForRelationship(DeleteElasticsearch5.REL_NOT_FOUND).get(0);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_FILENAME, documentId);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_INDEX, INDEX1);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_TYPE, type);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 60 with TestRunner

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

the class TestFetchElasticsearch5 method testFetchElasticsearch5Batch.

@Test
@Ignore("Comment this out if you want to run against local or test ES")
public void testFetchElasticsearch5Batch() throws IOException {
    System.out.println("Starting test " + new Object() {
    }.getClass().getEnclosingMethod().getName());
    final TestRunner runner = TestRunners.newTestRunner(new FetchElasticsearch5());
    runner.setValidateExpressionUsage(true);
    // Local Cluster - Mac pulled from brew
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.CLUSTER_NAME, "elasticsearch_brew");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.HOSTS, "127.0.0.1:9300");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.PING_TIMEOUT, "5s");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.SAMPLER_INTERVAL, "5s");
    runner.setProperty(FetchElasticsearch5.INDEX, "doc");
    runner.setProperty(FetchElasticsearch5.TYPE, "status");
    runner.setProperty(FetchElasticsearch5.DOC_ID, "${doc_id}");
    runner.assertValid();
    String message = convertStreamToString(docExample);
    for (int i = 0; i < 100; i++) {
        long newId = 28039652140L + i;
        final String newStrId = Long.toString(newId);
        runner.enqueue(message.getBytes(), new HashMap<String, String>() {

            {
                put("doc_id", newStrId);
            }
        });
    }
    runner.run();
    runner.assertAllFlowFilesTransferred(FetchElasticsearch5.REL_SUCCESS, 100);
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) Matchers.anyString(org.mockito.Matchers.anyString) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TestRunner (org.apache.nifi.util.TestRunner)1337 Test (org.junit.Test)1315 MockFlowFile (org.apache.nifi.util.MockFlowFile)741 HashMap (java.util.HashMap)297 File (java.io.File)137 ProcessContext (org.apache.nifi.processor.ProcessContext)56 Connection (java.sql.Connection)44 Statement (java.sql.Statement)37 UpdateAttribute (org.apache.nifi.processors.attributes.UpdateAttribute)32 ProcessSession (org.apache.nifi.processor.ProcessSession)31 ResultSet (java.sql.ResultSet)30 Schema (org.apache.avro.Schema)28 Relationship (org.apache.nifi.processor.Relationship)27 ByteArrayOutputStream (org.apache.nifi.stream.io.ByteArrayOutputStream)27 ByteArrayInputStream (java.io.ByteArrayInputStream)26 MockProcessContext (org.apache.nifi.util.MockProcessContext)25 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)24 Ignore (org.junit.Ignore)24 InputStream (java.io.InputStream)22 PutFlowFile (org.apache.nifi.hbase.put.PutFlowFile)22