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);
}
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));
}
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")));
}
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")));
}
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());
}
Aggregations