Java Code Examples for org.apache.nifi.util.TestRunner#setNonLoopConnection()

The following examples show how to use org.apache.nifi.util.TestRunner#setNonLoopConnection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuerySolrIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testStandardResponse() throws IOException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty(QuerySolr.SOLR_PARAM_QUERY, "id:(doc0 OR doc1)");
    runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id");
    runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id desc");

    runner.setNonLoopConnection(false);
    runner.run();
    runner.assertAllFlowFilesTransferred(QuerySolr.RESULTS, 1);

    MockFlowFile flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);

    String expectedXml = "<docs><doc boost=\"1.0\"><field name=\"id\">doc1</field></doc><doc boost=\"1.0\"><field name=\"id\">doc0</field></doc></docs>";
    assertThat(expectedXml, CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(flowFile))));

    solrClient.close();
}
 
Example 2
Source File: QuerySolrIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrievalOfFullResults3() throws IOException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id");
    runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id asc");
    runner.setProperty(QuerySolr.SOLR_PARAM_ROWS, "3");
    runner.setProperty(QuerySolr.AMOUNT_DOCUMENTS_TO_RETURN, QuerySolr.RETURN_ALL_RESULTS);
    runner.setProperty("facet", "true");
    runner.setProperty("stats", "true");

    runner.setNonLoopConnection(false);
    runner.run();

    runner.assertTransferCount(QuerySolr.RESULTS, 4);
    runner.assertTransferCount(QuerySolr.ORIGINAL, 0);
    runner.assertTransferCount(QuerySolr.FACETS, 1);
    runner.assertTransferCount(QuerySolr.STATS, 1);

    solrClient.close();
}
 
Example 3
Source File: TestQuerySolr.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testStandardResponse() throws IOException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty(QuerySolr.SOLR_PARAM_QUERY, "id:(doc0 OR doc1)");
    runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id");
    runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id desc");

    runner.setNonLoopConnection(false);
    runner.run();
    runner.assertAllFlowFilesTransferred(QuerySolr.RESULTS, 1);

    MockFlowFile flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);

    String expectedXml = "<docs><doc><field name=\"id\">doc1</field></doc><doc><field name=\"id\">doc0</field></doc></docs>";
    assertThat(expectedXml, CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(flowFile))));

    solrClient.close();
}
 
Example 4
Source File: TestQuerySolr.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrievalOfFullResults3() throws IOException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id");
    runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id asc");
    runner.setProperty(QuerySolr.SOLR_PARAM_ROWS, "3");
    runner.setProperty(QuerySolr.AMOUNT_DOCUMENTS_TO_RETURN, QuerySolr.RETURN_ALL_RESULTS);
    runner.setProperty("facet", "true");
    runner.setProperty("stats", "true");

    runner.setNonLoopConnection(false);
    runner.run();

    runner.assertTransferCount(QuerySolr.RESULTS, 4);
    runner.assertTransferCount(QuerySolr.ORIGINAL, 0);
    runner.assertTransferCount(QuerySolr.FACETS, 1);
    runner.assertTransferCount(QuerySolr.STATS, 1);

    solrClient.close();
}
 
