@Test public void testRegisterTwice() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); try { vertx.eventBus().registerCodec(codec); fail("Should throw exception"); } catch (IllegalStateException e) { // OK } }
@Test public void testRegisterSystemDecoder() throws Exception { try { vertx.eventBus().registerCodec(new MySystemDecoder()); fail("Should throw exception"); } catch (IllegalArgumentException e) { // OK } }
@Test public void testCodecNullName() throws Exception { try { vertx.eventBus().registerCodec(new NullNameCodec()); fail("Should throw exception"); } catch (NullPointerException e) { // OK } }
@Test public void testDecoderReplySymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder2(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testReply(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderSendSymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder2(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testSend(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderSendAsymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder1(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testSend(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderReplyAsymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder1(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testReply(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderSendAsymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testSend(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderReplySymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder2(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testReply(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderReplyAsymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testReply(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderSendSymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder2(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testSend(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testMessageBodyInterceptor() throws Exception { String content = TestUtils.randomUnicodeString(13); startNodes(2); waitFor(2); CountDownLatch latch = new CountDownLatch(1); vertices[0].eventBus().registerCodec(new StringLengthCodec()).<Integer>consumer("whatever", msg -> { assertEquals(content.length(), (int) msg.body()); complete(); }).completionHandler(ar -> latch.countDown()); awaitLatch(latch); StringLengthCodec codec = new StringLengthCodec(); vertices[1].eventBus().registerCodec(codec).addOutboundInterceptor(sc -> { if ("whatever".equals(sc.message().address())) { assertEquals(content, sc.body()); complete(); } sc.next(); }).send("whatever", content, new DeliveryOptions().setCodecName(codec.name())); await(); } }
@Test public void testUnregisterDecoder() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); vertx.eventBus().unregisterCodec(codec.name()); try { vertx.eventBus().send(ADDRESS1, new MyPOJO("foo"), new DeliveryOptions().setCodecName(codec.name())); fail("Should throw exception"); } catch (IllegalArgumentException e) { // OK } }
@Test public void testCodecNullName() throws Exception { try { vertx.eventBus().registerCodec(new NullNameCodec()); fail("Should throw exception"); } catch (NullPointerException e) { // OK } }
@Test public void testArgumentValidation() throws Exception { assertNullPointerException(() -> eb.send(null, "")); assertNullPointerException(() -> eb.send(null, "", handler -> {})); assertNullPointerException(() -> eb.send(null, "", new DeliveryOptions())); assertNullPointerException(() -> eb.send("", "", (DeliveryOptions) null)); assertNullPointerException(() -> eb.send(null, "", new DeliveryOptions(), handler -> {})); assertNullPointerException(() -> eb.send("", "", null, handler -> {})); assertNullPointerException(() -> eb.publish(null, "")); assertNullPointerException(() -> eb.publish(null, "", new DeliveryOptions())); assertNullPointerException(() -> eb.publish("", "", null)); assertNullPointerException(() -> eb.consumer(null)); assertNullPointerException(() -> eb.consumer(null, msg -> {})); assertNullPointerException(() -> eb.consumer(ADDRESS1, null)); assertNullPointerException(() -> eb.localConsumer(null)); assertNullPointerException(() -> eb.localConsumer(null, msg -> {})); assertNullPointerException(() -> eb.localConsumer(ADDRESS1, null)); assertNullPointerException(() -> eb.sender(null)); assertNullPointerException(() -> eb.sender(null, new DeliveryOptions())); assertNullPointerException(() -> eb.publisher("", null)); assertNullPointerException(() -> eb.publisher(null, new DeliveryOptions())); assertNullPointerException(() -> eb.registerCodec(null)); assertNullPointerException(() -> eb.unregisterCodec(null)); assertNullPointerException(() -> eb.registerDefaultCodec(null, new MyPOJOEncoder1())); assertNullPointerException(() -> eb.registerDefaultCodec(Object.class, null)); assertNullPointerException(() -> eb.unregisterDefaultCodec(null)); }
@Test public void testDecoderReplyAsymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder1(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testReply(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderReplySymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder2(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testReply(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderReplyAsymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testReply(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderSendAsymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testSend(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testUnregisterDecoder() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); vertx.eventBus().unregisterCodec(codec.name()); try { vertx.eventBus().send(ADDRESS1, new MyPOJO("foo"), new DeliveryOptions().setCodecName(codec.name())); fail("Should throw exception"); } catch (IllegalArgumentException e) { // OK } }