use of org.jgroups.BytesMessage in project JGroups by belaban.
the class MessageDispatcherUnitTest method testNullMessageToAll.
public void testNullMessageToAll() throws Exception {
da.setRequestHandler(new MyHandler(null));
b = createChannel().name("B");
long stop, start = System.currentTimeMillis();
db = new MessageDispatcher(b, new MyHandler(null));
stop = System.currentTimeMillis();
b.connect("MessageDispatcherUnitTest");
Assert.assertEquals(2, b.getView().size());
System.out.println("view: " + b.getView());
System.out.println("casting message");
start = System.currentTimeMillis();
RspList<byte[]> rsps = da.castMessage(null, new BytesMessage(null, buf), new RequestOptions(ResponseMode.GET_ALL, 0));
stop = System.currentTimeMillis();
System.out.println("rsps:\n" + rsps);
System.out.println("call took " + (stop - start) + " ms");
assert rsps != null;
assert 2 == rsps.size();
Rsp<byte[]> rsp = rsps.get(a.getAddress());
assert rsp != null;
Object ret = rsp.getValue();
assert ret == null;
rsp = rsps.get(b.getAddress());
assert rsp != null;
ret = rsp.getValue();
assert ret == null;
}
use of org.jgroups.BytesMessage in project JGroups by belaban.
the class ByteBufferOutputStreamTest method testConstruction.
public void testConstruction() throws Exception {
Address dest = Util.createRandomAddress("A");
Message msg = new BytesMessage(dest, "hello world").setFlag(Message.Flag.DONT_BUNDLE, Message.Flag.OOB).putHeader((short) 22, NakAckHeader2.createMessageHeader(322649));
int size = msg.size();
ByteBuffer buf = ByteBuffer.allocate(size);
ByteBufferOutputStream out = new ByteBufferOutputStream(buf);
msg.writeTo(out);
buf.flip();
byte[] array = new byte[buf.limit()];
System.arraycopy(buf.array(), buf.arrayOffset(), array, 0, buf.limit());
ByteBufferInputStream in = new ByteBufferInputStream(ByteBuffer.wrap(array));
Message copy = new BytesMessage();
copy.readFrom(in);
System.out.println("copy = " + copy);
assert msg.getDest() != null && msg.getDest().equals(dest);
}
use of org.jgroups.BytesMessage in project JGroups by belaban.
the class STABLE_Test method testStableWithDontLoopback.
public void testStableWithDontLoopback() throws Exception {
byte[] payload = new byte[5000];
for (int i = 0; i < 10; i++) {
Message msg = new BytesMessage(null, payload).setFlag(Message.TransientFlag.DONT_LOOPBACK);
b.send(msg);
// prevents batches, which trigger STABLE msgs in non-10000 increments
Util.sleep(200);
}
Util.waitUntil(5000, 500, () -> Stream.of(r1, r3).allMatch(r -> r.size() == 10));
assert r2.size() == 0;
Util.waitUntilTrue(5000, 500, () -> Stream.of(a, b, c).map(c -> ((NAKACK2) c.getProtocolStack().findProtocol(NAKACK2.class)).getWindow(b.getAddress())).allMatch(t -> t.getHighestReceived() == 10 && t.getHighestDelivered() == 10 && t.getLow() == 10));
for (JChannel ch : List.of(a, b, c)) {
NAKACK2 n = ch.getProtocolStack().findProtocol(NAKACK2.class);
Table<Message> t = n.getWindow(b.getAddress());
assert t.getHighestReceived() == 10 && t.getHighestDelivered() == 10 && t.getLow() == 10 : String.format("table for %s is %s (low is probably 0)", ch.getName(), t);
}
}
use of org.jgroups.BytesMessage in project JGroups by belaban.
the class ENCRYPTKeystoreTest method testEncryptEntireMessage.
public void testEncryptEntireMessage() throws Exception {
SYM_ENCRYPT encrypt = create("defaultStore.keystore");
Message msg = new BytesMessage(null, "hello world".getBytes()).putHeader((short) 1, new TpHeader("cluster"));
MockProtocol mock = new MockProtocol();
encrypt.setDownProtocol(mock);
encrypt.down(msg);
Message encrypted_msg = mock.getDownMessages().get("message0");
encrypt.setDownProtocol(null);
encrypt.setUpProtocol(mock);
encrypt.up(encrypted_msg);
Message decrypted_msg = mock.getUpMessages().get("message1");
String temp = new String(decrypted_msg.getArray(), decrypted_msg.getOffset(), decrypted_msg.getLength());
assert "hello world".equals(temp);
}
use of org.jgroups.BytesMessage in project JGroups by belaban.
the class ENCRYPTKeystoreTest method testMessageUpDecode.
public void testMessageUpDecode() throws Exception {
SYM_ENCRYPT encrypt = create("defaultStore.keystore"), encrypt2 = create("defaultStore.keystore");
MockProtocol observer = new MockProtocol();
encrypt.setUpProtocol(observer);
String messageText = "hello this is a test message";
byte[] bytes = messageText.getBytes();
byte[] iv = encrypt2.makeIv();
byte[] encodedBytes = encrypt2.code(bytes, 0, bytes.length, iv, false);
assert !new String(encodedBytes).equals(messageText);
MessageDigest digest = MessageDigest.getInstance("MD5");
digest.reset();
digest.update(encrypt.secretKey().getEncoded());
byte[] symVersion = digest.digest();
Message msg = new BytesMessage(null, encodedBytes).putHeader(ENCRYPT_ID, new EncryptHeader((byte) 0, symVersion, iv));
encrypt.up(msg);
Message rcvdMsg = observer.getUpMessages().get("message0");
String decText = new String(rcvdMsg.getArray(), rcvdMsg.getOffset(), rcvdMsg.getLength());
assert decText.equals(messageText);
}
Aggregations