Example 5
Source File: QuerySolrIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testRelationshipRoutings() throws IOException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty("facet", "true");
    runner.setProperty("stats", "true");

    // Set request handler for request failure
    runner.setProperty(QuerySolr.SOLR_PARAM_REQUEST_HANDLER, "/nonexistentrequesthandler");

    // Processor has no input connection and fails
    runner.setNonLoopConnection(false);
    runner.run(1, false);
    runner.assertAllFlowFilesTransferred(QuerySolr.FAILURE, 1);

    MockFlowFile flowFile = runner.getFlowFilesForRelationship(QuerySolr.FAILURE).get(0);
    flowFile.assertAttributeExists(QuerySolr.EXCEPTION);
    flowFile.assertAttributeExists(QuerySolr.EXCEPTION_MESSAGE);
    runner.clearTransferState();

    // Processor has an input connection and fails
    runner.setNonLoopConnection(true);
    runner.enqueue(new byte[0]);
    runner.run(1, false);
    runner.assertAllFlowFilesTransferred(QuerySolr.FAILURE, 1);

    flowFile = runner.getFlowFilesForRelationship(QuerySolr.FAILURE).get(0);
    flowFile.assertAttributeExists(QuerySolr.EXCEPTION);
    flowFile.assertAttributeExists(QuerySolr.EXCEPTION_MESSAGE);
    runner.clearTransferState();

    // Set request handler for successful request
    runner.setProperty(QuerySolr.SOLR_PARAM_REQUEST_HANDLER, "/select");

    // Processor has no input connection and succeeds
    runner.setNonLoopConnection(false);
    runner.run(1, false);
    runner.assertTransferCount(QuerySolr.RESULTS, 1);
    runner.assertTransferCount(QuerySolr.FACETS, 1);
    runner.assertTransferCount(QuerySolr.STATS, 1);

    flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    runner.clearTransferState();

    // Processor has an input connection and succeeds
    runner.setNonLoopConnection(true);
    runner.enqueue(new byte[0]);
    runner.run(1, true);
    runner.assertTransferCount(QuerySolr.RESULTS, 1);
    runner.assertTransferCount(QuerySolr.FACETS, 1);
    runner.assertTransferCount(QuerySolr.STATS, 1);
    runner.assertTransferCount(QuerySolr.ORIGINAL, 1);
    runner.assertAllFlowFilesContainAttribute(QuerySolr.ATTRIBUTE_SOLR_CONNECT);

    flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    flowFile = runner.getFlowFilesForRelationship(QuerySolr.FACETS).get(0);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    flowFile = runner.getFlowFilesForRelationship(QuerySolr.STATS).get(0);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    runner.clearTransferState();

    solrClient.close();
}
 
Example 6
Source File: QuerySolrIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testRecordResponse() throws IOException, InitializationException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty(QuerySolr.RETURN_TYPE, QuerySolr.MODE_REC.getValue());
    runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id,created,integer_single");
    runner.setProperty(QuerySolr.SOLR_PARAM_ROWS, "10");

    final String outputSchemaText = new String(Files.readAllBytes(Paths.get("src/test/resources/test-schema.avsc")));

    final JsonRecordSetWriter jsonWriter = new JsonRecordSetWriter();
    runner.addControllerService("writer", jsonWriter);
    runner.setProperty(jsonWriter, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.SCHEMA_TEXT_PROPERTY);
    runner.setProperty(jsonWriter, SchemaAccessUtils.SCHEMA_TEXT, outputSchemaText);
    runner.setProperty(jsonWriter, "Pretty Print JSON", "true");
    runner.setProperty(jsonWriter, "Schema Write Strategy", "full-schema-attribute");
    runner.enableControllerService(jsonWriter);
    runner.setProperty(SolrUtils.RECORD_WRITER, "writer");

    runner.setNonLoopConnection(false);

    runner.run(1);
    runner.assertQueueEmpty();
    runner.assertTransferCount(QuerySolr.RESULTS, 1);

    JsonReader reader = new JsonReader(new InputStreamReader(new ByteArrayInputStream(
            runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0)))));
    reader.beginArray();
    int controlScore = 0;
    while (reader.hasNext()) {
        reader.beginObject();
        while (reader.hasNext()) {
            if (reader.nextName().equals("integer_single")) {
                controlScore += reader.nextInt();
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
    }
    reader.close();
    solrClient.close();

    assertEquals(controlScore, 45);
}
 
Example 7
Source File: TestQuerySolr.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testRelationshipRoutings() throws IOException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty("facet", "true");
    runner.setProperty("stats", "true");

    // Set request handler for request failure
    runner.setProperty(QuerySolr.SOLR_PARAM_REQUEST_HANDLER, "/nonexistentrequesthandler");

    // Processor has no input connection and fails
    runner.setNonLoopConnection(false);
    runner.run(1, false);
    runner.assertAllFlowFilesTransferred(QuerySolr.FAILURE, 1);

    MockFlowFile flowFile = runner.getFlowFilesForRelationship(QuerySolr.FAILURE).get(0);
    flowFile.assertAttributeExists(QuerySolr.EXCEPTION);
    flowFile.assertAttributeExists(QuerySolr.EXCEPTION_MESSAGE);
    runner.clearTransferState();

    // Processor has an input connection and fails
    runner.setNonLoopConnection(true);
    runner.enqueue(new byte[0]);
    runner.run(1, false);
    runner.assertAllFlowFilesTransferred(QuerySolr.FAILURE, 1);

    flowFile = runner.getFlowFilesForRelationship(QuerySolr.FAILURE).get(0);
    flowFile.assertAttributeExists(QuerySolr.EXCEPTION);
    flowFile.assertAttributeExists(QuerySolr.EXCEPTION_MESSAGE);
    runner.clearTransferState();

    // Set request handler for successful request
    runner.setProperty(QuerySolr.SOLR_PARAM_REQUEST_HANDLER, "/select");

    // Processor has no input connection and succeeds
    runner.setNonLoopConnection(false);
    runner.run(1, false);
    runner.assertTransferCount(QuerySolr.RESULTS, 1);
    runner.assertTransferCount(QuerySolr.FACETS, 1);
    runner.assertTransferCount(QuerySolr.STATS, 1);

    flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    runner.clearTransferState();

    // Processor has an input connection and succeeds
    runner.setNonLoopConnection(true);
    runner.enqueue(new byte[0]);
    runner.run(1, true);
    runner.assertTransferCount(QuerySolr.RESULTS, 1);
    runner.assertTransferCount(QuerySolr.FACETS, 1);
    runner.assertTransferCount(QuerySolr.STATS, 1);
    runner.assertTransferCount(QuerySolr.ORIGINAL, 1);
    runner.assertAllFlowFilesContainAttribute(QuerySolr.ATTRIBUTE_SOLR_CONNECT);

    flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    flowFile = runner.getFlowFilesForRelationship(QuerySolr.FACETS).get(0);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    flowFile = runner.getFlowFilesForRelationship(QuerySolr.STATS).get(0);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    runner.clearTransferState();

    solrClient.close();
}
 
