Search in sources :

Example 1 with FlowFileCodec

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));
}
Also used : HttpServerCommunicationsSession(org.apache.nifi.remote.io.http.HttpServerCommunicationsSession) HttpInput(org.apache.nifi.remote.io.http.HttpInput) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpRemoteSiteListener(org.apache.nifi.remote.HttpRemoteSiteListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataPacket(org.apache.nifi.remote.protocol.DataPacket) StandardDataPacket(org.apache.nifi.remote.util.StandardDataPacket) FlowFileCodec(org.apache.nifi.remote.codec.FlowFileCodec) StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec)

Example 2 with FlowFileCodec

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);
}
Also used : MockProcessSession(org.apache.nifi.util.MockProcessSession) ProcessSession(org.apache.nifi.processor.ProcessSession) HttpServerCommunicationsSession(org.apache.nifi.remote.io.http.HttpServerCommunicationsSession) HttpInput(org.apache.nifi.remote.io.http.HttpInput) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Peer(org.apache.nifi.remote.Peer) FlowFileCodec(org.apache.nifi.remote.codec.FlowFileCodec) StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec) MockProcessContext(org.apache.nifi.util.MockProcessContext) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Example 3 with FlowFileCodec

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) {
    }
}
Also used : MockProcessSession(org.apache.nifi.util.MockProcessSession) ProcessSession(org.apache.nifi.processor.ProcessSession) Peer(org.apache.nifi.remote.Peer) StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec) FlowFileCodec(org.apache.nifi.remote.codec.FlowFileCodec) StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec) MockProcessContext(org.apache.nifi.util.MockProcessContext) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Example 4 with FlowFileCodec

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);
}
Also used : MockProcessSession(org.apache.nifi.util.MockProcessSession) ProcessSession(org.apache.nifi.processor.ProcessSession) Peer(org.apache.nifi.remote.Peer) FlowFileCodec(org.apache.nifi.remote.codec.FlowFileCodec) StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec) MockProcessContext(org.apache.nifi.util.MockProcessContext) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Example 5 with FlowFileCodec

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;
}
Also used : FlowFileCodec(org.apache.nifi.remote.codec.FlowFileCodec)

Aggregations

FlowFileCodec (org.apache.nifi.remote.codec.FlowFileCodec)10 StandardFlowFileCodec (org.apache.nifi.remote.codec.StandardFlowFileCodec)6 Peer (org.apache.nifi.remote.Peer)4 ProcessContext (org.apache.nifi.processor.ProcessContext)3 ProcessSession (org.apache.nifi.processor.ProcessSession)3 CommunicationsSession (org.apache.nifi.remote.protocol.CommunicationsSession)3 MockProcessContext (org.apache.nifi.util.MockProcessContext)3 MockProcessSession (org.apache.nifi.util.MockProcessSession)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HttpRemoteSiteListener (org.apache.nifi.remote.HttpRemoteSiteListener)2 HandshakeException (org.apache.nifi.remote.exception.HandshakeException)2 ProtocolException (org.apache.nifi.remote.exception.ProtocolException)2 TransmissionDisabledException (org.apache.nifi.remote.exception.TransmissionDisabledException)2 HttpInput (org.apache.nifi.remote.io.http.HttpInput)2 HttpServerCommunicationsSession (org.apache.nifi.remote.io.http.HttpServerCommunicationsSession)2