Search in sources :

Example 91 with MockFlowFile

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

the class TestPutElasticsearch method testPutElasticsearchOnTriggerWithIndexFromAttribute.

@Test
public void testPutElasticsearchOnTriggerWithIndexFromAttribute() throws IOException {
    runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false));
    runner.setValidateExpressionUsage(false);
    runner.setProperty(AbstractElasticsearchTransportClientProcessor.CLUSTER_NAME, "elasticsearch");
    runner.setProperty(AbstractElasticsearchTransportClientProcessor.HOSTS, "127.0.0.1:9300");
    runner.setProperty(AbstractElasticsearchTransportClientProcessor.PING_TIMEOUT, "5s");
    runner.setProperty(AbstractElasticsearchTransportClientProcessor.SAMPLER_INTERVAL, "5s");
    runner.setProperty(PutElasticsearch.INDEX, "${i}");
    runner.setProperty(PutElasticsearch.TYPE, "${type}");
    runner.setProperty(PutElasticsearch.BATCH_SIZE, "1");
    runner.setProperty(PutElasticsearch.ID_ATTRIBUTE, "doc_id");
    runner.enqueue(docExample, new HashMap<String, String>() {

        {
            put("doc_id", "28039652144");
            put("i", "doc");
            put("type", "status");
        }
    });
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(PutElasticsearch.REL_SUCCESS, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(PutElasticsearch.REL_SUCCESS).get(0);
    assertNotNull(out);
    runner.clearTransferState();
    // Now try an empty attribute value, should fail
    runner.enqueue(docExample, new HashMap<String, String>() {

        {
            put("doc_id", "28039652144");
            put("type", "status");
        }
    });
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(PutElasticsearch.REL_RETRY, 1);
    final MockFlowFile out2 = runner.getFlowFilesForRelationship(PutElasticsearch.REL_RETRY).get(0);
    assertNotNull(out2);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 92 with MockFlowFile

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

the class TestPutElasticsearch method testPutElasticSearchOnTriggerWithInvalidIndexOp.

@Test
public void testPutElasticSearchOnTriggerWithInvalidIndexOp() throws IOException {
    // no failures
    runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false));
    runner.setValidateExpressionUsage(true);
    runner.setProperty(AbstractElasticsearchTransportClientProcessor.CLUSTER_NAME, "elasticsearch");
    runner.setProperty(AbstractElasticsearchTransportClientProcessor.HOSTS, "127.0.0.1:9300");
    runner.setProperty(AbstractElasticsearchTransportClientProcessor.PING_TIMEOUT, "5s");
    runner.setProperty(AbstractElasticsearchTransportClientProcessor.SAMPLER_INTERVAL, "5s");
    runner.setProperty(PutElasticsearch.INDEX, "doc");
    runner.assertNotValid();
    runner.setProperty(PutElasticsearch.TYPE, "status");
    runner.setProperty(PutElasticsearch.BATCH_SIZE, "1");
    runner.assertNotValid();
    runner.setProperty(PutElasticsearch.ID_ATTRIBUTE, "doc_id");
    runner.assertValid();
    runner.setProperty(PutElasticsearch.INDEX_OP, "index_fail");
    runner.assertValid();
    runner.enqueue(docExample, new HashMap<String, String>() {

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

Example 93 with MockFlowFile

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

the class TestPutElasticsearchHttp method testPutElasticSearchOnTriggerUpdate.

@Test
public void testPutElasticSearchOnTriggerUpdate() throws IOException {
    // no failures
    runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false));
    runner.setValidateExpressionUsage(true);
    runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200");
    runner.setProperty(PutElasticsearchHttp.INDEX, "doc");
    runner.setProperty(PutElasticsearchHttp.TYPE, "status");
    runner.setProperty(PutElasticsearchHttp.BATCH_SIZE, "1");
    runner.setProperty(PutElasticsearchHttp.ID_ATTRIBUTE, "doc_id");
    runner.setProperty(PutElasticsearchHttp.INDEX_OP, "Update");
    runner.enqueue(docExample, new HashMap<String, String>() {

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

Example 94 with MockFlowFile

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

the class TestPutElasticsearchHttp method testPutElasticSearchOnTriggerWithInvalidIndexOp.

@Test
public void testPutElasticSearchOnTriggerWithInvalidIndexOp() throws IOException {
    // no failures
    runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false));
    runner.setValidateExpressionUsage(true);
    runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200");
    runner.setProperty(PutElasticsearchHttp.INDEX, "doc");
    runner.assertNotValid();
    runner.setProperty(PutElasticsearchHttp.TYPE, "status");
    runner.setProperty(PutElasticsearchHttp.BATCH_SIZE, "1");
    runner.assertValid();
    runner.setProperty(PutElasticsearchHttp.ID_ATTRIBUTE, "doc_id");
    runner.assertValid();
    runner.setProperty(PutElasticsearchHttp.INDEX_OP, "index_fail");
    runner.assertValid();
    runner.enqueue(docExample, new HashMap<String, String>() {

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

Example 95 with MockFlowFile

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

the class TestPutElasticsearchHttp method testPutElasticSearchOnTriggerQueryParameter.

@Test
public void testPutElasticSearchOnTriggerQueryParameter() throws IOException {
    // no failures
    PutElasticsearchTestProcessor p = new PutElasticsearchTestProcessor(false);
    p.setExpectedUrl("http://127.0.0.1:9200/_bulk?pipeline=my-pipeline");
    runner = TestRunners.newTestRunner(p);
    runner.setValidateExpressionUsage(true);
    runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200");
    runner.setProperty(PutElasticsearchHttp.INDEX, "doc");
    runner.setProperty(PutElasticsearchHttp.TYPE, "status");
    runner.setProperty(PutElasticsearchHttp.BATCH_SIZE, "1");
    runner.setProperty(PutElasticsearchHttp.ID_ATTRIBUTE, "doc_id");
    // Set dynamic property, to be added to the URL as a query parameter
    runner.setProperty("pipeline", "my-pipeline");
    runner.enqueue(docExample, new HashMap<String, String>() {

        {
            put("doc_id", "28039652140");
        }
    });
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(PutElasticsearchHttp.REL_SUCCESS, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(PutElasticsearchHttp.REL_SUCCESS).get(0);
    assertNotNull(out);
}
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