use of org.jgroups.BytesMessage in project JGroups by belaban.
the class MessageDispatcherUnitTest method sendMessage.
private void sendMessage(int size) throws Exception {
long start, stop;
MyHandler handler = new MyHandler(new byte[size]);
da.setRequestHandler(handler);
Message msg = new BytesMessage(null, buf);
RequestOptions opts = new RequestOptions(ResponseMode.GET_ALL, 0);
start = System.currentTimeMillis();
RspList<byte[]> rsps = da.castMessage(null, msg, opts);
stop = System.currentTimeMillis();
System.out.println("rsps:\n" + rsps);
System.out.println("call took " + (stop - start) + " ms");
assert rsps != null;
Assert.assertEquals(1, rsps.size());
byte[] tmp = rsps.getFirst();
assert tmp != null;
Assert.assertEquals(size, tmp.length);
}
use of org.jgroups.BytesMessage in project JGroups by belaban.
the class MessageDispatcherUnitTest method testNullMessageToSelf.
public void testNullMessageToSelf() throws Exception {
MyHandler handler = new MyHandler(null);
da.setRequestHandler(handler);
RspList<byte[]> rsps = da.castMessage(null, new BytesMessage(null, buf), new RequestOptions(ResponseMode.GET_ALL, 0));
System.out.println("rsps:\n" + rsps);
assert rsps != null;
assert 1 == rsps.size();
Object obj = rsps.getFirst();
assert obj == null;
}
use of org.jgroups.BytesMessage in project JGroups by belaban.
the class UnicastTestTcpSlow method readMessage.
protected static Message readMessage(byte[] buf, int offset, int length) throws Exception {
ByteArrayDataInputStream in = new ByteArrayDataInputStream(buf, offset, length);
short ver = in.readShort();
byte flags = in.readByte();
// final boolean multicast=(flags & (byte)2) == (byte)2;
// don't create headers, readFrom() will do this
Message msg = new BytesMessage();
msg.readFrom(in);
return msg;
}
use of org.jgroups.BytesMessage in project JGroups by belaban.
the class UnicastTestTcpSlow method sendMessages.
void sendMessages() throws Exception {
if (num_threads > 1 && num_msgs % num_threads != 0) {
System.err.println("num_msgs (" + num_msgs + " ) has to be divisible by num_threads (" + num_threads + ")");
return;
}
System.out.println("sending " + num_msgs + " messages (" + Util.printBytes(msg_size) + ") to " + remote + ": oob=" + oob + ", " + num_threads + " sender thread(s)");
ByteBuffer buf = ByteBuffer.allocate(Global.BYTE_SIZE + Global.LONG_SIZE).put(START).putLong(num_msgs);
Message msg = new BytesMessage(null, buf.array());
// msg.writeTo(output);
ByteArrayDataOutputStream dos = new ByteArrayDataOutputStream(msg.size());
byte flags = 0;
// write the version
dos.writeShort(Version.version);
if (msg.getDest() == null)
flags += (byte) 2;
dos.writeByte(flags);
msg.writeTo(dos);
ByteArray buffer = dos.getBuffer();
// need to sync if we have more than 1 sender
output_lock.lock();
try {
// msg.writeTo(output);
output.writeInt(buffer.getLength());
output.write(buffer.getArray(), buffer.getOffset(), buffer.getLength());
} finally {
output_lock.unlock();
}
int msgs_per_sender = num_msgs / num_threads;
Sender[] senders = new Sender[num_threads];
for (int i = 0; i < senders.length; i++) senders[i] = new Sender(msgs_per_sender, msg_size, num_msgs / 10);
for (Sender sender : senders) sender.start();
for (Sender sender : senders) sender.join();
output.flush();
System.out.println("done sending " + num_msgs + " to " + remote);
}
use of org.jgroups.BytesMessage in project JGroups by belaban.
the class TableTest method _testSeqnoOverflow.
protected static void _testSeqnoOverflow(long seqno, final int delta) {
long orig_seqno = seqno;
Table<Message> win = new Table<>(3, 10, seqno);
for (int i = 1; i <= delta; i++) {
Message msg = new BytesMessage(null, "hello");
win.add(++seqno, msg);
}
System.out.println("win = " + win);
assert win.size() == delta;
assertIndices(win, orig_seqno, orig_seqno, seqno);
List<Message> msgs = win.removeMany(true, 200, null);
System.out.printf("removed %d msgs\n", msgs.size());
assert win.isEmpty();
assertIndices(win, seqno, seqno, seqno);
}
Aggregations