use of org.apache.nifi.remote.protocol.Response in project nifi by apache.
the class TestSocketFlowFileServerProtocol method testSendPeerListCluster.
@Test
public void testSendPeerListCluster() throws Exception {
final SocketFlowFileServerProtocol protocol = getDefaultSocketFlowFileServerProtocol();
final List<NodeInformation> nodeInfoList = new ArrayList<>();
final ClusterNodeInformation clusterNodeInformation = new ClusterNodeInformation();
clusterNodeInformation.setNodeInformation(nodeInfoList);
final Optional<ClusterNodeInformation> clusterNodeInfo = Optional.of(clusterNodeInformation);
for (int i = 0; i < 3; i++) {
final String siteToSiteHostname = String.format("node%d.example.com", i);
final Integer siteToSitePort = 8081;
final Integer siteToSiteHttpPort = null;
final int apiPort = 8080;
final boolean isSiteToSiteSecure = true;
final int numOfQueuedFlowFiles = 100 + i;
final NodeInformation nodeInformation = new NodeInformation(siteToSiteHostname, siteToSitePort, siteToSiteHttpPort, apiPort, isSiteToSiteSecure, numOfQueuedFlowFiles);
nodeInfoList.add(nodeInformation);
}
final NodeInformation self = nodeInfoList.get(0);
final HandshakeProperties handshakeProperties = new HandshakeProperties();
handshakeProperties.setCommsIdentifier("communication-identifier");
handshakeProperties.setTransitUriPrefix("uri-prefix");
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final Peer peer = getDefaultPeer(handshakeProperties, outputStream);
protocol.handshake(peer);
protocol.sendPeerList(peer, clusterNodeInfo, self);
try (final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(outputStream.toByteArray()))) {
final Response handshakeResponse = Response.read(dis);
assertEquals(ResponseCode.PROPERTIES_OK, handshakeResponse.getCode());
final int numPeers = dis.readInt();
assertEquals(nodeInfoList.size(), numPeers);
for (int i = 0; i < nodeInfoList.size(); i++) {
final NodeInformation node = nodeInfoList.get(i);
assertEquals(node.getSiteToSiteHostname(), dis.readUTF());
assertEquals(node.getSiteToSitePort().intValue(), dis.readInt());
assertEquals(node.isSiteToSiteSecure(), dis.readBoolean());
assertEquals(node.getTotalFlowFiles(), dis.readInt());
}
}
}
use of org.apache.nifi.remote.protocol.Response in project nifi by apache.
the class TestSocketFlowFileServerProtocol method testSendPeerListStandalone.
@Test
public void testSendPeerListStandalone() throws Exception {
final SocketFlowFileServerProtocol protocol = getDefaultSocketFlowFileServerProtocol();
final Optional<ClusterNodeInformation> clusterNodeInfo = Optional.empty();
final String siteToSiteHostname = "node1.example.com";
final Integer siteToSitePort = 8081;
final Integer siteToSiteHttpPort = null;
final int apiPort = 8080;
final boolean isSiteToSiteSecure = true;
final int numOfQueuedFlowFiles = 100;
final NodeInformation self = new NodeInformation(siteToSiteHostname, siteToSitePort, siteToSiteHttpPort, apiPort, isSiteToSiteSecure, numOfQueuedFlowFiles);
final HandshakeProperties handshakeProperties = new HandshakeProperties();
handshakeProperties.setCommsIdentifier("communication-identifier");
handshakeProperties.setTransitUriPrefix("uri-prefix");
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final Peer peer = getDefaultPeer(handshakeProperties, outputStream);
protocol.handshake(peer);
protocol.sendPeerList(peer, clusterNodeInfo, self);
try (final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(outputStream.toByteArray()))) {
final Response handshakeResponse = Response.read(dis);
assertEquals(ResponseCode.PROPERTIES_OK, handshakeResponse.getCode());
final int numPeers = dis.readInt();
assertEquals(1, numPeers);
assertEquals(siteToSiteHostname, dis.readUTF());
assertEquals(siteToSitePort.intValue(), dis.readInt());
assertEquals(isSiteToSiteSecure, dis.readBoolean());
assertEquals(numOfQueuedFlowFiles, dis.readInt());
}
}
use of org.apache.nifi.remote.protocol.Response in project nifi by apache.
the class TestSocketClientTransaction method testReceiveOneFlowFile.
@Test
public void testReceiveOneFlowFile() throws IOException {
ByteArrayOutputStream serverResponseBos = new ByteArrayOutputStream();
DataOutputStream serverResponse = new DataOutputStream(serverResponseBos);
ResponseCode.MORE_DATA.writeResponse(serverResponse);
codec.encode(createDataPacket("contents on server 1"), serverResponse);
ResponseCode.FINISH_TRANSACTION.writeResponse(serverResponse);
ResponseCode.CONFIRM_TRANSACTION.writeResponse(serverResponse, "Checksum has been verified at server.");
ByteArrayInputStream bis = new ByteArrayInputStream(serverResponseBos.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
SocketClientTransaction transaction = getClientTransaction(bis, bos, TransferDirection.RECEIVE);
execReceiveOneFlowFile(transaction);
// Verify what client has sent.
DataInputStream sentByClient = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
assertEquals(RequestType.RECEIVE_FLOWFILES, RequestType.readRequestType(sentByClient));
Response confirmResponse = Response.read(sentByClient);
assertEquals(ResponseCode.CONFIRM_TRANSACTION, confirmResponse.getCode());
assertEquals("Checksum should be calculated at client", "3680976076", confirmResponse.getMessage());
Response completeResponse = Response.read(sentByClient);
assertEquals(ResponseCode.TRANSACTION_FINISHED, completeResponse.getCode());
assertEquals(-1, sentByClient.read());
}
use of org.apache.nifi.remote.protocol.Response in project nifi by apache.
the class TestSocketClientTransaction method testSendWithInvalidChecksum.
@Test
public void testSendWithInvalidChecksum() throws IOException {
ByteArrayOutputStream serverResponseBos = new ByteArrayOutputStream();
DataOutputStream serverResponse = new DataOutputStream(serverResponseBos);
ResponseCode.CONFIRM_TRANSACTION.writeResponse(serverResponse, "Different checksum");
ByteArrayInputStream bis = new ByteArrayInputStream(serverResponseBos.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
SocketClientTransaction transaction = getClientTransaction(bis, bos, TransferDirection.SEND);
execSendWithInvalidChecksum(transaction);
// Verify what client has sent.
DataInputStream sentByClient = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
assertEquals(RequestType.SEND_FLOWFILES, RequestType.readRequestType(sentByClient));
DataPacket packetByClient = codec.decode(sentByClient);
assertEquals("contents on client 1", readContents(packetByClient));
Response continueDataResponse = Response.read(sentByClient);
assertEquals(ResponseCode.CONTINUE_TRANSACTION, continueDataResponse.getCode());
packetByClient = codec.decode(sentByClient);
assertEquals("contents on client 2", readContents(packetByClient));
Response endOfDataResponse = Response.read(sentByClient);
assertEquals(ResponseCode.FINISH_TRANSACTION, endOfDataResponse.getCode());
Response confirmResponse = Response.read(sentByClient);
assertEquals(ResponseCode.BAD_CHECKSUM, confirmResponse.getCode());
assertEquals(-1, sentByClient.read());
}
use of org.apache.nifi.remote.protocol.Response in project nifi by apache.
the class TestSocketClientTransaction method testReceiveWithInvalidChecksum.
@Test
public void testReceiveWithInvalidChecksum() throws IOException {
ByteArrayOutputStream serverResponseBos = new ByteArrayOutputStream();
DataOutputStream serverResponse = new DataOutputStream(serverResponseBos);
ResponseCode.MORE_DATA.writeResponse(serverResponse);
codec.encode(createDataPacket("contents on server 1"), serverResponse);
ResponseCode.CONTINUE_TRANSACTION.writeResponse(serverResponse);
codec.encode(createDataPacket("contents on server 2"), serverResponse);
ResponseCode.FINISH_TRANSACTION.writeResponse(serverResponse);
ResponseCode.BAD_CHECKSUM.writeResponse(serverResponse);
ByteArrayInputStream bis = new ByteArrayInputStream(serverResponseBos.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
SocketClientTransaction transaction = getClientTransaction(bis, bos, TransferDirection.RECEIVE);
execReceiveWithInvalidChecksum(transaction);
// Verify what client has sent.
DataInputStream sentByClient = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
assertEquals(RequestType.RECEIVE_FLOWFILES, RequestType.readRequestType(sentByClient));
Response confirmResponse = Response.read(sentByClient);
assertEquals(ResponseCode.CONFIRM_TRANSACTION, confirmResponse.getCode());
assertEquals("Checksum should be calculated at client", "2969091230", confirmResponse.getMessage());
assertEquals(-1, sentByClient.read());
}
Aggregations