use of zmq.Ctx in project jeromq by zeromq.
the class PushPullSpecTest method testSpecPushBlockOnSendNoPeers.
@Test
public void testSpecPushBlockOnSendNoPeers() throws IOException, InterruptedException {
Ctx ctx = ZMQ.createContext();
List<String> binds = Arrays.asList("inproc://a", "tcp://127.0.0.1:*");
for (String bindAddress : binds) {
// PUSH: SHALL block on sending, or return a suitable error, when it has no
// available peers.
blockOnSendNoPeers(ctx, bindAddress, ZMQ.ZMQ_PUSH);
}
ZMQ.term(ctx);
}
use of zmq.Ctx in project jeromq by zeromq.
the class PushPullSpecTest method testSpecDestroyQueueOnDisconnect.
@Test
@Ignore
public void testSpecDestroyQueueOnDisconnect() throws IOException, InterruptedException {
Ctx ctx = ZMQ.createContext();
List<String> binds = Arrays.asList("inproc://a", "tcp://127.0.0.1:*");
for (String bindAddress : binds) {
// PUSH and PULL: SHALL create this queue when a peer connects to it. If
// this peer disconnects, the socket SHALL destroy its queue and SHALL
// discard any messages it contains.
// *** Test disabled until libzmq does this properly ***
}
ZMQ.term(ctx);
}
use of zmq.Ctx in project jeromq by zeromq.
the class PubSubHwmTest method testDefaults.
private int testDefaults(int sendHwm, int msgCnt) {
Ctx ctx = ZMQ.createContext();
// Set up bind socket
SocketBase pub = ctx.createSocket(ZMQ.ZMQ_PUB);
boolean rc = ZMQ.bind(pub, "inproc://a");
assertThat(rc, is(true));
// Set up connect socket
SocketBase sub = ctx.createSocket(ZMQ.ZMQ_SUB);
rc = ZMQ.connect(sub, "inproc://a");
assertThat(rc, is(true));
// set a hwm on publisher
rc = ZMQ.setSocketOption(pub, ZMQ.ZMQ_SNDHWM, sendHwm);
assertThat(rc, is(true));
rc = ZMQ.setSocketOption(sub, ZMQ.ZMQ_SUBSCRIBE, new byte[0]);
assertThat(rc, is(true));
// Send until we block
int sendCount = 0;
while (sendCount < msgCnt && ZMQ.send(pub, "", ZMQ.ZMQ_DONTWAIT) == 0) {
++sendCount;
}
// Now receive all sent messages
int recvCount = 0;
while (null != ZMQ.recv(sub, ZMQ.ZMQ_DONTWAIT)) {
++recvCount;
}
assertThat(sendCount, is(recvCount));
// Clean up
ZMQ.close(sub);
ZMQ.close(pub);
ZMQ.term(ctx);
return recvCount;
}
use of zmq.Ctx in project jeromq by zeromq.
the class PubSubHwmTest method testResetHwm.
@Test
public void testResetHwm() {
// hwm should apply to the messages that have already been received
// with hwm 11024: send 9999 msg, receive 9999, send 1100, receive 1100
int firstCount = 9999;
int secondCount = 1100;
int hwm = 11024;
Ctx ctx = ZMQ.createContext();
// Set up bind socket
SocketBase pub = ctx.createSocket(ZMQ.ZMQ_PUB);
boolean rc = ZMQ.setSocketOption(pub, ZMQ.ZMQ_SNDHWM, hwm);
assertThat(rc, is(true));
rc = ZMQ.bind(pub, "tcp://localhost:*");
assertThat(rc, is(true));
String host = (String) ZMQ.getSocketOptionExt(pub, ZMQ.ZMQ_LAST_ENDPOINT);
assertThat(host, notNullValue());
// Set up connect socket
SocketBase sub = ctx.createSocket(ZMQ.ZMQ_SUB);
rc = ZMQ.setSocketOption(sub, ZMQ.ZMQ_RCVHWM, hwm);
assertThat(rc, is(true));
rc = ZMQ.connect(sub, host);
assertThat(rc, is(true));
rc = ZMQ.setSocketOption(sub, ZMQ.ZMQ_SUBSCRIBE, new byte[0]);
assertThat(rc, is(true));
ZMQ.sleep(1);
// Send messages
int sendCount = 0;
while (sendCount < firstCount && ZMQ.send(pub, "1", ZMQ.ZMQ_DONTWAIT) == 1) {
++sendCount;
}
assertThat(sendCount, is(firstCount));
ZMQ.msleep(500);
// Now receive all sent messages
int recvCount = 0;
while (null != ZMQ.recv(sub, ZMQ.ZMQ_DONTWAIT)) {
++recvCount;
}
assertThat(recvCount, is(firstCount));
ZMQ.msleep(100);
sendCount = 0;
while (sendCount < secondCount && ZMQ.send(pub, "2", ZMQ.ZMQ_DONTWAIT) == 1) {
++sendCount;
}
assertThat(sendCount, is(secondCount));
ZMQ.msleep(200);
// Now receive all sent messages
recvCount = 0;
while (null != ZMQ.recv(sub, ZMQ.ZMQ_DONTWAIT)) {
++recvCount;
}
assertThat(recvCount, is(secondCount));
// Clean up
ZMQ.close(sub);
ZMQ.close(pub);
ZMQ.term(ctx);
}
use of zmq.Ctx in project jeromq by zeromq.
the class SubTest method testSetNullOption.
@Test
public void testSetNullOption() {
Ctx ctx = ZMQ.createContext();
SocketBase pub = null;
try {
pub = ctx.createSocket(ZMQ.ZMQ_SUB);
boolean rc = pub.setSocketOpt(ZMQ.ZMQ_SUBSCRIBE, null);
assertThat(rc, is(false));
} catch (IllegalArgumentException e) {
assertThat(pub.errno.get(), is(ZError.EINVAL));
} finally {
ZMQ.close(pub);
ZMQ.term(ctx);
}
}
Aggregations