Search in sources :

Example 56 with Ctx

use of zmq.Ctx in project jeromq by zeromq.

the class XPubTest method testSetNoDrop.

@Test
public void testSetNoDrop() {
    Ctx ctx = ZMQ.createContext();
    SocketBase pub = null;
    try {
        pub = ctx.createSocket(ZMQ.ZMQ_XPUB);
        boolean rc = pub.setSocketOpt(ZMQ.ZMQ_XPUB_NODROP, 0);
        assertThat(rc, is(true));
    } finally {
        ZMQ.close(pub);
        ZMQ.term(ctx);
    }
}
Also used : SocketBase(zmq.SocketBase) Ctx(zmq.Ctx) Test(org.junit.Test)

Example 57 with Ctx

use of zmq.Ctx in project jeromq by zeromq.

the class DealerDealerTest method testIssue131.

@Test
public void testIssue131() throws IOException {
    Ctx ctx = ZMQ.createContext();
    assertThat(ctx, notNullValue());
    SocketBase sender = ZMQ.socket(ctx, ZMQ.ZMQ_DEALER);
    assertThat(sender, notNullValue());
    final int port = Utils.findOpenPort();
    final String addr = "tcp://localhost:" + port;
    boolean rc = ZMQ.connect(sender, addr);
    assertThat(rc, is(true));
    byte[] sbuf = msg(255);
    int sent = ZMQ.send(sender, sbuf, 0);
    assertThat(sent, is(255));
    byte[] quit = { 'q' };
    sent = ZMQ.send(sender, quit, 0);
    assertThat(sent, is(1));
    ZMQ.close(sender);
    SocketBase receiver = ZMQ.socket(ctx, ZMQ.ZMQ_DEALER);
    assertThat(receiver, notNullValue());
    rc = ZMQ.bind(receiver, addr);
    assertThat(rc, is(true));
    int nbytes = 0;
    do {
        Msg msg = ZMQ.recv(receiver, 0);
        nbytes = msg.size();
        System.out.println(msg);
    } while (nbytes != 1);
    ZMQ.close(receiver);
    ZMQ.term(ctx);
}
Also used : Msg(zmq.Msg) SocketBase(zmq.SocketBase) Ctx(zmq.Ctx) Test(org.junit.Test)

Example 58 with Ctx

use of zmq.Ctx in project jeromq by zeromq.

the class DealerSpecTest method testSpecFairQueueIn.

@Test
public void testSpecFairQueueIn() throws IOException, InterruptedException {
    Ctx ctx = ZMQ.createContext();
    List<String> binds = Arrays.asList("inproc://a", "tcp://127.0.0.1:*");
    for (String bindAddress : binds) {
        // SHALL receive incoming messages from its peers using a fair-queuing
        // strategy.
        fairQueueIn(ctx, bindAddress, ZMQ.ZMQ_DEALER, ZMQ.ZMQ_DEALER);
    }
    ZMQ.term(ctx);
}
Also used : Ctx(zmq.Ctx) Test(org.junit.Test) AbstractSpecTest(zmq.socket.AbstractSpecTest)

Example 59 with Ctx

use of zmq.Ctx in project jeromq by zeromq.

the class ReqSpecTest method testSpecBlockOnSendNoPeers.

@Test
public void testSpecBlockOnSendNoPeers() throws IOException, InterruptedException {
    Ctx ctx = ZMQ.createContext();
    List<String> binds = Arrays.asList("inproc://a", "tcp://127.0.0.1:*");
    for (String bindAddress : binds) {
        // SHALL block on sending, or return a suitable error, when it has no
        // connected peers.
        blockOnSendNoPeers(ctx, bindAddress, ZMQ.ZMQ_REQ);
    }
    ZMQ.term(ctx);
}
Also used : Ctx(zmq.Ctx) Test(org.junit.Test) AbstractSpecTest(zmq.socket.AbstractSpecTest)

Example 60 with Ctx

use of zmq.Ctx in project jeromq by zeromq.

the class ReqSpecTest method testSpecOnlyListensToCurrentPeer.

@Test
@Ignore
public void testSpecOnlyListensToCurrentPeer() throws IOException, InterruptedException {
    Ctx ctx = ZMQ.createContext();
    List<String> binds = Arrays.asList("inproc://a", "tcp://127.0.0.1:*");
    for (String bindAddress : binds) {
        // SHALL accept an incoming message only from the last peer that it sent a
        // request to.
        // SHALL discard silently any messages received from other peers.
        // PH: this test is still failing; disabled for now to allow build to
        // complete.
        onlyListensToCurrentPeer(ctx, bindAddress, ZMQ.ZMQ_REQ, ZMQ.ZMQ_ROUTER);
    }
    ZMQ.term(ctx);
}
Also used : Ctx(zmq.Ctx) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractSpecTest(zmq.socket.AbstractSpecTest)

Aggregations

Ctx (zmq.Ctx)81 Test (org.junit.Test)73 SocketBase (zmq.SocketBase)63 Msg (zmq.Msg)31 AbstractSpecTest (zmq.socket.AbstractSpecTest)16 OutputStream (java.io.OutputStream)5 Socket (java.net.Socket)5 Ignore (org.junit.Ignore)4 ExecutorService (java.util.concurrent.ExecutorService)3 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Curve (zmq.io.mechanism.curve.Curve)2 InputStream (java.io.InputStream)1 UncaughtExceptionHandler (java.lang.Thread.UncaughtExceptionHandler)1 ClosedSelectorException (java.nio.channels.ClosedSelectorException)1 Selector (java.nio.channels.Selector)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1