Search in sources :

Example 86 with MockFlowFile

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

the class TestFetchElasticsearchHttp method testFetchElasticsearchOnTriggerWithDocNotFound.

@Test
public void testFetchElasticsearchOnTriggerWithDocNotFound() throws IOException {
    // simulate doc not found
    runner = TestRunners.newTestRunner(new FetchElasticsearchHttpTestProcessor(false));
    runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200");
    runner.setProperty(FetchElasticsearchHttp.INDEX, "doc");
    runner.setValidateExpressionUsage(true);
    runner.setProperty(FetchElasticsearchHttp.DOC_ID, "${doc_id}");
    runner.setIncomingConnection(true);
    runner.enqueue(docExample, new HashMap<String, String>() {

        {
            put("doc_id", "28039652140");
        }
    });
    runner.run(1, true, true);
    // This test generates a "document not found"
    runner.assertAllFlowFilesTransferred(FetchElasticsearchHttp.REL_NOT_FOUND, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(FetchElasticsearchHttp.REL_NOT_FOUND).get(0);
    assertNotNull(out);
    out.assertAttributeEquals("doc_id", "28039652140");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Example 87 with MockFlowFile

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

the class TestFetchElasticsearchHttp method testFetchElasticsearchOnTrigger.

@Test
public void testFetchElasticsearchOnTrigger() throws IOException {
    // all docs are found
    runner = TestRunners.newTestRunner(new FetchElasticsearchHttpTestProcessor(true));
    runner.setValidateExpressionUsage(true);
    runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200");
    runner.setProperty(FetchElasticsearchHttp.INDEX, "doc");
    runner.assertNotValid();
    runner.setProperty(FetchElasticsearchHttp.TYPE, "status");
    runner.assertNotValid();
    runner.setProperty(FetchElasticsearchHttp.DOC_ID, "${doc_id}");
    runner.assertValid();
    runner.enqueue(docExample, new HashMap<String, String>() {

        {
            put("doc_id", "28039652140");
        }
    });
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(FetchElasticsearchHttp.REL_SUCCESS, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(FetchElasticsearchHttp.REL_SUCCESS).get(0);
    assertNotNull(out);
    out.assertAttributeEquals("doc_id", "28039652140");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Example 88 with MockFlowFile

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

the class TestFetchElasticsearchHttp method testFetchElasticsearchOnTriggerEL.

@Test
public void testFetchElasticsearchOnTriggerEL() throws IOException {
    // all docs are found
    runner = TestRunners.newTestRunner(new FetchElasticsearchHttpTestProcessor(true));
    runner.setValidateExpressionUsage(true);
    runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "${es.url}");
    runner.setProperty(FetchElasticsearchHttp.INDEX, "doc");
    runner.assertNotValid();
    runner.setProperty(FetchElasticsearchHttp.TYPE, "status");
    runner.assertNotValid();
    runner.setProperty(FetchElasticsearchHttp.DOC_ID, "${doc_id}");
    runner.assertValid();
    runner.setProperty(AbstractElasticsearchHttpProcessor.CONNECT_TIMEOUT, "${connect.timeout}");
    runner.assertValid();
    runner.setVariable("es.url", "http://127.0.0.1:9200");
    runner.setVariable("connect.timeout", "5s");
    runner.enqueue(docExample, new HashMap<String, String>() {

        {
            put("doc_id", "28039652140");
        }
    });
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(FetchElasticsearchHttp.REL_SUCCESS, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(FetchElasticsearchHttp.REL_SUCCESS).get(0);
    assertNotNull(out);
    out.assertAttributeEquals("doc_id", "28039652140");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Example 89 with MockFlowFile

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

the class TestFetchElasticsearchHttp method testFetchElasticsearchOnTriggerWithServerFail.

@Test
public void testFetchElasticsearchOnTriggerWithServerFail() throws IOException {
    FetchElasticsearchHttpTestProcessor processor = new FetchElasticsearchHttpTestProcessor(false);
    processor.setStatus(100, "Should fail");
    // simulate doc not found
    runner = TestRunners.newTestRunner(processor);
    runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200");
    runner.setProperty(FetchElasticsearchHttp.INDEX, "doc");
    runner.setProperty(FetchElasticsearchHttp.TYPE, "status");
    runner.setValidateExpressionUsage(true);
    runner.setProperty(FetchElasticsearchHttp.DOC_ID, "${doc_id}");
    runner.enqueue(docExample, new HashMap<String, String>() {

        {
            put("doc_id", "28039652140");
        }
    });
    runner.run(1, true, true);
    // This test generates a HTTP 100
    runner.assertAllFlowFilesTransferred(FetchElasticsearchHttp.REL_FAILURE, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(FetchElasticsearchHttp.REL_FAILURE).get(0);
    assertNotNull(out);
    out.assertAttributeEquals("doc_id", "28039652140");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Example 90 with MockFlowFile

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

the class TestFetchElasticsearchHttp method testFetchElasticsearchOnTriggerWithFields.

@Test
public void testFetchElasticsearchOnTriggerWithFields() throws IOException {
    // all docs are found
    runner = TestRunners.newTestRunner(new FetchElasticsearchHttpTestProcessor(true));
    runner.setValidateExpressionUsage(true);
    runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200");
    runner.setProperty(FetchElasticsearchHttp.INDEX, "doc");
    runner.assertNotValid();
    runner.setProperty(FetchElasticsearchHttp.TYPE, "status");
    runner.assertNotValid();
    runner.setProperty(FetchElasticsearchHttp.DOC_ID, "${doc_id}");
    runner.assertValid();
    runner.setProperty(FetchElasticsearchHttp.FIELDS, "id,, userinfo.location");
    runner.assertValid();
    runner.enqueue(docExample, new HashMap<String, String>() {

        {
            put("doc_id", "28039652140");
        }
    });
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(FetchElasticsearchHttp.REL_SUCCESS, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(FetchElasticsearchHttp.REL_SUCCESS).get(0);
    assertNotNull(out);
    out.assertAttributeEquals("doc_id", "28039652140");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) 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