Search in sources :

Example 6 with PeerDescription

use of org.apache.nifi.remote.PeerDescription in project nifi by apache.

the class TestPeerSelector method testFormulateDestinationListForOutputHugeDifference.

@Test
public void testFormulateDestinationListForOutputHugeDifference() throws IOException {
    final Set<PeerStatus> collection = new HashSet<>();
    collection.add(new PeerStatus(new PeerDescription("HasLittle", 1111, true), 500, true));
    collection.add(new PeerStatus(new PeerDescription("HasLots", 2222, true), 50000, true));
    PeerStatusProvider peerStatusProvider = Mockito.mock(PeerStatusProvider.class);
    PeerSelector peerSelector = new PeerSelector(peerStatusProvider, null);
    final List<PeerStatus> destinations = peerSelector.formulateDestinationList(collection, TransferDirection.RECEIVE);
    final Map<String, Integer> selectedCounts = calculateAverageSelectedCount(collection, destinations);
    logger.info("selectedCounts={}", selectedCounts);
    assertTrue("HasLots should send lots", selectedCounts.get("HasLots") > selectedCounts.get("HasLittle"));
}
Also used : PeerDescription(org.apache.nifi.remote.PeerDescription) PeerStatus(org.apache.nifi.remote.PeerStatus) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with PeerDescription

use of org.apache.nifi.remote.PeerDescription in project nifi by apache.

the class TestPeerSelector method testFormulateDestinationListForInputPortsHugeDifference.

@Test
public void testFormulateDestinationListForInputPortsHugeDifference() throws IOException {
    final Set<PeerStatus> collection = new HashSet<>();
    collection.add(new PeerStatus(new PeerDescription("HasLots", 1111, true), 500, true));
    collection.add(new PeerStatus(new PeerDescription("HasLittle", 2222, true), 50000, true));
    PeerStatusProvider peerStatusProvider = Mockito.mock(PeerStatusProvider.class);
    PeerSelector peerSelector = new PeerSelector(peerStatusProvider, null);
    final List<PeerStatus> destinations = peerSelector.formulateDestinationList(collection, TransferDirection.RECEIVE);
    final Map<String, Integer> selectedCounts = calculateAverageSelectedCount(collection, destinations);
    logger.info("selectedCounts={}", selectedCounts);
    assertTrue("HasLots should get little", selectedCounts.get("HasLots") < selectedCounts.get("HasLittle"));
}
Also used : PeerDescription(org.apache.nifi.remote.PeerDescription) PeerStatus(org.apache.nifi.remote.PeerStatus) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with PeerDescription

use of org.apache.nifi.remote.PeerDescription in project nifi by apache.

the class TestPeerSelector method testFormulateDestinationListForInputPorts.

@Test
public void testFormulateDestinationListForInputPorts() throws IOException {
    final Set<PeerStatus> collection = new HashSet<>();
    collection.add(new PeerStatus(new PeerDescription("HasMedium", 1111, true), 4096, true));
    collection.add(new PeerStatus(new PeerDescription("HasLittle", 2222, true), 10240, true));
    collection.add(new PeerStatus(new PeerDescription("HasLots", 3333, true), 1024, true));
    collection.add(new PeerStatus(new PeerDescription("HasMedium", 4444, true), 4096, true));
    collection.add(new PeerStatus(new PeerDescription("HasMedium", 5555, true), 4096, true));
    PeerStatusProvider peerStatusProvider = Mockito.mock(PeerStatusProvider.class);
    PeerSelector peerSelector = new PeerSelector(peerStatusProvider, null);
    final List<PeerStatus> destinations = peerSelector.formulateDestinationList(collection, TransferDirection.RECEIVE);
    final Map<String, Integer> selectedCounts = calculateAverageSelectedCount(collection, destinations);
    logger.info("selectedCounts={}", selectedCounts);
    assertTrue("HasLots should get little", selectedCounts.get("HasLots") < selectedCounts.get("HasMedium"));
    assertTrue("HasMedium should get medium", selectedCounts.get("HasMedium") < selectedCounts.get("HasLittle"));
}
Also used : PeerDescription(org.apache.nifi.remote.PeerDescription) PeerStatus(org.apache.nifi.remote.PeerStatus) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with PeerDescription

use of org.apache.nifi.remote.PeerDescription 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);
}
Also used : HttpServerCommunicationsSession(org.apache.nifi.remote.io.http.HttpServerCommunicationsSession) PeerDescription(org.apache.nifi.remote.PeerDescription) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Peer(org.apache.nifi.remote.Peer) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 10 with PeerDescription

use of org.apache.nifi.remote.PeerDescription 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)

Aggregations

PeerDescription (org.apache.nifi.remote.PeerDescription)18 PeerStatus (org.apache.nifi.remote.PeerStatus)13 HashSet (java.util.HashSet)10 Peer (org.apache.nifi.remote.Peer)9 IOException (java.io.IOException)6 Test (org.junit.Test)5 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 InputStream (java.io.InputStream)4 SocketChannelCommunicationsSession (org.apache.nifi.remote.io.socket.SocketChannelCommunicationsSession)4 CommunicationsSession (org.apache.nifi.remote.protocol.CommunicationsSession)4 OutputStream (java.io.OutputStream)3 URI (java.net.URI)3 Set (java.util.Set)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 EventReporter (org.apache.nifi.events.EventReporter)3 TransferDirection (org.apache.nifi.remote.TransferDirection)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3