Example 8
Source File: TestQuerySolr.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testRecordResponse() throws IOException, InitializationException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty(QuerySolr.RETURN_TYPE, QuerySolr.MODE_REC.getValue());
    runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id,created,integer_single");
    runner.setProperty(QuerySolr.SOLR_PARAM_ROWS, "10");

    final String outputSchemaText = new String(Files.readAllBytes(Paths.get("src/test/resources/test-schema.avsc")));

    final JsonRecordSetWriter jsonWriter = new JsonRecordSetWriter();
    runner.addControllerService("writer", jsonWriter);
    runner.setProperty(jsonWriter, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.SCHEMA_TEXT_PROPERTY);
    runner.setProperty(jsonWriter, SchemaAccessUtils.SCHEMA_TEXT, outputSchemaText);
    runner.setProperty(jsonWriter, "Pretty Print JSON", "true");
    runner.setProperty(jsonWriter, "Schema Write Strategy", "full-schema-attribute");
    runner.enableControllerService(jsonWriter);
    runner.setProperty(SolrUtils.RECORD_WRITER, "writer");

    runner.setNonLoopConnection(false);

    runner.run(1);
    runner.assertQueueEmpty();
    runner.assertTransferCount(QuerySolr.RESULTS, 1);

    JsonReader reader = new JsonReader(new InputStreamReader(new ByteArrayInputStream(
            runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0)))));
    reader.beginArray();
    int controlScore = 0;
    while (reader.hasNext()) {
        reader.beginObject();
        while (reader.hasNext()) {
            if (reader.nextName().equals("integer_single")) {
                controlScore += reader.nextInt();
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
    }
    reader.close();
    solrClient.close();

    assertEquals(controlScore, 45);
}
 
Example 9
Source File: TestQuerySolr.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testExceedStartParam() throws IOException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty(QuerySolr.SOLR_PARAM_START, "10001");

    runner.setNonLoopConnection(false);

    runner.run();
    runner.assertAllFlowFilesTransferred(QuerySolr.RESULTS, 1);

    MockFlowFile flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0);

    assertEquals("10001", flowFile.getAttribute(QuerySolr.ATTRIBUTE_SOLR_START));
    assertEquals(0, runner.getContentAsByteArray(flowFile).length);

    solrClient.close();
}