Package org.jboss.as.clustering

Examples of org.jboss.as.clustering.GroupRpcDispatcher


    protected ClusterNode node2 = new MockClusterNode(2);
    protected ClusterNode node3 = new MockClusterNode(3);

    @Test
    public void start() throws Exception {
        GroupRpcDispatcher rpcDispatcher = mock(GroupRpcDispatcher.class);
        GroupMembershipNotifier notifier = mock(GroupMembershipNotifier.class);
        LocalLockHandler handler = mock(LocalLockHandler.class);
        try {
            createClusteredLockManager(null, rpcDispatcher, notifier, handler);
            fail("Null serviceHAName should prevent construction");
        } catch (IllegalArgumentException good) {
        }

        try {
            createClusteredLockManager("test", null, notifier, handler);
            fail("Null GroupRpcDispatcher should prevent construction");
        } catch (IllegalArgumentException good) {
        }

        try {
            createClusteredLockManager("test", rpcDispatcher, null, handler);
            fail("Null GroupMembershipNotifier should prevent construction");
        } catch (IllegalArgumentException good) {
        }

        try {
            createClusteredLockManager("test", rpcDispatcher, notifier, null);
            fail("Null LocalLockHandler should prevent construction");
        } catch (IllegalArgumentException good) {
        }

        when(rpcDispatcher.isConsistentWith(notifier)).thenReturn(Boolean.TRUE);
        when(rpcDispatcher.getClusterNode()).thenReturn(node1);
        when(rpcDispatcher.getGroupName()).thenReturn("TestPartition");

        T testee = createClusteredLockManager("test", rpcDispatcher, notifier, handler);

        assertEquals("test", testee.getServiceHAName());
        assertEquals("TestPartition", testee.getGroupName());
       
        try {
            testee.lock("id", 1000);
            fail("Call to lock() should fail if not started");
        } catch (IllegalStateException good) {
        }

        try {
            testee.unlock("id");
            fail("Call to unlock() should fail if not started");
        } catch (IllegalStateException good) {
        }

        assertEquals("Current view is empty when unstarted", 0, testee.getCurrentView().size());

        when(rpcDispatcher.getClusterNodes()).thenReturn(Arrays.asList(node1));

        testee.start();

        verify(rpcDispatcher).registerRPCHandler(eq("test"), any(RpcTarget.class), isA(ClassResolver.class));
        verify(notifier).registerGroupMembershipListener(testee);
View Full Code Here


    private void basicClusterLockTest(int viewSize) throws Exception {
        int viewPos = viewSize == 1 ? 0 : 1;
        TesteeSet<T> testeeSet = getTesteeSet(node1, viewPos, viewSize);
        AbstractClusterLockSupport testee = testeeSet.impl;
        GroupRpcDispatcher rpcDispatcher = testee.getGroupRpcDispatcher();
        LocalLockHandler handler = testee.getLocalHandler();

        List<RemoteLockResponse> rspList = new ArrayList<RemoteLockResponse>();
        for (int i = 0; i < viewSize - 1; i++) {
            rspList.add(new RemoteLockResponse(null, 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))).thenReturn(rspList);

        assertTrue(testee.lock("test", 200000));
       
        verify(handler).lockFromCluster(eq("test"), eq(node1), anyLong());
View Full Code Here

    @Test
    public void testRemoteRejectionFromSuperiorCaller() throws Exception {
        TesteeSet<T> testeeSet = getTesteeSet(node1, 1, 3);
        AbstractClusterLockSupport testee = testeeSet.impl;
        GroupRpcDispatcher rpcDispatcher = testee.getGroupRpcDispatcher();
/*
        resetToNice(partition);
        resetToStrict(handler);
*/
        ClusterNode superior = testee.getCurrentView().get(0);

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

        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);

        assertFalse(testee.lock("test", 50));
    }
View Full Code Here

    @Test
    public void testRemoteRejectionFromInferiorCaller() throws Exception {
        TesteeSet<T> testeeSet = getTesteeSet(node1, 1, 3);
        AbstractClusterLockSupport testee = testeeSet.impl;
        GroupRpcDispatcher rpcDispatcher = testee.getGroupRpcDispatcher();
        LocalLockHandler handler = testee.getLocalHandler();
/*
        resetToStrict(partition);
        resetToStrict(handler);
*/
        ClusterNode inferior = testee.getCurrentView().get(2);

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

        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((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>());

        rspList = new ArrayList<RemoteLockResponse>();
        rspList.add(new RemoteLockResponse(null, RemoteLockResponse.Flag.OK));
        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);

        assertTrue(testee.lock("test", 50));

        verify(handler).lockFromCluster(eq("test"), eq(node1), anyLong());
View Full Code Here

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

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

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

     */
    @Test
    public void testSpuriousRemoteLockReleaseIgnored() throws Exception {
        TesteeSet<T> testeeSet = getTesteeSet(node1, 1, 2);
        AbstractClusterLockSupport testee = testeeSet.impl;
        GroupRpcDispatcher rpcDispatcher = testee.getGroupRpcDispatcher();
        LocalLockHandler handler = testee.getLocalHandler();

        ClusterNode other = testee.getCurrentView().get(0);

        ArrayList<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"), LockParamsMatcher.eqLockParams(node1, 200000),
                AdditionalMatchers.aryEq(AbstractClusterLockSupport.REMOTE_LOCK_TYPES), eq(true), eq(NULL_FILTER), anyInt(), eq(false))).thenReturn(rspList);

        when(handler.getLockHolder("test")).thenReturn(node1);

        assertTrue(testee.lock("test", 200000));
View Full Code Here

        verify(handler, never()).unlockFromCluster("test", other);
    }

    protected TesteeSet<T> getTesteeSet(ClusterNode node, int viewPos, int viewSize) throws Exception {
        GroupRpcDispatcher rpcDispatcher = mock(GroupRpcDispatcher.class);
        GroupMembershipNotifier notifier = mock(GroupMembershipNotifier.class);
        LocalLockHandler handler = mock(LocalLockHandler.class);
        when(rpcDispatcher.isConsistentWith(notifier)).thenReturn(true);
        when(rpcDispatcher.getClusterNode()).thenReturn(node);
        when(rpcDispatcher.getGroupName()).thenReturn("TestPartition");

        ArgumentCaptor<RpcTarget> c = ArgumentCaptor.forClass(RpcTarget.class);
       
        List<ClusterNode> view = getView(node, viewPos, viewSize);
        when(rpcDispatcher.getClusterNodes()).thenReturn(view);
        when(rpcDispatcher.isConsistentWith(notifier)).thenReturn(true);
       
        T testee = createClusteredLockManager("test", rpcDispatcher, notifier, handler);

        testee.start();
       
View Full Code Here

    private void basicClusterLockFailsAgainstLocalLockTest(int viewSize) throws Exception {
        int viewPos = viewSize == 1 ? 0 : 1;
        TesteeSet<NonGloballyExclusiveClusterLockSupport> testeeSet = getTesteeSet(node1, viewPos, viewSize);
        NonGloballyExclusiveClusterLockSupport testee = testeeSet.impl;
        GroupRpcDispatcher rpcDispatcher = testee.getGroupRpcDispatcher();
        LocalLockHandler handler = testee.getLocalHandler();

        List<RemoteLockResponse> rspList = new ArrayList<RemoteLockResponse>();
        for (int i = 0; i < viewSize - 1; i++) {
            rspList.add(new RemoteLockResponse(null, RemoteLockResponse.Flag.OK));
        }

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

        doThrow(new TimeoutException(node1)).when(handler).lockFromCluster(eq("test"), eq(node1), 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>());
       
        assertFalse(testee.lock("test", 10));
    }
View Full Code Here

TOP

Related Classes of org.jboss.as.clustering.GroupRpcDispatcher

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.