summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Rudyy <orudyy@apache.org>2014-02-19 16:30:10 +0000
committerAlex Rudyy <orudyy@apache.org>2014-02-19 16:30:10 +0000
commita1b37fcc9c91b32ec1e4c43df43b5150563d0826 (patch)
tree5ba57ffcbc317c5cc1757791c16d633173026c74
parentcb14ed57053dde009d289e6a230496ca8f00ab59 (diff)
downloadqpid-python-a1b37fcc9c91b32ec1e4c43df43b5150563d0826.tar.gz
QPID-5409: Fix failing unit test LocalReplicationNodeWithReplicatedEnvironmentFacadeTest#testSetRole
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/java-broker-bdb-ha@1569813 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNode.java23
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/RemoteReplicationNode.java1
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java12
-rw-r--r--qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNodeWithReplicatedEnvironmentFacadeTest.java29
4 files changed, 49 insertions, 16 deletions
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNode.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNode.java
index 721acf758a..c5517450d4 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNode.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNode.java
@@ -446,6 +446,11 @@ public class LocalReplicationNode extends AbstractAdapter implements Replication
@Override
protected boolean setState(State currentState, State desiredState)
{
+ if (desiredState == getActualState())
+ {
+ return false;
+ }
+
switch (desiredState)
{
case ACTIVE:
@@ -454,9 +459,7 @@ public class LocalReplicationNode extends AbstractAdapter implements Replication
_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 extends AbstractAdapter implements Replication
}
return true;
}
+ break;
case DELETED:
if (getActualState() == State.ACTIVE)
{
@@ -477,22 +481,15 @@ public class LocalReplicationNode extends AbstractAdapter implements Replication
{
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
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/RemoteReplicationNode.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/RemoteReplicationNode.java
index de301b91ba..8244923912 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/RemoteReplicationNode.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/RemoteReplicationNode.java
@@ -258,6 +258,7 @@ public class RemoteReplicationNode extends AbstractAdapter implements Replicatio
}
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);
}
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
index 722a0bca31..253c68bfb7 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
@@ -346,6 +346,14 @@ public class ReplicatedEnvironmentFacade implements EnvironmentFacade, StateChan
}
});
}
+ 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 implements EnvironmentFacade, StateChan
restore.execute(ile, config);
environment = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
}
+ if (LOGGER.isInfoEnabled())
+ {
+ LOGGER.info("Environment is created for node " + _prettyGroupNodeName);
+ }
return environment;
}
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNodeWithReplicatedEnvironmentFacadeTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNodeWithReplicatedEnvironmentFacadeTest.java
index a4100046a3..ff51bce9e6 100644
--- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNodeWithReplicatedEnvironmentFacadeTest.java
+++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/LocalReplicationNodeWithReplicatedEnvironmentFacadeTest.java
@@ -63,6 +63,7 @@ public class LocalReplicationNodeWithReplicatedEnvironmentFacadeTest extends Qpi
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 LocalReplicationNodeWithReplicatedEnvironmentFacadeTest extends Qpi
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 LocalReplicationNodeWithReplicatedEnvironmentFacadeTest extends Qpi
assertEquals("Unexpected role attribute", "MASTER", node.getAttribute(ReplicationNode.ROLE));
return node;
}
+
}