use of org.apache.geode.distributed.internal.membership.NetView 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.NetView 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.membership.NetView in project geode by apache.
the class JGroupsMessengerJUnitTest method testReceiver.
@Test
public void testReceiver() throws Exception {
try {
DistributionStats.enableClockStats = true;
initMocks(false);
JGroupsReceiver receiver = (JGroupsReceiver) messenger.myChannel.getReceiver();
// a zero-length message is ignored
Message msg = new Message(new JGAddress(messenger.getMemberID()));
Object result = messenger.readJGMessage(msg);
assertNull(result);
// for code coverage we need to pump this message through the receiver
receiver.receive(msg);
// for more code coverage we need to actually set a buffer in the message
msg.setBuffer(new byte[0]);
result = messenger.readJGMessage(msg);
assertNull(result);
receiver.receive(msg);
// now create a view and a real distribution-message
InternalDistributedMember myAddress = messenger.getMemberID();
InternalDistributedMember other = createAddress(8888);
NetView v = new NetView(myAddress);
v.add(other);
when(joinLeave.getView()).thenReturn(v);
messenger.installView(v);
List<InternalDistributedMember> recipients = v.getMembers();
SerialAckedMessage dmsg = new SerialAckedMessage();
dmsg.setRecipients(recipients);
// a message is ignored during manager shutdown
msg = messenger.createJGMessage(dmsg, new JGAddress(other), Version.CURRENT_ORDINAL);
when(manager.shutdownInProgress()).thenReturn(Boolean.TRUE);
receiver.receive(msg);
verify(manager, never()).processMessage(isA(DistributionMessage.class));
assertTrue("There should be UDPDispatchRequestTime stats", services.getStatistics().getUDPDispatchRequestTime() > 0);
} finally {
DistributionStats.enableClockStats = false;
}
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSMembershipManagerJUnitTest method testReplyProcessorInitiatesSuspicion.
@Test
public void testReplyProcessorInitiatesSuspicion() throws Exception {
DM dm = mock(DM.class);
DMStats stats = mock(DMStats.class);
InternalDistributedSystem system = InternalDistributedSystem.newInstanceForTesting(dm, distProperties);
when(dm.getStats()).thenReturn(stats);
when(dm.getSystem()).thenReturn(system);
when(dm.getCancelCriterion()).thenReturn(stopper);
when(dm.getMembershipManager()).thenReturn(manager);
when(dm.getViewMembers()).thenReturn(members);
when(dm.getDistributionManagerIds()).thenReturn(new HashSet(members));
when(dm.addMembershipListenerAndGetDistributionManagerIds(any(MembershipListener.class))).thenReturn(new HashSet(members));
manager.start();
manager.started();
manager.isJoining = true;
List<InternalDistributedMember> viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], mockMembers[1], myMemberId });
manager.installView(new NetView(myMemberId, 2, viewmembers));
List<InternalDistributedMember> mbrs = new ArrayList<>(1);
mbrs.add(mockMembers[0]);
ReplyProcessor21 rp = new ReplyProcessor21(dm, mbrs);
rp.enableSevereAlertProcessing();
boolean result = rp.waitForReplies(WAIT_FOR_REPLIES_MILLIS);
// the wait should have timed out
assertFalse(result);
verify(healthMonitor, atLeastOnce()).checkIfAvailable(isA(InternalDistributedMember.class), isA(String.class), isA(Boolean.class));
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSMembershipManagerJUnitTest method testStartupEvents.
@Test
public void testStartupEvents() throws Exception {
manager.start();
manager.started();
manager.isJoining = true;
List<InternalDistributedMember> viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], myMemberId });
manager.installView(new NetView(myMemberId, 2, viewmembers));
// add a surprise member that will be shunned due to it's having
// an old view ID
InternalDistributedMember surpriseMember = mockMembers[2];
surpriseMember.setVmViewId(1);
manager.handleOrDeferSurpriseConnect(surpriseMember);
assertEquals(1, manager.getStartupEvents().size());
// add a surprise member that will be accepted
InternalDistributedMember surpriseMember2 = mockMembers[3];
surpriseMember2.setVmViewId(3);
manager.handleOrDeferSurpriseConnect(surpriseMember2);
assertEquals(2, manager.getStartupEvents().size());
// suspect a member
InternalDistributedMember suspectMember = mockMembers[1];
manager.handleOrDeferSuspect(new SuspectMember(mockMembers[0], suspectMember, "testing"));
// suspect messages aren't queued - they're ignored before joining the system
assertEquals(2, manager.getStartupEvents().size());
verify(listener, never()).memberSuspect(suspectMember, mockMembers[0], "testing");
HighPriorityAckedMessage m = new HighPriorityAckedMessage();
mockMembers[0].setVmViewId(1);
m.setRecipient(mockMembers[0]);
m.setSender(mockMembers[1]);
manager.handleOrDeferMessage(m);
assertEquals(3, manager.getStartupEvents().size());
// this view officially adds surpriseMember2
viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], myMemberId, surpriseMember2 });
manager.handleOrDeferViewEvent(new NetView(myMemberId, 3, viewmembers));
assertEquals(4, manager.getStartupEvents().size());
// add a surprise member that will be shunned due to it's having
// an old view ID
InternalDistributedMember surpriseMember3 = mockMembers[4];
surpriseMember.setVmViewId(1);
manager.handleOrDeferSurpriseConnect(surpriseMember);
assertEquals(5, manager.getStartupEvents().size());
// process a new view after we finish joining but before event processing has started
manager.isJoining = false;
mockMembers[4].setVmViewId(4);
viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], myMemberId, surpriseMember2, mockMembers[4] });
manager.handleOrDeferViewEvent(new NetView(myMemberId, 4, viewmembers));
assertEquals(6, manager.getStartupEvents().size());
// exercise the toString methods for code coverage
for (StartupEvent ev : manager.getStartupEvents()) {
ev.toString();
}
manager.startEventProcessing();
// all startup events should have been processed
assertEquals(0, manager.getStartupEvents().size());
// the new view should have been installed
assertEquals(4, manager.getView().getViewId());
// supriseMember2 should have been announced
verify(listener).newMemberConnected(surpriseMember2);
// supriseMember should have been rejected (old view ID)
verify(listener, never()).newMemberConnected(surpriseMember);
// for code coverage also install a view after we finish joining but before
// event processing has started. This should notify the distribution manager
// with a LocalViewMessage to process the view
reset(listener);
manager.handleOrDeferViewEvent(new NetView(myMemberId, 5, viewmembers));
assertEquals(0, manager.getStartupEvents().size());
verify(listener).messageReceived(isA(LocalViewMessage.class));
// process a suspect now - it will be passed to the listener
reset(listener);
suspectMember = mockMembers[1];
manager.handleOrDeferSuspect(new SuspectMember(mockMembers[0], suspectMember, "testing"));
verify(listener).memberSuspect(suspectMember, mockMembers[0], "testing");
}
Aggregations