Search in sources :

Example 61 with TestRunner

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

the class TestPutElasticsearch5 method testPutElasticSearchBasic.

// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Integration test section below
// 
// The tests below are meant to run on real ES instances, and are thus @Ignored during normal test execution.
// However if you wish to execute them as part of a test phase, comment out the @Ignored line for each
// desired test.
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * Tests basic ES functionality against a local or test ES cluster
 */
@Test
@Ignore("Comment this out if you want to run against local or test ES")
public void testPutElasticSearchBasic() {
    System.out.println("Starting test " + new Object() {
    }.getClass().getEnclosingMethod().getName());
    final TestRunner runner = TestRunners.newTestRunner(new PutElasticsearch5());
    runner.setValidateExpressionUsage(false);
    // 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(PutElasticsearch5.INDEX, "doc");
    runner.setProperty(PutElasticsearch5.BATCH_SIZE, "1");
    runner.setProperty(PutElasticsearch5.TYPE, "status");
    runner.setProperty(PutElasticsearch5.ID_ATTRIBUTE, "doc_id");
    runner.assertValid();
    runner.enqueue(docExample, new HashMap<String, String>() {

        {
            put("doc_id", "28039652140");
        }
    });
    runner.enqueue(docExample);
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(PutElasticsearch5.REL_SUCCESS, 1);
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) Matchers.anyString(org.mockito.Matchers.anyString) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 62 with TestRunner

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

the class TestFetchElasticsearchHttp method testFetchElasticsearchBasic.

// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Integration test section below
// 
// The tests below are meant to run on real ES instances, and are thus @Ignored during normal test execution.
// However if you wish to execute them as part of a test phase, comment out the @Ignored line for each
// desired test.
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * Tests basic ES functionality against a local or test ES cluster
 */
@Test
@Ignore("Comment this out if you want to run against local or test ES")
public void testFetchElasticsearchBasic() {
    System.out.println("Starting test " + new Object() {
    }.getClass().getEnclosingMethod().getName());
    final TestRunner runner = TestRunners.newTestRunner(new FetchElasticsearchHttp());
    runner.setValidateExpressionUsage(true);
    // Local Cluster - Mac pulled from brew
    runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200");
    runner.setProperty(FetchElasticsearchHttp.INDEX, "doc");
    runner.setProperty(FetchElasticsearchHttp.TYPE, "status");
    runner.setProperty(FetchElasticsearchHttp.DOC_ID, "${doc_id}");
    runner.assertValid();
    runner.enqueue(docExample, new HashMap<String, String>() {

        {
            put("doc_id", "28039652140");
        }
    });
    runner.enqueue(docExample);
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(FetchElasticsearchHttp.REL_SUCCESS, 1);
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 63 with TestRunner

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

the class TestPutElasticsearch method testPutElasticSearchBatch.

@Test
@Ignore("Comment this out if you want to run against local or test ES")
public void testPutElasticSearchBatch() throws IOException {
    System.out.println("Starting test " + new Object() {
    }.getClass().getEnclosingMethod().getName());
    final TestRunner runner = TestRunners.newTestRunner(new PutElasticsearch());
    runner.setValidateExpressionUsage(false);
    // Local Cluster - Mac pulled from brew
    runner.setProperty(AbstractElasticsearchTransportClientProcessor.CLUSTER_NAME, "elasticsearch_brew");
    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.setProperty(PutElasticsearch.BATCH_SIZE, "100");
    runner.setProperty(PutElasticsearch.TYPE, "status");
    runner.setProperty(PutElasticsearch.ID_ATTRIBUTE, "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(PutElasticsearch.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)

Example 64 with TestRunner

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

the class TestPutElasticsearchHttpRecord method testPutElasticSearchBasic.

// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Integration test section below
// 
// The tests below are meant to run on real ES instances, and are thus @Ignored during normal test execution.
// However if you wish to execute them as part of a test phase, comment out the @Ignored line for each
// desired test.
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * Tests basic ES functionality against a local or test ES cluster
 */
@Test
@Ignore("Comment this out if you want to run against local or test ES")
public void testPutElasticSearchBasic() {
    System.out.println("Starting test " + new Object() {
    }.getClass().getEnclosingMethod().getName());
    final TestRunner runner = TestRunners.newTestRunner(new PutElasticsearchHttpRecord());
    runner.setValidateExpressionUsage(false);
    runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200");
    runner.setProperty(PutElasticsearchHttpRecord.INDEX, "doc");
    runner.setProperty(PutElasticsearchHttpRecord.TYPE, "status");
    runner.setProperty(PutElasticsearchHttpRecord.ID_RECORD_PATH, "/id");
    runner.assertValid();
    runner.enqueue(new byte[0], new HashMap<String, String>() {

        {
            put("doc_id", "28039652140");
        }
    });
    runner.enqueue(new byte[0]);
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(PutElasticsearchHttpRecord.REL_SUCCESS, 1);
    List<ProvenanceEventRecord> provEvents = runner.getProvenanceEvents();
    assertNotNull(provEvents);
    assertEquals(1, provEvents.size());
    assertEquals(ProvenanceEventType.SEND, provEvents.get(0).getEventType());
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 65 with TestRunner

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

the class JsonQueryElasticsearchTest method testErrorDuringSearch.

@Test
public void testErrorDuringSearch() throws Exception {
    String query = "{\n" + "\t\"query\": {\n" + "\t\t\"match_all\": {}\n" + "\t},\n" + "\t\"aggs\": {\n" + "\t\t\"test_agg\": {\n" + "\t\t\t\"terms\": {\n" + "\t\t\t\t\"field\": \"msg\"\n" + "\t\t\t}\n" + "\t\t},\n" + "\t\t\"test_agg2\": {\n" + "\t\t\t\"terms\": {\n" + "\t\t\t\t\"field\": \"msg\"\n" + "\t\t\t}\n" + "\t\t}\n" + "\t}\n" + "}";
    JsonQueryElasticsearch processor = new JsonQueryElasticsearch();
    TestRunner runner = TestRunners.newTestRunner(processor);
    TestElasticSearchClientService service = new TestElasticSearchClientService(true);
    service.setThrowErrorInSearch(true);
    runner.addControllerService("esService", service);
    runner.enableControllerService(service);
    runner.setProperty(JsonQueryElasticsearch.CLIENT_SERVICE, "esService");
    runner.setProperty(JsonQueryElasticsearch.INDEX, INDEX_NAME);
    runner.setProperty(JsonQueryElasticsearch.TYPE, "message");
    runner.setValidateExpressionUsage(true);
    runner.setProperty(JsonQueryElasticsearch.QUERY, query);
    runner.enqueue("test");
    runner.run(1, true, true);
    testCounts(runner, 0, 0, 1, 0);
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) 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