use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage 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.membership.gms.messages.JoinResponseMessage in project geode by apache.
the class JGroupsMessengerJUnitTest method testMessageFiltering.
@Test
public void testMessageFiltering() throws Exception {
initMocks(true);
InternalDistributedMember mbr = createAddress(8888);
NetView view = new NetView(mbr);
// the digest should be set in an outgoing join response
JoinResponseMessage joinResponse = new JoinResponseMessage(mbr, view, 0);
messenger.filterOutgoingMessage(joinResponse);
assertNotNull(joinResponse.getMessengerData());
// save the view digest for later
byte[] data = joinResponse.getMessengerData();
// the digest should be used and the message bytes nulled out in an incoming join response
messenger.filterIncomingMessage(joinResponse);
assertNull(joinResponse.getMessengerData());
// the digest shouldn't be set in an outgoing rejection message
joinResponse = new JoinResponseMessage("you can't join my distributed system. nyah nyah nyah!", 0);
messenger.filterOutgoingMessage(joinResponse);
assertNull(joinResponse.getMessengerData());
// the digest shouldn't be installed from an incoming rejection message
joinResponse.setMessengerData(data);
messenger.filterIncomingMessage(joinResponse);
assertNotNull(joinResponse.getMessengerData());
}
use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.
the class GMSJoinLeaveJUnitTest method testCoordinatorFindRequestFailure.
@Test
public void testCoordinatorFindRequestFailure() throws Exception {
try {
initMocks(false);
HashSet<InternalDistributedMember> registrants = new HashSet<>();
registrants.add(mockMembers[0]);
FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, null, registrants, false, true, null);
NetView view = createView();
JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view, 0);
gmsJoinLeave.setJoinResponseMessage(jrm);
TcpClientWrapper tcpClientWrapper = mock(TcpClientWrapper.class);
gmsJoinLeave.setTcpClientWrapper(tcpClientWrapper);
FindCoordinatorRequest fcreq = new FindCoordinatorRequest(gmsJoinLeaveMemberId, new HashSet<>(), -1, null, 0, "");
int connectTimeout = (int) services.getConfig().getMemberTimeout() * 2;
// passing wrong port here, so ot will fail
when(tcpClientWrapper.sendCoordinatorFindRequest(new InetSocketAddress("localhost", 12346), fcreq, connectTimeout)).thenReturn(fcr);
assertFalse("Should not be able to join ", gmsJoinLeave.join());
} finally {
}
}
use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.
the class GMSJoinLeaveJUnitTest method testProcessJoinResponseIsRecorded.
// This test does not test the actual join process but rather that the join response gets loggedß
@Test
public void testProcessJoinResponseIsRecorded() throws IOException {
initMocks();
when(services.getAuthenticator()).thenReturn(authenticator);
when(authenticator.authenticate(mockMembers[0], null)).thenThrow(new AuthenticationFailedException("we want to fail auth here"));
when(services.getMessenger()).thenReturn(messenger);
JoinResponseMessage[] joinResponse = gmsJoinLeave.getJoinResponseMessage();
JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], new byte[9], 233);
gmsJoinLeave.processMessage(jrm);
// this should NOT logs, this is just to inform member succesful joining
Assert.assertEquals(null, joinResponse[0]);
jrm = new JoinResponseMessage("rejected...", 0);
gmsJoinLeave.processMessage(jrm);
// this should log..
Assert.assertEquals(jrm, joinResponse[0]);
gmsJoinLeave.setJoinResponseMessage(null);
jrm = new JoinResponseMessage(mockMembers[0], new NetView(), 0);
gmsJoinLeave.processMessage(jrm);
// this should log..
Assert.assertEquals(jrm, joinResponse[0]);
}
use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.
the class GMSJoinLeave method waitForJoinResponse.
private JoinResponseMessage waitForJoinResponse() throws InterruptedException {
JoinResponseMessage response;
synchronized (joinResponse) {
if (joinResponse[0] == null && !isJoined) {
// Note that if we give up waiting but a response is on
// the way we will get the new view and join that way.
// See installView()
long timeout = Math.max(services.getConfig().getMemberTimeout(), services.getConfig().getJoinTimeout() / 5);
joinResponse.wait(timeout);
}
response = joinResponse[0];
if (response != null && response.getCurrentView() != null && !isJoined) {
// reset joinResponse[0]
joinResponse[0] = null;
// we got view here that means either we have to wait for
NetView v = response.getCurrentView();
InternalDistributedMember coord = v.getCoordinator();
if (searchState.alreadyTried.contains(coord)) {
searchState.view = response.getCurrentView();
// we already sent join request to it..so lets wait some more time here
// assuming we got this response immediately, so wait for same timeout here..
long timeout = Math.max(services.getConfig().getMemberTimeout(), services.getConfig().getJoinTimeout() / 5);
joinResponse.wait(timeout);
response = joinResponse[0];
} else {
// try on this coordinator
searchState.view = response.getCurrentView();
response = null;
}
searchState.view = v;
}
if (isJoined) {
return null;
}
}
return response;
}
Aggregations