use of org.apache.nifi.remote.io.http.HttpServerCommunicationsSession in project nifi by apache.
the class TestHttpFlowFileServerProtocol method getDefaultPeer.
private Peer getDefaultPeer(final String transactionId) {
final PeerDescription description = new PeerDescription("peer-host", 8080, false);
final InputStream inputStream = new ByteArrayInputStream(new byte[] {});
final OutputStream outputStream = new ByteArrayOutputStream();
final HttpServerCommunicationsSession commsSession = new HttpServerCommunicationsSession(inputStream, outputStream, transactionId, "user");
commsSession.putHandshakeParam(HandshakeProperty.GZIP, "false");
commsSession.putHandshakeParam(HandshakeProperty.REQUEST_EXPIRATION_MILLIS, "1234");
final String peerUrl = "http://peer-host:8080/";
final String clusterUrl = "cluster-url";
return new Peer(description, commsSession, peerUrl, clusterUrl);
}
use of org.apache.nifi.remote.io.http.HttpServerCommunicationsSession in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testTransferOneFile.
@Test
public void testTransferOneFile() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final String transactionId = "testTransferOneFile";
final Peer peer = getDefaultPeer(transactionId);
final HttpServerCommunicationsSession commsSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
final String endpointUri = "https://remote-host:8443/nifi-api/output-ports/port-id/transactions/" + transactionId + "/flow-files";
commsSession.putHandshakeParam(HandshakeProperty.BATCH_COUNT, "1");
commsSession.setUserDn("unit-test");
commsSession.setDataTransferUrl(endpointUri);
transferFlowFiles(serverProtocol, transactionId, peer, processSession -> {
final MockFlowFile flowFile = processSession.createFlowFile("Server content".getBytes());
final HashMap<String, String> attributes = new HashMap<>();
attributes.put("uuid", "server-uuid");
attributes.put("filename", "server-filename");
attributes.put("server-attr-1", "server-attr-1-value");
attributes.put("server-attr-2", "server-attr-2-value");
flowFile.putAttributes(attributes);
return Arrays.asList(flowFile);
});
// Commit transaction
final int flowFileSent = serverProtocol.commitTransferTransaction(peer, "3229577812");
assertEquals(1, flowFileSent);
// Assert provenance
final List<ProvenanceEventRecord> provenanceEvents = sessionState.getProvenanceEvents();
assertEquals(1, provenanceEvents.size());
final ProvenanceEventRecord provenanceEvent = provenanceEvents.get(0);
assertEquals(ProvenanceEventType.SEND, provenanceEvent.getEventType());
assertEquals(endpointUri, provenanceEvent.getTransitUri());
assertEquals("Remote Host=peer-host, Remote DN=unit-test", provenanceEvent.getDetails());
}
use of org.apache.nifi.remote.io.http.HttpServerCommunicationsSession in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testReceiveOneFile.
@Test
public void testReceiveOneFile() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final String transactionId = "testReceiveOneFile";
final String endpointUri = "https://remote-host:8443/nifi-api/input-ports/port-id/transactions/" + transactionId + "/flow-files";
final Peer peer = getDefaultPeer(transactionId);
final HttpServerCommunicationsSession commsSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
commsSession.putHandshakeParam(HandshakeProperty.BATCH_COUNT, "1");
commsSession.setUserDn("unit-test");
commsSession.setDataTransferUrl(endpointUri);
final DataPacket dataPacket = createClientDataPacket();
receiveFlowFiles(serverProtocol, transactionId, peer, dataPacket);
// Commit transaction
commsSession.setResponseCode(ResponseCode.CONFIRM_TRANSACTION);
final int flowFileReceived = serverProtocol.commitReceiveTransaction(peer);
assertEquals(1, flowFileReceived);
// Assert provenance.
final List<ProvenanceEventRecord> provenanceEvents = sessionState.getProvenanceEvents();
assertEquals(1, provenanceEvents.size());
final ProvenanceEventRecord provenanceEvent = provenanceEvents.get(0);
assertEquals(ProvenanceEventType.RECEIVE, provenanceEvent.getEventType());
assertEquals(endpointUri, provenanceEvent.getTransitUri());
assertEquals("Remote Host=peer-host, Remote DN=unit-test", provenanceEvent.getDetails());
// Assert received flow files.
processSession.assertAllFlowFilesTransferred(Relationship.ANONYMOUS);
final List<MockFlowFile> flowFiles = processSession.getFlowFilesForRelationship(Relationship.ANONYMOUS);
assertEquals(1, flowFiles.size());
final MockFlowFile flowFile = flowFiles.get(0);
flowFile.assertAttributeEquals(SiteToSiteAttributes.S2S_HOST.key(), peer.getHost());
flowFile.assertAttributeEquals(SiteToSiteAttributes.S2S_ADDRESS.key(), peer.getHost() + ":" + peer.getPort());
flowFile.assertAttributeEquals("client-attr-1", "client-attr-1-value");
flowFile.assertAttributeEquals("client-attr-2", "client-attr-2-value");
}
use of org.apache.nifi.remote.io.http.HttpServerCommunicationsSession in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testReceiveOneFileBadChecksum.
@Test
public void testReceiveOneFileBadChecksum() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final String transactionId = "testReceiveOneFileBadChecksum";
final Peer peer = getDefaultPeer(transactionId);
final HttpServerCommunicationsSession commsSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
receiveFlowFiles(serverProtocol, transactionId, peer, createClientDataPacket());
// Commit transaction
commsSession.setResponseCode(ResponseCode.BAD_CHECKSUM);
try {
serverProtocol.commitReceiveTransaction(peer);
fail();
} catch (final IOException e) {
assertTrue(e.getMessage().contains("Received a BadChecksum response"));
}
}
use of org.apache.nifi.remote.io.http.HttpServerCommunicationsSession in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testUnknownPort.
@Test
public void testUnknownPort() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final Peer peer = getDefaultPeer();
((HttpServerCommunicationsSession) peer.getCommunicationsSession()).putHandshakeParam(HandshakeProperty.PORT_IDENTIFIER, "port-identifier");
final ProcessGroup processGroup = mock(ProcessGroup.class);
doReturn(true).when(processGroup).isRootGroup();
serverProtocol.setRootProcessGroup(processGroup);
try {
serverProtocol.handshake(peer);
fail();
} catch (final HandshakeException e) {
assertEquals(ResponseCode.UNKNOWN_PORT, e.getResponseCode());
}
assertFalse(serverProtocol.isHandshakeSuccessful());
}
Aggregations