Java Code Examples for org.apache.nifi.util.TestRunner#setPrimaryNode()

The following examples show how to use org.apache.nifi.util.TestRunner#setPrimaryNode() . 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: TestMonitorActivity.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterMonitorActive() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(100));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    // This has to be very small threshold, otherwise, MonitorActivity skip persisting state.
    runner.setProperty(MonitorActivity.THRESHOLD, "1 ms");

    runner.enqueue("Incoming data");

    runner.run();

    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_SUCCESS);

    final StateMap updatedState = runner.getStateManager().getState(Scope.CLUSTER);
    assertNotNull("Latest timestamp should be persisted", updatedState.get(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER));
    // Should be null because COPY_ATTRIBUTES is null.
    assertNull(updatedState.get("key1"));
    assertNull(updatedState.get("key2"));
}
 
Example 2
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterMonitorInactivity() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(TimeUnit.MINUTES.toMillis(120)));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.THRESHOLD, "3 mins");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE);
    final List<MockFlowFile> inactiveFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_INACTIVE);
    assertEquals(1, inactiveFiles.size());

    final MockFlowFile inactiveFile = inactiveFiles.get(0);
    assertNotNull(inactiveFile.getAttribute("inactivityStartMillis"));
    assertNotNull(inactiveFile.getAttribute("inactivityDurationMillis"));

    runner.clearTransferState();

}
 
Example 3
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterMonitorActiveCopyAttribute() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(TimeUnit.MINUTES.toMillis(120)));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    // This has to be very small threshold, otherwise, MonitorActivity skip persisting state.
    runner.setProperty(MonitorActivity.THRESHOLD, "1 ms");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    final HashMap<String, String> attributes = new HashMap<>();
    attributes.put("key1", "value1");
    attributes.put("key2", "value2");
    runner.enqueue("Incoming data", attributes);

    runner.run();

    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_SUCCESS);

    final StateMap updatedState = runner.getStateManager().getState(Scope.CLUSTER);
    assertNotNull("Latest timestamp should be persisted", updatedState.get(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER));
    assertEquals("value1", updatedState.get("key1"));
    assertEquals("value2", updatedState.get("key2"));
}
 
Example 4
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterMonitorActiveFallbackToNodeScope() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(TimeUnit.MINUTES.toMillis(120)));
    runner.setClustered(false);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    // This has to be very small threshold, otherwise, MonitorActivity skip persisting state.
    runner.setProperty(MonitorActivity.THRESHOLD, "1 ms");

    runner.enqueue("Incoming data");

    runner.run();

    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_SUCCESS);

    final StateMap updatedState = runner.getStateManager().getState(Scope.CLUSTER);
    assertNull("Latest timestamp should NOT be persisted, because it's running as 'node' scope",
            updatedState.get(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER));
}
 
Example 5
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterMonitorInactivityOnNode() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(TimeUnit.MINUTES.toMillis(120)));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);
    runner.setProperty(MonitorActivity.THRESHOLD, "3 mins");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive, but this not shouldn't send flow file
    runner.run();
    runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 0);
    runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 0);
    runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 0);

    runner.clearTransferState();
}
 
Example 6
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterMonitorInactivityOnPrimaryNode() throws Exception {
    final TestableProcessor processor = new TestableProcessor(TimeUnit.MINUTES.toMillis(120));

    final TestRunner runner = TestRunners.newTestRunner(processor);
    runner.setClustered(true);
    runner.setPrimaryNode(true);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);
    runner.setProperty(MonitorActivity.THRESHOLD, "3 mins");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE);
    final List<MockFlowFile> inactiveFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_INACTIVE);
    assertEquals(1, inactiveFiles.size());

    final MockFlowFile inactiveFile = inactiveFiles.get(0);
    assertNotNull(inactiveFile.getAttribute("inactivityStartMillis"));
    assertNotNull(inactiveFile.getAttribute("inactivityDurationMillis"));

    runner.clearTransferState();

}
 
