Search in sources :

Example 1 with SocketChannelOutput

use of org.apache.nifi.remote.io.socket.SocketChannelOutput in project nifi by apache.

the class TestSocketFlowFileServerProtocol method getDefaultPeer.

private Peer getDefaultPeer(final HandshakeProperties handshakeProperties, final OutputStream outputStream) throws IOException {
    final PeerDescription description = new PeerDescription("peer-host", 8080, false);
    final byte[] inputBytes;
    try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final DataOutputStream dos = new DataOutputStream(bos)) {
        dos.writeUTF(handshakeProperties.getCommsIdentifier());
        dos.writeUTF(handshakeProperties.getTransitUriPrefix());
        // num of properties
        dos.writeInt(1);
        dos.writeUTF(HandshakeProperty.GZIP.name());
        dos.writeUTF(String.valueOf(handshakeProperties.isUseGzip()));
        dos.flush();
        inputBytes = bos.toByteArray();
    }
    final InputStream inputStream = new ByteArrayInputStream(inputBytes);
    final SocketChannelCommunicationsSession commsSession = mock(SocketChannelCommunicationsSession.class);
    final SocketChannelInput channelInput = mock(SocketChannelInput.class);
    final SocketChannelOutput channelOutput = mock(SocketChannelOutput.class);
    when(commsSession.getInput()).thenReturn(channelInput);
    when(commsSession.getOutput()).thenReturn(channelOutput);
    when(channelInput.getInputStream()).thenReturn(inputStream);
    when(channelOutput.getOutputStream()).thenReturn(outputStream);
    final String peerUrl = "http://peer-host:8080/";
    final String clusterUrl = "cluster-url";
    return new Peer(description, commsSession, peerUrl, clusterUrl);
}
Also used : PeerDescription(org.apache.nifi.remote.PeerDescription) SocketChannelInput(org.apache.nifi.remote.io.socket.SocketChannelInput) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Peer(org.apache.nifi.remote.Peer) SocketChannelOutput(org.apache.nifi.remote.io.socket.SocketChannelOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SocketChannelCommunicationsSession(org.apache.nifi.remote.io.socket.SocketChannelCommunicationsSession)

Example 2 with SocketChannelOutput

use of org.apache.nifi.remote.io.socket.SocketChannelOutput in project nifi by apache.

the class TestSocketClientTransaction method getClientTransaction.

private SocketClientTransaction getClientTransaction(ByteArrayInputStream bis, ByteArrayOutputStream bos, TransferDirection direction) throws IOException {
    PeerDescription description = null;
    String peerUrl = "";
    SocketChannelCommunicationsSession commsSession = mock(SocketChannelCommunicationsSession.class);
    SocketChannelInput socketIn = mock(SocketChannelInput.class);
    SocketChannelOutput socketOut = mock(SocketChannelOutput.class);
    when(commsSession.getInput()).thenReturn(socketIn);
    when(commsSession.getOutput()).thenReturn(socketOut);
    when(socketIn.getInputStream()).thenReturn(bis);
    when(socketOut.getOutputStream()).thenReturn(bos);
    String clusterUrl = "";
    Peer peer = new Peer(description, commsSession, peerUrl, clusterUrl);
    boolean useCompression = false;
    int penaltyMillis = 1000;
    EventReporter eventReporter = null;
    int protocolVersion = 5;
    String destinationId = "destinationId";
    return new SocketClientTransaction(protocolVersion, destinationId, peer, codec, direction, useCompression, penaltyMillis, eventReporter);
}
Also used : PeerDescription(org.apache.nifi.remote.PeerDescription) SocketChannelInput(org.apache.nifi.remote.io.socket.SocketChannelInput) Peer(org.apache.nifi.remote.Peer) SocketChannelOutput(org.apache.nifi.remote.io.socket.SocketChannelOutput) SocketChannelCommunicationsSession(org.apache.nifi.remote.io.socket.SocketChannelCommunicationsSession) EventReporter(org.apache.nifi.events.EventReporter)

Aggregations

Peer (org.apache.nifi.remote.Peer)2 PeerDescription (org.apache.nifi.remote.PeerDescription)2 SocketChannelCommunicationsSession (org.apache.nifi.remote.io.socket.SocketChannelCommunicationsSession)2 SocketChannelInput (org.apache.nifi.remote.io.socket.SocketChannelInput)2 SocketChannelOutput (org.apache.nifi.remote.io.socket.SocketChannelOutput)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 InputStream (java.io.InputStream)1 EventReporter (org.apache.nifi.events.EventReporter)1