use of org.apache.geode.management.membership.UniversalMembershipListenerAdapter in project geode by apache.
the class UniversalMembershipListenerAdapterDUnitTest method testNoDuplicates.
/**
* Tests use of history to prevent duplicate events.
*/
@Test
public void testNoDuplicates() throws Exception {
getSystem();
final boolean[] fired = new boolean[3];
final DistributedMember[] member = new DistributedMember[3];
final String[] memberId = new String[3];
UniversalMembershipListenerAdapter listener = new UniversalMembershipListenerAdapter() {
@Override
public synchronized void memberJoined(MembershipEvent event) {
assertFalse(fired[JOINED]);
assertNull(member[JOINED]);
assertNull(memberId[JOINED]);
fired[JOINED] = true;
member[JOINED] = event.getDistributedMember();
memberId[JOINED] = event.getMemberId();
notify();
}
@Override
public synchronized void memberLeft(MembershipEvent event) {
assertFalse(fired[LEFT]);
assertNull(member[LEFT]);
assertNull(memberId[LEFT]);
fired[LEFT] = true;
member[LEFT] = event.getDistributedMember();
memberId[LEFT] = event.getMemberId();
notify();
}
@Override
public synchronized void memberCrashed(MembershipEvent event) {
// assures no dupes
assertFalse(fired[CRASHED]);
assertNull(member[CRASHED]);
assertNull(memberId[CRASHED]);
fired[CRASHED] = true;
member[CRASHED] = event.getDistributedMember();
memberId[CRASHED] = event.getMemberId();
notify();
}
};
DistributedMember memberA = new TestDistributedMember("memberA");
ServerLocation serverA = new ServerLocation("serverA", 0);
// first join
InternalClientMembership.notifyClientJoined(memberA);
synchronized (listener) {
if (!fired[JOINED]) {
listener.wait(SYNC_ASYNC_EVENT_WAIT_MILLIS);
}
}
assertTrue(fired[JOINED]);
assertEquals(memberA, member[JOINED]);
assertEquals(memberA.getId(), memberId[JOINED]);
fired[JOINED] = false;
member[JOINED] = null;
memberId[JOINED] = null;
// duplicate join
InternalClientMembership.notifyClientJoined(memberA);
Wait.pause(BRIEF_PAUSE_MILLIS);
assertFalse(fired[JOINED]);
assertNull(member[JOINED]);
assertNull(memberId[JOINED]);
// first left
InternalClientMembership.notifyClientLeft(memberA);
synchronized (listener) {
if (!fired[LEFT]) {
listener.wait(SYNC_ASYNC_EVENT_WAIT_MILLIS);
}
}
assertTrue(fired[LEFT]);
assertEquals(memberA, member[LEFT]);
assertEquals(memberA.getId(), memberId[LEFT]);
fired[LEFT] = false;
member[LEFT] = null;
memberId[LEFT] = null;
// duplicate left
InternalClientMembership.notifyClientLeft(memberA);
Wait.pause(BRIEF_PAUSE_MILLIS);
assertFalse(fired[LEFT]);
assertNull(member[LEFT]);
assertNull(memberId[LEFT]);
// rejoin
InternalClientMembership.notifyClientJoined(memberA);
synchronized (listener) {
if (!fired[JOINED]) {
listener.wait(SYNC_ASYNC_EVENT_WAIT_MILLIS);
}
}
assertTrue(fired[JOINED]);
assertEquals(memberA, member[JOINED]);
assertEquals(memberA.getId(), memberId[JOINED]);
}
Aggregations