use of org.apache.nifi.util.MockComponentLog in project nifi by apache.
the class TestLogAttribute method testLogPropertyCSVWithIgnoreRegex.
@Test
public void testLogPropertyCSVWithIgnoreRegex() {
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();
// we're saying add and remove the same properties, so the net result should be nothing
runner.setProperty(LogAttribute.ATTRIBUTES_TO_LOG_CSV, "foo");
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")));
}
use of org.apache.nifi.util.MockComponentLog in project nifi by apache.
the class TestLogAttribute method testLogPropertyCSVNoIgnore.
@Test
public void testLogPropertyCSVNoIgnore() {
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_CSV, "foo, 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, not(containsString("foobaz-value")));
assertThat(logMessage, containsString("foo-value"));
assertThat(logMessage, containsString("bar-value"));
}
use of org.apache.nifi.util.MockComponentLog in project nifi by apache.
the class TestLogAttribute method testLogPropertyWithIgnoreRegex.
@Test
public void testLogPropertyWithIgnoreRegex() {
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_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, containsString("bar-value"));
}
use of org.apache.nifi.util.MockComponentLog in project nifi by apache.
the class TestLogMessage method testInfoMessageWithPrefixLogged.
@Test
public void testInfoMessageWithPrefixLogged() throws InitializationException, IOException {
runner.setProperty(LogMessage.LOG_PREFIX, "FOOBAR>>>");
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("FOOBAR>>>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());
}
use of org.apache.nifi.util.MockComponentLog in project nifi by apache.
the class TestRollbackOnFailure method processInputs.
private void processInputs(RollbackOnFailure context, Integer[][] inputs, List<Integer> results) {
final ExternalProcedure p = new ExternalProcedure();
final MockComponentLog componentLog = new MockComponentLog("processor-id", this);
final ExceptionHandler<RollbackOnFailure> handler = getContextAwareExceptionHandler(componentLog);
for (Integer[] input : inputs) {
if (!handler.execute(context, input, (in) -> {
results.add(p.divide(in[0], in[1]));
context.proceed();
})) {
continue;
}
assertEquals(input[2], results.get(results.size() - 1));
}
}
Aggregations