{
TesteeSet<T> testeeSet = getTesteeSet(node1, 1, 3);
T testee = testeeSet.impl;
HAPartition partition = testee.getPartition();
LocalLockHandler handler = testee.getLocalHandler();
final RpcTarget target = testeeSet.target;
ClusterNode superiorCaller = testee.getCurrentView().get(0);
assertFalse(node1.equals(superiorCaller));
resetToStrict(partition);
makeThreadSafe(partition, true);
resetToStrict(handler);
makeThreadSafe(handler, true);
ArrayList<RemoteLockResponse> rspList = new ArrayList<RemoteLockResponse>();
rspList.add(new RemoteLockResponse(null, RemoteLockResponse.Flag.OK));
expect(partition.callMethodOnCluster(eq("test"),
eq("remoteLock"),
eqLockParams(node1, 200000),
aryEq(AbstractClusterLockSupport.REMOTE_LOCK_TYPES),
eq(true))).andReturn(rspList);
// When caller 1 invokes, block before giving response
CountDownLatch answerAwaitLatch = new CountDownLatch(1);
CountDownLatch answerStartLatch = new CountDownLatch(1);
CountDownLatch answerDoneLatch = new CountDownLatch(1);
BlockingAnswer<Boolean> caller1Answer = new BlockingAnswer<Boolean>(Boolean.TRUE, answerAwaitLatch, answerStartLatch, null);
handler.lockFromCluster(eq("test"), eq(node1), anyLong());
expectLastCall().andAnswer(caller1Answer);
replay(partition);
replay(handler);
LocalLockCaller winner = new LocalLockCaller(testee, null, null, answerDoneLatch, 500);
Thread t1 = new Thread(winner);
t1.setDaemon(true);
try
{
t1.start();
assertTrue(answerStartLatch.await(500, TimeUnit.SECONDS));
// t1 should now be blocking in caller1Answer
RemoteLockResponse rsp = target.remoteLock("test", superiorCaller, 1);
assertEquals(RemoteLockResponse.Flag.REJECT, rsp.flag);
assertEquals(node1, rsp.holder);
// release t1
answerAwaitLatch.countDown();