org.apache.nifi.util.MockComponentLog Java Examples
The following examples show how to use
org.apache.nifi.util.MockComponentLog.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestLogAttribute.java From nifi with Apache License 2.0 | 6 votes |
@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"))); }
Example #2
Source File: AMQPPublisherTest.java From nifi with Apache License 2.0 | 6 votes |
@Test public void validateSuccessfullPublishingAndUndeliverableRoutingKey() throws Exception { Map<String, List<String>> routingMap = new HashMap<>(); routingMap.put("key1", Arrays.asList("queue1", "queue2")); Map<String, String> exchangeToRoutingKeymap = new HashMap<>(); exchangeToRoutingKeymap.put("myExchange", "key1"); Connection connection = new TestConnection(exchangeToRoutingKeymap, routingMap); ReturnListener retListener = mock(ReturnListener.class); connection.createChannel().addReturnListener(retListener); try (AMQPPublisher sender = new AMQPPublisher(connection, new MockComponentLog("foo", ""))) { sender.publish("hello".getBytes(), null, "key1", "myExchange"); } verify(retListener, atMost(1)).handleReturn(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(BasicProperties.class), (byte[]) Mockito.any()); connection.close(); }
Example #3
Source File: TestInFlightMessageTracker.java From nifi with Apache License 2.0 | 6 votes |
@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(); }
Example #4
Source File: TestInFlightMessageTracker.java From nifi with Apache License 2.0 | 6 votes |
@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); }
Example #5
Source File: TestInFlightMessageTracker.java From nifi with Apache License 2.0 | 6 votes |
@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(); }
Example #6
Source File: TestInFlightMessageTracker.java From nifi with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: TestInFlightMessageTracker.java From nifi with Apache License 2.0 | 6 votes |
@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(); }
Example #8
Source File: TestInFlightMessageTracker.java From nifi with Apache License 2.0 | 6 votes |
@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); }
Example #9
Source File: MetricsReportingTaskTest.java From nifi with Apache License 2.0 | 6 votes |
/** * 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); 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)); }
Example #10
Source File: TestLogAttribute.java From nifi with Apache License 2.0 | 6 votes |
@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(); runner.setProperty(LogAttribute.ATTRIBUTES_TO_LOG_REGEX, "foo.*"); // includes foo,foobaz runner.setProperty(LogAttribute.ATTRIBUTES_TO_IGNORE_REGEX, "foobaz.*"); // includes 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"))); }
Example #11
Source File: TestLogAttribute.java From nifi with Apache License 2.0 | 6 votes |
@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"))); }
Example #12
Source File: TestLogAttribute.java From nifi with Apache License 2.0 | 6 votes |
@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"))); }
Example #13
Source File: TestLogAttribute.java From nifi with Apache License 2.0 | 6 votes |
@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")); }
Example #14
Source File: TestLogAttribute.java From nifi with Apache License 2.0 | 6 votes |
@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"))); }
Example #15
Source File: TestLogAttribute.java From nifi with Apache License 2.0 | 6 votes |
@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"))); }
Example #16
Source File: TestLogAttribute.java From nifi with Apache License 2.0 | 6 votes |
@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"))); }
Example #17
Source File: AMQPPublisherTest.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void validateSuccessfullPublishingAndUndeliverableRoutingKey() throws Exception { Map<String, List<String>> routingMap = new HashMap<>(); routingMap.put("key1", Arrays.asList("queue1", "queue2")); Map<String, String> exchangeToRoutingKeymap = new HashMap<>(); exchangeToRoutingKeymap.put("myExchange", "key1"); Connection connection = new TestConnection(exchangeToRoutingKeymap, routingMap); ReturnListener retListener = mock(ReturnListener.class); connection.createChannel().addReturnListener(retListener); try (AMQPPublisher sender = new AMQPPublisher(connection, new MockComponentLog("foo", ""))) { sender.publish("hello".getBytes(), null, "key1", "myExchange"); Thread.sleep(1000); } Thread.sleep(200); verify(retListener, atMost(1)).handleReturn(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(BasicProperties.class), (byte[]) Mockito.any()); connection.close(); }
Example #18
Source File: TestRollbackOnFailure.java From nifi with Apache License 2.0 | 6 votes |
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)); } }
Example #19
Source File: TestConsumeAzureEventHub.java From nifi with Apache License 2.0 | 6 votes |
@Before public void setupProcessor() { processor = new ConsumeAzureEventHub(); final ProcessorInitializationContext initContext = Mockito.mock(ProcessorInitializationContext.class); final String componentId = "componentId"; when(initContext.getIdentifier()).thenReturn(componentId); MockComponentLog componentLog = new MockComponentLog(componentId, processor); when(initContext.getLogger()).thenReturn(componentLog); processor.initialize(initContext); final ProcessSessionFactory processSessionFactory = Mockito.mock(ProcessSessionFactory.class); processor.setProcessSessionFactory(processSessionFactory); processor.setNamespaceName("namespace"); sharedState = new SharedSessionState(processor, new AtomicLong(0)); processSession = new MockProcessSession(sharedState, processor); when(processSessionFactory.createSession()).thenReturn(processSession); eventProcessor = processor.new EventProcessor(); partitionContext = Mockito.mock(PartitionContext.class); when(partitionContext.getEventHubPath()).thenReturn("eventhub-name"); when(partitionContext.getPartitionId()).thenReturn("partition-id"); when(partitionContext.getConsumerGroupName()).thenReturn("consumer-group"); }
Example #20
Source File: TestLogAttribute.java From nifi with Apache License 2.0 | 6 votes |
@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")); }
Example #21
Source File: JMSConnectionFactoryProviderTest.java From nifi with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void validateGetConnectionFactoryFailureIfServiceNotConfigured() { JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider() { @Override protected ComponentLog getLogger() { return new MockComponentLog("cfProvider", this); } }; cfProvider.onEnabled(new MockConfigurationContext(Collections.emptyMap(), null)); cfProvider.getConnectionFactory(); }
Example #22
Source File: TestContent.java From nifi-scripting-samples with Apache License 2.0 | 5 votes |
/** * Demonstrates splitting an array in a single incoming FlowFile into multiple output FlowFiles * @throws Exception */ @Test public void testSplitJavascript() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript()); runner.setValidateExpressionUsage(false); runner.setProperty(SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/content/split.js"); runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript"); runner.assertValid(); String inputContent = "["; inputContent += "{ \"color\": \"blue\" },"; inputContent += "{ \"color\": \"green\" },"; inputContent += "{ \"color\": \"red\" }"; inputContent += "]"; runner.enqueue(inputContent.getBytes(StandardCharsets.UTF_8)); runner.run(); MockComponentLog log = runner.getLogger(); List<LogMessage> infoMessages = log.getInfoMessages(); runner.assertAllFlowFilesTransferred("success", 3); final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success"); MockFlowFile blueFlowFile = successFlowFiles.get(0); blueFlowFile.assertAttributeEquals("color", "blue"); MockFlowFile greenFlowFile = successFlowFiles.get(1); greenFlowFile.assertAttributeEquals("color", "green"); MockFlowFile redFlowFile = successFlowFiles.get(2); redFlowFile.assertAttributeEquals("color", "red"); }
Example #23
Source File: TestContent.java From nifi-scripting-samples with Apache License 2.0 | 5 votes |
/** * Demonstrates splitting an array in a single incoming FlowFile into multiple output FlowFiles * @throws Exception */ @Test public void testSplitPython() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript()); runner.setValidateExpressionUsage(false); runner.setProperty(SCRIPT_ENGINE, "python"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/content/split.py"); runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript"); runner.assertValid(); String inputContent = "["; inputContent += "{ \"color\": \"blue\" },"; inputContent += "{ \"color\": \"green\" },"; inputContent += "{ \"color\": \"red\" }"; inputContent += "]"; runner.enqueue(inputContent.getBytes(StandardCharsets.UTF_8)); runner.run(); MockComponentLog log = runner.getLogger(); List<LogMessage> infoMessages = log.getInfoMessages(); runner.assertAllFlowFilesTransferred("success", 3); final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success"); MockFlowFile blueFlowFile = successFlowFiles.get(0); blueFlowFile.assertAttributeEquals("color", "blue"); MockFlowFile greenFlowFile = successFlowFiles.get(1); greenFlowFile.assertAttributeEquals("color", "green"); MockFlowFile redFlowFile = successFlowFiles.get(2); redFlowFile.assertAttributeEquals("color", "red"); }
Example #24
Source File: TestLog.java From nifi-scripting-samples with Apache License 2.0 | 5 votes |
/** * Demonstrates logging from within scripts * @throws Exception */ @Test public void testLogJavascript() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript()); runner.setValidateExpressionUsage(false); runner.setProperty(SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/log/log.js"); runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript"); runner.assertValid(); final Map<String, String> attributes = new HashMap<>(); attributes.put("greeting", "Hello"); runner.enqueue("sample text".getBytes(StandardCharsets.UTF_8), attributes); runner.run(); runner.assertAllFlowFilesTransferred("success", 1); final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success"); MockFlowFile result = successFlowFiles.get(0); MockComponentLog log = runner.getLogger(); List<LogMessage> debugMessages = log.getDebugMessages(); Assert.assertEquals(1, debugMessages.size()); Assert.assertTrue(debugMessages.get(0).getMsg().contains("Hello, Debug")); List<LogMessage> infoMessages = log.getInfoMessages(); Assert.assertEquals(1, infoMessages.size()); Assert.assertTrue(infoMessages.get(0).getMsg().contains("Hello, Info")); List<LogMessage> warnMessages = log.getWarnMessages(); Assert.assertEquals(1, warnMessages.size()); Assert.assertTrue(warnMessages.get(0).getMsg().contains("Hello, Warn")); List<LogMessage> errorMessages = log.getErrorMessages(); Assert.assertEquals(1, errorMessages.size()); Assert.assertTrue(errorMessages.get(0).getMsg().contains("Hello, Error")); }
Example #25
Source File: TestLog.java From nifi-scripting-samples with Apache License 2.0 | 5 votes |
/** * Demonstrates logging from within scripts * @throws Exception */ @Test public void testLogPython() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript()); runner.setValidateExpressionUsage(false); runner.setProperty(SCRIPT_ENGINE, "python"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/log/log.py"); runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript"); runner.assertValid(); final Map<String, String> attributes = new HashMap<>(); attributes.put("greeting", "Hello"); runner.enqueue("sample text".getBytes(StandardCharsets.UTF_8), attributes); runner.run(); runner.assertAllFlowFilesTransferred("success", 1); final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success"); MockFlowFile result = successFlowFiles.get(0); MockComponentLog log = runner.getLogger(); List<LogMessage> debugMessages = log.getDebugMessages(); Assert.assertEquals(1, debugMessages.size()); Assert.assertTrue(debugMessages.get(0).getMsg().contains("Hello, Debug")); List<LogMessage> infoMessages = log.getInfoMessages(); Assert.assertEquals(1, infoMessages.size()); Assert.assertTrue(infoMessages.get(0).getMsg().contains("Hello, Info")); List<LogMessage> warnMessages = log.getWarnMessages(); Assert.assertEquals(1, warnMessages.size()); Assert.assertTrue(warnMessages.get(0).getMsg().contains("Hello, Warn")); List<LogMessage> errorMessages = log.getErrorMessages(); Assert.assertEquals(1, errorMessages.size()); Assert.assertTrue(errorMessages.get(0).getMsg().contains("Hello, Error")); }
Example #26
Source File: TestAzureLogAnalyticsReportingTask.java From nifi with Apache License 2.0 | 5 votes |
@Before public void setup() { testedReportingTask = new TestableAzureLogAnalyticsReportingTask(); rootGroupStatus = new ProcessGroupStatus(); reportingInitContextStub = new MockReportingInitializationContext(TEST_INIT_CONTEXT_ID, TEST_INIT_CONTEXT_NAME, new MockComponentLog(TEST_TASK_ID, testedReportingTask)); reportingContextStub = new MockReportingContext(Collections.emptyMap(), new MockStateManager(testedReportingTask), new MockVariableRegistry()); reportingContextStub.setProperty(AzureLogAnalyticsReportingTask.INSTANCE_ID.getName(), TEST_TASK_ID); reportingContextStub.setProperty(AzureLogAnalyticsReportingTask.LOG_ANALYTICS_WORKSPACE_ID.getName(), TEST_TASK_ID); reportingContextStub.setProperty(AzureLogAnalyticsReportingTask.LOG_ANALYTICS_WORKSPACE_KEY.getName(), MOCK_KEY); rootGroupStatus.setId("1234"); rootGroupStatus.setFlowFilesReceived(5); rootGroupStatus.setBytesReceived(10000); rootGroupStatus.setFlowFilesSent(10); rootGroupStatus.setBytesSent(20000); rootGroupStatus.setQueuedCount(100); rootGroupStatus.setQueuedContentSize(1024L); rootGroupStatus.setBytesRead(60000L); rootGroupStatus.setBytesWritten(80000L); rootGroupStatus.setActiveThreadCount(5); rootGroupStatus.setName("root"); rootGroupStatus.setFlowFilesTransferred(5); rootGroupStatus.setBytesTransferred(10000); rootGroupStatus.setOutputContentSize(1000L); rootGroupStatus.setInputContentSize(1000L); rootGroupStatus.setOutputCount(100); rootGroupStatus.setInputCount(1000); initProcessorStatuses(); }
Example #27
Source File: TestNiFiRecordSerDe.java From nifi with Apache License 2.0 | 5 votes |
NiFiRecordSerDe createSerDe(String columnNames, String typeInfo) throws SerDeException{ Properties props = new Properties(); props.setProperty(serdeConstants.LIST_COLUMNS, columnNames); props.setProperty(serdeConstants.LIST_COLUMN_TYPES, typeInfo); NiFiRecordSerDe serDe = new NiFiRecordSerDe(null, new MockComponentLog("logger", new Object())); //reader isn't used serDe.initialize(null, props); //conf isn't used return serDe; }
Example #28
Source File: GetHDFSSequenceFileTest.java From nifi with Apache License 2.0 | 5 votes |
private void init() throws IOException { final MockProcessContext context = new MockProcessContext(getHDFSSequenceFile); ProcessorInitializationContext mockProcessorInitializationContext = mock(ProcessorInitializationContext.class); when(mockProcessorInitializationContext.getLogger()).thenReturn(new MockComponentLog("GetHDFSSequenceFileTest", getHDFSSequenceFile )); getHDFSSequenceFile.initialize(mockProcessorInitializationContext); getHDFSSequenceFile.init(mockProcessorInitializationContext); getHDFSSequenceFile.onScheduled(context); }
Example #29
Source File: TestListHDFS.java From nifi with Apache License 2.0 | 5 votes |
@Before public void setup() throws InitializationException { mockNiFiProperties = mock(NiFiProperties.class); when(mockNiFiProperties.getKerberosConfigurationFile()).thenReturn(null); kerberosProperties = new KerberosProperties(null); proc = new ListHDFSWithMockedFileSystem(kerberosProperties); mockLogger = spy(new MockComponentLog(UUID.randomUUID().toString(), proc)); runner = TestRunners.newTestRunner(proc, mockLogger); runner.setProperty(ListHDFS.HADOOP_CONFIGURATION_RESOURCES, "src/test/resources/core-site.xml"); runner.setProperty(ListHDFS.DIRECTORY, "/test"); }
Example #30
Source File: TestLogMessage.java From nifi with Apache License 2.0 | 5 votes |
@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.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()); }