break;
Utils.justSleep(500);
}
assertTrue(sess.isReady());
Packet packet = new Packet();
BufferedInputStream socketInput = new BufferedInputStream(socket.getInputStream());
BufferedOutputStream socketOutput = new BufferedOutputStream(socket.getOutputStream());
/**
* Send a message to foo.out
*/
MistMessage.MessageBlock msg = MistMessage.MessageBlock.newBuilder().setId("queue:foo.out").setMessage(ByteString.copyFrom("test".getBytes())).build();
packet.setPayload(msg.toByteArray());
packet.write(socketOutput);
packet.read(socketInput);
assertTrue(GateTalk.Response.newBuilder().mergeFrom(packet.getPayload()).build().getSuccess());
byte[] recvMsg = brk.getMessage(true, "foo.out");
assertEquals("test", new String(recvMsg));
/**
* Send a message to bar.out
*/
msg = MistMessage.MessageBlock.newBuilder().setId("queue:bar.out").setMessage(ByteString.copyFrom("test-bar".getBytes())).build();
packet.setPayload(msg.toByteArray());
packet.write(socketOutput);
packet.read(socketInput);
assertTrue(GateTalk.Response.newBuilder().mergeFrom(packet.getPayload()).build().getSuccess());
recvMsg = brk.getMessage(true, "bar.out");
assertEquals("test-bar", new String(recvMsg));
/**
* Test Local Forwarding: foo.out->bar.in, ,log.in
*/
Vector<Exchange> destList = new Vector<Exchange>();
destList.add(new Exchange("bar.in"));
destList.add(new Exchange(""));
destList.add(new Exchange("log.in"));
RouteFarm.getInstance().getRouteTable().put("foo.out", destList);
// Wait until local routing cache expires
Utils.justSleep(2000);
msg = MistMessage.MessageBlock.newBuilder().setId("queue:foo.out").setMessage(ByteString.copyFrom("test-route".getBytes())).build();
packet.setPayload(msg.toByteArray());
packet.write(socketOutput);
packet.read(socketInput);
assertTrue(GateTalk.Response.newBuilder().mergeFrom(packet.getPayload()).build().getSuccess());
recvMsg = brk.getMessage(true, "bar.in");
assertEquals("test-route", new String(recvMsg));
recvMsg = brk.getMessage(true, "log.in");
assertEquals("test-route", new String(recvMsg));
brk.stop();