Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public NiFiInstanceFactory getInstanceFactory() {
return createTwoNodeInstanceFactory();
}

@Override
protected boolean isAllowFactoryReuse() {
return false;
}

@Override
protected boolean isDestroyEnvironmentAfterEachTest() {
// This test intentionally corrupts the persisted flow, so the environment must not be reused.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static org.junit.jupiter.api.Assertions.assertEquals;

public abstract class AbstractStateKeyDropIT extends NiFiSystemIT {

private static final Logger logger = LoggerFactory.getLogger(AbstractStateKeyDropIT.class);
Expand Down Expand Up @@ -82,6 +84,22 @@ protected Map<String, String> getProcessorState(final String processorId, final
}
}

protected void waitForProcessorState(final String processorId, final Scope scope, final Map<String, String> expectedState)
throws NiFiClientException, IOException, InterruptedException {
final long maxTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(RETRY_TIMEOUT_SECONDS);
Map<String, String> currentState;

do {
currentState = getProcessorState(processorId, scope);
if (expectedState.equals(currentState)) {
return;
}
Thread.sleep(RETRY_DELAY_MILLIS);
} while (System.currentTimeMillis() <= maxTime);

assertEquals(expectedState, currentState);
}

/**
* Drops the state for a given processor, optionally setting a new state.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public void testCannotDropStateKeyIfFlagNotTrue() throws NiFiClientException, IO

runProcessorOnce(processor);

final Map<String, String> currentState = getProcessorState(processorId, Scope.CLUSTER);
assertEquals(Map.of("a", "1", "b", "1", "c", "1"), currentState);
waitForProcessorState(processorId, Scope.CLUSTER, Map.of("a", "1", "b", "1", "c", "1"));

// trying to remove key a
final Map<String, String> newState = Map.of("b", "1", "c", "1");
Expand All @@ -90,8 +89,7 @@ public void testCannotDropStateKeyWithMismatchedState() throws NiFiClientExcepti

runProcessorOnce(processor);

final Map<String, String> currentState = getProcessorState(processorId, Scope.CLUSTER);
assertEquals(Map.of("a", "1", "b", "1", "c", "1"), currentState);
waitForProcessorState(processorId, Scope.CLUSTER, Map.of("a", "1", "b", "1", "c", "1"));

// trying to remove key "a" but with wrong value for "b"
assertThrows(NiFiClientException.class, () -> {
Expand All @@ -105,8 +103,7 @@ public void testCannotDropMultipleStateKeys() throws NiFiClientException, IOExce
final String processorId = processor.getId();
runProcessorOnce(processor);

final Map<String, String> currentState = getProcessorState(processorId, Scope.CLUSTER);
assertEquals(Map.of("a", "1", "b", "1", "c", "1"), currentState);
waitForProcessorState(processorId, Scope.CLUSTER, Map.of("a", "1", "b", "1", "c", "1"));

// trying to remove two keys
assertThrows(NiFiClientException.class, () -> {
Expand All @@ -120,8 +117,7 @@ public void testCanDropSpecificStateKey() throws NiFiClientException, IOExceptio
final String processorId = processor.getId();
runProcessorOnce(processor);

final Map<String, String> currentState = getProcessorState(processorId, Scope.CLUSTER);
assertEquals(Map.of("a", "1", "b", "1", "c", "1"), currentState);
waitForProcessorState(processorId, Scope.CLUSTER, Map.of("a", "1", "b", "1", "c", "1"));

// trying to remove key a
final Map<String, String> newState = Map.of("b", "1", "c", "1");
Expand All @@ -131,8 +127,7 @@ public void testCanDropSpecificStateKey() throws NiFiClientException, IOExceptio
response.getComponentState().getClusterState().getState().forEach(entry -> updatedState.put(entry.getKey(), entry.getValue()));
assertEquals(newState, updatedState);

final Map<String, String> state = getProcessorState(processorId, Scope.CLUSTER);
assertEquals(newState, state);
waitForProcessorState(processorId, Scope.CLUSTER, newState);
}

@Test
Expand All @@ -141,14 +136,12 @@ public void testClearAllStateWithNullPayload() throws NiFiClientException, IOExc
final String processorId = processor.getId();
runProcessorOnce(processor);

final Map<String, String> currentState = getProcessorState(processorId, Scope.CLUSTER);
assertEquals(Map.of("a", "1", "b", "1", "c", "1"), currentState);
waitForProcessorState(processorId, Scope.CLUSTER, Map.of("a", "1", "b", "1", "c", "1"));

final ComponentStateEntity response = dropProcessorState(processorId, null);
assertTrue(response.getComponentState().getClusterState().getState().isEmpty());

final Map<String, String> state = getProcessorState(processorId, Scope.CLUSTER);
assertTrue(state.isEmpty());
waitForProcessorState(processorId, Scope.CLUSTER, Map.of());
}

@Test
Expand All @@ -157,13 +150,11 @@ public void testClearAllStateWithEmptyPayload() throws NiFiClientException, IOEx
final String processorId = processor.getId();
runProcessorOnce(processor);

final Map<String, String> currentState = getProcessorState(processorId, Scope.CLUSTER);
assertEquals(Map.of("a", "1", "b", "1", "c", "1"), currentState);
waitForProcessorState(processorId, Scope.CLUSTER, Map.of("a", "1", "b", "1", "c", "1"));

final ComponentStateEntity response = dropProcessorState(processorId, Map.of());
assertTrue(response.getComponentState().getClusterState().getState().isEmpty());

final Map<String, String> state = getProcessorState(processorId, Scope.CLUSTER);
assertTrue(state.isEmpty());
waitForProcessorState(processorId, Scope.CLUSTER, Map.of());
}
}
Loading