use of org.apache.nifi.cluster.protocol.DataFlow in project nifi by apache.
the class TestFlowController method testSynchronizeFlowWhenCurrentAuthorizationsAreEmptyAndProposedAreNot.
@Test
public void testSynchronizeFlowWhenCurrentAuthorizationsAreEmptyAndProposedAreNot() {
final FlowSynchronizer standardFlowSynchronizer = new StandardFlowSynchronizer(StringEncryptor.createEncryptor(nifiProperties), nifiProperties);
// create a mock proposed data flow with the same auth fingerprint as the current authorizer
final String authFingerprint = authorizer.getFingerprint();
final DataFlow proposedDataFlow = Mockito.mock(DataFlow.class);
when(proposedDataFlow.getAuthorizerFingerprint()).thenReturn(authFingerprint.getBytes(StandardCharsets.UTF_8));
authorizer = new MockPolicyBasedAuthorizer();
assertNotEquals(authFingerprint, authorizer.getFingerprint());
controller.shutdown(true);
controller = FlowController.createStandaloneInstance(flowFileEventRepo, nifiProperties, authorizer, auditService, encryptor, bulletinRepo, variableRegistry, Mockito.mock(FlowRegistryClient.class));
controller.synchronize(standardFlowSynchronizer, proposedDataFlow);
assertEquals(authFingerprint, authorizer.getFingerprint());
}
use of org.apache.nifi.cluster.protocol.DataFlow in project nifi by apache.
the class TestFlowController method testSynchronizeFlowWhenProposedMissingComponentsAreDifferent.
@Test
public void testSynchronizeFlowWhenProposedMissingComponentsAreDifferent() {
final FlowSynchronizer standardFlowSynchronizer = new StandardFlowSynchronizer(StringEncryptor.createEncryptor(nifiProperties), nifiProperties);
final Set<String> missingComponents = new HashSet<>();
missingComponents.add("1");
missingComponents.add("2");
final DataFlow proposedDataFlow = Mockito.mock(DataFlow.class);
when(proposedDataFlow.getMissingComponents()).thenReturn(missingComponents);
try {
controller.synchronize(standardFlowSynchronizer, proposedDataFlow);
Assert.fail("Should have thrown exception");
} catch (UninheritableFlowException e) {
assertTrue(e.getMessage().contains("Proposed flow has missing components that are not considered missing in the current flow (1,2)"));
}
}
use of org.apache.nifi.cluster.protocol.DataFlow in project nifi by apache.
the class TestFlowController method testSynchronizeFlowWhenAuthorizationsAreEqual.
@Test
public void testSynchronizeFlowWhenAuthorizationsAreEqual() {
final FlowSynchronizer standardFlowSynchronizer = new StandardFlowSynchronizer(StringEncryptor.createEncryptor(nifiProperties), nifiProperties);
// create a mock proposed data flow with the same auth fingerprint as the current authorizer
final String authFingerprint = authorizer.getFingerprint();
final DataFlow proposedDataFlow = Mockito.mock(DataFlow.class);
when(proposedDataFlow.getAuthorizerFingerprint()).thenReturn(authFingerprint.getBytes(StandardCharsets.UTF_8));
controller.synchronize(standardFlowSynchronizer, proposedDataFlow);
assertEquals(authFingerprint, authorizer.getFingerprint());
}
use of org.apache.nifi.cluster.protocol.DataFlow in project nifi by apache.
the class TestPopularVoteFlowElection method testAutoGeneratedVsPopulatedFlowElection.
@Test
public void testAutoGeneratedVsPopulatedFlowElection() throws IOException {
final FingerprintFactory fingerprintFactory = new FingerprintFactory(StringEncryptor.createEncryptor(getNiFiProperties()));
final PopularVoteFlowElection election = new PopularVoteFlowElection(1, TimeUnit.MINUTES, 4, fingerprintFactory);
final byte[] emptyFlow = Files.readAllBytes(Paths.get("src/test/resources/conf/auto-generated-empty-flow.xml"));
final byte[] nonEmptyFlow = Files.readAllBytes(Paths.get("src/test/resources/conf/reporting-task-flow.xml"));
for (int i = 0; i < 4; i++) {
assertFalse(election.isElectionComplete());
assertNull(election.getElectedDataFlow());
final DataFlow dataFlow;
if (i % 2 == 0) {
dataFlow = createDataFlow(emptyFlow);
} else {
dataFlow = createDataFlow(nonEmptyFlow);
}
final DataFlow electedDataFlow = election.castVote(dataFlow, createNodeId(i));
if (i == 3) {
assertNotNull(electedDataFlow);
assertEquals(new String(nonEmptyFlow), new String(electedDataFlow.getFlow()));
} else {
assertNull(electedDataFlow);
}
}
}
use of org.apache.nifi.cluster.protocol.DataFlow in project nifi by apache.
the class TestPopularVoteFlowElection method testDifferentPopulatedFlowsElection.
@Test
public void testDifferentPopulatedFlowsElection() throws IOException {
final FingerprintFactory fingerprintFactory = new FingerprintFactory(StringEncryptor.createEncryptor(getNiFiProperties()));
final PopularVoteFlowElection election = new PopularVoteFlowElection(1, TimeUnit.MINUTES, 4, fingerprintFactory);
final byte[] nonEmptyCandidateA = Files.readAllBytes(Paths.get("src/test/resources/conf/controller-service-flow.xml"));
final byte[] nonEmptyCandidateB = Files.readAllBytes(Paths.get("src/test/resources/conf/reporting-task-flow.xml"));
for (int i = 0; i < 4; i++) {
assertFalse(election.isElectionComplete());
assertNull(election.getElectedDataFlow());
final DataFlow dataFlow;
if (i % 2 == 0) {
dataFlow = createDataFlow(nonEmptyCandidateA);
} else {
dataFlow = createDataFlow(nonEmptyCandidateB);
}
final DataFlow electedDataFlow = election.castVote(dataFlow, createNodeId(i));
if (i == 3) {
assertNotNull(electedDataFlow);
assertEquals(new String(nonEmptyCandidateA), new String(electedDataFlow.getFlow()));
} else {
assertNull(electedDataFlow);
}
}
}
Aggregations