Search in sources :

Example 1 with MockComponentLog

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

the class TestInFlightMessageTracker method testAwaitCompletionWhileWaiting.

@Test(timeout = 5000L)
public void testAwaitCompletionWhileWaiting() throws InterruptedException, ExecutionException {
    final MockFlowFile flowFile = new MockFlowFile(1L);
    final InFlightMessageTracker tracker = new InFlightMessageTracker(new MockComponentLog("1", "unit-test"));
    tracker.incrementSentCount(flowFile);
    verifyNotComplete(tracker);
    tracker.incrementSentCount(flowFile);
    verifyNotComplete(tracker);
    final ExecutorService exec = Executors.newFixedThreadPool(1);
    final Future<?> future = exec.submit(() -> {
        try {
            tracker.awaitCompletion(10000L);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    tracker.incrementAcknowledgedCount(flowFile);
    tracker.incrementAcknowledgedCount(flowFile);
    future.get();
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) MockComponentLog(org.apache.nifi.util.MockComponentLog) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 2 with MockComponentLog

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

the class TestLogAttribute method testLogPropertyWithIgnoreCSVAndRegex.

@Test
public void testLogPropertyWithIgnoreCSVAndRegex() {
    final LogAttribute logAttribute = new LogAttribute();
    final TestRunner runner = TestRunners.newTestRunner(logAttribute);
    final ProcessContext context = runner.getProcessContext();
    final ProcessSession session = runner.getProcessSessionFactory().createSession();
    final MockComponentLog LOG = runner.getLogger();
    // there's an OR relationship between like properties, so anything starting with foo or bar are removed. that's everything we're adding
    runner.setProperty(LogAttribute.ATTRIBUTES_TO_IGNORE_CSV, "foo,bar");
    runner.setProperty(LogAttribute.ATTRIBUTES_TO_IGNORE_REGEX, "foo.*");
    final Map<String, String> attrs = Maps.newHashMap();
    attrs.put("foo", "foo-value");
    attrs.put("bar", "bar-value");
    attrs.put("foobaz", "foobaz-value");
    final MockFlowFile flowFile = runner.enqueue("content", attrs);
    final String logMessage = logAttribute.processFlowFile(LOG, LogAttribute.DebugLevels.info, flowFile, session, context);
    assertThat(logMessage, not(containsString("foobaz-value")));
    assertThat(logMessage, not(containsString("foo-value")));
    assertThat(logMessage, not(containsString("bar-value")));
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) MockComponentLog(org.apache.nifi.util.MockComponentLog) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Example 3 with MockComponentLog

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

the class TestLogAttribute method testLogPropertyWithCSVAndRegexNoIgnore.

@Test
public void testLogPropertyWithCSVAndRegexNoIgnore() {
    final LogAttribute logAttribute = new LogAttribute();
    final TestRunner runner = TestRunners.newTestRunner(logAttribute);
    final ProcessContext context = runner.getProcessContext();
    final ProcessSession session = runner.getProcessSessionFactory().createSession();
    final MockComponentLog LOG = runner.getLogger();
    // there's an AND relationship between like properties, so only foo should be logged in this case
    runner.setProperty(LogAttribute.ATTRIBUTES_TO_LOG_CSV, "foo, bar");
    runner.setProperty(LogAttribute.ATTRIBUTES_TO_LOG_REGEX, "foo*");
    final Map<String, String> attrs = Maps.newHashMap();
    attrs.put("foo", "foo-value");
    attrs.put("bar", "bar-value");
    attrs.put("foobaz", "foobaz-value");
    final MockFlowFile flowFile = runner.enqueue("content", attrs);
    final String logMessage = logAttribute.processFlowFile(LOG, LogAttribute.DebugLevels.info, flowFile, session, context);
    assertThat(logMessage, not(containsString("foobaz-value")));
    assertThat(logMessage, containsString("foo-value"));
    assertThat(logMessage, not(containsString("bar-value")));
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) MockComponentLog(org.apache.nifi.util.MockComponentLog) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Example 4 with MockComponentLog

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

the class TestLogAttribute method testLogPropertyWithIgnoreCSV.

@Test
public void testLogPropertyWithIgnoreCSV() {
    final LogAttribute logAttribute = new LogAttribute();
    final TestRunner runner = TestRunners.newTestRunner(logAttribute);
    final ProcessContext context = runner.getProcessContext();
    final ProcessSession session = runner.getProcessSessionFactory().createSession();
    final MockComponentLog LOG = runner.getLogger();
    runner.setProperty(LogAttribute.ATTRIBUTES_TO_IGNORE_CSV, "bar");
    final Map<String, String> attrs = Maps.newHashMap();
    attrs.put("foo", "foo-value");
    attrs.put("bar", "bar-value");
    attrs.put("foobaz", "foobaz-value");
    final MockFlowFile flowFile = runner.enqueue("content", attrs);
    final String logMessage = logAttribute.processFlowFile(LOG, LogAttribute.DebugLevels.info, flowFile, session, context);
    assertThat(logMessage, containsString("foobaz-value"));
    assertThat(logMessage, containsString("foo-value"));
    assertThat(logMessage, not(containsString("bar-value")));
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) MockComponentLog(org.apache.nifi.util.MockComponentLog) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Example 5 with MockComponentLog

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

the class TestLogAttribute method testLogPropertyCSVWithIgnoreCSV.

@Test
public void testLogPropertyCSVWithIgnoreCSV() {
    final LogAttribute logAttribute = new LogAttribute();
    final TestRunner runner = TestRunners.newTestRunner(logAttribute);
    final ProcessContext context = runner.getProcessContext();
    final ProcessSession session = runner.getProcessSessionFactory().createSession();
    final MockComponentLog LOG = runner.getLogger();
    // add foo,foobaz and remove foobaz
    runner.setProperty(LogAttribute.ATTRIBUTES_TO_LOG_CSV, "foo,foobaz");
    runner.setProperty(LogAttribute.ATTRIBUTES_TO_IGNORE_CSV, "foobaz");
    final Map<String, String> attrs = Maps.newHashMap();
    attrs.put("foo", "foo-value");
    attrs.put("bar", "bar-value");
    attrs.put("foobaz", "foobaz-value");
    final MockFlowFile flowFile = runner.enqueue("content", attrs);
    final String logMessage = logAttribute.processFlowFile(LOG, LogAttribute.DebugLevels.info, flowFile, session, context);
    assertThat(logMessage, not(containsString("foobaz-value")));
    assertThat(logMessage, containsString("foo-value"));
    assertThat(logMessage, not(containsString("bar-value")));
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) MockComponentLog(org.apache.nifi.util.MockComponentLog) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Aggregations

MockComponentLog (org.apache.nifi.util.MockComponentLog)19 Test (org.junit.Test)15 MockFlowFile (org.apache.nifi.util.MockFlowFile)13 ProcessContext (org.apache.nifi.processor.ProcessContext)9 ProcessSession (org.apache.nifi.processor.ProcessSession)9 TestRunner (org.apache.nifi.util.TestRunner)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 HashMap (java.util.HashMap)4 MockStateManager (org.apache.nifi.state.MockStateManager)3 List (java.util.List)2 ComponentLog (org.apache.nifi.logging.ComponentLog)2 MockConfigurationContext (org.apache.nifi.util.MockConfigurationContext)2 Before (org.junit.Before)2 PartitionContext (com.microsoft.azure.eventprocessorhost.PartitionContext)1 BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)1 Connection (com.rabbitmq.client.Connection)1 ReturnListener (com.rabbitmq.client.ReturnListener)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1