Search in sources :

Example 11 with MockComponentLog

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

the class TestInFlightMessageTracker method testAwaitCompletionWhenComplete.

@Test(timeout = 5000L)
public void testAwaitCompletionWhenComplete() throws InterruptedException, TimeoutException {
    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);
    tracker.incrementAcknowledgedCount(flowFile);
    verifyNotComplete(tracker);
    tracker.incrementAcknowledgedCount(flowFile);
    tracker.awaitCompletion(1L);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) MockComponentLog(org.apache.nifi.util.MockComponentLog) Test(org.junit.Test)

Example 12 with MockComponentLog

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

the class MetricsReportingTaskTest method setUp.

/**
 * Set up the test environment and mock behaviour. This includes registering {@link #reporterServiceStub} in the
 * different contexts, overriding {@link MetricsReportingTask#currentStatusReference} and instantiating the test
 * subject.
 */
@Before
public void setUp() throws Exception {
    Map<String, ControllerService> services = new HashMap<>();
    services.put(REPORTER_SERVICE_IDENTIFIER, reporterServiceStub);
    testedReportingTask = new MetricsReportingTask();
    reportingContextStub = new MockReportingContext(services, new MockStateManager(testedReportingTask), new MockVariableRegistry());
    rootGroupStatus = new ProcessGroupStatus();
    innerGroupStatus = new ProcessGroupStatus();
    when(reporterServiceStub.createReporter(any())).thenReturn(reporterMock);
    when(reporterServiceStub.getIdentifier()).thenReturn(REPORTER_SERVICE_IDENTIFIER);
    reportingContextStub.setProperty(MetricsReportingTask.REPORTER_SERVICE.getName(), REPORTER_SERVICE_IDENTIFIER);
    reportingContextStub.addControllerService(reporterServiceStub, REPORTER_SERVICE_IDENTIFIER);
    configurationContextStub = new MockConfigurationContext(reportingContextStub.getProperties(), reportingContextStub.getControllerServiceLookup());
    reportingInitContextStub = new MockReportingInitializationContext(TEST_INIT_CONTEXT_ID, TEST_INIT_CONTEXT_NAME, new MockComponentLog(TEST_TASK_ID, testedReportingTask));
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) MockConfigurationContext(org.apache.nifi.util.MockConfigurationContext) HashMap(java.util.HashMap) MockStateManager(org.apache.nifi.state.MockStateManager) MockComponentLog(org.apache.nifi.util.MockComponentLog) MockVariableRegistry(org.apache.nifi.util.MockVariableRegistry) MockReportingInitializationContext(org.apache.nifi.util.MockReportingInitializationContext) ControllerService(org.apache.nifi.controller.ControllerService) MockReportingContext(org.apache.nifi.util.MockReportingContext) Before(org.junit.Before)

Example 13 with MockComponentLog

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

the class TestLogAttribute method testLogPropertyRegexNoIgnore.

@Test
public void testLogPropertyRegexNoIgnore() {
    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_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, 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 14 with MockComponentLog

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

the class TestLogAttribute method testLogPropertyRegexWithIgnoreRegex.

@Test
public void testLogPropertyRegexWithIgnoreRegex() {
    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();
    // includes foo,foobaz
    runner.setProperty(LogAttribute.ATTRIBUTES_TO_LOG_REGEX, "foo.*");
    // includes foobaz
    runner.setProperty(LogAttribute.ATTRIBUTES_TO_IGNORE_REGEX, "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)

Example 15 with MockComponentLog

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

the class TestLogMessage method testInfoMessageLogged.

@Test
public void testInfoMessageLogged() throws InitializationException, IOException {
    runner.setProperty(LogMessage.LOG_MESSAGE, "This should help the operator to follow the flow: ${foobar}");
    runner.setProperty(LogMessage.LOG_LEVEL, LogMessage.MessageLogLevel.info.toString());
    HashMap<String, String> flowAttributes = new HashMap<>();
    flowAttributes.put("foobar", "baz");
    runner.enqueue("This is a message!", flowAttributes);
    runner.setValidateExpressionUsage(false);
    runner.run();
    List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship(LogMessage.REL_SUCCESS);
    Assert.assertEquals(1, successFlowFiles.size());
    MockComponentLog mockComponentLog = testableLogMessage.getMockComponentLog();
    List<org.apache.nifi.util.LogMessage> infoMessages = mockComponentLog.getInfoMessages();
    Assert.assertEquals(1, infoMessages.size());
    Assert.assertTrue(infoMessages.get(0).getMsg().endsWith("This should help the operator to follow the flow: baz"));
    Assert.assertTrue(mockComponentLog.getTraceMessages().isEmpty());
    Assert.assertTrue(mockComponentLog.getDebugMessages().isEmpty());
    Assert.assertTrue(mockComponentLog.getWarnMessages().isEmpty());
    Assert.assertTrue(mockComponentLog.getErrorMessages().isEmpty());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) MockComponentLog(org.apache.nifi.util.MockComponentLog) 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