FmqServer { public FmqServer () { ctx = new ZContext (); pipe = ZThread.fork (ctx, new ServerThread ()); } FmqServer(); void destroy(); void configure(final String config_file); void setoption(final String path, final String value); int bind(final String endpoint); void publish(final String location,final String alias); void setAnonymous(long enabled); static void zclock_log(String fmt, Object ... args); static int bind(Socket sock, String addr);  }
@Test public void testFmqServer () { System.out.printf (" * fmq_server: "); ZContext ctx = new ZContext (); FmqServer self; Socket dealer = ctx.createSocket (ZMQ.DEALER); dealer.setReceiveTimeOut (2000); dealer.connect ("tcp: FmqMsg request, reply; self = new FmqServer (); assert (self != null); int port = self.bind ("tcp: assertEquals (port, 5670); request = new FmqMsg (FmqMsg.OHAI); request.send (dealer); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.SRSLY); reply.destroy (); request = new FmqMsg (FmqMsg.ICANHAZ); request.send (dealer); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.RTFM); reply.destroy (); request = new FmqMsg (FmqMsg.NOM); request.send (dealer); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.RTFM); reply.destroy (); request = new FmqMsg (FmqMsg.HUGZ); request.send (dealer); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.RTFM); reply.destroy (); self.destroy (); self = new FmqServer (); assert (self != null); self.configure ("src/test/resources/anonymous.cfg"); port = self.bind ("tcp: assertEquals (port, 5670); request = new FmqMsg (FmqMsg.OHAI); request.send (dealer); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.OHAI_OK); reply.destroy (); request = new FmqMsg (FmqMsg.NOM); request.send (dealer); request = new FmqMsg (FmqMsg.HUGZ); request.send (dealer); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.HUGZ_OK); reply.destroy (); request = new FmqMsg (FmqMsg.YARLY); request.send (dealer); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.RTFM); reply.destroy (); self.destroy (); self = new FmqServer (); assert (self != null); self.configure ("src/test/resources/server_test.cfg"); port = self.bind ("tcp: assertEquals (port, 5670); request = new FmqMsg (FmqMsg.OHAI); request.send (dealer); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.ORLY); reply.destroy (); request = new FmqMsg (FmqMsg.YARLY); request.setMechanism ("PLAIN"); request.setResponse (FmqSasl.plainEncode ("guest", "guest")); request.send (dealer); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.OHAI_OK); reply.destroy (); request = new FmqMsg (FmqMsg.NOM); request.send (dealer); request = new FmqMsg (FmqMsg.HUGZ); request.send (dealer); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.HUGZ_OK); reply.destroy (); reply = FmqMsg.recv (dealer); assert (reply != null); assertEquals (reply.id (), FmqMsg.HUGZ); reply.destroy (); self.destroy (); ctx.destroy (); try {Thread.sleep (200);} catch (Exception e) {}; System.out.printf ("OK\n"); }