bobpaulin commented on code in PR #11872:
URL: https://github.com/apache/nifi/pull/11872#discussion_r4552838168
##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/components/connector/TestStandardConnectorRepository.java:
##########
@@ -3217,6 +3296,318 @@ public List<ConfigVerificationResult>
verifyConfigurationStep(final String stepN
}
}
+ @Test
+ public void testSyncMatchingBundleRestoresPersistedFlowWithoutEvolution()
throws Exception {
+ final StandardConnectorNode connectorNode =
createRealConnectorNode("connector-1", new FlowEvolutionHookConnector());
+ final StandardConnectorRepository repository =
createRepositoryWithShortTimeout(null);
+ repository.restoreConnector(connectorNode);
+ final VersionedProcessGroup persisted = flowGroup("persisted-flow");
+ final Bundle matchingBundle = new Bundle("org.apache.nifi",
"test-standard-connector-node", "1.0.0");
+
+ final ConnectorSyncResult result =
repository.syncConnector(versionedConnector(matchingBundle, persisted));
+
+ assertNotEquals(ConnectorSyncResult.Outcome.FAILED,
result.getOutcome());
+ assertFalse(connectorNode.isPendingFlowEvolution());
+ assertEquals("persisted-flow",
connectorNode.getAuthoritativeFlowSnapshot().flow().getName());
+ verify(connectorNode.getActiveFlowContext().getManagedProcessGroup())
+
.restoreFlowPreservingIdentifiers(any(VersionedExternalFlow.class));
+ }
+
+ @Test
+ public void testSyncInfersMissingManagedFlowBundleAndRegistersEvolution()
throws Exception {
+ final StandardConnectorNode connectorNode =
createRealConnectorNode("connector-1", new FlowEvolutionHookConnector());
+ final StandardConnectorRepository repository =
createRepositoryWithShortTimeout(null);
+ repository.restoreConnector(connectorNode);
+ final VersionedProcessGroup persisted = flowGroup("outgoing-flow");
+ final Bundle outgoingBundle = new Bundle("org.apache.nifi",
"test-standard-connector-node", "0.9.0");
+ final VersionedConnector versioned =
versionedConnector(outgoingBundle, persisted);
+ assertNull(versioned.getManagedFlowBundle());
+
+ final ConnectorSyncResult result = repository.syncConnector(versioned);
+
+ assertNotEquals(ConnectorSyncResult.Outcome.FAILED,
result.getOutcome());
+ assertTrue(connectorNode.isPendingFlowEvolution());
+ assertEquals("0.9.0",
connectorNode.getAuthoritativeFlowSnapshot().bundle().getVersion());
+ }
+
+ @Test
+ public void testSyncWithoutPersistedFlowUsesLoadedBundleWithoutEvolution()
throws Exception {
+ final StandardConnectorNode connectorNode =
createRealConnectorNode("connector-1", new FlowEvolutionHookConnector());
+ final StandardConnectorRepository repository =
createRepositoryWithShortTimeout(null);
+ repository.restoreConnector(connectorNode);
+ final Bundle matchingBundle = new Bundle("org.apache.nifi",
"test-standard-connector-node", "1.0.0");
+
+ final ConnectorSyncResult result =
repository.syncConnector(versionedConnector(matchingBundle, null));
+
+ assertNotEquals(ConnectorSyncResult.Outcome.FAILED,
result.getOutcome());
+ assertFalse(connectorNode.isPendingFlowEvolution());
+ assertEquals("1.0.0",
connectorNode.getAuthoritativeFlowSnapshot().bundle().getVersion());
+ }
+
+ @Test
+ public void
testSyncTroubleshootingWithBundleMismatchRestoresPendingEvolution() throws
Exception {
+ final StandardConnectorNode connectorNode =
createRealConnectorNode("connector-1", new FlowEvolutionHookConnector());
+ final StandardConnectorRepository repository =
createRepositoryWithShortTimeout(null);
+ repository.restoreConnector(connectorNode);
+ final VersionedConnector versioned = versionedConnector(
+ new Bundle("org.apache.nifi", "test-standard-connector-node",
"0.9.0"), flowGroup("troubleshooting-flow"));
+ versioned.setScheduledState(VersionedConnectorState.TROUBLESHOOTING);
+
+ final ConnectorSyncResult result = repository.syncConnector(versioned);
+
+ assertNotEquals(ConnectorSyncResult.Outcome.FAILED,
result.getOutcome());
+ assertEquals(ConnectorState.TROUBLESHOOTING,
connectorNode.getCurrentState());
+ assertTrue(connectorNode.isPendingFlowEvolution());
+ assertEquals("troubleshooting-flow",
connectorNode.getAuthoritativeFlowSnapshot().flow().getName());
+ }
+
+
+ @Test
+ public void testPersistedComponentBundleResolution() throws Exception {
+ final StandardConnectorNode ambiguous =
createRealConnectorNode("connector-1", new FlowEvolutionHookConnector());
+ final StandardConnectorRepository ambiguousRepository =
createRepositoryWithShortTimeout(null);
+ ambiguousRepository.restoreConnector(ambiguous);
+ useBundleLookup(ambiguous, List.of(
+ componentBundle("org.apache.nifi", "processor-nar", "2.0.0"),
+ componentBundle("org.apache.nifi", "processor-nar", "3.0.0")));
+ final VersionedProcessGroup ambiguousFlow =
componentGroup("outgoing-flow", componentBundle("org.apache.nifi",
"processor-nar", "1.0.0"));
+ ambiguousRepository.syncConnector(versionedConnector(new
Bundle("org.apache.nifi", "test-nar", "1.0.0"), ambiguousFlow));
+ assertEquals("1.0.0",
ambiguousFlow.getProcessors().iterator().next().getBundle().getVersion());
+ assertEquals("1.0.0",
ambiguous.getAuthoritativeFlowSnapshot().flow().getProcessors().iterator().next().getBundle().getVersion());
+
+ final StandardConnectorNode ghost =
createRealConnectorNode("connector-1", new FlowEvolutionHookConnector(), true);
+ final StandardConnectorRepository ghostRepository =
createRepositoryWithShortTimeout(null);
+ ghostRepository.restoreConnector(ghost);
+ useBundleLookup(ghost, List.of(componentBundle("org.apache.nifi",
"processor-nar", "2.0.0")));
+ final VersionedProcessGroup ghostFlow = componentGroup("ghost-flow",
componentBundle("org.apache.nifi", "processor-nar", "1.0.0"));
+ ghostRepository.syncConnector(versionedConnector(new
Bundle("org.apache.nifi", "test-nar", "1.0.0"), ghostFlow));
+ assertTrue(ghost.isExtensionMissing());
+ assertEquals("1.0.0",
ghostFlow.getProcessors().iterator().next().getBundle().getVersion());
+ assertEquals("1.0.0",
ghost.getAuthoritativeFlowSnapshot().flow().getProcessors().iterator().next().getBundle().getVersion());
+ }
+
+ @Test
+ public void testGhostSyncRestoreFailureFlagsConnectorAndAdoptsSnapshot()
throws Exception {
+ final StandardConnectorNode connectorNode =
createRealConnectorNode("connector-1", new FlowEvolutionHookConnector(), true);
+ final StandardConnectorRepository repository =
createRepositoryWithShortTimeout(null);
+ repository.restoreConnector(connectorNode);
+ doThrow(new IllegalStateException("Expected restore
failure")).when(connectorNode.getActiveFlowContext().getManagedProcessGroup())
+ .restoreFlowPreservingIdentifiers(any(), eq(false));
+ final VersionedProcessGroup persisted = flowGroup("ghost-flow");
+
+ final ConnectorSyncResult result = repository.syncConnector(
+ versionedConnector(new Bundle("org.apache.nifi", "test-nar",
"1.0.0"), persisted));
+
+ assertNotEquals(ConnectorSyncResult.Outcome.FAILED,
result.getOutcome());
+ assertTrue(connectorNode.isManagedFlowMissingAtStartup());
+ assertEquals("ghost-flow",
connectorNode.getAuthoritativeFlowSnapshot().flow().getName());
+ }
+
+ @Test
+ public void testSecondStartDuringEvolutionReturnsClaimedFuture() throws
Exception {
+ final FlowEvolutionHookConnector connector = new
FlowEvolutionHookConnector();
+ connector.leaveFutureIncomplete = true;
+ final StandardConnectorNode connectorNode =
pendingEvolutionNode("second-start", connector);
+ final StandardConnectorRepository repository =
createRepositoryWithShortTimeout(null);
+
+ final Future<Void> evolution =
repository.startConnector(connectorNode, NO_OP_PERSISTENCE);
+ assertTrue(connector.evolutionFuturePublished.await(5,
TimeUnit.SECONDS));
+ assertSame(evolution, repository.startConnector(connectorNode,
NO_OP_PERSISTENCE));
+ assertEquals(1, connector.hookCalls);
+
+ connector.evolutionFuture.complete(null);
+ evolution.get(5, TimeUnit.SECONDS);
+ assertEquals(1, connector.hookCalls);
+ assertEquals(ConnectorState.RUNNING, connectorNode.getCurrentState());
+ }
+
+ @Test
+ public void testPersistenceFailureRetriesApplyWithoutRerunningHook()
throws Exception {
Review Comment:
I dropped the repository test and testResumeSkipsHook. I kept the system
test, now
ClusteredConnectorChangeVersionDrainIT.testApplyFailureRetriesApplyWithoutRepeatingEvolutionPreparation.
It's the most expensive of the three, but it's the only one that covers the
cluster case: one node has applied the upgraded flow and the other failed. It
shows that the retry applies the flow only where needed, doesn't rerun
preparation, and both nodes end up on the new flow.
--
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]