Search in sources :

Example 1 with DatagramSocketOptions

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

the class DummyMetricsTest method testDummyDatagramSocketMetrics.

@Test
public void testDummyDatagramSocketMetrics() {
    DatagramSocket sock = vertx.createDatagramSocket(new DatagramSocketOptions());
    assertFalse(sock.isMetricsEnabled());
}
Also used : DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) DatagramSocket(io.vertx.core.datagram.DatagramSocket) Test(org.junit.Test)

Example 2 with DatagramSocketOptions

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

the class DatagramTest method testSendReceiveLargePacket.

@Test
public void testSendReceiveLargePacket() {
    int packetSize = 10000;
    peer1 = vertx.createDatagramSocket(new DatagramSocketOptions().setSendBufferSize(packetSize));
    // OSX needs 16 more
    peer2 = vertx.createDatagramSocket(new DatagramSocketOptions().setReceiveBufferSize(packetSize + 16));
    peer2.exceptionHandler(t -> fail(t.getMessage()));
    peer2.listen(1234, "127.0.0.1", ar -> {
        assertTrue(ar.succeeded());
        Buffer buffer = TestUtils.randomBuffer(packetSize);
        peer2.handler(packet -> {
            assertEquals(buffer, packet.data());
            testComplete();
        });
        peer1.send(buffer, 1234, "127.0.0.1", ar2 -> assertTrue(ar2.succeeded()));
    });
    await();
}
Also used : DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) Buffer(io.vertx.core.buffer.Buffer) Test(org.junit.Test)

Example 3 with DatagramSocketOptions

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

the class DatagramTest method testBroadcast.

@Test
public void testBroadcast() {
    peer1 = vertx.createDatagramSocket(new DatagramSocketOptions().setBroadcast(true));
    peer2 = vertx.createDatagramSocket(new DatagramSocketOptions().setBroadcast(true));
    peer2.exceptionHandler(t -> fail(t.getMessage()));
    peer2.listen(1234, "0.0.0.0", ar1 -> {
        assertTrue(ar1.succeeded());
        Buffer buffer = TestUtils.randomBuffer(128);
        peer2.handler(packet -> {
            assertEquals(buffer, packet.data());
            testComplete();
        });
        peer1.send(buffer, 1234, "255.255.255.255", ar2 -> {
            assertTrue(ar2.succeeded());
        });
    });
    await();
}
Also used : DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) Buffer(io.vertx.core.buffer.Buffer) Test(org.junit.Test)

Example 4 with DatagramSocketOptions

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

the class DatagramTest method testNoLogging.

@Test
public void testNoLogging() throws Exception {
    TestLoggerFactory factory = testLogging(new DatagramSocketOptions(), new DatagramSocketOptions());
    assertFalse(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 5 with DatagramSocketOptions

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

the class DatagramTest method testEcho.

@Test
public void testEcho() {
    peer1 = vertx.createDatagramSocket(new DatagramSocketOptions());
    peer2 = vertx.createDatagramSocket(new DatagramSocketOptions());
    peer1.exceptionHandler(t -> fail(t.getMessage()));
    peer2.exceptionHandler(t -> fail(t.getMessage()));
    peer2.listen(1234, "127.0.0.1", ar -> {
        assertTrue(ar.succeeded());
        Buffer buffer = TestUtils.randomBuffer(128);
        peer2.handler(packet -> {
            assertEquals("127.0.0.1", packet.sender().host());
            assertEquals(1235, packet.sender().port());
            assertEquals(buffer, packet.data());
            peer2.send(packet.data(), 1235, "127.0.0.1", ar2 -> assertTrue(ar2.succeeded()));
        });
        peer1.listen(1235, "127.0.0.1", ar2 -> {
            peer1.handler(packet -> {
                assertEquals(buffer, packet.data());
                assertEquals("127.0.0.1", packet.sender().host());
                assertEquals(1234, packet.sender().port());
                testComplete();
            });
            peer1.send(buffer, 1234, "127.0.0.1", ar3 -> assertTrue(ar3.succeeded()));
        });
    });
    await();
}
Also used : DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) Buffer(io.vertx.core.buffer.Buffer) Test(org.junit.Test)

Aggregations

DatagramSocketOptions (io.vertx.core.datagram.DatagramSocketOptions)25 Test (org.junit.Test)19 Buffer (io.vertx.core.buffer.Buffer)11 DatagramSocket (io.vertx.core.datagram.DatagramSocket)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 TestLoggerFactory (io.vertx.test.netty.TestLoggerFactory)3 io.vertx.core (io.vertx.core)2 EventBus (io.vertx.core.eventbus.EventBus)2 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)2 io.vertx.core.http (io.vertx.core.http)2 JsonObject (io.vertx.core.json.JsonObject)2 MetricsOptions (io.vertx.core.metrics.MetricsOptions)2 DummyVertxMetrics (io.vertx.core.metrics.impl.DummyVertxMetrics)2 io.vertx.core.net (io.vertx.core.net)2 VertxMetricsFactory (io.vertx.core.spi.VertxMetricsFactory)2 Random (java.util.Random)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 BiConsumer (java.util.function.BiConsumer)2