Search in sources :

Example 6 with IContext

use of org.apache.storm.messaging.IContext in project storm by apache.

the class NettyTest method connectToFixedPort.

private void connectToFixedPort(Map<String, Object> stormConf, int port) throws Exception {
    LOG.info("7. Should be able to rebind to a port quickly");
    String reqMessage = "0123456789abcdefghijklmnopqrstuvwxyz";
    IContext context = TransportFactory.makeContext(stormConf, null);
    try {
        AtomicReference<TaskMessage> response = new AtomicReference<>();
        try (IConnection server = context.bind(null, port, mkConnectionCallback(response::set), null);
            IConnection client = context.connect(null, "localhost", server.getPort(), remoteBpStatus)) {
            waitUntilReady(client, server);
            byte[] messageBytes = reqMessage.getBytes(StandardCharsets.UTF_8);
            send(client, taskId, messageBytes);
            waitForNotNull(response);
            TaskMessage responseMessage = response.get();
            assertThat(responseMessage.task(), is(taskId));
            assertThat(responseMessage.message(), is(messageBytes));
        }
    } finally {
        context.term();
    }
}
Also used : IContext(org.apache.storm.messaging.IContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) IConnection(org.apache.storm.messaging.IConnection) TaskMessage(org.apache.storm.messaging.TaskMessage)

Example 7 with IContext

use of org.apache.storm.messaging.IContext in project storm by apache.

the class NettyTest method doTestLargeMessage.

private void doTestLargeMessage(Map<String, Object> stormConf) throws Exception {
    LOG.info("3 Should send and receive a large message");
    String reqMessage = StringUtils.repeat("c", 2_048_000);
    IContext context = TransportFactory.makeContext(stormConf, null);
    try {
        AtomicReference<TaskMessage> response = new AtomicReference<>();
        try (IConnection server = context.bind(null, 0, mkConnectionCallback(response::set), null);
            IConnection client = context.connect(null, "localhost", server.getPort(), remoteBpStatus)) {
            waitUntilReady(client, server);
            byte[] messageBytes = reqMessage.getBytes(StandardCharsets.UTF_8);
            send(client, taskId, messageBytes);
            waitForNotNull(response);
            TaskMessage responseMessage = response.get();
            assertThat(responseMessage.task(), is(taskId));
            assertThat(responseMessage.message(), is(messageBytes));
        }
    } finally {
        context.term();
    }
}
Also used : IContext(org.apache.storm.messaging.IContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) IConnection(org.apache.storm.messaging.IConnection) TaskMessage(org.apache.storm.messaging.TaskMessage)

Aggregations

AtomicReference (java.util.concurrent.atomic.AtomicReference)7 IConnection (org.apache.storm.messaging.IConnection)7 IContext (org.apache.storm.messaging.IContext)7 TaskMessage (org.apache.storm.messaging.TaskMessage)7 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Load (org.apache.storm.grouping.Load)2 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 IntStream (java.util.stream.IntStream)1 StringUtils (org.apache.commons.lang.StringUtils)1 Config (org.apache.storm.Config)1