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

The following examples show how to use org.apache.nifi.util.TestRunner#setVariable() . 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: TestJoltTransformJSON.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testTransformInputWithDefaultrExpressionLanguage() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
    runner.setValidateExpressionUsage(false);
    final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/defaultrELSpec.json")));
    runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
    runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.DEFAULTR);
    runner.setVariable("quota","5");
    runner.enqueue(JSON_INPUT);
    runner.run();
    runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS);
    final MockFlowFile transformed = runner.getFlowFilesForRelationship(JoltTransformJSON.REL_SUCCESS).get(0);
    Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
    Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestJoltTransformJson/defaultrELOutput.json")));
    assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
}
 
Example 2
Source File: AbstractHadoopTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testKerberosOptionsWithEL() throws Exception {
    SimpleHadoopProcessor processor = new SimpleHadoopProcessor(kerberosProperties);
    TestRunner runner = TestRunners.newTestRunner(processor);

    // initialize the runner with EL for the kerberos properties
    runner.setProperty(AbstractHadoopProcessor.HADOOP_CONFIGURATION_RESOURCES, "${variableHadoopConfigResources}");
    runner.setProperty(kerberosProperties.getKerberosPrincipal(), "${variablePrincipal}");
    runner.setProperty(kerberosProperties.getKerberosKeytab(), "${variableKeytab}");

    // add variables for all the kerberos properties except for the keytab
    runner.setVariable("variableHadoopConfigResources", "src/test/resources/core-site-security.xml");
    runner.setVariable("variablePrincipal", "principal");
    // test that the config is not valid, since the EL for keytab will return nothing, no keytab
    runner.assertNotValid();

    // add variable for the keytab
    runner.setVariable("variableKeytab", temporaryFile.getAbsolutePath());
    // test that the config is valid
    runner.assertValid();
}
 
Example 3
Source File: JMSConnectionFactoryProviderTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void dynamicPropertiesSetOnSingleTestBrokerConnectionFactory() throws InitializationException {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));

    JMSConnectionFactoryProviderForTest cfProvider = new JMSConnectionFactoryProviderForTest();
    runner.addControllerService(controllerServiceId, cfProvider);

    runner.setVariable("test", "dynamicValue");

    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, SINGLE_TEST_BROKER);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CLIENT_LIBRARIES, dummyResource);
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, TEST_CONNECTION_FACTORY_IMPL);
    runner.setProperty(cfProvider, "dynamicProperty", "${test}");

    runner.enableControllerService(cfProvider);

    assertEquals(cfProvider.getConfiguredProperties(), ImmutableMap.of("dynamicProperty", "dynamicValue", "hostName", HOSTNAME, "port", PORT));
}
 
Example 4
Source File: JMSConnectionFactoryProviderTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClientLibResourcesLoaded() throws InitializationException {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
    runner.setValidateExpressionUsage(true);

    JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
    runner.addControllerService(controllerServiceId, cfProvider);

    runner.setVariable("broker.uri", SINGLE_TEST_BROKER_WITH_SCHEME_AND_IP);
    runner.setVariable("client.lib", allDummyResources);

    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, "${broker.uri}");
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CLIENT_LIBRARIES, "${client.lib}");
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, TEST_CONNECTION_FACTORY_IMPL);

    runner.assertValid(cfProvider);

    ClassLoader loader = runner.getClass().getClassLoader();
    Assert.assertNotNull(loader.getResource(DUMMY_CONF));
    Assert.assertNotNull(loader.getResource(DUMMY_JAR_1));
    Assert.assertNotNull(loader.getResource(DUMMY_JAR_2));
}
 
Example 5
Source File: JMSConnectionFactoryProviderTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void validateELExpression() throws InitializationException {
    TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
    runner.setValidateExpressionUsage(true);

    JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
    runner.addControllerService(controllerServiceId, cfProvider);

    runner.setVariable("broker.uri", SINGLE_TEST_BROKER_WITH_SCHEME_AND_IP);
    runner.setVariable("client.lib", dummyResource);

    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, "${broker.uri}");
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CLIENT_LIBRARIES, "${client.lib}");
    runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, TEST_CONNECTION_FACTORY_IMPL);

    runner.assertValid(cfProvider);
}
 
