Package org.jboss.as.clustering.lock.AbstractClusterLockSupport

Examples of org.jboss.as.clustering.lock.AbstractClusterLockSupport.RpcTarget


    public void testLocalLockingStateRejectsSuperiorRemoteCaller() throws Exception {
        TesteeSet<T> testeeSet = getTesteeSet(node1, 1, 3);
        T testee = testeeSet.impl;
        GroupRpcDispatcher rpcDispatcher = testee.getGroupRpcDispatcher();
        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);
*/
        List<RemoteLockResponse> rspList = new ArrayList<RemoteLockResponse>();
        rspList.add(new RemoteLockResponse(null, RemoteLockResponse.Flag.OK));

        when(rpcDispatcher.getMethodCallTimeout()).thenReturn(60000l);
        when(rpcDispatcher.<RemoteLockResponse>callMethodOnCluster(eq("test"), eq("remoteLock"), eqLockParams(node1, 200000),
                        aryEq(AbstractClusterLockSupport.REMOTE_LOCK_TYPES), eq(true), eq(NULL_FILTER), anyInt(), eq(false))).thenReturn(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);
        doAnswer(caller1Answer).when(handler).lockFromCluster(eq("test"), eq(node1), anyLong());

        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();
View Full Code Here


    public void testRemoteLockingStateAllowsSuperiorRemoteCaller() throws Exception {
        TesteeSet<T> testeeSet = getTesteeSet(node1, 1, 3);
        T testee = testeeSet.impl;
        GroupRpcDispatcher rpcDispatcher = testee.getGroupRpcDispatcher();
        LocalLockHandler handler = testee.getLocalHandler();
        final RpcTarget target = testeeSet.target;

        ClusterNode superiorCaller = testee.getCurrentView().get(0);
        assertFalse(node1.equals(superiorCaller));

        // When caller 1 invokes, block before giving response
        CountDownLatch answerAwaitLatch = new CountDownLatch(1);
        CountDownLatch answerStartLatch = new CountDownLatch(1);

        ArrayList<RemoteLockResponse> rspList = new ArrayList<RemoteLockResponse>();
        rspList.add(new RemoteLockResponse(null, RemoteLockResponse.Flag.OK));
        rspList.add(new RemoteLockResponse(null, RemoteLockResponse.Flag.REJECT, superiorCaller));

        BlockingAnswer<List<RemoteLockResponse>> caller1Answer = new BlockingAnswer<List<RemoteLockResponse>>(rspList,
                answerAwaitLatch, answerStartLatch, null);

        when(rpcDispatcher.getMethodCallTimeout()).thenReturn(60000l);
        doAnswer(caller1Answer).when(rpcDispatcher).callMethodOnCluster(eq("test"), eq("remoteLock"), eqLockParams(node1, 200000),
                        aryEq(AbstractClusterLockSupport.REMOTE_LOCK_TYPES), eq(true), eq(NULL_FILTER), anyInt(), eq(false));

        handler.lockFromCluster(eq("test"), eq(superiorCaller), anyLong());

        when((List<Object>) rpcDispatcher.callMethodOnCluster(eq("test"), eq("releaseRemoteLock"), aryEq(new Object[] { "test",
                        node1 }), aryEq(AbstractClusterLockSupport.RELEASE_REMOTE_LOCK_TYPES), eq(true))).thenReturn(
                new ArrayList<Object>());
/*
        replay(partition);
        replay(handler);
*/
        CountDownLatch finishedLatch = new CountDownLatch(1);
        LocalLockCaller loser = new LocalLockCaller(testee, null, null, finishedLatch);

        Thread t1 = new Thread(loser);
        t1.setDaemon(true);

        try {
            t1.start();
            assertTrue(answerStartLatch.await(1, TimeUnit.SECONDS));
            // t1 should now be blocking in caller1Answer

            RemoteLockResponse rsp = target.remoteLock("test", superiorCaller, 1);
            assertEquals(RemoteLockResponse.Flag.OK, rsp.flag);

            // release t1
            answerAwaitLatch.countDown();

View Full Code Here

    public void testBasicRemoteLock() throws Exception {
        TesteeSet<YieldingGloballyExclusiveClusterLockSupport> testeeSet = getTesteeSet(node1, 1, 2);
        YieldingGloballyExclusiveClusterLockSupport testee = testeeSet.impl;
        LocalLockHandler handler = testee.getLocalHandler();
        RpcTarget target = testeeSet.target;

        ClusterNode caller = testee.getCurrentView().get(0);
        assertFalse(node1.equals(caller));

        RemoteLockResponse rsp = target.remoteLock("test", caller, 1000);

        verify(handler).lockFromCluster("test", caller, 1000);
       
        assertEquals(RemoteLockResponse.Flag.OK, rsp.flag);
        assertNull(rsp.holder);

        // Do it again; should still work
        rsp = target.remoteLock("test", caller, 1000);

        verify(handler).lockFromCluster("test", caller, 1000);
       
        assertEquals(RemoteLockResponse.Flag.OK, rsp.flag);
        assertNull(rsp.holder);
View Full Code Here

    public void testContestedRemoteLock() throws Exception {
        TesteeSet<YieldingGloballyExclusiveClusterLockSupport> testeeSet = getTesteeSet(node1, 1, 3);
        YieldingGloballyExclusiveClusterLockSupport testee = testeeSet.impl;
        LocalLockHandler handler = testee.getLocalHandler();
        RpcTarget target = testeeSet.target;

        ClusterNode caller1 = testee.getCurrentView().get(0);
        assertFalse(node1.equals(caller1));

        ClusterNode caller2 = testee.getCurrentView().get(2);
        assertFalse(node1.equals(caller2));

        RemoteLockResponse rsp = target.remoteLock("test", caller1, 1000);

        verify(handler).lockFromCluster("test", caller1, 1000);

        assertEquals(RemoteLockResponse.Flag.OK, rsp.flag);
        assertNull(rsp.holder);

        // A call from a different caller should still work as
        // w/ supportLockOnly==false we only reject if WE hold the lock
        rsp = target.remoteLock("test", caller2, 1000);

        verify(handler).lockFromCluster("test", caller2, 1000);

        assertEquals(RemoteLockResponse.Flag.OK, rsp.flag);
        assertNull(rsp.holder);
View Full Code Here

     */
    public void testDeadMemberCleanupAllowsRemoteLock() throws Exception {
        TesteeSet<YieldingGloballyExclusiveClusterLockSupport> testeeSet = getTesteeSet(node1, 1, 3);
        YieldingGloballyExclusiveClusterLockSupport testee = testeeSet.impl;
        LocalLockHandler handler = testee.getLocalHandler();
        RpcTarget target = testeeSet.target;

        List<ClusterNode> members = testee.getCurrentView();
        ClusterNode caller1 = members.get(0);
        assertFalse(node1.equals(caller1));

        ClusterNode caller2 = members.get(2);
        assertFalse(node1.equals(caller2));

        RemoteLockResponse rsp = target.remoteLock("test", caller1, 1000);

        verify(handler).lockFromCluster("test", caller1, 1000);

        assertEquals(RemoteLockResponse.Flag.OK, rsp.flag);
        assertNull(rsp.holder);

        // Change the view
        Vector<ClusterNode> dead = new Vector<ClusterNode>();
        dead.add(caller1);

        Vector<ClusterNode> all = new Vector<ClusterNode>(members);
        all.remove(caller1);

        testee.membershipChanged(dead, new Vector<ClusterNode>(), all);

        // A call from a different caller should work
        rsp = target.remoteLock("test", caller2, 1000);

        verify(handler).lockFromCluster("test", caller2, 1000);

        assertEquals(RemoteLockResponse.Flag.OK, rsp.flag);
        assertNull(rsp.holder);
View Full Code Here

    public void testRemoteLockingStateRejectsInferiorRemoteCaller() throws Exception {
        TesteeSet<T> testeeSet = getTesteeSet(node1, 1, 3);
        T testee = testeeSet.impl;
        GroupRpcDispatcher rpcDispatcher = testee.getGroupRpcDispatcher();
        LocalLockHandler handler = testee.getLocalHandler();
        final RpcTarget target = testeeSet.target;

        ClusterNode inferiorNode = testee.getCurrentView().get(2);
        assertFalse(node1.equals(inferiorNode));

        ClusterNode superiorNode = testee.getCurrentView().get(0);
        assertFalse(node1.equals(superiorNode));

        // When caller 1 invokes, block before giving response
        CountDownLatch answerAwaitLatch = new CountDownLatch(1);
        CountDownLatch answerStartLatch = new CountDownLatch(1);

        ArrayList<RemoteLockResponse> rspList = new ArrayList<RemoteLockResponse>();
        rspList.add(new RemoteLockResponse(superiorNode, RemoteLockResponse.Flag.OK));
        rspList.add(new RemoteLockResponse(inferiorNode, RemoteLockResponse.Flag.REJECT, inferiorNode));

        BlockingAnswer<List<RemoteLockResponse>> caller1Answer = new BlockingAnswer<List<RemoteLockResponse>>(rspList, answerAwaitLatch, answerStartLatch, null);

        rspList = new ArrayList<RemoteLockResponse>();
        rspList.add(new RemoteLockResponse(superiorNode, RemoteLockResponse.Flag.OK));
        rspList.add(new RemoteLockResponse(inferiorNode, RemoteLockResponse.Flag.OK));

        when(rpcDispatcher.getMethodCallTimeout()).thenReturn(60000l);
        when(rpcDispatcher.<RemoteLockResponse>callMethodOnCluster(eq("test"), eq("remoteLock"), LockParamsMatcher.eqLockParams(node1, 200000),
                AdditionalMatchers.aryEq(AbstractClusterLockSupport.REMOTE_LOCK_TYPES), eq(true), eq(NULL_FILTER), anyInt(), eq(false))).thenAnswer(caller1Answer).thenReturn(rspList);

        when((List<Object>) rpcDispatcher.callMethodOnCluster(eq("test"), eq("releaseRemoteLock"), AdditionalMatchers.aryEq(new Object[] { "test", node1 }), AdditionalMatchers.aryEq(AbstractClusterLockSupport.RELEASE_REMOTE_LOCK_TYPES), eq(true))).thenReturn(new ArrayList<Object>());

        doNothing().when(handler).lockFromCluster(eq("test"), eq(node1), anyLong());

        CountDownLatch finishedLatch = new CountDownLatch(1);
        LocalLockCaller winner = new LocalLockCaller(testee, null, null, finishedLatch);

        Thread t1 = new Thread(winner);
        t1.setDaemon(true);

        try {
            t1.start();
            assertTrue(answerStartLatch.await(1, TimeUnit.SECONDS));
            // t1 should now be blocking in caller1Answer

            RemoteLockResponse rsp = target.remoteLock("test", inferiorNode, 1);
            assertEquals(RemoteLockResponse.Flag.REJECT, rsp.flag);
            assertEquals(node1, rsp.holder);

            // release t1
            answerAwaitLatch.countDown();
View Full Code Here

    @Test
    public void testBasicRemoteLock() throws Exception {
        TesteeSet<NonGloballyExclusiveClusterLockSupport> testeeSet = getTesteeSet(node1, 1, 2);
        NonGloballyExclusiveClusterLockSupport testee = testeeSet.impl;
        LocalLockHandler handler = testee.getLocalHandler();
        RpcTarget target = testeeSet.target;

        ClusterNode caller = testee.getCurrentView().get(0);
        assertFalse(node1.equals(caller));

//        resetToStrict(handler);
        RemoteLockResponse rsp = target.remoteLock("test", caller, 1000);

        assertEquals(RemoteLockResponse.Flag.OK, rsp.flag);
        assertNull(rsp.holder);

        verify(handler).lockFromCluster("test", caller, 1000);

        // Do it again; should fail as another thread from caller already
        // acquired the lock
//        resetToStrict(handler); // fail if we call the local handler
//        replay(handler);

        rsp = target.remoteLock("test", caller, 1000);

        assertEquals(RemoteLockResponse.Flag.REJECT, rsp.flag);
        assertEquals(caller, rsp.holder);

        verifyZeroInteractions(handler);
View Full Code Here

    @Test
    public void testContestedRemoteLock() throws Exception {
        TesteeSet<NonGloballyExclusiveClusterLockSupport> testeeSet = getTesteeSet(node1, 1, 3);
        NonGloballyExclusiveClusterLockSupport testee = testeeSet.impl;
        LocalLockHandler handler = testee.getLocalHandler();
        RpcTarget target = testeeSet.target;

        ClusterNode caller1 = testee.getCurrentView().get(0);
        assertFalse(node1.equals(caller1));

        ClusterNode caller2 = testee.getCurrentView().get(2);
        assertFalse(node1.equals(caller2));

        RemoteLockResponse rsp = target.remoteLock("test", caller1, 1000);

        assertEquals(RemoteLockResponse.Flag.OK, rsp.flag);
        assertNull(rsp.holder);

        verify(handler).lockFromCluster("test", caller1, 1000);

        // A call from a different caller should be rejected without need
        // to go to the LocalLockHandler
//        resetToStrict(handler);
//        replay(handler);

        rsp = target.remoteLock("test", caller2, 1000);

        assertEquals(RemoteLockResponse.Flag.REJECT, rsp.flag);
        assertEquals(caller1, rsp.holder);

        verifyNoMoreInteractions(handler);
View Full Code Here

    @Test
    public void testConcurrentRemoteLock() throws Exception {
        TesteeSet<NonGloballyExclusiveClusterLockSupport> testeeSet = getTesteeSet(node1, 1, 3);
        NonGloballyExclusiveClusterLockSupport testee = testeeSet.impl;
        LocalLockHandler handler = testee.getLocalHandler();
        final RpcTarget target = testeeSet.target;

        ClusterNode caller1 = testee.getCurrentView().get(0);
        assertFalse(node1.equals(caller1));

        ClusterNode caller2 = testee.getCurrentView().get(2);
View Full Code Here

    @Test
    public void testRemoteLockFailsAgainstLocalLock() throws Exception {
        TesteeSet<NonGloballyExclusiveClusterLockSupport> testeeSet = getTesteeSet(node1, 1, 2);
        NonGloballyExclusiveClusterLockSupport testee = testeeSet.impl;
        LocalLockHandler handler = testee.getLocalHandler();
        RpcTarget target = testeeSet.target;

        ClusterNode caller1 = testee.getCurrentView().get(0);
        assertFalse(node1.equals(caller1));

        // We throw TimeoutException to indicate "node1" holds the lock
        // A second attempt should succeed if the local lock is released
        // We return normally to indicate success
        doThrow(new TimeoutException(node1)).doNothing().when(handler).lockFromCluster("test", caller1, 1000);

        RemoteLockResponse rsp = target.remoteLock("test", caller1, 1000);

        assertEquals(RemoteLockResponse.Flag.FAIL, rsp.flag);
        assertEquals(node1, rsp.holder);

        rsp = target.remoteLock("test", caller1, 1000);
       
        assertEquals(RemoteLockResponse.Flag.OK, rsp.flag);
        assertNull(rsp.holder);
    }
View Full Code Here

TOP

Related Classes of org.jboss.as.clustering.lock.AbstractClusterLockSupport.RpcTarget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.