use of org.apache.nifi.remote.codec.FlowFileCodec in project nifi by apache.
the class TestHttpFlowFileServerProtocol method receiveFlowFiles.
private void receiveFlowFiles(final HttpFlowFileServerProtocol serverProtocol, final String transactionId, final Peer peer, final DataPacket... dataPackets) throws IOException {
final HttpRemoteSiteListener remoteSiteListener = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
final HttpServerCommunicationsSession commsSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
serverProtocol.handshake(peer);
assertTrue(serverProtocol.isHandshakeSuccessful());
setupMockProcessSession();
// Emulate dataPackets sent from a Site-to-Site client.
final FlowFileCodec negotiatedCoded = serverProtocol.negotiateCodec(peer);
final ByteArrayOutputStream testDataOs = new ByteArrayOutputStream();
for (final DataPacket dataPacket : dataPackets) {
negotiatedCoded.encode(dataPacket, testDataOs);
}
final InputStream httpInputStream = new ByteArrayInputStream(testDataOs.toByteArray());
((HttpInput) commsSession.getInput()).setInputStream(httpInputStream);
// Execute test using mock
final int flowFileReceived = serverProtocol.receiveFlowFiles(peer, processContext, processSession, negotiatedCoded);
assertEquals(dataPackets.length, flowFileReceived);
assertTrue(remoteSiteListener.isTransactionActive(transactionId));
}
use of org.apache.nifi.remote.codec.FlowFileCodec in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testReceiveZeroFile.
@Test
public void testReceiveZeroFile() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final Peer peer = getDefaultPeer("testReceiveZeroFile");
final HttpServerCommunicationsSession commsSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
commsSession.setUserDn("unit-test");
serverProtocol.handshake(peer);
assertTrue(serverProtocol.isHandshakeSuccessful());
final FlowFileCodec negotiatedCoded = serverProtocol.negotiateCodec(peer);
final ProcessContext context = null;
final ProcessSession processSession = mock(ProcessSession.class);
final InputStream httpInputStream = new ByteArrayInputStream(new byte[] {});
((HttpInput) commsSession.getInput()).setInputStream(httpInputStream);
// Execute test using mock
final int flowFileReceived = serverProtocol.receiveFlowFiles(peer, context, processSession, negotiatedCoded);
assertEquals(0, flowFileReceived);
}
use of org.apache.nifi.remote.codec.FlowFileCodec in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testShutdown.
@Test
public void testShutdown() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final Peer peer = getDefaultPeer();
serverProtocol.handshake(peer);
assertTrue(serverProtocol.isHandshakeSuccessful());
final FlowFileCodec negotiatedCoded = serverProtocol.negotiateCodec(peer);
assertTrue(negotiatedCoded instanceof StandardFlowFileCodec);
assertEquals(negotiatedCoded, serverProtocol.getPreNegotiatedCodec());
assertEquals(1234, serverProtocol.getRequestExpiration());
serverProtocol.shutdown(peer);
final ProcessContext context = null;
final ProcessSession processSession = null;
try {
serverProtocol.transferFlowFiles(peer, context, processSession, negotiatedCoded);
fail("transferFlowFiles should fail since it's already shutdown.");
} catch (final IllegalStateException e) {
}
try {
serverProtocol.receiveFlowFiles(peer, context, processSession, negotiatedCoded);
fail("receiveFlowFiles should fail since it's already shutdown.");
} catch (final IllegalStateException e) {
}
}
use of org.apache.nifi.remote.codec.FlowFileCodec in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testTransferZeroFile.
@Test
public void testTransferZeroFile() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final Peer peer = getDefaultPeer();
serverProtocol.handshake(peer);
assertTrue(serverProtocol.isHandshakeSuccessful());
final FlowFileCodec negotiatedCoded = serverProtocol.negotiateCodec(peer);
final ProcessContext context = null;
final ProcessSession processSession = mock(ProcessSession.class);
// Execute test using mock
final int flowFileSent = serverProtocol.transferFlowFiles(peer, context, processSession, negotiatedCoded);
assertEquals(0, flowFileSent);
}
use of org.apache.nifi.remote.codec.FlowFileCodec in project nifi by apache.
the class RemoteResourceManager method createCodec.
public static FlowFileCodec createCodec(final String codecName, final int version) {
final FlowFileCodec codec = createCodec(codecName);
final VersionNegotiator negotiator = codec.getVersionNegotiator();
if (!negotiator.isVersionSupported(version)) {
throw new IllegalArgumentException("FlowFile Codec " + codecName + " does not support version " + version);
}
negotiator.setVersion(version);
return codec;
}
Aggregations