Example 6
Source File: ConsumeKafkaTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testJaasConfiguration() throws Exception {
    ConsumeKafka_0_11 consumeKafka = new ConsumeKafka_0_11();
    TestRunner runner = TestRunners.newTestRunner(consumeKafka);
    runner.setProperty(KafkaProcessorUtils.BOOTSTRAP_SERVERS, "okeydokey:1234");
    runner.setProperty(ConsumeKafka_0_11.TOPICS, "foo");
    runner.setProperty(ConsumeKafka_0_11.GROUP_ID, "foo");
    runner.setProperty(ConsumeKafka_0_11.AUTO_OFFSET_RESET, ConsumeKafka_0_11.OFFSET_EARLIEST);

    runner.setProperty(KafkaProcessorUtils.SECURITY_PROTOCOL, KafkaProcessorUtils.SEC_SASL_PLAINTEXT);
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.JAAS_SERVICE_NAME, "kafka");
    runner.assertValid();

    runner.setProperty(KafkaProcessorUtils.USER_PRINCIPAL, "[email protected]");
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "not.A.File");
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "src/test/resources/server.properties");
    runner.assertValid();

    runner.setVariable("keytab", "src/test/resources/server.properties");
    runner.setVariable("principal", "[email protected]");
    runner.setVariable("service", "kafka");
    runner.setProperty(KafkaProcessorUtils.USER_PRINCIPAL, "${principal}");
    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "${keytab}s");
    runner.setProperty(KafkaProcessorUtils.JAAS_SERVICE_NAME, "${service}");
    runner.assertValid();
}
 
Example 7
Source File: TestPutSolrContentStream.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsernamePasswordValidation() {
    final TestRunner runner = TestRunners.newTestRunner(PutSolrContentStream.class);
    runner.setProperty(PutSolrContentStream.SOLR_TYPE, PutSolrContentStream.SOLR_TYPE_STANDARD.getValue());
    runner.setProperty(PutSolrContentStream.SOLR_LOCATION, "http://localhost:8443/solr");
    runner.assertValid();

    runner.setProperty(PutSolrContentStream.BASIC_USERNAME, "user1");
    runner.assertNotValid();

    runner.setProperty(PutSolrContentStream.BASIC_PASSWORD, "password");
    runner.assertValid();

    runner.setProperty(PutSolrContentStream.BASIC_USERNAME, "");
    runner.assertNotValid();

    runner.setProperty(PutSolrContentStream.BASIC_USERNAME, "${solr.user}");
    runner.assertNotValid();

    runner.setVariable("solr.user", "solrRocks");
    runner.assertValid();

    runner.setProperty(PutSolrContentStream.BASIC_PASSWORD, "${solr.password}");
    runner.assertNotValid();

    runner.setVariable("solr.password", "solrRocksPassword");
    runner.assertValid();
}
 
Example 8
Source File: ConsumeKafkaTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testJaasConfiguration() throws Exception {
    ConsumeKafka_0_10 consumeKafka = new ConsumeKafka_0_10();
    TestRunner runner = TestRunners.newTestRunner(consumeKafka);
    runner.setProperty(KafkaProcessorUtils.BOOTSTRAP_SERVERS, "okeydokey:1234");
    runner.setProperty(ConsumeKafka_0_10.TOPICS, "foo");
    runner.setProperty(ConsumeKafka_0_10.GROUP_ID, "foo");
    runner.setProperty(ConsumeKafka_0_10.AUTO_OFFSET_RESET, ConsumeKafka_0_10.OFFSET_EARLIEST);

    runner.setProperty(KafkaProcessorUtils.SECURITY_PROTOCOL, KafkaProcessorUtils.SEC_SASL_PLAINTEXT);
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.JAAS_SERVICE_NAME, "kafka");
    runner.assertValid();

    runner.setProperty(KafkaProcessorUtils.USER_PRINCIPAL, "[email protected]");
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "not.A.File");
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "src/test/resources/server.properties");
    runner.assertValid();

    runner.setVariable("keytab", "src/test/resources/server.properties");
    runner.setVariable("principal", "[email protected]");
    runner.setVariable("service", "kafka");
    runner.setProperty(KafkaProcessorUtils.USER_PRINCIPAL, "${principal}");
    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "${keytab}s");
    runner.setProperty(KafkaProcessorUtils.JAAS_SERVICE_NAME, "${service}");
    runner.assertValid();
}
 
