Search in sources :

Example 6 with FrameParser

use of io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser in project vertx-tcp-eventbus-bridge by vert-x3.

the class TcpEventBusBridgeTest method testNoHandlers.

@Test
public void testNoHandlers(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.assertEquals("err", frame.getString("type"));
            context.assertEquals("#backtrack", frame.getString("address"));
            client.close();
            async.complete();
        });
        socket.handler(parser);
        FrameHelper.sendFrame("send", "test", "#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 7 with FrameParser

use of io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser in project vertx-tcp-eventbus-bridge by vert-x3.

the class TcpEventBusBridgeTest 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)

Example 8 with FrameParser

use of io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser 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 9 with FrameParser

use of io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser 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 10 with FrameParser

use of io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser 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

JsonObject (io.vertx.core.json.JsonObject)10 FrameParser (io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser)10 NetClient (io.vertx.core.net.NetClient)9 NetSocket (io.vertx.core.net.NetSocket)9 Async (io.vertx.ext.unit.Async)9 Test (org.junit.Test)9 Message (io.vertx.core.eventbus.Message)2 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)1 BridgeEventType (io.vertx.ext.bridge.BridgeEventType)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1