Search in sources :

Example 6 with DatagramSocketOptions

use of io.vertx.core.datagram.DatagramSocketOptions in project vert.x by eclipse.

the class DatagramTest method testListenLogging.

@Test
public void testListenLogging() throws Exception {
    TestLoggerFactory factory = testLogging(new DatagramSocketOptions(), new DatagramSocketOptions().setLogActivity(true));
    assertTrue(factory.hasName("io.netty.handler.logging.LoggingHandler"));
}
Also used : DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) Test(org.junit.Test)

Example 7 with DatagramSocketOptions

use of io.vertx.core.datagram.DatagramSocketOptions in project vert.x by eclipse.

the class DatagramTest method testSender.

@Test
public void testSender() {
    peer1 = vertx.createDatagramSocket(new DatagramSocketOptions());
    peer2 = vertx.createDatagramSocket(new DatagramSocketOptions());
    peer2.exceptionHandler(t -> fail(t.getMessage()));
    peer2.listen(1234, "127.0.0.1", ar -> {
        Buffer buffer = TestUtils.randomBuffer(128);
        peer2.handler(packet -> {
            assertEquals(buffer, packet.data());
            testComplete();
        });
        WriteStream<Buffer> sender1 = peer1.sender(1234, "127.0.0.1");
        sender1.write(buffer);
    });
}
Also used : DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) Buffer(io.vertx.core.buffer.Buffer) Test(org.junit.Test)

Example 8 with DatagramSocketOptions

use of io.vertx.core.datagram.DatagramSocketOptions in project vert.x by eclipse.

the class DatagramTest method testUseInMultithreadedWorker.

@Test
public void testUseInMultithreadedWorker() throws Exception {
    class MyVerticle extends AbstractVerticle {

        @Override
        public void start() {
            assertIllegalStateException(() -> peer1 = vertx.createDatagramSocket(new DatagramSocketOptions()));
            testComplete();
        }
    }
    MyVerticle verticle = new MyVerticle();
    vertx.deployVerticle(verticle, new DeploymentOptions().setWorker(true).setMultiThreaded(true));
    await();
}
Also used : DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) DeploymentOptions(io.vertx.core.DeploymentOptions) AbstractVerticle(io.vertx.core.AbstractVerticle) Test(org.junit.Test)

Example 9 with DatagramSocketOptions

use of io.vertx.core.datagram.DatagramSocketOptions in project vert.x by eclipse.

the class DatagramTest method testDefaultJsonOptions.

@Test
public void testDefaultJsonOptions() {
    DatagramSocketOptions def = new DatagramSocketOptions();
    DatagramSocketOptions json = new DatagramSocketOptions(new JsonObject());
    assertEquals(def.isBroadcast(), json.isBroadcast());
    assertEquals(def.isLoopbackModeDisabled(), json.isLoopbackModeDisabled());
    assertEquals(def.getMulticastTimeToLive(), json.getMulticastTimeToLive());
    assertEquals(def.getMulticastNetworkInterface(), json.getMulticastNetworkInterface());
    assertEquals(def.isIpV6(), json.isIpV6());
}
Also used : DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 10 with DatagramSocketOptions

use of io.vertx.core.datagram.DatagramSocketOptions in project vert.x by eclipse.

the class DatagramTest method testPauseResume.

@Test
public void testPauseResume() {
    peer1 = vertx.createDatagramSocket(new DatagramSocketOptions());
    peer2 = vertx.createDatagramSocket(new DatagramSocketOptions());
    peer2.exceptionHandler(t -> fail(t.getMessage()));
    peer2.listen(1234, "127.0.0.1", ar -> {
        Buffer buffer = TestUtils.randomBuffer(128);
        AtomicBoolean received = new AtomicBoolean();
        peer2.handler(packet -> received.set(true));
        peer2.pause();
        peer1.send(buffer, 1234, "127.0.0.1", ar2 -> {
            assertTrue(ar2.succeeded());
        });
        vertx.setTimer(1000, l -> {
            AtomicInteger count = new AtomicInteger();
            peer2.handler(packet -> {
                switch(count.getAndIncrement()) {
                    case 0:
                        assertEquals(buffer, packet.data());
                        peer1.send(buffer, 1234, "127.0.0.1", ar2 -> {
                            assertTrue(ar2.succeeded());
                        });
                        break;
                    case 1:
                        assertFalse(received.get());
                        assertEquals(buffer, packet.data());
                        testComplete();
                        break;
                    default:
                        fail();
                }
            });
            peer2.resume();
        });
    });
    await();
}
Also used : DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) Buffer(io.vertx.core.buffer.Buffer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

DatagramSocketOptions (io.vertx.core.datagram.DatagramSocketOptions)24 Test (org.junit.Test)18 Buffer (io.vertx.core.buffer.Buffer)10 DatagramSocket (io.vertx.core.datagram.DatagramSocket)8 TestLoggerFactory (io.vertx.test.netty.TestLoggerFactory)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 JsonObject (io.vertx.core.json.JsonObject)2 Random (java.util.Random)2 ByteBuf (io.netty.buffer.ByteBuf)1 io.vertx.core (io.vertx.core)1 AbstractVerticle (io.vertx.core.AbstractVerticle)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 EventBus (io.vertx.core.eventbus.EventBus)1 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)1 io.vertx.core.http (io.vertx.core.http)1 MetricsOptions (io.vertx.core.metrics.MetricsOptions)1 DummyVertxMetrics (io.vertx.core.metrics.impl.DummyVertxMetrics)1 io.vertx.core.net (io.vertx.core.net)1 VertxMetricsFactory (io.vertx.core.spi.VertxMetricsFactory)1 io.vertx.core.spi.metrics (io.vertx.core.spi.metrics)1