Example 9
Source File: ConsumeKafkaTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testJaasConfiguration() throws Exception {
    ConsumeKafka_1_0 consumeKafka = new ConsumeKafka_1_0();
    TestRunner runner = TestRunners.newTestRunner(consumeKafka);
    runner.setProperty(KafkaProcessorUtils.BOOTSTRAP_SERVERS, "okeydokey:1234");
    runner.setProperty(ConsumeKafka_1_0.TOPICS, "foo");
    runner.setProperty(ConsumeKafka_1_0.GROUP_ID, "foo");
    runner.setProperty(ConsumeKafka_1_0.AUTO_OFFSET_RESET, ConsumeKafka_1_0.OFFSET_EARLIEST);

    runner.setProperty(KafkaProcessorUtils.SECURITY_PROTOCOL, KafkaProcessorUtils.SEC_SASL_PLAINTEXT);
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.JAAS_SERVICE_NAME, "kafka");
    runner.assertValid();

    runner.setProperty(KafkaProcessorUtils.USER_PRINCIPAL, "[email protected]");
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "not.A.File");
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "src/test/resources/server.properties");
    runner.assertValid();

    runner.setVariable("keytab", "src/test/resources/server.properties");
    runner.setVariable("principal", "[email protected]");
    runner.setVariable("service", "kafka");
    runner.setProperty(KafkaProcessorUtils.USER_PRINCIPAL, "${principal}");
    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "${keytab}s");
    runner.setProperty(KafkaProcessorUtils.JAAS_SERVICE_NAME, "${service}");
    runner.assertValid();
}
 
Example 10
Source File: MongoWriteTestBase.java    From nifi with Apache License 2.0 5 votes vote down vote up
public TestRunner init(Class processor) {
    TestRunner runner = TestRunners.newTestRunner(processor);
    runner.setVariable("uri", MONGO_URI);
    runner.setVariable("db", DATABASE_NAME);
    runner.setVariable("collection", COLLECTION_NAME);
    runner.setProperty(AbstractMongoProcessor.URI, "${uri}");
    runner.setProperty(AbstractMongoProcessor.DATABASE_NAME, "${db}");
    runner.setProperty(AbstractMongoProcessor.COLLECTION_NAME, "${collection}");
    return runner;
}
 
Example 11
Source File: TestScanAttribute.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleMatch() {
    final TestRunner runner = TestRunners.newTestRunner(new ScanAttribute());
    runner.setVariable("dictionary", "src/test/resources/ScanAttribute/dictionary1");
    runner.setProperty(ScanAttribute.DICTIONARY_FILE, "${dictionary}");

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("abc", "world");

    runner.enqueue(new byte[0], attributes);
    runner.run();

    runner.assertAllFlowFilesTransferred(ScanAttribute.REL_MATCHED, 1);
    runner.clearTransferState();

    attributes.remove("abc");
    runner.enqueue(new byte[0], attributes);
    runner.run();

    runner.assertAllFlowFilesTransferred(ScanAttribute.REL_UNMATCHED, 1);
    runner.clearTransferState();

    attributes.put("abc", "world");
    runner.setProperty(ScanAttribute.ATTRIBUTE_PATTERN, "a.*");
    runner.enqueue(new byte[0], attributes);
    runner.run();
    runner.assertAllFlowFilesTransferred(ScanAttribute.REL_MATCHED, 1);
    runner.clearTransferState();

    runner.setProperty(ScanAttribute.ATTRIBUTE_PATTERN, "c.*");
    runner.enqueue(new byte[0], attributes);
    runner.run();
    runner.assertAllFlowFilesTransferred(ScanAttribute.REL_UNMATCHED, 1);
    runner.clearTransferState();

}
 
