use of org.apache.nifi.cluster.manager.exception.DisconnectedNodeMutableRequestException in project nifi by apache.
the class TestThreadPoolRequestReplicator method testMutableRequestRequiresAllNodesConnected.
@Test
public void testMutableRequestRequiresAllNodesConnected() throws URISyntaxException {
final ClusterCoordinator coordinator = createClusterCoordinator();
// build a map of connection state to node ids
final Map<NodeConnectionState, List<NodeIdentifier>> nodeMap = new HashMap<>();
final List<NodeIdentifier> connectedNodes = new ArrayList<>();
connectedNodes.add(new NodeIdentifier("1", "localhost", 8100, "localhost", 8101, "localhost", 8102, 8103, false));
connectedNodes.add(new NodeIdentifier("2", "localhost", 8200, "localhost", 8201, "localhost", 8202, 8203, false));
nodeMap.put(NodeConnectionState.CONNECTED, connectedNodes);
final List<NodeIdentifier> otherState = new ArrayList<>();
otherState.add(new NodeIdentifier("3", "localhost", 8300, "localhost", 8301, "localhost", 8302, 8303, false));
nodeMap.put(NodeConnectionState.CONNECTING, otherState);
when(coordinator.getConnectionStates()).thenReturn(nodeMap);
final NiFiProperties props = NiFiProperties.createBasicNiFiProperties(null, null);
final ThreadPoolRequestReplicator replicator = new ThreadPoolRequestReplicator(2, 5, 100, ClientBuilder.newClient(), coordinator, "1 sec", "1 sec", null, null, props) {
@Override
public AsyncClusterResponse replicate(Set<NodeIdentifier> nodeIds, String method, URI uri, Object entity, Map<String, String> headers, boolean indicateReplicated, boolean verify) {
return null;
}
};
try {
// set the user
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(StandardNiFiUser.ANONYMOUS));
SecurityContextHolder.getContext().setAuthentication(authentication);
try {
replicator.replicate(HttpMethod.POST, new URI("http://localhost:80/processors/1"), new ProcessorEntity(), new HashMap<>());
Assert.fail("Expected ConnectingNodeMutableRequestException");
} catch (final ConnectingNodeMutableRequestException e) {
// expected behavior
}
nodeMap.remove(NodeConnectionState.CONNECTING);
nodeMap.put(NodeConnectionState.DISCONNECTED, otherState);
try {
replicator.replicate(HttpMethod.POST, new URI("http://localhost:80/processors/1"), new ProcessorEntity(), new HashMap<>());
Assert.fail("Expected DisconnectedNodeMutableRequestException");
} catch (final DisconnectedNodeMutableRequestException e) {
// expected behavior
}
nodeMap.remove(NodeConnectionState.DISCONNECTED);
nodeMap.put(NodeConnectionState.DISCONNECTING, otherState);
try {
replicator.replicate(HttpMethod.POST, new URI("http://localhost:80/processors/1"), new ProcessorEntity(), new HashMap<>());
Assert.fail("Expected DisconnectedNodeMutableRequestException");
} catch (final DisconnectedNodeMutableRequestException e) {
// expected behavior
}
// should not throw an Exception because it's a GET
replicator.replicate(HttpMethod.GET, new URI("http://localhost:80/processors/1"), new MultiValueMap<>(), new HashMap<>());
// should not throw an Exception because all nodes are now connected
nodeMap.remove(NodeConnectionState.DISCONNECTING);
replicator.replicate(HttpMethod.POST, new URI("http://localhost:80/processors/1"), new ProcessorEntity(), new HashMap<>());
} finally {
replicator.shutdown();
}
}
Aggregations