Program: 47786
Project: 47786
Buggy source:
@Test public void testSwitchingMasters() throws Exception {
  Config c1=buildConfig(false);
  Config c2=buildConfig(false);
  Config c3=buildConfig(false);
  Config c4=buildConfig(false);
  Config c5=buildConfig(false);
  c1.getNetworkConfig().setPort(55701);
  c2.getNetworkConfig().setPort(55702);
  c3.getNetworkConfig().setPort(55703);
  c4.getNetworkConfig().setPort(55704);
  c5.getNetworkConfig().setPort(55705);
  List<String> allMembers=Arrays.asList("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
  c1.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
  c2.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
  c3.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
  c4.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
  c5.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
  final HazelcastInstance h1=Hazelcast.newHazelcastInstance(c1);
  final HazelcastInstance h2=Hazelcast.newHazelcastInstance(c2);
  final HazelcastInstance h3=Hazelcast.newHazelcastInstance(c3);
  final HazelcastInstance h4=Hazelcast.newHazelcastInstance(c4);
  final HazelcastInstance h5=Hazelcast.newHazelcastInstance(c5);
  assertEquals(5,h1.getCluster().getMembers().size());
  assertEquals(5,h2.getCluster().getMembers().size());
  assertEquals(5,h3.getCluster().getMembers().size());
  assertEquals(5,h4.getCluster().getMembers().size());
  assertEquals(5,h5.getCluster().getMembers().size());
  Thread.sleep(15 * 1000);
  Member master=h1.getCluster().getLocalMember();
  assertEquals(master,h2.getCluster().getMembers().iterator().next());
  assertEquals(master,h3.getCluster().getMembers().iterator().next());
  assertEquals(master,h4.getCluster().getMembers().iterator().next());
  assertEquals(master,h5.getCluster().getMembers().iterator().next());
  h1.shutdown();
  assertEquals(4,h2.getCluster().getMembers().size());
  assertEquals(4,h3.getCluster().getMembers().size());
  assertEquals(4,h4.getCluster().getMembers().size());
  assertEquals(4,h5.getCluster().getMembers().size());
  master=h2.getCluster().getLocalMember();
  assertEquals(master,h2.getCluster().getMembers().iterator().next());
  assertEquals(master,h3.getCluster().getMembers().iterator().next());
  assertEquals(master,h4.getCluster().getMembers().iterator().next());
  assertEquals(master,h5.getCluster().getMembers().iterator().next());
  Thread.sleep(10 * 1000);
  assertEquals(4,h2.getCluster().getMembers().size());
  assertEquals(4,h3.getCluster().getMembers().size());
  assertEquals(4,h4.getCluster().getMembers().size());
  assertEquals(4,h5.getCluster().getMembers().size());
  assertEquals(master,h2.getCluster().getMembers().iterator().next());
  assertEquals(master,h3.getCluster().getMembers().iterator().next());
  assertEquals(master,h4.getCluster().getMembers().iterator().next());
  assertEquals(master,h5.getCluster().getMembers().iterator().next());
}

Fixed version (ground truth):
@Test public void testSwitchingMasters() throws Exception {
  List<HazelcastInstance> instanceList=buildInstances(5,55701);
  final HazelcastInstance h1=instanceList.get(0);
  final HazelcastInstance h2=instanceList.get(1);
  final HazelcastInstance h3=instanceList.get(2);
  final HazelcastInstance h4=instanceList.get(3);
  final HazelcastInstance h5=instanceList.get(4);
  assertEquals(5,h1.getCluster().getMembers().size());
  assertEquals(5,h2.getCluster().getMembers().size());
  assertEquals(5,h3.getCluster().getMembers().size());
  assertEquals(5,h4.getCluster().getMembers().size());
  assertEquals(5,h5.getCluster().getMembers().size());
  Thread.sleep(15 * 1000);
  Member master=h1.getCluster().getLocalMember();
  assertEquals(master,h2.getCluster().getMembers().iterator().next());
  assertEquals(master,h3.getCluster().getMembers().iterator().next());
  assertEquals(master,h4.getCluster().getMembers().iterator().next());
  assertEquals(master,h5.getCluster().getMembers().iterator().next());
  h1.shutdown();
  assertEquals(4,h2.getCluster().getMembers().size());
  assertEquals(4,h3.getCluster().getMembers().size());
  assertEquals(4,h4.getCluster().getMembers().size());
  assertEquals(4,h5.getCluster().getMembers().size());
  master=h2.getCluster().getLocalMember();
  assertEquals(master,h2.getCluster().getMembers().iterator().next());
  assertEquals(master,h3.getCluster().getMembers().iterator().next());
  assertEquals(master,h4.getCluster().getMembers().iterator().next());
  assertEquals(master,h5.getCluster().getMembers().iterator().next());
  Thread.sleep(10 * 1000);
  assertEquals(4,h2.getCluster().getMembers().size());
  assertEquals(4,h3.getCluster().getMembers().size());
  assertEquals(4,h4.getCluster().getMembers().size());
  assertEquals(4,h5.getCluster().getMembers().size());
  assertEquals(master,h2.getCluster().getMembers().iterator().next());
  assertEquals(master,h3.getCluster().getMembers().iterator().next());
  assertEquals(master,h4.getCluster().getMembers().iterator().next());
  assertEquals(master,h5.getCluster().getMembers().iterator().next());
}