Example 7
Source File: TestMonitorActivity.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterMonitorInactivityOnPrimaryNode() throws Exception {
    final TestableProcessor processor = new TestableProcessor(10000);

    final TestRunner runner = TestRunners.newTestRunner(processor);
    runner.setClustered(true);
    runner.setPrimaryNode(true);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);
    runner.setProperty(MonitorActivity.THRESHOLD, "100 ms");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE);
    final List<MockFlowFile> inactiveFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_INACTIVE);
    assertEquals(1, inactiveFiles.size());

    final MockFlowFile inactiveFile = inactiveFiles.get(0);
    assertNotNull(inactiveFile.getAttribute("inactivityStartMillis"));
    assertNotNull(inactiveFile.getAttribute("inactivityDurationMillis"));

    runner.clearTransferState();

}
 
Example 8
Source File: TestMonitorActivity.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterMonitorInactivityFallbackToNodeScope() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(10000));
    runner.setClustered(false);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.THRESHOLD, "100 ms");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE);
    final List<MockFlowFile> inactiveFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_INACTIVE);
    assertEquals(1, inactiveFiles.size());

    final MockFlowFile inactiveFile = inactiveFiles.get(0);
    assertNotNull(inactiveFile.getAttribute("inactivityStartMillis"));
    assertNotNull(inactiveFile.getAttribute("inactivityDurationMillis"));

    runner.clearTransferState();

}
 
Example 9
Source File: TestMonitorActivity.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterMonitorInactivity() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(10000));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.THRESHOLD, "100 ms");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE);
    final List<MockFlowFile> inactiveFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_INACTIVE);
    assertEquals(1, inactiveFiles.size());

    final MockFlowFile inactiveFile = inactiveFiles.get(0);
    assertNotNull(inactiveFile.getAttribute("inactivityStartMillis"));
    assertNotNull(inactiveFile.getAttribute("inactivityDurationMillis"));

    runner.clearTransferState();

}
 
Example 10
Source File: TestMonitorActivity.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testClusterMonitorActiveCopyAttribute() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(100));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    // This has to be very small threshold, otherwise, MonitorActivity skip persisting state.
    runner.setProperty(MonitorActivity.THRESHOLD, "1 ms");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    final HashMap<String, String> attributes = new HashMap<>();
    attributes.put("key1", "value1");
    attributes.put("key2", "value2");
    runner.enqueue("Incoming data", attributes);

    runner.run();

    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_SUCCESS);

    final StateMap updatedState = runner.getStateManager().getState(Scope.CLUSTER);
    assertNotNull("Latest timestamp should be persisted", updatedState.get(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER));
    assertEquals("value1", updatedState.get("key1"));
    assertEquals("value2", updatedState.get("key2"));
}
 
Example 11
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterMonitorActivityRestoredByOtherNode() throws Exception {

    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(TimeUnit.MINUTES.toMillis(120)));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.THRESHOLD, "3 mins");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE);
    runner.clearTransferState();

    // Activity restored, even if this node doesn't have activity, other node updated the cluster state.
    final HashMap<String, String> clusterState = new HashMap<>();
    clusterState.put(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER, String.valueOf(System.currentTimeMillis()));
    clusterState.put("key1", "value1");
    clusterState.put("key2", "value2");
    runner.getStateManager().setState(clusterState, Scope.CLUSTER);
    runner.getStateManager().replace(runner.getStateManager().getState(Scope.CLUSTER), clusterState, Scope.CLUSTER);

    runNext(runner);
    final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_SUCCESS);
    final List<MockFlowFile> activityRestoredFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED);
    assertEquals("Should be zero since it doesn't have incoming file.", 0, successFiles.size());
    assertEquals(1, activityRestoredFiles.size());
    assertEquals("value1", activityRestoredFiles.get(0).getAttribute("key1"));
    assertEquals("value2", activityRestoredFiles.get(0).getAttribute("key2"));
    runner.clearTransferState();

}
 
Example 12
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterMonitorActivityRestoredBySelfOnNode() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(TimeUnit.MINUTES.toMillis(120)));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);
    runner.setProperty(MonitorActivity.THRESHOLD, "3 mins");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    // This node won't send notification files
    runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 0);
    runner.clearTransferState();

    // Activity restored
    final HashMap<String, String> attributes = new HashMap<>();
    attributes.put("key1", "value1");
    attributes.put("key2", "value2");
    runner.enqueue("Incoming data", attributes);

    runNext(runner);
    // This node should not send restored flow file
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_SUCCESS, 1);

    // Latest activity should be persisted
    final StateMap updatedState = runner.getStateManager().getState(Scope.CLUSTER);
    assertNotNull("Latest timestamp should be persisted", updatedState.get(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER));
    assertEquals("value1", updatedState.get("key1"));
    assertEquals("value2", updatedState.get("key2"));
    runner.clearTransferState();
}
 
