Program: 49681
Project: 49681
Buggy source:
@Test(timeout=100000) public void testKeyOwnerDies() throws Exception {
  final HazelcastInstance h1=Hazelcast.newHazelcastInstance(new Config());
  final IMap map1=h1.getMap("String_Node_Str");
  final HazelcastInstance h2=Hazelcast.newHazelcastInstance(new Config());
  final IMap map2=h2.getMap("String_Node_Str");
  final HazelcastInstance h3=Hazelcast.newHazelcastInstance(new Config());
  final IMap map3=h3.getMap("String_Node_Str");
  CMap cmap1=getCMap(h1,"String_Node_Str");
  CMap cmap2=getCMap(h2,"String_Node_Str");
  CMap cmap3=getCMap(h3,"String_Node_Str");
  Data dKey=toData(1);
  map1.put(1,1);
  migrateKey(1,h1,h2,0);
  migrateKey(1,h1,h3,1);
  cmap1.startCleanup(true);
  assertTrue(h1.getPartitionService().getPartition(1).getOwner().equals(h2.getCluster().getLocalMember()));
  assertTrue(h3.getPartitionService().getPartition(1).getOwner().equals(h2.getCluster().getLocalMember()));
  assertTrue(h2.getPartitionService().getPartition(1).getOwner().localMember());
  assertTrue(map1.tryLock(1));
  final CountDownLatch latchLock=new CountDownLatch(1);
  new Thread(new Runnable(){
    public void run(){
      try {
        map3.lock(1);
        assertTrue(latchLock.await(10,TimeUnit.SECONDS));
      }
 catch (      Throwable e) {
        fail();
      }
    }
  }
).start();
  Thread.sleep(2000);
  Record rec1=cmap1.getRecord(dKey);
  Record rec2=cmap2.getRecord(dKey);
  Record rec3=cmap3.getRecord(dKey);
  assertNull(rec1);
  assertNotNull(rec2);
  assertNotNull(rec3);
  DistributedLock lock2=rec2.getLock();
  DistributedLock lock3=rec3.getLock();
  assertEquals(1,rec2.getScheduledActionCount());
  assertTrue(rec2.getScheduledActions().iterator().next().isValid());
  Assert.assertNotNull(lock2);
  Assert.assertNotNull(lock3);
  System.out.println(lock2);
  System.out.println(lock3);
  h2.getLifecycleService().shutdown();
  Thread.sleep(3000);
  assertEquals(h3.getCluster().getLocalMember(),h1.getPartitionService().getPartition(1).getOwner());
  assertEquals(h3.getCluster().getLocalMember(),h3.getPartitionService().getPartition(1).getOwner());
  assertEquals(1,map1.put(1,2));
  rec3=cmap3.getRecord(dKey);
  assertEquals(1,rec3.getScheduledActionCount());
  assertTrue(rec3.getScheduledActions().iterator().next().isValid());
  map1.unlock(1);
  lock3=rec3.getLock();
  assertNotNull(lock3);
  assertEquals(lock3.getLockAddress(),((MemberImpl)h3.getCluster().getLocalMember()).getAddress());
  assertEquals(1,lock3.getLockCount());
  latchLock.countDown();
  assertFalse(map1.tryLock(1));
}

Fixed version (ground truth):
@Test(timeout=100000) public void testKeyOwnerDies() throws Exception {
  final HazelcastInstance h1=Hazelcast.newHazelcastInstance(new Config());
  final IMap map1=h1.getMap("String_Node_Str");
  final HazelcastInstance h2=Hazelcast.newHazelcastInstance(new Config());
  final IMap map2=h2.getMap("String_Node_Str");
  final HazelcastInstance h3=Hazelcast.newHazelcastInstance(new Config());
  final IMap map3=h3.getMap("String_Node_Str");
  CMap cmap1=getCMap(h1,"String_Node_Str");
  CMap cmap2=getCMap(h2,"String_Node_Str");
  CMap cmap3=getCMap(h3,"String_Node_Str");
  Data dKey=toData(1);
  map1.put(1,1);
  migrateKey(1,h1,h2,0);
  migrateKey(1,h1,h3,1);
  cmap1.startCleanup(true);
  assertTrue(h1.getPartitionService().getPartition(1).getOwner().equals(h2.getCluster().getLocalMember()));
  assertTrue(h3.getPartitionService().getPartition(1).getOwner().equals(h2.getCluster().getLocalMember()));
  assertTrue(h2.getPartitionService().getPartition(1).getOwner().localMember());
  assertTrue(map1.tryLock(1));
  final CountDownLatch latchLock=new CountDownLatch(1);
  new Thread(new Runnable(){
    public void run(){
      try {
        map3.lock(1);
        assertTrue(latchLock.await(10,TimeUnit.SECONDS));
      }
 catch (      Throwable e) {
        fail();
      }
    }
  }
).start();
  Thread.sleep(2000);
  Record rec1=cmap1.getRecord(dKey);
  Record rec2=cmap2.getRecord(dKey);
  Record rec3=cmap3.getRecord(dKey);
  assertNull(rec1);
  assertNotNull(rec2);
  assertNotNull(rec3);
  DistributedLock lock2=rec2.getLock();
  DistributedLock lock3=rec3.getLock();
  assertEquals(1,rec2.getScheduledActionCount());
  assertTrue(rec2.getScheduledActions().iterator().next().isValid());
  Assert.assertNotNull(lock2);
  Assert.assertNotNull(lock3);
  h2.getLifecycleService().shutdown();
  Thread.sleep(3000);
  assertEquals(h3.getCluster().getLocalMember(),h1.getPartitionService().getPartition(1).getOwner());
  assertEquals(h3.getCluster().getLocalMember(),h3.getPartitionService().getPartition(1).getOwner());
  assertEquals(1,map1.put(1,2));
  rec3=cmap3.getRecord(dKey);
  assertEquals(1,rec3.getScheduledActionCount());
  assertTrue(rec3.getScheduledActions().iterator().next().isValid());
  map1.unlock(1);
  lock3=rec3.getLock();
  assertNotNull(lock3);
  assertEquals(lock3.getLockAddress(),((MemberImpl)h3.getCluster().getLocalMember()).getAddress());
  assertEquals(1,lock3.getLockCount());
  latchLock.countDown();
  assertFalse(map1.tryLock(1));
}