You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2014/02/19 17:30:11 UTC

svn commit: r1569813 - in /qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src: main/java/org/apache/qpid/server/store/berkeleydb/replication/ test/java/org/apache/qpid/server/store/berkeleydb/replication/

Author: orudyy
Date: Wed Feb 19 16:30:10 2014
New Revision: 1569813

URL: http://svn.apache.org/r1569813
Log:
QPID-5409: Fix failing unit test LocalReplicationNodeWithReplicatedEnvironmentFacadeTest#testSetRole

Modified:
    qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNode.java
    qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/RemoteReplicationNode.java
    qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
    qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNodeWithReplicatedEnvironmentFacadeTest.java

Modified: qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNode.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNode.java?rev=1569813&r1=1569812&r2=1569813&view=diff
==============================================================================
--- qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNode.java (original)
+++ qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNode.java Wed Feb 19 16:30:10 2014
@@ -446,6 +446,11 @@ public class LocalReplicationNode extend
     @Override
     protected boolean setState(State currentState, State desiredState)
     {
+        if (desiredState == getActualState())
+        {
+            return false;
+        }
+
         switch (desiredState)
         {
         case ACTIVE:
@@ -454,9 +459,7 @@ public class LocalReplicationNode extend
                 _replicatedEnvironmentFacade = _factory.createReplicatedEnvironmentFacade(this, new DefaultRemoteReplicationNodeFactory(_virtualHost));
                 return true;
             }
-        //TODO: Should we use UNAVAILABLE state instead of STOPPED to to stop the node
-        //      When node is stopped the corresponding remote node will have UNAVAILABLE state...
-        //      Alternatively, on DBPing failure, we can display the remote node state as STOPPED
+            break;
         case STOPPED:
             if (_state.compareAndSet(State.ACTIVE, State.STOPPED))
             {
@@ -466,6 +469,7 @@ public class LocalReplicationNode extend
                 }
                 return true;
             }
+            break;
         case DELETED:
             if (getActualState() == State.ACTIVE)
             {
@@ -477,22 +481,15 @@ public class LocalReplicationNode extend
             {
                 return true;
             }
+            break;
         case INITIALISING:
         case UNAVAILABLE:
         case ERRORED:
         case QUIESCED:
         default:
-            if (getActualState() == desiredState)
-            {
-                return false;
-            }
-            else
-            {
-                throw new IllegalStateTransitionException("Cannot transit into desired state " + desiredState + " from "
-                        + currentState);
-            }
-
         }
+        throw new IllegalStateTransitionException("Cannot transit into desired state " + desiredState + " from "
+                + currentState);
     }
 
     @Override

Modified: qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/RemoteReplicationNode.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/RemoteReplicationNode.java?rev=1569813&r1=1569812&r2=1569813&view=diff
==============================================================================
--- qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/RemoteReplicationNode.java (original)
+++ qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/RemoteReplicationNode.java Wed Feb 19 16:30:10 2014
@@ -258,6 +258,7 @@ public class RemoteReplicationNode exten
         }
         catch (IOException e)
         {
+            //TODO: Should it be STOPPED?
             _role = com.sleepycat.je.rep.ReplicatedEnvironment.State.UNKNOWN.name();
             LOGGER.warn("Cannot connect to node " + _replicationNode.getName() + " from " + _groupName);
         }

Modified: qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java?rev=1569813&r1=1569812&r2=1569813&view=diff
==============================================================================
--- qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java (original)
+++ qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java Wed Feb 19 16:30:10 2014
@@ -346,6 +346,14 @@ public class ReplicatedEnvironmentFacade
                 }
             });
         }
+        else
+        {
+            if (LOGGER.isDebugEnabled())
+            {
+                LOGGER.debug("Ignoring the state environment change event as the environment facade for node '" + _prettyGroupNodeName
+                        + "' is in state " + _state.get());
+            }
+        }
     }
 
     private void stateChanged(StateChangeEvent stateChangeEvent)
