use of org.zeromq.ZMQ.Context in project jeromq by zeromq.
the class TestEvents method testEventBindFailed.
@Test
public void testEventBindFailed() {
Context context = ZMQ.context(1);
ZMQ.Event event;
Socket helper = context.socket(SocketType.REP);
int port = helper.bindToRandomPort("tcp://127.0.0.1");
Socket socket = context.socket(SocketType.REP);
Socket monitor = context.socket(SocketType.PAIR);
monitor.setReceiveTimeOut(100);
assertTrue(socket.monitor("inproc://monitor.socket", ZMQ.EVENT_BIND_FAILED));
monitor.connect("inproc://monitor.socket");
try {
socket.bind("tcp://127.0.0.1:" + port);
} catch (ZMQException ex) {
}
event = ZMQ.Event.recv(monitor);
assertNotNull("No event was received", event);
assertEquals(ZMQ.EVENT_BIND_FAILED, event.getEvent());
helper.close();
socket.close();
monitor.close();
context.term();
}
use of org.zeromq.ZMQ.Context in project jeromq by zeromq.
the class TestEvents method testEventAccepted.
@Test
public void testEventAccepted() {
Context context = ZMQ.context(1);
ZMQ.Event event;
Socket socket = context.socket(SocketType.REP);
Socket monitor = context.socket(SocketType.PAIR);
Socket helper = context.socket(SocketType.REQ);
monitor.setReceiveTimeOut(100);
assertTrue(socket.monitor("inproc://monitor.socket", ZMQ.EVENT_ACCEPTED));
monitor.connect("inproc://monitor.socket");
int port = socket.bindToRandomPort("tcp://127.0.0.1");
helper.connect("tcp://127.0.0.1:" + port);
event = ZMQ.Event.recv(monitor);
assertNotNull("No event was received", event);
assertEquals(ZMQ.EVENT_ACCEPTED, event.getEvent());
helper.close();
socket.close();
monitor.close();
context.term();
}
use of org.zeromq.ZMQ.Context in project jeromq by zeromq.
the class TestEvents method testEventListening.
@Test
public void testEventListening() {
Context context = ZMQ.context(1);
ZMQ.Event event;
Socket socket = context.socket(SocketType.REP);
Socket monitor = context.socket(SocketType.PAIR);
monitor.setReceiveTimeOut(100);
assertTrue(socket.monitor("inproc://monitor.socket", ZMQ.EVENT_LISTENING));
monitor.connect("inproc://monitor.socket");
socket.bindToRandomPort("tcp://127.0.0.1");
event = ZMQ.Event.recv(monitor);
assertNotNull("No event was received", event);
assertEquals(ZMQ.EVENT_LISTENING, event.getEvent());
socket.close();
monitor.close();
context.term();
}
use of org.zeromq.ZMQ.Context in project jeromq by zeromq.
the class TestEvents method testEventDisconnected.
@Test
public void testEventDisconnected() {
Context context = ZMQ.context(1);
ZMQ.Event event;
Socket socket = context.socket(SocketType.REP);
Socket monitor = context.socket(SocketType.PAIR);
Socket helper = context.socket(SocketType.REQ);
monitor.setReceiveTimeOut(100);
int port = socket.bindToRandomPort("tcp://127.0.0.1");
helper.connect("tcp://127.0.0.1:" + port);
assertTrue(socket.monitor("inproc://monitor.socket", ZMQ.EVENT_DISCONNECTED));
monitor.connect("inproc://monitor.socket");
zmq.ZMQ.sleep(1);
helper.close();
event = ZMQ.Event.recv(monitor);
assertNotNull("No event was received", event);
assertEquals(ZMQ.EVENT_DISCONNECTED, event.getEvent());
socket.close();
monitor.close();
context.term();
}
use of org.zeromq.ZMQ.Context in project jeromq by zeromq.
the class TestEvents method testEventClosed.
@Test
public void testEventClosed() {
Context context = ZMQ.context(1);
Socket monitor = context.socket(SocketType.PAIR);
try {
ZMQ.Event event;
Socket socket = context.socket(SocketType.REP);
monitor.setReceiveTimeOut(100);
socket.bindToRandomPort("tcp://127.0.0.1");
assertTrue(socket.monitor("inproc://monitor.socket", ZMQ.EVENT_CLOSED));
monitor.connect("inproc://monitor.socket");
socket.close();
event = ZMQ.Event.recv(monitor);
assertNotNull("No event was received", event);
assertEquals(ZMQ.EVENT_CLOSED, event.getEvent());
} finally {
monitor.close();
context.term();
}
}
Aggregations