Example 12
Source File: TestValidateXml.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidEL() throws IOException, SAXException {
    final TestRunner runner = TestRunners.newTestRunner(new ValidateXml());
    runner.setProperty(ValidateXml.SCHEMA_FILE, "${my.schema}");
    runner.setVariable("my.schema", "src/test/resources/TestXml/XmlBundle.xsd");

    runner.enqueue(Paths.get("src/test/resources/TestXml/xml-snippet.xml"));
    runner.run();

    runner.assertAllFlowFilesTransferred(ValidateXml.REL_VALID, 1);
}
 
Example 13
Source File: TestExecuteProcess.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void validateProcessInterruptOnStop() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(ExecuteProcess.class);
    runner.setVariable("command", "ping");
    runner.setProperty(ExecuteProcess.COMMAND, "${command}");
    runner.setProperty(ExecuteProcess.COMMAND_ARGUMENTS, "nifi.apache.org");
    runner.setProperty(ExecuteProcess.BATCH_DURATION, "500 millis");

    runner.run();
    Thread.sleep(500);
    ExecuteProcess processor = (ExecuteProcess) runner.getProcessor();
    try {
        Field executorF = ExecuteProcess.class.getDeclaredField("executor");
        executorF.setAccessible(true);
        ExecutorService executor = (ExecutorService) executorF.get(processor);
        assertTrue(executor.isShutdown());
        assertTrue(executor.isTerminated());

        Field processF = ExecuteProcess.class.getDeclaredField("externalProcess");
        processF.setAccessible(true);
        Process process = (Process) processF.get(processor);
        assertFalse(process.isAlive());
    } catch (Exception e) {
        fail();
    }

    final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS);
    if(!flowFiles.isEmpty()) {
        assertTrue(flowFiles.get(0).getAttribute("command").equals("ping"));
    }
}
 
Example 14
Source File: TestAttributesToJSON.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAttributesRegex() throws IOException {
    final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToJSON());
    testRunner.setVariable("regex", "delimited\\.header\\.column\\.[0-9]+");
    testRunner.setProperty(AttributesToJSON.ATTRIBUTES_REGEX, "${regex}");
    testRunner.setProperty(AttributesToJSON.ATTRIBUTES_LIST, "test, test1");

    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("delimited.header.column.1", "Registry");
    attributes.put("delimited.header.column.2", "Assignment");
    attributes.put("delimited.header.column.3", "Organization Name");
    attributes.put("delimited.header.column.4", "Organization Address");
    attributes.put("delimited.footer.column.1", "not included");
    attributes.put("test", "test");
    attributes.put("test1", "test1");
    testRunner.enqueue("".getBytes(), attributes);

    testRunner.run();

    testRunner.assertTransferCount(AttributesToJSON.REL_FAILURE, 0);
    testRunner.assertTransferCount(AttributesToJSON.REL_SUCCESS, 1);

    MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS).get(0);

    Map<String, String> val = new ObjectMapper().readValue(flowFile.getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME), HashMap.class);
    assertTrue(val.keySet().contains("delimited.header.column.1"));
    assertTrue(val.keySet().contains("delimited.header.column.2"));
    assertTrue(val.keySet().contains("delimited.header.column.3"));
    assertTrue(val.keySet().contains("delimited.header.column.4"));
    assertTrue(!val.keySet().contains("delimited.footer.column.1"));
    assertTrue(val.keySet().contains("test"));
    assertTrue(val.keySet().contains("test1"));
}
 
Example 15
Source File: TestValidateCsv.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidateWithEL() {
    final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
    runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, "${comma}");
    runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "${crlf}");
    runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "${quote}");
    runner.setProperty(ValidateCsv.HEADER, "false");

    runner.setProperty(ValidateCsv.SCHEMA, "RequireSubString(\"test\")");
    runner.assertNotValid();

    runner.setProperty(ValidateCsv.SCHEMA, "''");
    runner.assertNotValid();

    runner.setProperty(ValidateCsv.SCHEMA, "\"\"");
    runner.assertNotValid();

    runner.setProperty(ValidateCsv.SCHEMA, "${schema}");
    runner.assertValid();

    int hashcode = "test".hashCode();
    runner.setVariable("schema", "RequireHashCode(" + hashcode + "), RequireSubStr(\"test\")");
    runner.setVariable("comma", ",");
    runner.setVariable("quote", "\"");
    runner.setVariable("crlf", "\r\n");

    runner.enqueue("test,test");
    runner.run();
    runner.assertAllFlowFilesTransferred(ValidateCsv.REL_VALID, 1);
}
 
