Package org.jboss.ha.framework.server.lock

Examples of org.jboss.ha.framework.server.lock.LocalLockHandler


   }

   public void testConstructor() throws Exception
   {
      HAPartition haPartition = createNiceMock(HAPartition.class);     
      LocalLockHandler handler = createNiceMock(LocalLockHandler.class);
     
      try
      {
         createClusteredLockManager(null, haPartition, handler);
         fail("Null serviceHAName should prevent construction");
View Full Code Here


   }

   public void testStart() throws Exception
   {
      HAPartition haPartition = createNiceMock(HAPartition.class);     
      LocalLockHandler handler = createNiceMock(LocalLockHandler.class);      
      expect(haPartition.getClusterNode()).andReturn(node1);
      expect(haPartition.getPartitionName()).andReturn("TestPartition");
     
      replay(haPartition);
      replay(handler);     
View Full Code Here

   {
      int viewPos = viewSize == 1 ? 0 : 1;
      TesteeSet<T> testeeSet = getTesteeSet(node1, viewPos, viewSize);
      AbstractClusterLockSupport testee = testeeSet.impl;
      HAPartition partition = testee.getPartition();
      LocalLockHandler handler = testee.getLocalHandler();
     
      resetToStrict(partition);
      resetToStrict(handler);
     
      ArrayList<RemoteLockResponse> rspList = new ArrayList<RemoteLockResponse>();
      for (int i = 0; i < viewSize - 1; i++)
      {
         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);
     
      handler.lockFromCluster(eq("test"), eq(node1), anyLong());
     
      replay(partition);
      replay(handler);
     
      assertTrue(testee.lock("test", 200000));
View Full Code Here

   public void testRemoteRejectionFromSuperiorCaller() throws Exception
   {
      TesteeSet<T> testeeSet = getTesteeSet(node1, 1, 3);
      AbstractClusterLockSupport testee = testeeSet.impl;
      HAPartition partition = testee.getPartition();
      LocalLockHandler handler = testee.getLocalHandler();
     
      resetToNice(partition);
      resetToStrict(handler);
     
      ClusterNode superior = testee.getCurrentView().get(0);
View Full Code Here

   public void testRemoteRejectionFromInferiorCaller() throws Exception
   {
      TesteeSet<T> testeeSet = getTesteeSet(node1, 1, 3);
      AbstractClusterLockSupport testee = testeeSet.impl;
      HAPartition partition = testee.getPartition();
      LocalLockHandler handler = testee.getLocalHandler();
     
      resetToStrict(partition);
      resetToStrict(handler);
     
      ClusterNode inferior = testee.getCurrentView().get(2);
     
      ArrayList<RemoteLockResponse> rspList = new ArrayList<RemoteLockResponse>();
      rspList.add(new RemoteLockResponse(null, RemoteLockResponse.Flag.OK));
      rspList.add(new RemoteLockResponse(null, RemoteLockResponse.Flag.REJECT, inferior));
     
     
      expect(partition.callMethodOnCluster(eq("test"),
                                           eq("remoteLock"),
                                           eqLockParams(node1, 200000),
                                           aryEq(AbstractClusterLockSupport.REMOTE_LOCK_TYPES),
                                           eq(true))).andReturn(rspList);

     
      expect(partition.callMethodOnCluster(eq("test"),
                                           eq("releaseRemoteLock"),
                                           aryEq(new Object[]{"test", node1}),
                                           aryEq(AbstractClusterLockSupport.RELEASE_REMOTE_LOCK_TYPES),
                                           eq(true))).andReturn(rspList);
     
      rspList = new ArrayList<RemoteLockResponse>();
      rspList.add(new RemoteLockResponse(null, RemoteLockResponse.Flag.OK));
      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);
     
      handler.lockFromCluster(eq("test"), eq(node1), anyLong());     
      expectLastCall().atLeastOnce();
     
      replay(partition);
      replay(handler);
     
View Full Code Here

   public void testLocalLockingStateRejectsSuperiorRemoteCaller() throws Exception
   {
      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);
     
View Full Code Here

   public void testRemoteLockingStateAllowsSuperiorRemoteCaller() throws Exception
   {
      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));

      resetToNice(partition);   // nice as we may loop retrying and failing
      makeThreadSafe(partition, true);
      resetToStrict(handler);  
      makeThreadSafe(handler, true);
     
      // 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<ArrayList<RemoteLockResponse>> caller1Answer = new BlockingAnswer<ArrayList<RemoteLockResponse>>(rspList, answerAwaitLatch, answerStartLatch, null);
     
      expect(partition.callMethodOnCluster(eq("test"),
                                           eq("remoteLock"),
                                           eqLockParams(node1, 200000),
                                           aryEq(AbstractClusterLockSupport.REMOTE_LOCK_TYPES),
                                           eq(true))).andAnswer(caller1Answer).atLeastOnce();
     
      handler.lockFromCluster(eq("test"), eq(superiorCaller), anyLong());  
     
      expect(partition.callMethodOnCluster(eq("test"),
            eq("releaseRemoteLock"),
            aryEq(new Object[]{"test", node1}),
            aryEq(AbstractClusterLockSupport.RELEASE_REMOTE_LOCK_TYPES),
View Full Code Here

   public void testRemoteLockingStateRejectsInferiorRemoteCaller() throws Exception
   {
      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 inferiorNode = testee.getCurrentView().get(2);
      assertFalse(node1.equals(inferiorNode));
     
      ClusterNode superiorNode = testee.getCurrentView().get(0);
      assertFalse(node1.equals(superiorNode));

      resetToStrict(partition);   
      makeThreadSafe(partition, true);
      resetToStrict(handler);  
      makeThreadSafe(handler, true);
     
      // 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<ArrayList<RemoteLockResponse>> caller1Answer =
         new BlockingAnswer<ArrayList<RemoteLockResponse>>(rspList, answerAwaitLatch, answerStartLatch, null);
     
      expect(partition.callMethodOnCluster(eq("test"),
                                           eq("remoteLock"),
                                           eqLockParams(node1, 200000),
                                           aryEq(AbstractClusterLockSupport.REMOTE_LOCK_TYPES),
                                           eq(true))).andAnswer(caller1Answer)
     
      expect(partition.callMethodOnCluster(eq("test"),
            eq("releaseRemoteLock"),
            aryEq(new Object[]{"test", node1}),
            aryEq(AbstractClusterLockSupport.RELEASE_REMOTE_LOCK_TYPES),
            eq(true))).andReturn(new ArrayList<Object>());
     
      rspList = new ArrayList<RemoteLockResponse>();
      rspList.add(new RemoteLockResponse(superiorNode, RemoteLockResponse.Flag.OK));
      rspList.add(new RemoteLockResponse(inferiorNode, RemoteLockResponse.Flag.OK));
     
      expect(partition.callMethodOnCluster(eq("test"),
                                           eq("remoteLock"),
                                           eqLockParams(node1, 200000),
                                           aryEq(AbstractClusterLockSupport.REMOTE_LOCK_TYPES),
                                           eq(true))).andReturn(rspList)
     
      handler.lockFromCluster(eq("test"), eq(node1), anyLong());
     
      replay(partition);
      replay(handler);

      CountDownLatch finishedLatch = new CountDownLatch(1);
View Full Code Here

   public void testSpuriousRemoteLockReleaseIgnored() throws Exception
   {
      TesteeSet<T> testeeSet = getTesteeSet(node1, 1, 2);
      AbstractClusterLockSupport testee = testeeSet.impl;
      HAPartition partition = testee.getPartition();
      LocalLockHandler handler = testee.getLocalHandler();
     
      ClusterNode other = testee.getCurrentView().get(0);
      resetToStrict(partition);
      resetToStrict(handler);
     
      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);
     
      handler.lockFromCluster(eq("test"), eq(node1), anyLong());
     
      expect(handler.getLockHolder("test")).andReturn(node1);
     
      replay(partition);
      replay(handler);
     
      assertTrue(testee.lock("test", 200000));
View Full Code Here

   }

   protected TesteeSet<T> getTesteeSet(ClusterNode node, int viewPos, int viewSize) throws Exception
   {
      HAPartition haPartition = createNiceMock(HAPartition.class);     
      LocalLockHandler handler = createNiceMock(LocalLockHandler.class);      
      expect(haPartition.getClusterNode()).andReturn(node);
      expect(haPartition.getPartitionName()).andReturn("TestPartition");
     
      Capture<RpcTarget>  c = new Capture<RpcTarget>();
      haPartition.registerRPCHandler(eq("test"), and(isA(RpcTarget.class), capture(c)));
View Full Code Here

TOP

Related Classes of org.jboss.ha.framework.server.lock.LocalLockHandler

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.