Search in sources :

Example 6 with NodeInformation

use of org.apache.nifi.remote.cluster.NodeInformation 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());
    }
}
Also used : NodeInformation(org.apache.nifi.remote.cluster.NodeInformation) ClusterNodeInformation(org.apache.nifi.remote.cluster.ClusterNodeInformation) Peer(org.apache.nifi.remote.Peer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Response(org.apache.nifi.remote.protocol.Response) ClusterNodeInformation(org.apache.nifi.remote.cluster.ClusterNodeInformation) ByteArrayInputStream(java.io.ByteArrayInputStream) HandshakeProperties(org.apache.nifi.remote.protocol.HandshakeProperties) Test(org.junit.Test)

Aggregations

NodeInformation (org.apache.nifi.remote.cluster.NodeInformation)6 ClusterNodeInformation (org.apache.nifi.remote.cluster.ClusterNodeInformation)5 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInputStream (java.io.DataInputStream)2 Peer (org.apache.nifi.remote.Peer)2 HandshakeProperties (org.apache.nifi.remote.protocol.HandshakeProperties)2 Response (org.apache.nifi.remote.protocol.Response)2 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 CommunicationsSession (org.apache.nifi.remote.protocol.CommunicationsSession)1 ServerProtocol (org.apache.nifi.remote.protocol.ServerProtocol)1 NiFiProperties (org.apache.nifi.util.NiFiProperties)1