Source:
<code>public void testMultiMemberRestart() throws ExecutionException, InterruptedException { HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(newConfig()); HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(newConfig()); HazelcastInstance client = hazelcastFactory.newHazelcastClient(newClientConfig()); Member oldMember1 = instance1.getCluster().getLocalMember(); Member oldMember2 = instance2.getCluster().getLocalMember(); final CountDownLatch memberAdded = new CountDownLatch(2); final Set<Member> addedMembers = Collections.newSetFromMap(new ConcurrentHashMap<Member, Boolean>()); final CountDownLatch memberRemoved = new CountDownLatch(2); final Set<Member> removedMembers = Collections.newSetFromMap(new ConcurrentHashMap<Member, Boolean>()); client.getCluster().addMembershipListener(new MembershipListener() { @Override public void memberAdded(MembershipEvent membershipEvent) { addedMembers.add(membershipEvent.getMember()); memberAdded.countDown(); } @Override public void memberRemoved(MembershipEvent membershipEvent) { removedMembers.add(membershipEvent.getMember()); memberRemoved.countDown(); } }); <START> changeClusterStateEventually(instance1, ClusterState.PASSIVE); <END> instance1.getCluster().shutdown(); Future<HazelcastInstance> f1 = spawn(() -> hazelcastFactory.newHazelcastInstance(newConfig())); Future<HazelcastInstance> f2 = spawn(() -> hazelcastFactory.newHazelcastInstance(newConfig())); instance1 = f1.get(); instance2 = f2.get(); Member newMember1 = instance1.getCluster().getLocalMember(); Member newMember2 = instance2.getCluster().getLocalMember(); assertOpenEventually(memberRemoved); assertEquals(2, removedMembers.size()); assertContains(removedMembers, oldMember1); assertContains(removedMembers, oldMember2); assertOpenEventually(memberAdded); assertEquals(2, addedMembers.size()); assertContains(addedMembers, newMember1); assertContains(addedMembers, newMember2); Set<Member> members = client.getCluster().getMembers(); assertContains(members, newMember1); assertContains(members, newMember2); assertEquals(2, members.size()); }</code><technical_language>test ClientClusterStateTest a similar cluster shutdown, do need test well</technical_language>

Target:
public void testMultiMemberRestart() throws ExecutionException, InterruptedException { HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(newConfig()); HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(newConfig()); HazelcastInstance client = hazelcastFactory.newHazelcastClient(newClientConfig()); Member oldMember1 = instance1.getCluster().getLocalMember(); Member oldMember2 = instance2.getCluster().getLocalMember(); final CountDownLatch memberAdded = new CountDownLatch(2); final Set<Member> addedMembers = Collections.newSetFromMap(new ConcurrentHashMap<Member, Boolean>()); final CountDownLatch memberRemoved = new CountDownLatch(2); final Set<Member> removedMembers = Collections.newSetFromMap(new ConcurrentHashMap<Member, Boolean>()); client.getCluster().addMembershipListener(new MembershipListener() { @Override public void memberAdded(MembershipEvent membershipEvent) { addedMembers.add(membershipEvent.getMember()); memberAdded.countDown(); } @Override public void memberRemoved(MembershipEvent membershipEvent) { removedMembers.add(membershipEvent.getMember()); memberRemoved.countDown(); } }); Cluster cluster = instance1.getCluster(); assertTrueEventually(() -> { try { cluster.shutdown(); } catch (Exception e) { throw new AssertionError(e); } }); Future<HazelcastInstance> f1 = spawn(() -> hazelcastFactory.newHazelcastInstance(newConfig())); Future<HazelcastInstance> f2 = spawn(() -> hazelcastFactory.newHazelcastInstance(newConfig())); instance1 = f1.get(); instance2 = f2.get(); Member newMember1 = instance1.getCluster().getLocalMember(); Member newMember2 = instance2.getCluster().getLocalMember(); assertOpenEventually(memberRemoved); assertEquals(2, removedMembers.size()); assertContains(removedMembers, oldMember1); assertContains(removedMembers, oldMember2); assertOpenEventually(memberAdded); assertEquals(2, addedMembers.size()); assertContains(addedMembers, newMember1); assertContains(addedMembers, newMember2); Set<Member> members = client.getCluster().getMembers(); assertContains(members, newMember1); assertContains(members, newMember2); assertEquals(2, members.size()); }