Example 16
Source File: TestJoltTransformJSON.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransformInputWithDefaultrExpressionLanguage() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
    final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/defaultrELSpec.json")));
    runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
    runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.DEFAULTR);
    runner.setVariable("quota","5");
    runner.enqueue(JSON_INPUT);
    runner.run();
    runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS);
    final MockFlowFile transformed = runner.getFlowFilesForRelationship(JoltTransformJSON.REL_SUCCESS).get(0);
    Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
    Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestJoltTransformJson/defaultrELOutput.json")));
    assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
}
 
Example 17
Source File: TestPutSolrContentStream.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsernamePasswordValidation() {
    final TestRunner runner = TestRunners.newTestRunner(PutSolrContentStream.class);
    runner.setProperty(SolrUtils.SOLR_TYPE, SolrUtils.SOLR_TYPE_STANDARD.getValue());
    runner.setProperty(SolrUtils.SOLR_LOCATION, "http://localhost:8443/solr");
    runner.assertValid();

    runner.setProperty(SolrUtils.BASIC_USERNAME, "user1");
    runner.assertNotValid();

    runner.setProperty(SolrUtils.BASIC_PASSWORD, "password");
    runner.assertValid();

    runner.setProperty(SolrUtils.BASIC_USERNAME, "");
    runner.assertNotValid();

    runner.setProperty(SolrUtils.BASIC_USERNAME, "${solr.user}");
    runner.assertNotValid();

    runner.setVariable("solr.user", "solrRocks");
    runner.assertValid();

    runner.setProperty(SolrUtils.BASIC_PASSWORD, "${solr.password}");
    runner.assertNotValid();

    runner.setVariable("solr.password", "solrRocksPassword");
    runner.assertValid();
}
 
Example 18
Source File: TestConsumeKafka_2_0.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testJaasConfiguration() throws Exception {
    ConsumeKafka_2_0 consumeKafka = new ConsumeKafka_2_0();
    TestRunner runner = TestRunners.newTestRunner(consumeKafka);
    runner.setProperty(KafkaProcessorUtils.BOOTSTRAP_SERVERS, "okeydokey:1234");
    runner.setProperty(ConsumeKafka_2_0.TOPICS, "foo");
    runner.setProperty(ConsumeKafka_2_0.GROUP_ID, "foo");
    runner.setProperty(ConsumeKafka_2_0.AUTO_OFFSET_RESET, ConsumeKafka_2_0.OFFSET_EARLIEST);

    runner.setProperty(KafkaProcessorUtils.SECURITY_PROTOCOL, KafkaProcessorUtils.SEC_SASL_PLAINTEXT);
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.JAAS_SERVICE_NAME, "kafka");
    runner.assertValid();

    runner.setProperty(KafkaProcessorUtils.USER_PRINCIPAL, "[email protected]");
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "not.A.File");
    runner.assertNotValid();

    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "src/test/resources/server.properties");
    runner.assertValid();

    runner.setVariable("keytab", "src/test/resources/server.properties");
    runner.setVariable("principal", "[email protected]");
    runner.setVariable("service", "kafka");
    runner.setProperty(KafkaProcessorUtils.USER_PRINCIPAL, "${principal}");
    runner.setProperty(KafkaProcessorUtils.USER_KEYTAB, "${keytab}s");
    runner.setProperty(KafkaProcessorUtils.JAAS_SERVICE_NAME, "${service}");
    runner.assertValid();
}
 