@@ -931,6 +939,10 @@ public class ReplicatedEnvironmentFacade
             restore.execute(ile, config);
             environment = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
         }
+        if (LOGGER.isInfoEnabled())
+        {
+            LOGGER.info("Environment is created for node " + _prettyGroupNodeName);
+        }
         return environment;
     }
 

Modified: qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNodeWithReplicatedEnvironmentFacadeTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNodeWithReplicatedEnvironmentFacadeTest.java?rev=1569813&r1=1569812&r2=1569813&view=diff
==============================================================================
--- qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNodeWithReplicatedEnvironmentFacadeTest.java (original)
+++ qpid/branches/java-broker-bdb-ha/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNodeWithReplicatedEnvironmentFacadeTest.java Wed Feb 19 16:30:10 2014
@@ -63,6 +63,7 @@ public class LocalReplicationNodeWithRep
        when(_virtualHost.getAttribute(VirtualHost.REMOTE_REPLICATION_NODE_MONITOR_INTERVAL)).thenReturn(100l);
        when(_virtualHost.getTaskExecutor()).thenReturn(_taskExecutor);
        _evironmentWorkingFolder = TMP_FOLDER + File.separator + getTestName();
+       FileUtils.delete(new File(_evironmentWorkingFolder), true);
    }
 
    @Override
@@ -176,17 +177,38 @@ public class LocalReplicationNodeWithRep
        int replicaPort = getNextAvailable(port + 1);
        Map<String, Object> replicaAttributes = createValidAttributes(replicaPort, port);
        String replicaEnvironmentFolder = _evironmentWorkingFolder + "-replica";
+       FileUtils.delete(new File(replicaEnvironmentFolder), true);
        replicaAttributes.put(ReplicationNode.STORE_PATH, replicaEnvironmentFolder);
        replicaAttributes.put(ReplicationNode.NAME, "testNode2");
        replicaAttributes.put(ReplicationNode.DESIGNATED_PRIMARY, true);
        LocalReplicationNode node = new LocalReplicationNode(_id, replicaAttributes, _virtualHost, _taskExecutor, new NodeReplicatedEnvironmentFacadeFactory());
+
        node.attainDesiredState();
+       ReplicatedEnvironmentFacade facade = node.getReplicatedEnvironmentFacade();
+       final CountDownLatch replicaMasterLatch = new CountDownLatch(1);
+       final CountDownLatch replicaReplicaLatch = new CountDownLatch(1);
+       facade.setStateChangeListener(new StateChangeListener()
+       {
+           @Override
+           public void stateChange(StateChangeEvent stateEvent) throws RuntimeException
+           {
+               if (stateEvent.getState() == com.sleepycat.je.rep.ReplicatedEnvironment.State.MASTER)
+               {
+                   replicaMasterLatch.countDown();
+               } else  if (stateEvent.getState() == com.sleepycat.je.rep.ReplicatedEnvironment.State.REPLICA)
+               {
+                   replicaReplicaLatch.countDown();
+               }
+           }
+       });
+
+       assertTrue("Transistion to REPLICA did not happen", replicaReplicaLatch.await(10, TimeUnit.SECONDS));
+
+       assertEquals("Unexpected role", "REPLICA", node.getAttribute(ReplicationNode.ROLE));
        try
        {
-           CountDownLatch replicaLatch = createMasterStateChangeAwaiter(node);
            node.setAttributes(Collections.<String, Object>singletonMap(ReplicationNode.ROLE, ReplicatedEnvironment.State.MASTER.name()));
-
-           assertTrue("Transistion to master did not happen", replicaLatch.await(10, TimeUnit.SECONDS));
+           assertTrue("Transistion to master did not happen", replicaMasterLatch.await(10, TimeUnit.SECONDS));
        }
        finally
        {
@@ -287,5 +309,6 @@ public class LocalReplicationNodeWithRep
        assertEquals("Unexpected role attribute", "MASTER", node.getAttribute(ReplicationNode.ROLE));
        return  node;
    }
+
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org