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