Search in sources :

Example 31 with NetSocket

use of io.vertx.core.net.NetSocket in project vertx-tcp-eventbus-bridge by vert-x3.

the class TcpEventBusBridgeTest method testSendsFromOtherSideOfBridge.

@Test
public void testSendsFromOtherSideOfBridge(TestContext context) {
    NetClient client = vertx.createNetClient();
    final Async async = context.async();
    client.connect(7000, "localhost", conn -> {
        context.assertFalse(conn.failed());
        NetSocket socket = conn.result();
        final FrameParser parser = new FrameParser(parse -> {
            context.assertTrue(parse.succeeded());
            JsonObject frame = parse.result();
            context.assertNotEquals("err", frame.getString("type"));
            context.assertEquals(true, frame.getBoolean("send"));
            context.assertEquals("hi", frame.getJsonObject("body").getString("value"));
            client.close();
            async.complete();
        });
        socket.handler(parser);
        FrameHelper.sendFrame("register", "ping", null, socket);
    });
}
Also used : NetSocket(io.vertx.core.net.NetSocket) NetClient(io.vertx.core.net.NetClient) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) FrameParser(io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser) Test(org.junit.Test)

Example 32 with NetSocket

use of io.vertx.core.net.NetSocket in project vertx-tcp-eventbus-bridge by vert-x3.

the class TcpEventBusBridgeTest method testSendMessageWithReplyBacktrack.

@Test
public void testSendMessageWithReplyBacktrack(TestContext context) {
    // Send a request and get a response
    NetClient client = vertx.createNetClient();
    final Async async = context.async();
    client.connect(7000, "localhost", conn -> {
        context.assertFalse(conn.failed());
        NetSocket socket = conn.result();
        final FrameParser parser = new FrameParser(parse -> {
            context.assertTrue(parse.succeeded());
            JsonObject frame = parse.result();
            context.assertNotEquals("err", frame.getString("type"));
            context.assertEquals(true, frame.getBoolean("send"));
            context.assertEquals("Hello vert.x", frame.getJsonObject("body").getString("value"));
            client.close();
            async.complete();
        });
        socket.handler(parser);
        FrameHelper.sendFrame("send", "hello", "#backtrack", new JsonObject().put("value", "vert.x"), socket);
    });
}
Also used : NetSocket(io.vertx.core.net.NetSocket) NetClient(io.vertx.core.net.NetClient) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) FrameParser(io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser) Test(org.junit.Test)

Example 33 with NetSocket

use of io.vertx.core.net.NetSocket in project vertx-tcp-eventbus-bridge by vert-x3.

the class TcpEventBusBridgeInteropTest method testSendMessageWithDuplicateReplyID.

@Test
public void testSendMessageWithDuplicateReplyID(TestContext context) {
    // replies must always return to the same origin
    NetClient client = vertx.createNetClient();
    final Async async = context.async();
    client.connect(7000, "localhost", conn -> {
        context.assertFalse(conn.failed());
        NetSocket socket = conn.result();
        vertx.eventBus().consumer("third-party-receiver", msg -> context.fail());
        final FrameParser parser = new FrameParser(parse -> {
            context.assertTrue(parse.succeeded());
            client.close();
            async.complete();
        });
        socket.handler(parser);
        FrameHelper.sendFrame("send", "hello", "third-party-receiver", new JsonObject().put("value", "vert.x"), socket);
    });
}
Also used : NetSocket(io.vertx.core.net.NetSocket) NetClient(io.vertx.core.net.NetClient) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) FrameParser(io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser) Test(org.junit.Test)

Aggregations

NetSocket (io.vertx.core.net.NetSocket)33 Test (org.junit.Test)23 NetClient (io.vertx.core.net.NetClient)16 Buffer (io.vertx.core.buffer.Buffer)14 Handler (io.vertx.core.Handler)13 Async (io.vertx.ext.unit.Async)11 Vertx (io.vertx.core.Vertx)10 JsonObject (io.vertx.core.json.JsonObject)10 AsyncResult (io.vertx.core.AsyncResult)9 Context (io.vertx.core.Context)9 Future (io.vertx.core.Future)9 FrameParser (io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser)9 ByteBuf (io.netty.buffer.ByteBuf)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Unpooled (io.netty.buffer.Unpooled)6 Channel (io.netty.channel.Channel)6 SslHandler (io.netty.handler.ssl.SslHandler)6 MultiMap (io.vertx.core.MultiMap)6 VertxInternal (io.vertx.core.impl.VertxInternal)6 NetClientOptions (io.vertx.core.net.NetClientOptions)6