Skip to content

Commit

Permalink
Merge pull request #13825 from sancar/fix/ClientLockRetryWhenOwnerDie…
Browse files Browse the repository at this point in the history
…sTest/maint3.x

Fixing a timing issue on ClientLockRetryWhenOwnerDiesTest
  • Loading branch information
mustafa sancar koyunlu committed Sep 24, 2018
2 parents 65a18c3 + 52df8d6 commit 8f5ac07
Showing 1 changed file with 16 additions and 7 deletions.
Expand Up @@ -23,6 +23,7 @@
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ILock;
import com.hazelcast.core.IMap;
import com.hazelcast.core.Member;
import com.hazelcast.test.HazelcastParallelParametersRunnerFactory;
import com.hazelcast.test.annotation.ParallelTest;
import com.hazelcast.test.annotation.QuickTest;
Expand Down Expand Up @@ -251,11 +252,12 @@ public void testKeyOwnerCloses_afterInvocationTimeout() throws Exception {
String.valueOf(TimeUnit.MILLISECONDS.toSeconds(invocationTimeoutMillis)));
final HazelcastInstance client = factory.newHazelcastClient(clientConfig);

//this is needed in the test because we set the timeout too short for faster test.
makeSureConnectedToServers(client, 2);

final String key = generateKeyOwnedBy(keyOwner);
ILock serverLock = client.getLock(key);
serverLock.lock();
ILock lock = client.getLock(key);
lock.lock();

final CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable() {
Expand All @@ -268,11 +270,18 @@ public void run() {
Thread.sleep(invocationTimeoutMillis * 2);
closePolicy.accept(keyOwner);

assertTrue(serverLock.isLocked());
assertTrue(serverLock.isLockedByCurrentThread());
assertTrue(serverLock.tryLock());
serverLock.unlock();
serverLock.unlock();
//wait for the key owned by second member after close to avoid operation timeout during transition
//this is needed in the test because we set the timeout too short for faster test.
Member secondMember = instance.getCluster().getLocalMember();
while (!secondMember.equals(client.getPartitionService().getPartition(key).getOwner())) {
Thread.sleep(100);
}

assertTrue(lock.isLocked());
assertTrue(lock.isLockedByCurrentThread());
assertTrue(lock.tryLock());
lock.unlock();
lock.unlock();
assertOpenEventually(latch);
}

Expand Down

0 comments on commit 8f5ac07

Please sign in to comment.