Search in sources :

Example 11 with LogMessage

use of org.apache.nifi.util.LogMessage in project kylo by Teradata.

the class TdchUtilsTest method testGetExportHiveToTeradataJobExitCode_InvalidCodeShort.

@Test
public void testGetExportHiveToTeradataJobExitCode_InvalidCodeShort() {
    TestRunner runner = TestRunners.newTestRunner(TestAbstractTdchProcessor.class);
    MockComponentLog componentLog = runner.getLogger();
    TdchUtils tdchUtils = new TdchUtils();
    long code = tdchUtils.getExportHiveToTeradataJobExitCode(getTdchProcessResultWithShortInvalidExitCode(), componentLog);
    Assert.assertEquals(-1, code);
    List<LogMessage> warnMessages = componentLog.getWarnMessages();
    Assert.assertEquals(1, warnMessages.size());
    Assert.assertTrue(warnMessages.get(0).getMsg().endsWith("Skipping attempt to retrieve TDCH exit code"));
}
Also used : TdchUtils(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.processor.export.utils.TdchUtils) LogMessage(org.apache.nifi.util.LogMessage) TestRunner(org.apache.nifi.util.TestRunner) MockComponentLog(org.apache.nifi.util.MockComponentLog) Test(org.junit.Test)

Example 12 with LogMessage

use of org.apache.nifi.util.LogMessage in project kylo by Teradata.

the class TdchUtilsTest method testGetExportHiveToTeradataJobExitCode_InvalidCodeLong.

@Test
public void testGetExportHiveToTeradataJobExitCode_InvalidCodeLong() {
    TestRunner runner = TestRunners.newTestRunner(TestAbstractTdchProcessor.class);
    MockComponentLog componentLog = runner.getLogger();
    TdchUtils tdchUtils = new TdchUtils();
    long code = tdchUtils.getExportHiveToTeradataJobExitCode(getTdchProcessResultWithLongInvalidExitCode(), componentLog);
    Assert.assertEquals(-1, code);
    List<LogMessage> warnMessages = componentLog.getWarnMessages();
    Assert.assertEquals(1, warnMessages.size());
    Assert.assertTrue(warnMessages.get(0).getMsg().contains("Unable to parse TDCH exit code"));
}
Also used : TdchUtils(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.processor.export.utils.TdchUtils) LogMessage(org.apache.nifi.util.LogMessage) TestRunner(org.apache.nifi.util.TestRunner) MockComponentLog(org.apache.nifi.util.MockComponentLog) Test(org.junit.Test)

Example 13 with LogMessage

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

the class TestExecuteProcess method testNotRedirectErrorStream.

@Test
public void testNotRedirectErrorStream() {
    final TestRunner runner = TestRunners.newTestRunner(ExecuteProcess.class);
    runner.setProperty(ExecuteProcess.COMMAND, "cd");
    runner.setProperty(ExecuteProcess.COMMAND_ARGUMENTS, "does-not-exist");
    ProcessContext processContext = runner.getProcessContext();
    ExecuteProcess processor = (ExecuteProcess) runner.getProcessor();
    processor.updateScheduledTrue();
    processor.setupExecutor(processContext);
    processor.onTrigger(processContext, runner.getProcessSessionFactory());
    if (isCommandFailed(runner))
        return;
    // ExecuteProcess doesn't wait for finishing to drain error stream if it's configure NOT to redirect stream.
    // This causes test failure when draining the error stream didn't finish
    // fast enough before the thread of this test case method checks the warn msg count.
    // So, this loop wait for a while until the log msg count becomes expected number, otherwise let it fail.
    final int expectedWarningMessages = 1;
    final int maxRetry = 5;
    for (int i = 0; i < maxRetry && (runner.getLogger().getWarnMessages().size() < expectedWarningMessages); i++) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
    }
    final List<LogMessage> warnMessages = runner.getLogger().getWarnMessages();
    assertEquals("If redirect error stream is false, " + "the output should be logged as a warning so that user can notice on bulletin.", expectedWarningMessages, warnMessages.size());
    final List<MockFlowFile> succeeded = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS);
    assertEquals(0, succeeded.size());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) LogMessage(org.apache.nifi.util.LogMessage) TestRunner(org.apache.nifi.util.TestRunner) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Example 14 with LogMessage

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

the class TestExecuteProcess method testRedirectErrorStream.

@Test
public void testRedirectErrorStream() {
    final TestRunner runner = TestRunners.newTestRunner(ExecuteProcess.class);
    runner.setProperty(ExecuteProcess.COMMAND, "cd");
    runner.setProperty(ExecuteProcess.COMMAND_ARGUMENTS, "does-not-exist");
    runner.setProperty(ExecuteProcess.REDIRECT_ERROR_STREAM, "true");
    ProcessContext processContext = runner.getProcessContext();
    ExecuteProcess processor = (ExecuteProcess) runner.getProcessor();
    processor.updateScheduledTrue();
    processor.setupExecutor(processContext);
    processor.onTrigger(processContext, runner.getProcessSessionFactory());
    if (isCommandFailed(runner))
        return;
    final List<LogMessage> warnMessages = runner.getLogger().getWarnMessages();
    assertEquals("If redirect error stream is true " + "the output should be sent as a content of flow-file.", 0, warnMessages.size());
    final List<MockFlowFile> succeeded = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS);
    assertEquals(1, succeeded.size());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) LogMessage(org.apache.nifi.util.LogMessage) TestRunner(org.apache.nifi.util.TestRunner) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Example 15 with LogMessage

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

the class TestPutEmail method testEmptyFrom.

@Test
public void testEmptyFrom() throws Exception {
    // verifies that if the FROM property evaluates to an empty string at
    // runtime the flow file is transferred to failure.
    runner.setProperty(PutEmail.SMTP_HOSTNAME, "smtp-host");
    runner.setProperty(PutEmail.HEADER_XMAILER, "TestingNiFi");
    runner.setProperty(PutEmail.FROM, "${MISSING_PROPERTY}");
    runner.setProperty(PutEmail.MESSAGE, "Message Body");
    runner.setProperty(PutEmail.TO, "recipient@apache.org");
    runner.enqueue("Some Text".getBytes());
    runner.run();
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(PutEmail.REL_FAILURE);
    assertEquals("Expected no messages to be sent", 0, processor.getMessages().size());
    final LogMessage logMessage = runner.getLogger().getErrorMessages().get(0);
    assertTrue(((String) logMessage.getArgs()[2]).contains("Required property 'From' evaluates to an empty string"));
}
Also used : LogMessage(org.apache.nifi.util.LogMessage) Test(org.junit.Test)

Aggregations

LogMessage (org.apache.nifi.util.LogMessage)30 Test (org.junit.Test)30 TestRunner (org.apache.nifi.util.TestRunner)29 MockComponentLog (org.apache.nifi.util.MockComponentLog)25 TdchUtils (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.processor.export.utils.TdchUtils)24 ProcessContext (org.apache.nifi.processor.ProcessContext)3 MockFlowFile (org.apache.nifi.util.MockFlowFile)3 TdchBuilder (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.processor.export.utils.TdchBuilder)1