summaryrefslogtreecommitdiff
path: root/cpp/src/tests/InitialStatusMap.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2009-11-17 18:09:21 +0000
committerAlan Conway <aconway@apache.org>2009-11-17 18:09:21 +0000
commit8b58b19ec3989b676cd5a1584089040caee14289 (patch)
treee0ca831f7fac0b26a4dcfa679b574e9a5dfafe06 /cpp/src/tests/InitialStatusMap.cpp
parentef7728a725272b88c3cd2f81f81ee60ed00cde90 (diff)
downloadqpid-python-8b58b19ec3989b676cd5a1584089040caee14289.tar.gz
Integrated InitialStatusMap into cluster code.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@881423 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests/InitialStatusMap.cpp')
-rw-r--r--cpp/src/tests/InitialStatusMap.cpp41
1 files changed, 32 insertions, 9 deletions
diff --git a/cpp/src/tests/InitialStatusMap.cpp b/cpp/src/tests/InitialStatusMap.cpp
index 7709b1fbfc..70b077b695 100644
--- a/cpp/src/tests/InitialStatusMap.cpp
+++ b/cpp/src/tests/InitialStatusMap.cpp
@@ -20,6 +20,7 @@
#include "unit_test.h"
#include "test_tools.h"
#include "qpid/cluster/InitialStatusMap.h"
+#include "qpid/framing/Uuid.h"
#include <boost/assign.hpp>
using namespace std;
@@ -34,58 +35,72 @@ QPID_AUTO_TEST_SUITE(InitialStatusMapTestSuite)
typedef InitialStatusMap::Status Status;
-Status activeStatus() { return Status(ProtocolVersion(), true, false, FieldTable()); }
-Status newcomerStatus() { return Status(ProtocolVersion(), false, false, FieldTable()); }
+Status activeStatus(const Uuid& id=Uuid()) { return Status(ProtocolVersion(), true, false, id, 0, ""); }
+Status newcomerStatus(const Uuid& id=Uuid()) { return Status(ProtocolVersion(), false, false, id, 0, ""); }
QPID_AUTO_TEST_CASE(testFirstInCluster) {
// Single member is first in cluster.
InitialStatusMap map(MemberId(0));
+ Uuid id(true);
BOOST_CHECK(!map.isComplete());
MemberSet members = list_of(MemberId(0));
map.configChange(members);
BOOST_CHECK(!map.isComplete());
- map.received(MemberId(0), newcomerStatus());
+ map.received(MemberId(0), newcomerStatus(id));
BOOST_CHECK(map.isComplete());
+ BOOST_CHECK(map.transitionToComplete());
BOOST_CHECK(map.getElders().empty());
BOOST_CHECK(!map.isUpdateNeeded());
+ BOOST_CHECK_EQUAL(id, map.getClusterId());
}
QPID_AUTO_TEST_CASE(testJoinExistingCluster) {
// Single member 0 joins existing cluster 1,2
InitialStatusMap map(MemberId(0));
+ Uuid id(true);
MemberSet members = list_of(MemberId(0))(MemberId(1))(MemberId(2));
map.configChange(members);
BOOST_CHECK(map.isResendNeeded());
BOOST_CHECK(!map.isComplete());
map.received(MemberId(0), newcomerStatus());
- map.received(MemberId(1), activeStatus());
+ map.received(MemberId(1), activeStatus(id));
BOOST_CHECK(!map.isComplete());
- map.received(MemberId(2), activeStatus());
+ map.received(MemberId(2), activeStatus(id));
BOOST_CHECK(map.isComplete());
+ BOOST_CHECK(map.transitionToComplete());
BOOST_CHECK_EQUAL(map.getElders(), list_of<MemberId>(1)(2));
BOOST_CHECK(map.isUpdateNeeded());
+ BOOST_CHECK_EQUAL(map.getClusterId(), id);
+
+ // Check that transitionToComplete is reset.
+ map.configChange(list_of<MemberId>(0)(1));
+ BOOST_CHECK(!map.transitionToComplete());
}
QPID_AUTO_TEST_CASE(testMultipleFirstInCluster) {
// Multiple members 0,1,2 join at same time.
InitialStatusMap map(MemberId(1)); // self is 1
+ Uuid id(true);
MemberSet members = list_of(MemberId(0))(MemberId(1))(MemberId(2));
map.configChange(members);
BOOST_CHECK(map.isResendNeeded());
// All new members
- map.received(MemberId(0), newcomerStatus());
+ map.received(MemberId(0), newcomerStatus(id));
map.received(MemberId(1), newcomerStatus());
map.received(MemberId(2), newcomerStatus());
BOOST_CHECK(!map.isResendNeeded());
BOOST_CHECK(map.isComplete());
+ BOOST_CHECK(map.transitionToComplete());
BOOST_CHECK_EQUAL(map.getElders(), list_of(MemberId(2)));
BOOST_CHECK(!map.isUpdateNeeded());
+ BOOST_CHECK_EQUAL(map.getClusterId(), id);
}
QPID_AUTO_TEST_CASE(testMultipleJoinExisting) {
// Multiple members 1,2,3 join existing cluster containing 0.
InitialStatusMap map(MemberId(2)); // self is 2
+ Uuid id(true);
MemberSet members = list_of(MemberId(0))(MemberId(1))(MemberId(2))(MemberId(3));
map.configChange(members);
BOOST_CHECK(map.isResendNeeded());
@@ -93,28 +108,34 @@ QPID_AUTO_TEST_CASE(testMultipleJoinExisting) {
map.received(MemberId(1), newcomerStatus());
map.received(MemberId(2), newcomerStatus());
map.received(MemberId(3), newcomerStatus());
- map.received(MemberId(0), activeStatus());
+ map.received(MemberId(0), activeStatus(id));
BOOST_CHECK(!map.isResendNeeded());
BOOST_CHECK(map.isComplete());
+ BOOST_CHECK(map.transitionToComplete());
BOOST_CHECK_EQUAL(map.getElders(), list_of(MemberId(0))(MemberId(3)));
BOOST_CHECK(map.isUpdateNeeded());
+ BOOST_CHECK_EQUAL(map.getClusterId(), id);
}
QPID_AUTO_TEST_CASE(testMembersLeave) {
// Test that map completes if members leave rather than send status.
InitialStatusMap map(MemberId(0));
+ Uuid id(true);
map.configChange(list_of(MemberId(0))(MemberId(1))(MemberId(2)));
map.received(MemberId(0), newcomerStatus());
- map.received(MemberId(1), activeStatus());
+ map.received(MemberId(1), activeStatus(id));
BOOST_CHECK(!map.isComplete());
map.configChange(list_of(MemberId(0))(MemberId(1))); // 2 left
BOOST_CHECK(map.isComplete());
+ BOOST_CHECK(map.transitionToComplete());
BOOST_CHECK_EQUAL(map.getElders(), list_of(MemberId(1)));
+ BOOST_CHECK_EQUAL(map.getClusterId(), id);
}
QPID_AUTO_TEST_CASE(testInteveningConfig) {
// Multiple config changes arrives before we complete the map.
InitialStatusMap map(MemberId(0));
+ Uuid id(true);
map.configChange(list_of<MemberId>(0)(1));
BOOST_CHECK(map.isResendNeeded());
@@ -125,7 +146,7 @@ QPID_AUTO_TEST_CASE(testInteveningConfig) {
map.configChange(list_of<MemberId>(0)(1)(2));
BOOST_CHECK(!map.isComplete());
BOOST_CHECK(map.isResendNeeded());
- map.received(1, activeStatus());
+ map.received(1, activeStatus(id));
map.received(2, newcomerStatus());
// We should not be complete as we haven't received 0 since new member joined
BOOST_CHECK(!map.isComplete());
@@ -133,7 +154,9 @@ QPID_AUTO_TEST_CASE(testInteveningConfig) {
map.received(0, newcomerStatus());
BOOST_CHECK(map.isComplete());
+ BOOST_CHECK(map.transitionToComplete());
BOOST_CHECK_EQUAL(map.getElders(), list_of<MemberId>(1));
+ BOOST_CHECK_EQUAL(map.getClusterId(), id);
}
QPID_AUTO_TEST_SUITE_END()