exceptionfactory commented on code in PR #8063:
URL: https://github.com/apache/nifi/pull/8063#discussion_r1454401906


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java:
##########
@@ -349,6 +408,50 @@ public void testFirstRunNoMessages() throws 
InterruptedException {
         while(rerun);
     }
 
+    @Test
+    public void testRunNoMessagesWithWaitForActivityTrue() throws 
InterruptedException {
+        // don't use the TestableProcessor, we want the real timestamp from 
@OnScheduled
+        final TestRunner runner = TestRunners.newTestRunner(new 
MonitorActivity());
+        runner.setProperty(MonitorActivity.CONTINUALLY_SEND_MESSAGES, "false");
+        runner.setProperty(MonitorActivity.THRESHOLD, "5 secs");
+        runner.setProperty(MonitorActivity.WAIT_FOR_ACTIVITY, "true");
+
+        // shouldn't generate inactivity b/c run() will reset the 
lastSuccessfulTransfer if @OnSchedule & onTrigger
+        // does not  get called more than MonitorActivity.THRESHOLD apart
+        runner.run();
+        runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 0);
+        runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 0);
+        runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 0);
+        Thread.sleep(10000L);
+        runNext(runner);
+        runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 0);
+        runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 0);
+        runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 0);
+        runner.clearTransferState();
+    }
+
+    @Test
+    public void testRunNoMessagesWithWaitForActivityFalse() throws 
InterruptedException {
+        // don't use the TestableProcessor, we want the real timestamp from 
@OnScheduled
+        final TestRunner runner = TestRunners.newTestRunner(new 
MonitorActivity());
+        runner.setProperty(MonitorActivity.CONTINUALLY_SEND_MESSAGES, "false");
+        runner.setProperty(MonitorActivity.THRESHOLD, "5 secs");
+        runner.setProperty(MonitorActivity.WAIT_FOR_ACTIVITY, "false");
+
+        // shouldn't generate inactivity b/c run() will reset the 
lastSuccessfulTransfer if @OnSchedule & onTrigger
+        // does not  get called more than MonitorActivity.THRESHOLD apart
+        runner.run();
+        runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 0);
+        runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 0);
+        runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 0);
+        Thread.sleep(10000L);
+        runNext(runner);
+        runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 0);
+        runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 1);
+        runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 0);
+        runner.clearTransferState();
+    }
+

Review Comment:
   The sleep of 10 seconds is too long for efficient unit testing. The other 
unit test method provides some basic coverage, so recommend removing these two 
test methods.



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java:
##########
@@ -100,6 +100,65 @@ public void testFirstMessage() {
         restoredFlowFile.assertAttributeNotExists("key1");
     }
 
+    @Test
+    public void testFirstMessageWithWaitForActivityTrue() {
+        final TestableProcessor processor = new TestableProcessor(1000);
+        final TestRunner runner = TestRunners.newTestRunner(processor);
+        runner.setProperty(MonitorActivity.CONTINUALLY_SEND_MESSAGES, "false");
+        runner.setProperty(MonitorActivity.THRESHOLD, "100 millis");
+        runner.setProperty(MonitorActivity.WAIT_FOR_ACTIVITY, "true");
+
+        runner.enqueue(new byte[0]);
+        runner.run();
+        runner.assertAllFlowFilesTransferred(MonitorActivity.REL_SUCCESS, 1);
+        runner.clearTransferState();
+
+        processor.resetLastSuccessfulTransfer();
+
+        runNext(runner);
+        runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE, 1);
+        runner.clearTransferState();
+
+        Map<String, String> attributes = new HashMap<>();
+        attributes.put("key", "value");
+        attributes.put("key1", "value1");
+
+        runner.enqueue(new byte[0], attributes);
+        runNext(runner);
+
+        runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 1);
+        runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 1);
+
+        MockFlowFile restoredFlowFile = 
runner.getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED).get(0);
+        String flowFileContent = new String(restoredFlowFile.toByteArray());
+        assertTrue(Pattern.matches("Activity restored at time: (.*) after 
being inactive for 0 minutes", flowFileContent));

Review Comment:
   It is best to avoid checking particular messages, as these are not 
necessarily part of the component's basic behavior. Recommend removing this 
assertion and the similar one at the end of the method.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to