Example 13
Source File: TestMonitorActivity.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterMonitorActivityRestoredBySelfOnNode() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(10000));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);
    runner.setProperty(MonitorActivity.THRESHOLD, "100 ms");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    // This node won't send notification files
    runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 0);
    runner.clearTransferState();

    // Activity restored
    final HashMap<String, String> attributes = new HashMap<>();
    attributes.put("key1", "value1");
    attributes.put("key2", "value2");
    runner.enqueue("Incoming data", attributes);

    runNext(runner);
    // This node should not send restored flow file
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_SUCCESS, 1);

    // Latest activity should be persisted
    final StateMap updatedState = runner.getStateManager().getState(Scope.CLUSTER);
    assertNotNull("Latest timestamp should be persisted", updatedState.get(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER));
    assertEquals("value1", updatedState.get("key1"));
    assertEquals("value2", updatedState.get("key2"));
    runner.clearTransferState();
}
 
Example 14
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterMonitorActivityRestoredBySelf() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(TimeUnit.MINUTES.toMillis(120)));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.THRESHOLD, "3 mins");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE);
    runner.clearTransferState();

    // Activity restored
    final HashMap<String, String> attributes = new HashMap<>();
    attributes.put("key1", "value1");
    attributes.put("key2", "value2");
    runner.enqueue("Incoming data", attributes);

    runNext(runner);
    final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_SUCCESS);
    final List<MockFlowFile> activityRestoredFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED);
    assertEquals(1, successFiles.size());
    assertEquals(1, activityRestoredFiles.size());
    assertEquals("value1", activityRestoredFiles.get(0).getAttribute("key1"));
    assertEquals("value2", activityRestoredFiles.get(0).getAttribute("key2"));

    // Latest activity should be persisted
    final StateMap updatedState = runner.getStateManager().getState(Scope.CLUSTER);
    assertNotNull("Latest timestamp should be persisted", updatedState.get(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER));
    assertEquals("value1", updatedState.get("key1"));
    assertEquals("value2", updatedState.get("key2"));
    runner.clearTransferState();
}
 
Example 15
Source File: TestMonitorActivity.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterMonitorActivityRestoredByOtherNodeOnPrimary() throws Exception {

    final TestableProcessor processor = new TestableProcessor(10000);

    final TestRunner runner = TestRunners.newTestRunner(processor);
    runner.setClustered(true);
    runner.setPrimaryNode(true);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);
    runner.setProperty(MonitorActivity.THRESHOLD, "100 ms");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE);
    runner.clearTransferState();

    // Activity restored, even if this node doesn't have activity, other node updated the cluster state.
    final HashMap<String, String> clusterState = new HashMap<>();
    clusterState.put(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER, String.valueOf(System.currentTimeMillis()));
    clusterState.put("key1", "value1");
    clusterState.put("key2", "value2");
    runner.getStateManager().setState(clusterState, Scope.CLUSTER);
    runner.getStateManager().replace(runner.getStateManager().getState(Scope.CLUSTER), clusterState, Scope.CLUSTER);

    runNext(runner);
    final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_SUCCESS);
    final List<MockFlowFile> activityRestoredFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED);
    assertEquals("Should be zero since it doesn't have incoming file.", 0, successFiles.size());
    assertEquals(1, activityRestoredFiles.size());
    assertEquals("value1", activityRestoredFiles.get(0).getAttribute("key1"));
    assertEquals("value2", activityRestoredFiles.get(0).getAttribute("key2"));
    runner.clearTransferState();

}
 
Example 16
Source File: TestMonitorActivity.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterMonitorActivityRestoredByOtherNodeOnNode() throws Exception {

    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(10000));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);
    runner.setProperty(MonitorActivity.THRESHOLD, "100 ms");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 0);
    runner.clearTransferState();

    // Activity restored, even if this node doesn't have activity, other node updated the cluster state.
    final HashMap<String, String> clusterState = new HashMap<>();
    clusterState.put(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER, String.valueOf(System.currentTimeMillis()));
    clusterState.put("key1", "value1");
    clusterState.put("key2", "value2");
    runner.getStateManager().setState(clusterState, Scope.CLUSTER);
    runner.getStateManager().replace(runner.getStateManager().getState(Scope.CLUSTER), clusterState, Scope.CLUSTER);

    runNext(runner);
    runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 0);
    runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 0);
    runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 0);
    runner.clearTransferState();

}
 