Example 19
Source File: GetMongoIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testValidators() {

    TestRunner runner = TestRunners.newTestRunner(GetMongo.class);
    Collection<ValidationResult> results;
    ProcessContext pc;

    // missing uri, db, collection
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    results = new HashSet<>();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(2, results.size());
    Iterator<ValidationResult> it = results.iterator();
    Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required"));
    Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required"));

    // missing query - is ok
    runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI);
    runner.setProperty(AbstractMongoProcessor.DATABASE_NAME, DB_NAME);
    runner.setProperty(AbstractMongoProcessor.COLLECTION_NAME, COLLECTION_NAME);
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    results = new HashSet<>();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(0, results.size());

    // invalid query
    runner.setProperty(GetMongo.QUERY, "{a: x,y,z}");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    results = new HashSet<>();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.iterator().next().toString().contains("is invalid because"));

    // invalid projection
    runner.setVariable("projection", "{a: x,y,z}");
    runner.setProperty(GetMongo.QUERY, "{\"a\": 1}");
    runner.setProperty(GetMongo.PROJECTION, "{a: z}");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    results = new HashSet<>();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.iterator().next().toString().contains("is invalid"));

    // invalid sort
    runner.removeProperty(GetMongo.PROJECTION);
    runner.setProperty(GetMongo.SORT, "{a: x,y,z}");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    results = new HashSet<>();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.iterator().next().toString().contains("is invalid"));
}
 
Example 20
Source File: DBCPServiceTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a few connections and step closes them to see what happens
 */
@Test
public void testIdle() throws InitializationException, SQLException, InterruptedException {
    final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
    final DBCPConnectionPool service = new DBCPConnectionPool();
    runner.addControllerService("test-good1", service);

    // set embedded Derby database connection url
    runner.setProperty(service, DBCPConnectionPool.DATABASE_URL, "jdbc:derby:" + dbLocation + ";create=true");
    runner.setProperty(service, DBCPConnectionPool.DB_USER, "tester");
    runner.setProperty(service, DBCPConnectionPool.DB_PASSWORD, "testerp");
    runner.setProperty(service, DBCPConnectionPool.DB_DRIVERNAME, "org.apache.derby.jdbc.EmbeddedDriver");
    runner.setProperty(service, DBCPConnectionPool.MAX_WAIT_TIME, "${max.wait.time}");
    runner.setProperty(service, DBCPConnectionPool.MAX_TOTAL_CONNECTIONS, "${max.total.connections}");
    runner.setProperty(service, DBCPConnectionPool.MAX_IDLE, "${max.idle}");
    runner.setProperty(service, DBCPConnectionPool.MIN_IDLE, "${min.idle}");
    runner.setProperty(service, DBCPConnectionPool.MAX_CONN_LIFETIME, "${max.conn.lifetime}");
    runner.setProperty(service, DBCPConnectionPool.EVICTION_RUN_PERIOD, "${eviction.run.period}");
    runner.setProperty(service, DBCPConnectionPool.MIN_EVICTABLE_IDLE_TIME, "${min.evictable.idle.time}");
    runner.setProperty(service, DBCPConnectionPool.SOFT_MIN_EVICTABLE_IDLE_TIME, "${soft.min.evictable.idle.time}");

    runner.setVariable("max.wait.time", "1 sec");
    runner.setVariable("max.total.connections", "7");
    runner.setVariable("max.idle", "4");
    runner.setVariable("min.idle", "1");
    runner.setVariable("max.conn.lifetime", "1000 millis");
    runner.setVariable("eviction.run.period", "100 millis");
    runner.setVariable("min.evictable.idle.time", "100 millis");
    runner.setVariable("soft.min.evictable.idle.time", "100 millis");

    runner.enableControllerService(service);

    ArrayList<Connection> connections = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        connections.add(service.getConnection());
    }

    Assert.assertEquals(6, service.getDataSource().getNumActive());

    connections.get(0).close();
    Assert.assertEquals(5, service.getDataSource().getNumActive());
    Assert.assertEquals(1, service.getDataSource().getNumIdle());

    connections.get(1).close();
    connections.get(2).close();
    connections.get(3).close();
    //now at max idle
    Assert.assertEquals(2, service.getDataSource().getNumActive());
    Assert.assertEquals(4, service.getDataSource().getNumIdle());

    //now a connection should get closed for real so that numIdle does not exceed maxIdle
    connections.get(4).close();
    Assert.assertEquals(4, service.getDataSource().getNumIdle());
    Assert.assertEquals(1, service.getDataSource().getNumActive());

    connections.get(5).close();
    Assert.assertEquals(4, service.getDataSource().getNumIdle());
    Assert.assertEquals(0, service.getDataSource().getNumActive());

    service.getDataSource().close();
}