summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2018-03-14 15:53:17 +0100
committerGitHub <noreply@github.com>2018-03-14 15:53:17 +0100
commit80b294229313dad887eb6623330ce94a2153371a (patch)
tree493523b3fff2ad8ef9717699e25bdba586fe8032
parentc31d6c74c74859a799b079c357f8b69a1f5f200f (diff)
parentd6cd374295c113c18f5435d144741e8340ec1f59 (diff)
Merge pull request #5335 from vespa-engine/geirst/reapply-finalize-cluster-state-bundle-to-return-derived-cluster-state-if-bucket-space-is-found
Finalize ClusterStateBundle to return derived cluster state if bucket…
-rw-r--r--vdslib/src/tests/state/CMakeLists.txt1
-rw-r--r--vdslib/src/tests/state/cluster_state_bundle_test.cpp77
-rw-r--r--vdslib/src/vespa/vdslib/state/cluster_state_bundle.cpp8
-rw-r--r--vdslib/src/vespa/vdslib/state/cluster_state_bundle.h1
4 files changed, 84 insertions, 3 deletions
diff --git a/vdslib/src/tests/state/CMakeLists.txt b/vdslib/src/tests/state/CMakeLists.txt
index 8e394fc18c5..8b1957a91bb 100644
--- a/vdslib/src/tests/state/CMakeLists.txt
+++ b/vdslib/src/tests/state/CMakeLists.txt
@@ -1,6 +1,7 @@
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
vespa_add_library(vdslib_teststate
SOURCES
+ cluster_state_bundle_test.cpp
clusterstatetest.cpp
nodestatetest.cpp
DEPENDS
diff --git a/vdslib/src/tests/state/cluster_state_bundle_test.cpp b/vdslib/src/tests/state/cluster_state_bundle_test.cpp
new file mode 100644
index 00000000000..4798fe505f8
--- /dev/null
+++ b/vdslib/src/tests/state/cluster_state_bundle_test.cpp
@@ -0,0 +1,77 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/vdslib/state/cluster_state_bundle.h>
+#include <vespa/vdslib/state/clusterstate.h>
+
+#include <cppunit/extensions/HelperMacros.h>
+
+using document::BucketSpace;
+
+namespace storage::lib {
+
+using ClusterStatePtr = std::shared_ptr<const ClusterState>;
+
+struct ClusterStateBundleTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(ClusterStateBundleTest);
+ CPPUNIT_TEST(derived_state_is_returned_if_bucket_space_is_found);
+ CPPUNIT_TEST(baseline_state_is_returned_if_bucket_space_is_not_found);
+ CPPUNIT_TEST(verify_equality_operator);
+ CPPUNIT_TEST_SUITE_END();
+
+ void derived_state_is_returned_if_bucket_space_is_found();
+ void baseline_state_is_returned_if_bucket_space_is_not_found();
+ void verify_equality_operator();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ClusterStateBundleTest);
+
+struct Fixture {
+ ClusterState baselineState;
+ ClusterStatePtr derivedState;
+ ClusterStateBundle bundle;
+ Fixture()
+ : baselineState("storage:2"),
+ derivedState(std::make_shared<const ClusterState>("storage:2 .1.s:m")),
+ bundle(baselineState, {{BucketSpace(1), derivedState}})
+ {}
+ ~Fixture() {}
+};
+
+void
+ClusterStateBundleTest::derived_state_is_returned_if_bucket_space_is_found()
+{
+ Fixture f;
+ CPPUNIT_ASSERT_EQUAL(*f.derivedState, *f.bundle.getDerivedClusterState(BucketSpace(1)));
+}
+
+void
+ClusterStateBundleTest::baseline_state_is_returned_if_bucket_space_is_not_found()
+{
+ Fixture f;
+ CPPUNIT_ASSERT_EQUAL(f.baselineState, *f.bundle.getDerivedClusterState(BucketSpace(2)));
+}
+
+ClusterStateBundle
+makeBundle(const vespalib::string &baselineState, const std::map<BucketSpace, vespalib::string> &derivedStates)
+{
+ ClusterStateBundle::BucketSpaceStateMapping derivedBucketSpaceStates;
+ for (const auto &entry : derivedStates) {
+ derivedBucketSpaceStates[entry.first] = std::make_shared<const ClusterState>(entry.second);
+ }
+ return ClusterStateBundle(ClusterState(baselineState), std::move(derivedBucketSpaceStates));
+}
+
+void
+ClusterStateBundleTest::verify_equality_operator()
+{
+ Fixture f;
+ CPPUNIT_ASSERT(f.bundle != makeBundle("storage:3", {{BucketSpace(1), "storage:2 .1.s:m"}}));
+ CPPUNIT_ASSERT(f.bundle != makeBundle("storage:2", {}));
+ CPPUNIT_ASSERT(f.bundle != makeBundle("storage:2", {{BucketSpace(1), "storage:2 .0.s:m"}}));
+ CPPUNIT_ASSERT(f.bundle != makeBundle("storage:2", {{BucketSpace(2), "storage:2 .1.s:m"}}));
+
+ CPPUNIT_ASSERT_EQUAL(f.bundle, makeBundle("storage:2", {{BucketSpace(1), "storage:2 .1.s:m"}}));
+}
+
+}
+
diff --git a/vdslib/src/vespa/vdslib/state/cluster_state_bundle.cpp b/vdslib/src/vespa/vdslib/state/cluster_state_bundle.cpp
index cf9c0ba6dff..ed561d67f6d 100644
--- a/vdslib/src/vespa/vdslib/state/cluster_state_bundle.cpp
+++ b/vdslib/src/vespa/vdslib/state/cluster_state_bundle.cpp
@@ -28,10 +28,12 @@ ClusterStateBundle::getBaselineClusterState() const
}
const std::shared_ptr<const lib::ClusterState> &
-ClusterStateBundle::getDerivedClusterState(document::BucketSpace) const
+ClusterStateBundle::getDerivedClusterState(document::BucketSpace bucketSpace) const
{
- // For now, just return the baseline cluster state.
- // TODO use _derivedBucketSpaceStates
+ auto itr = _derivedBucketSpaceStates.find(bucketSpace);
+ if (itr != _derivedBucketSpaceStates.end()) {
+ return itr->second;
+ }
return _baselineClusterState;
}
diff --git a/vdslib/src/vespa/vdslib/state/cluster_state_bundle.h b/vdslib/src/vespa/vdslib/state/cluster_state_bundle.h
index a8ee0b54713..a64416762b8 100644
--- a/vdslib/src/vespa/vdslib/state/cluster_state_bundle.h
+++ b/vdslib/src/vespa/vdslib/state/cluster_state_bundle.h
@@ -36,6 +36,7 @@ public:
}
uint32_t getVersion() const;
bool operator==(const ClusterStateBundle &rhs) const;
+ bool operator!=(const ClusterStateBundle &rhs) const { return !operator==(rhs); }
};
std::ostream& operator<<(std::ostream&, const ClusterStateBundle&);