Skip to content

Commit

Permalink
NIFI-11737: Improved performance of FlowSynchronizationIT
Browse files Browse the repository at this point in the history
- FlowSynchronizationIT no longer requires isDestroyEnvironmentAfterEachTest to return true

This closes #7420

Signed-off-by: David Handermann <exceptionfactory@apache.org>
(cherry picked from commit 9709bd6)
  • Loading branch information
markap14 authored and exceptionfactory committed Jun 21, 2023
1 parent 6f5e830 commit a47f5b8
Showing 1 changed file with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,11 @@ public NiFiInstanceFactory getInstanceFactory() {
);
}

@Override
protected boolean isDestroyEnvironmentAfterEachTest() {
return true;
}


@Test
public void testParameterUpdateWhileNodeDisconnected() throws NiFiClientException, IOException, InterruptedException {
// Add Parameter context with Param1 = 1
final ParameterContextEntity parameterContextEntity = getClientUtil().createParameterContext("Context1", Collections.singletonMap("Param1", "1"));
final ParameterContextEntity parameterContextEntity = getClientUtil().createParameterContext("testParameterUpdateWhileNodeDisconnected", Collections.singletonMap("Param1", "1"));
getClientUtil().setParameterContext("root", parameterContextEntity);

// Create a GenerateFlowFile that adds an attribute with name 'attr' and a value that references the parameter
Expand Down Expand Up @@ -166,7 +161,7 @@ public void testSensitivePropertiesInherited() throws NiFiClientException, IOExc
final ProcessorEntity countEvents3 = getClientUtil().createProcessor("CountEvents");

// Create parameter context with a sensitive parameter and set that on the root group
final ParameterContextEntity paramContext = getClientUtil().createParameterContext("context1", "MyParameter", "Our Secret", true);
final ParameterContextEntity paramContext = getClientUtil().createParameterContext("testSensitivePropertiesInherited", "MyParameter", "Our Secret", true);
getClientUtil().setParameterContext("root", paramContext);

// Set sensitive property of 1 processor to an explicit value and sensitive property of another to a sensitive parameter.
Expand Down Expand Up @@ -202,13 +197,14 @@ public void testSensitivePropertiesInherited() throws NiFiClientException, IOExc

@Test
public void testComponentsRecreatedOnRejoinCluster() throws NiFiClientException, IOException, InterruptedException {
final ProcessGroupEntity topLevel = getClientUtil().createProcessGroup("testComponentsRecreatedOnRejoinCluster", "root");
// Build dataflow with processors at root level and an inner group that contains an input port, output port, and a processor, as well as a Controller Service that the processor will use.
final ProcessorEntity generate = getClientUtil().createProcessor("GenerateFlowFile");
final ProcessGroupEntity group = getClientUtil().createProcessGroup("Inner Group", "root");
final ProcessorEntity generate = getClientUtil().createProcessor("GenerateFlowFile", topLevel.getId());
final ProcessGroupEntity group = getClientUtil().createProcessGroup("Inner Group", topLevel.getId());
final PortEntity inPort = getClientUtil().createInputPort("In", group.getId());
final PortEntity outPort = getClientUtil().createOutputPort("Out", group.getId());
final ProcessorEntity count = getClientUtil().createProcessor("CountFlowFiles", group.getId());
final ProcessorEntity terminate = getClientUtil().createProcessor("TerminateFlowFile");
final ProcessorEntity terminate = getClientUtil().createProcessor("TerminateFlowFile", topLevel.getId());
getClientUtil().updateProcessorSchedulingPeriod(generate, "60 sec");

final ControllerServiceEntity countService = getClientUtil().createControllerService("StandardCountService", group.getId());
Expand All @@ -230,7 +226,7 @@ public void testComponentsRecreatedOnRejoinCluster() throws NiFiClientException,
reportingTaskProperties.put("Text", "${now():toNumber()}");
getClientUtil().updateReportingTaskProperties(reportingTask, reportingTaskProperties);

final ParameterContextEntity context = getClientUtil().createParameterContext("Context1", "abc", "hello", false);
final ParameterContextEntity context = getClientUtil().createParameterContext("testComponentsRecreatedOnRejoinCluster", "abc", "hello", false);

// Disconnect Node 2
disconnectNode(2);
Expand Down Expand Up @@ -260,7 +256,7 @@ public void testComponentsRecreatedOnRejoinCluster() throws NiFiClientException,
// is on Node 2.
switchClientToNode(2);

final ProcessGroupFlowEntity flow = getNifiClient().getFlowClient(DO_NOT_REPLICATE).getProcessGroup("root");
final ProcessGroupFlowEntity flow = getNifiClient().getFlowClient(DO_NOT_REPLICATE).getProcessGroup(topLevel.getId());
final FlowDTO flowDto = flow.getProcessGroupFlow().getFlow();
assertEquals(2, flowDto.getConnections().size());
assertEquals(2, flowDto.getProcessors().size());
Expand Down Expand Up @@ -395,11 +391,12 @@ public void testCannotJoinClusterIfMissingNar() throws NiFiClientException, IOEx
// Wait for node to show as disconnected because it doesn't have the necessary nar
waitForNodeState(2, NodeConnectionState.DISCONNECTED);

// We need to either restart Node 2 or remove it from the cluster in order to ensure that we can properly shutdown.
// Reconnecting to the cluster would require restoring the NAR file and restarting, which will take longer than simply removing the
// node from the cluster. So we opt for shutting down the node and removing it from the cluster.
// We need to restore the extensions nar and restart the node so that subsequent tests can succeed
restoreExtensionsNar(node2);
node2.stop();
removeNode(2);
node2.start();

waitForAllNodesConnected();
}

private void removeNode(final int index) throws NiFiClientException, IOException, InterruptedException {
Expand Down Expand Up @@ -437,6 +434,17 @@ public void testCanJoinClusterIfAllNodesMissingNar() throws NiFiClientException,
waitForAllNodesConnected();

assertTrue(getNifiClient().getProcessorClient().getProcessor(generate.getId()).getComponent().getExtensionMissing());

// In order to ensure that subsequent tests are able to operate properly, we need to restore the nar and restart
node1.stop();
node2.stop();

restoreExtensionsNar(node1);
restoreExtensionsNar(node2);

node1.start(false);
node2.start(true);
waitForAllNodesConnected();
}


Expand Down Expand Up @@ -511,6 +519,12 @@ private void removeExtensionsNar(final NiFiInstance nifiInstance) {
assertTrue(extensionsNar.renameTo(backupFile));
}

private void restoreExtensionsNar(final NiFiInstance nifiInstance) {
final File backupFile = getExtensionsNar(nifiInstance);
final File extensionsNar = new File(backupFile.getParentFile(), backupFile.getName().replace(".backup", ""));
assertTrue(backupFile.renameTo(extensionsNar));
}

private File getExtensionsNar(final NiFiInstance nifiInstance) {
final File libDir = new File(nifiInstance.getInstanceDirectory(), "lib");
final File[] testExtensionsNar = libDir.listFiles(file -> file.getName().startsWith("nifi-system-test-extensions-nar-"));
Expand Down

0 comments on commit a47f5b8

Please sign in to comment.