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());
}
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();
}
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();
}
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"));
}
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();
}
Aggregations