bobpaulin commented on code in PR #11872:
URL: https://github.com/apache/nifi/pull/11872#discussion_r4556201249
##########
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 {
+ final FlowEvolutionHookConnector localConnector = new
FlowEvolutionHookConnector();
+ final StandardConnectorNode localFailure =
pendingEvolutionNode("local-failure", localConnector);
+ final StandardConnectorRepository localRepository =
createRepositoryWithShortTimeout(null);
+ final AtomicInteger localSaveCalls = new AtomicInteger();
+ final ConnectorUpdateContext persistenceContext = () -> {
+ if (localSaveCalls.getAndIncrement() == 0) {
+ throw new IllegalStateException("Expected persistence
failure");
+ }
+ };
+ final Future<Void> localEvolution =
localRepository.startConnector(localFailure, persistenceContext);
+ assertThrows(ExecutionException.class, () -> localEvolution.get(5,
TimeUnit.SECONDS));
+ assertEquals(ConnectorState.STOPPED, localFailure.getCurrentState());
+ assertEquals(1, localConnector.hookCalls);
+ assertTrue(localFailure.isFlowEvolutionPhaseOneComplete());
+ assertEquals(FlowEvolutionStatus.FAILED,
localFailure.getFlowEvolutionStatus());
+
+ localRepository.startConnector(localFailure,
persistenceContext).get(5, TimeUnit.SECONDS);
+ assertEquals(1, localConnector.hookCalls);
+ assertEquals(2, localConnector.applyCalls);
+ assertEquals(ConnectorState.RUNNING, localFailure.getCurrentState());
+ assertFalse(localFailure.isFlowEvolutionPhaseOneComplete());
+ assertEquals(FlowEvolutionStatus.INACTIVE,
localFailure.getFlowEvolutionStatus());
+ }
+
+ @Test
+ public void testHookFailureRerunsHookOnRetry() throws Exception {
+ final FlowEvolutionHookConnector connector = new
FlowEvolutionHookConnector();
+ connector.failHook = true;
+ final StandardConnectorNode connectorNode =
pendingEvolutionNode("hook-failure", connector);
+ final StandardConnectorRepository repository =
createRepositoryWithShortTimeout(null);
+
+ final Future<Void> failedEvolution =
repository.startConnector(connectorNode, NO_OP_PERSISTENCE);
+ assertThrows(ExecutionException.class, () -> failedEvolution.get(5,
TimeUnit.SECONDS));
+ assertEquals(FlowEvolutionStatus.FAILED,
connectorNode.getFlowEvolutionStatus());
+ assertFalse(connectorNode.isFlowEvolutionPhaseOneComplete());
+ assertEquals(1, connector.hookCalls);
+ assertEquals(0, connector.applyCalls);
+
+ connector.failHook = false;
+ repository.startConnector(connectorNode, NO_OP_PERSISTENCE).get(5,
TimeUnit.SECONDS);
+ assertEquals(2, connector.hookCalls);
+ assertEquals(1, connector.applyCalls);
+ }
+
+ @Test
+ public void testSuccessfulEvolutionRunsHookForLaterUpgrade() throws
Exception {
+ final FlowEvolutionHookConnector connector = new
FlowEvolutionHookConnector();
+ final StandardConnectorNode connectorNode =
pendingEvolutionNode("later-upgrade", connector);
+ final StandardConnectorRepository repository =
createRepositoryWithShortTimeout(null);
+
+ repository.startConnector(connectorNode, NO_OP_PERSISTENCE).get(5,
TimeUnit.SECONDS);
+ assertEquals(1, connector.hookCalls);
+ assertFalse(connectorNode.isFlowEvolutionPhaseOneComplete());
+ assertFalse(connectorNode.isPendingFlowEvolution());
+ assertEquals("1.0.0",
connectorNode.getAuthoritativeFlowSnapshot().bundle().getVersion());
+ repository.stopConnector(connectorNode).get(5, TimeUnit.SECONDS);
+
+
connectorNode.adoptAuthoritativeSnapshot(flowGroup("second-pre-upgrade"), null,
Map.of(), outgoingSnapshotBundle());
+ repository.startConnector(connectorNode, NO_OP_PERSISTENCE).get(5,
TimeUnit.SECONDS);
+
+ assertEquals(2, connector.hookCalls);
+ assertEquals(2, connector.applyCalls);
+ }
+
+ @Test
+ public void testFlowEvolutionTimeoutAbortsUpdate() throws Exception {
+ final ConnectorNode connector = mock(ConnectorNode.class);
+ when(connector.getIdentifier()).thenReturn("timeout-connector");
+ when(connector.isPendingFlowEvolution()).thenReturn(true);
+
when(connector.getFlowEvolutionStatus()).thenReturn(FlowEvolutionStatus.PHASE_ONE_PENDING);
+ when(connector.evolveFlow(any())).thenReturn(new
CompletableFuture<>());
+
+ final StandardConnectorRepository repository =
createRepositoryWithShortTimeout(null, Duration.ofMillis(200));
+ final Future<Void> evolution = repository.startConnector(connector,
NO_OP_PERSISTENCE);
+
+ final ExecutionException failure =
assertThrows(ExecutionException.class, () -> evolution.get(5,
TimeUnit.SECONDS));
+ assertInstanceOf(FlowUpdateException.class, failure.getCause());
+ assertTrue(failure.getCause().getMessage().contains("timed out"),
failure.getCause().getMessage());
+ verify(connector, times(2)).abortUpdate(any());
+ }
+
+ @Test
+ public void testEvolutionDrainTimeoutDoesNotBoundBarriersOrFinalStart()
throws Exception {
Review Comment:
[Claude Opus 5.5] Removed that test. The cross-node wait is covered by
`ClusteredConnectorChangeVersionDrainIT`. When the wait gets its time limit,
I'll add a test for the limit itself.
--
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]