Search in sources :

Example 6 with DataPacket

use of org.apache.nifi.remote.protocol.DataPacket in project nifi by apache.

the class TestHttpClient method testSendSuccessCompressed.

@Test
public void testSendSuccessCompressed() throws Exception {
    try (SiteToSiteClient client = getDefaultBuilder().portName("input-running").useCompression(true).build()) {
        final Transaction transaction = client.createTransaction(TransferDirection.SEND);
        assertNotNull(transaction);
        serverChecksum = "1071206772";
        for (int i = 0; i < 20; i++) {
            DataPacket packet = new DataPacketBuilder().contents("Example contents from client.").attr("Client attr 1", "Client attr 1 value").attr("Client attr 2", "Client attr 2 value").build();
            transaction.send(packet);
            long written = ((Peer) transaction.getCommunicant()).getCommunicationsSession().getBytesWritten();
            logger.info("{}: {} bytes have been written.", i, written);
        }
        transaction.confirm();
        transaction.complete();
    }
}
Also used : SiteToSiteClient(org.apache.nifi.remote.client.SiteToSiteClient) Transaction(org.apache.nifi.remote.Transaction) DataPacket(org.apache.nifi.remote.protocol.DataPacket) StandardDataPacket(org.apache.nifi.remote.util.StandardDataPacket) Test(org.junit.Test)

Example 7 with DataPacket

use of org.apache.nifi.remote.protocol.DataPacket in project nifi by apache.

the class TestHttpClient method testSendTimeout.

@Test
public void testSendTimeout() throws Exception {
    // skip on windows
    assumeFalse(isWindowsEnvironment());
    try (SiteToSiteClient client = getDefaultBuilder().timeout(1, TimeUnit.SECONDS).portName("input-timeout").build()) {
        final Transaction transaction = client.createTransaction(TransferDirection.SEND);
        assertNotNull(transaction);
        DataPacket packet = new DataPacketBuilder().contents("Example contents from client.").attr("Client attr 1", "Client attr 1 value").attr("Client attr 2", "Client attr 2 value").build();
        serverChecksum = "1345413116";
        transaction.send(packet);
        try {
            transaction.confirm();
            fail();
        } catch (IOException e) {
            logger.info("An exception was thrown as expected.", e);
            assertTrue(e.getMessage().contains("TimeoutException"));
        }
        completeShouldFail(transaction);
    }
}
Also used : SiteToSiteClient(org.apache.nifi.remote.client.SiteToSiteClient) Transaction(org.apache.nifi.remote.Transaction) IOException(java.io.IOException) DataPacket(org.apache.nifi.remote.protocol.DataPacket) StandardDataPacket(org.apache.nifi.remote.util.StandardDataPacket) Test(org.junit.Test)

Example 8 with DataPacket

use of org.apache.nifi.remote.protocol.DataPacket in project nifi by apache.

the class TestHttpClient method testReceive.

private void testReceive(SiteToSiteClient client) throws IOException {
    final Transaction transaction = client.createTransaction(TransferDirection.RECEIVE);
    assertNotNull(transaction);
    DataPacket packet;
    while ((packet = transaction.receive()) != null) {
        consumeDataPacket(packet);
    }
    transaction.confirm();
    transaction.complete();
}
Also used : Transaction(org.apache.nifi.remote.Transaction) DataPacket(org.apache.nifi.remote.protocol.DataPacket) StandardDataPacket(org.apache.nifi.remote.util.StandardDataPacket)

Example 9 with DataPacket

use of org.apache.nifi.remote.protocol.DataPacket in project nifi by apache.

the class TestHttpClient method testSend.

private void testSend(SiteToSiteClient client) throws Exception {
    testSendIgnoreProxyError(client, transaction -> {
        serverChecksum = "1071206772";
        for (int i = 0; i < 20; i++) {
            DataPacket packet = new DataPacketBuilder().contents("Example contents from client.").attr("Client attr 1", "Client attr 1 value").attr("Client attr 2", "Client attr 2 value").build();
            transaction.send(packet);
            long written = ((Peer) transaction.getCommunicant()).getCommunicationsSession().getBytesWritten();
            logger.info("{}: {} bytes have been written.", i, written);
        }
    });
}
Also used : DataPacket(org.apache.nifi.remote.protocol.DataPacket) StandardDataPacket(org.apache.nifi.remote.util.StandardDataPacket)

Example 10 with DataPacket

use of org.apache.nifi.remote.protocol.DataPacket in project nifi by apache.

the class TestHttpClient method testSendLargeFile.

private static void testSendLargeFile(SiteToSiteClient client) throws IOException {
    testSendIgnoreProxyError(client, transaction -> {
        serverChecksum = "1527414060";
        final int contentSize = 10_000;
        final StringBuilder sb = new StringBuilder(contentSize);
        for (int i = 0; i < contentSize; i++) {
            sb.append("a");
        }
        DataPacket packet = new DataPacketBuilder().contents(sb.toString()).attr("Client attr 1", "Client attr 1 value").attr("Client attr 2", "Client attr 2 value").build();
        transaction.send(packet);
        long written = ((Peer) transaction.getCommunicant()).getCommunicationsSession().getBytesWritten();
        logger.info("{} bytes have been written.", written);
    });
}
Also used : DataPacket(org.apache.nifi.remote.protocol.DataPacket) StandardDataPacket(org.apache.nifi.remote.util.StandardDataPacket)

Aggregations

DataPacket (org.apache.nifi.remote.protocol.DataPacket)36 Test (org.junit.Test)21 StandardDataPacket (org.apache.nifi.remote.util.StandardDataPacket)20 Transaction (org.apache.nifi.remote.Transaction)13 InputStream (java.io.InputStream)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 IOException (java.io.IOException)8 SiteToSiteClient (org.apache.nifi.remote.client.SiteToSiteClient)8 SiteToSiteTestUtils.createDataPacket (org.apache.nifi.remote.protocol.SiteToSiteTestUtils.createDataPacket)8 ByteArrayInputStream (org.apache.nifi.stream.io.ByteArrayInputStream)8 ByteArrayOutputStream (org.apache.nifi.stream.io.ByteArrayOutputStream)8 HttpCommunicationsSession (org.apache.nifi.remote.io.http.HttpCommunicationsSession)7 Peer (org.apache.nifi.remote.Peer)5 Response (org.apache.nifi.remote.protocol.Response)5 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)4 CommunicationsSession (org.apache.nifi.remote.protocol.CommunicationsSession)4