Example 17
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterMonitorInvalidReportingNode() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(TimeUnit.MINUTES.toMillis(120)));

    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_NODE);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);

    runner.assertNotValid();
}
 
Example 18
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterMonitorActivityRestoredBySelfOnPrimaryNode() throws Exception {
    final TestableProcessor processor = new TestableProcessor(TimeUnit.MINUTES.toMillis(120));

    final TestRunner runner = TestRunners.newTestRunner(processor);
    runner.setClustered(true);
    runner.setPrimaryNode(true);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);
    runner.setProperty(MonitorActivity.THRESHOLD, "3 mins");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE);
    runner.clearTransferState();

    // Activity restored
    final HashMap<String, String> attributes = new HashMap<>();
    attributes.put("key1", "value1");
    attributes.put("key2", "value2");
    runner.enqueue("Incoming data", attributes);

    runNext(runner);
    final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_SUCCESS);
    final List<MockFlowFile> activityRestoredFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED);
    assertEquals(1, successFiles.size());
    assertEquals(1, activityRestoredFiles.size());
    assertEquals("value1", activityRestoredFiles.get(0).getAttribute("key1"));
    assertEquals("value2", activityRestoredFiles.get(0).getAttribute("key2"));

    // Latest activity should be persisted
    final StateMap updatedState = runner.getStateManager().getState(Scope.CLUSTER);
    assertNotNull("Latest timestamp should be persisted", updatedState.get(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER));
    assertEquals("value1", updatedState.get("key1"));
    assertEquals("value2", updatedState.get("key2"));
    runner.clearTransferState();
}
 
Example 19
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterMonitorActivityRestoredByOtherNodeOnNode() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(TimeUnit.MINUTES.toMillis(120)));
    runner.setClustered(true);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);
    runner.setProperty(MonitorActivity.THRESHOLD, "3 mins");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 0);
    runner.clearTransferState();

    // Activity restored, even if this node doesn't have activity, other node updated the cluster state.
    final HashMap<String, String> clusterState = new HashMap<>();
    clusterState.put(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER, String.valueOf(System.currentTimeMillis()));
    clusterState.put("key1", "value1");
    clusterState.put("key2", "value2");
    runner.getStateManager().setState(clusterState, Scope.CLUSTER);
    runner.getStateManager().replace(runner.getStateManager().getState(Scope.CLUSTER), clusterState, Scope.CLUSTER);

    runNext(runner);
    runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 0);
    runner.assertTransferCount(MonitorActivity.REL_INACTIVE, 0);
    runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 0);
    runner.clearTransferState();

}
 
Example 20
Source File: TestMonitorActivity.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testClusterMonitorActivityRestoredBySelfOnPrimaryNodeFallbackToNodeScope() throws Exception {
    final TestableProcessor processor = new TestableProcessor(TimeUnit.MINUTES.toMillis(120));

    final TestRunner runner = TestRunners.newTestRunner(processor);
    runner.setClustered(false);
    runner.setPrimaryNode(false);
    runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_CLUSTER);
    runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY);
    runner.setProperty(MonitorActivity.THRESHOLD, "3 mins");
    runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");

    // Becomes inactive
    runner.run();
    runner.assertAllFlowFilesTransferred(MonitorActivity.REL_INACTIVE);
    runner.clearTransferState();

    // Activity restored
    final HashMap<String, String> attributes = new HashMap<>();
    attributes.put("key1", "value1");
    attributes.put("key2", "value2");
    runner.enqueue("Incoming data", attributes);

    runNext(runner);
    final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_SUCCESS);
    final List<MockFlowFile> activityRestoredFiles = runner.getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED);
    assertEquals(1, successFiles.size());
    assertEquals(1, activityRestoredFiles.size());
    assertEquals("value1", activityRestoredFiles.get(0).getAttribute("key1"));
    assertEquals("value2", activityRestoredFiles.get(0).getAttribute("key2"));

    // Latest activity should NOT be persisted
    final StateMap updatedState = runner.getStateManager().getState(Scope.CLUSTER);
    assertNull("Latest timestamp should NOT be persisted", updatedState.get(MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER));
    runner.clearTransferState();
}