use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class JGroupsMessengerJUnitTest method testEncryptedFindCoordinatorResponse.
@Test
public void testEncryptedFindCoordinatorResponse() throws Exception {
InternalDistributedMember otherMbr = new InternalDistributedMember("localhost", 8888);
Properties p = new Properties();
p.put(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
initMocks(false, p);
NetView v = createView(otherMbr);
GMSEncrypt otherMbrEncrptor = new GMSEncrypt(services);
otherMbrEncrptor.setPublicKey(messenger.getPublicKey(messenger.getMemberID()), messenger.getMemberID());
messenger.setPublicKey(otherMbrEncrptor.getPublicKeyBytes(), otherMbr);
messenger.initClusterKey();
FindCoordinatorResponse gfmsg = new FindCoordinatorResponse(messenger.getMemberID(), messenger.getMemberID(), messenger.getClusterSecretKey(), 1);
Set<InternalDistributedMember> recipients = new HashSet<>();
recipients.add(otherMbr);
gfmsg.setRecipients(recipients);
short version = Version.CURRENT_ORDINAL;
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
messenger.writeEncryptedMessage(gfmsg, version, out);
byte[] requestBytes = out.toByteArray();
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(requestBytes));
messenger.addRequestId(1, messenger.getMemberID());
DistributionMessage distributionMessage = messenger.readEncryptedMessage(dis, version, otherMbrEncrptor);
assertEquals(gfmsg, distributionMessage);
}
use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class JGroupsMessengerJUnitTest method doTestBigMessageIsFragmented.
public void doTestBigMessageIsFragmented(boolean mcastEnabled, boolean mcastMsg) throws Exception {
initMocks(mcastEnabled);
MessageHandler mh = mock(MessageHandler.class);
messenger.addHandler(JoinRequestMessage.class, mh);
InternalDistributedMember sender = messenger.getMemberID();
NetView v = new NetView(sender);
when(joinLeave.getView()).thenReturn(v);
messenger.installView(v);
JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0);
if (mcastMsg) {
msg.setMulticast(true);
}
messenger.send(msg);
int sentMessages = (mcastEnabled && mcastMsg) ? interceptor.mcastSentDataMessages : interceptor.unicastSentDataMessages;
assertTrue("expected 1 message to be sent but found " + sentMessages, sentMessages == 1);
// send a big message and expect fragmentation
msg = new JoinRequestMessage(messenger.localAddress, sender, new byte[(int) (services.getConfig().getDistributionConfig().getUdpFragmentSize() * (1.5))], -1, 0);
// configure an incoming message handler for JoinRequestMessage
final DistributionMessage[] messageReceived = new DistributionMessage[1];
MessageHandler handler = new MessageHandler() {
@Override
public void processMessage(DistributionMessage m) {
messageReceived[0] = m;
}
};
messenger.addHandler(JoinRequestMessage.class, handler);
// configure the outgoing message interceptor
interceptor.unicastSentDataMessages = 0;
interceptor.collectMessages = true;
interceptor.collectedMessages.clear();
messenger.send(msg);
assertTrue("expected 2 messages to be sent but found " + interceptor.unicastSentDataMessages, interceptor.unicastSentDataMessages == 2);
List<Message> messages = new ArrayList<>(interceptor.collectedMessages);
UUID fakeMember = new UUID(50, 50);
short unicastHeaderId = ClassConfigurator.getProtocolId(UNICAST3.class);
int seqno = 1;
for (Message m : messages) {
m.setSrc(fakeMember);
UNICAST3.Header oldHeader = (UNICAST3.Header) m.getHeader(unicastHeaderId);
if (oldHeader == null)
continue;
UNICAST3.Header newHeader = UNICAST3.Header.createDataHeader(seqno, oldHeader.connId(), seqno == 1);
seqno += 1;
m.putHeader(unicastHeaderId, newHeader);
interceptor.up(new Event(Event.MSG, m));
}
Thread.sleep(5000);
System.out.println("received message = " + messageReceived[0]);
}
use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class JGroupsMessengerJUnitTest method testEncryptedJoinResponse.
@Test
public void testEncryptedJoinResponse() throws Exception {
InternalDistributedMember otherMbr = new InternalDistributedMember("localhost", 8888);
Properties p = new Properties();
p.put(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
initMocks(false, p);
NetView v = createView(otherMbr);
GMSEncrypt otherMbrEncrptor = new GMSEncrypt(services);
otherMbrEncrptor.setPublicKey(messenger.getPublicKey(messenger.getMemberID()), messenger.getMemberID());
messenger.setPublicKey(otherMbrEncrptor.getPublicKeyBytes(), otherMbr);
messenger.initClusterKey();
JoinResponseMessage gfmsg = new JoinResponseMessage(otherMbr, messenger.getClusterSecretKey(), 1);
short version = Version.CURRENT_ORDINAL;
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
messenger.writeEncryptedMessage(gfmsg, version, out);
byte[] requestBytes = out.toByteArray();
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(requestBytes));
messenger.addRequestId(1, messenger.getMemberID());
DistributionMessage gfMessageAtOtherMbr = messenger.readEncryptedMessage(dis, version, otherMbrEncrptor);
assertEquals(gfmsg, gfMessageAtOtherMbr);
// lets send view as well..
InstallViewMessage installViewMessage = new InstallViewMessage(v, null, true);
out = new HeapDataOutputStream(Version.CURRENT);
messenger.writeEncryptedMessage(installViewMessage, version, out);
requestBytes = out.toByteArray();
otherMbrEncrptor.addClusterKey(((JoinResponseMessage) gfMessageAtOtherMbr).getSecretPk());
dis = new DataInputStream(new ByteArrayInputStream(requestBytes));
gfMessageAtOtherMbr = messenger.readEncryptedMessage(dis, version, otherMbrEncrptor);
assertEquals(installViewMessage, gfMessageAtOtherMbr);
}
use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class JGroupsMessengerJUnitTest method testEncryptedJoinRequest.
@Test
public void testEncryptedJoinRequest() throws Exception {
InternalDistributedMember otherMbr = new InternalDistributedMember("localhost", 8888);
Properties p = new Properties();
p.put(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
initMocks(false, p);
NetView v = createView(otherMbr);
GMSEncrypt otherMbrEncrptor = new GMSEncrypt(services);
messenger.setPublicKey(otherMbrEncrptor.getPublicKeyBytes(), otherMbr);
messenger.initClusterKey();
JoinRequestMessage gfmsg = new JoinRequestMessage(otherMbr, messenger.getMemberID(), null, 9789, 1);
short version = Version.CURRENT_ORDINAL;
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
messenger.writeEncryptedMessage(gfmsg, version, out);
byte[] requestBytes = out.toByteArray();
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(requestBytes));
DistributionMessage distributionMessage = messenger.readEncryptedMessage(dis, version, otherMbrEncrptor);
assertEquals(gfmsg, distributionMessage);
}
use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class DistributedLockServiceDUnitTest method testDestroyLockServiceBeforeGrantRequest.
@Test
public void testDestroyLockServiceBeforeGrantRequest() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
final String serviceName = getUniqueName();
vm0.invoke(new SerializableRunnable("Create the grantor") {
public void run() {
connectDistributedSystem();
final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
// lock and unlock to make sure this vm is grantor
assertTrue(service.lock("obj", -1, -1));
service.unlock("obj");
}
});
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof DLockRequestMessage) {
DistributedLockService.destroy(serviceName);
}
}
});
connectDistributedSystem();
final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
try {
service.lock("obj", -1, -1);
fail("The lock service should have been destroyed");
} catch (LockServiceDestroyedException expected) {
// Do nothing
}
vm0.invoke(new SerializableRunnable("check to make sure the lock is not orphaned") {
public void run() {
final DistributedLockService service = DistributedLockService.getServiceNamed(serviceName);
// lock and unlock to make sure this vm is grantor
assertTrue(service.lock("obj", -1, -1));
service.unlock("obj");
}
});
}
Aggregations