aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/distributor/nodemaintenancestatstrackertest.cpp
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /storage/src/tests/distributor/nodemaintenancestatstrackertest.cpp
Publish
Diffstat (limited to 'storage/src/tests/distributor/nodemaintenancestatstrackertest.cpp')
-rw-r--r--storage/src/tests/distributor/nodemaintenancestatstrackertest.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/storage/src/tests/distributor/nodemaintenancestatstrackertest.cpp b/storage/src/tests/distributor/nodemaintenancestatstrackertest.cpp
new file mode 100644
index 00000000000..f1c177e7939
--- /dev/null
+++ b/storage/src/tests/distributor/nodemaintenancestatstrackertest.cpp
@@ -0,0 +1,102 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/fastos/fastos.h>
+#include <vespa/vdstestlib/cppunit/macros.h>
+
+#include <vespa/storage/distributor/maintenance/node_maintenance_stats_tracker.h>
+
+namespace storage {
+namespace distributor {
+
+class NodeMaintenanceStatsTrackerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(NodeMaintenanceStatsTrackerTest);
+ CPPUNIT_TEST(emptyStatsInstancesAreEqual);
+ CPPUNIT_TEST(statsFieldsAffectEqualityComparison);
+ CPPUNIT_TEST(requestingNonExistingNodeGivesEmptyStats);
+ CPPUNIT_TEST(statsAreTrackedPerNode);
+ CPPUNIT_TEST_SUITE_END();
+
+ void emptyStatsInstancesAreEqual();
+ void statsFieldsAffectEqualityComparison();
+ void requestingNonExistingNodeGivesEmptyStats();
+ void statsAreTrackedPerNode();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(NodeMaintenanceStatsTrackerTest);
+
+void
+NodeMaintenanceStatsTrackerTest::emptyStatsInstancesAreEqual()
+{
+ NodeMaintenanceStats a;
+ NodeMaintenanceStats b;
+ CPPUNIT_ASSERT_EQUAL(a, b);
+}
+
+void
+NodeMaintenanceStatsTrackerTest::statsFieldsAffectEqualityComparison()
+{
+ NodeMaintenanceStats a;
+ NodeMaintenanceStats b;
+
+ a.movingOut = 1;
+ CPPUNIT_ASSERT(!(a == b));
+ b.movingOut = 1;
+ CPPUNIT_ASSERT(a == b);
+
+ a.syncing = 1;
+ CPPUNIT_ASSERT(!(a == b));
+ b.syncing = 1;
+ CPPUNIT_ASSERT(a == b);
+
+ a.copyingIn = 1;
+ CPPUNIT_ASSERT(!(a == b));
+ b.copyingIn = 1;
+ CPPUNIT_ASSERT(a == b);
+
+ a.copyingOut = 1;
+ CPPUNIT_ASSERT(!(a == b));
+ b.copyingOut = 1;
+ CPPUNIT_ASSERT(a == b);
+}
+
+void
+NodeMaintenanceStatsTrackerTest::requestingNonExistingNodeGivesEmptyStats()
+{
+ NodeMaintenanceStatsTracker tracker;
+ NodeMaintenanceStats wanted;
+ CPPUNIT_ASSERT_EQUAL(wanted, tracker.forNode(0));
+}
+
+void
+NodeMaintenanceStatsTrackerTest::statsAreTrackedPerNode()
+{
+ NodeMaintenanceStatsTracker tracker;
+ NodeMaintenanceStats wanted;
+
+ tracker.incMovingOut(0);
+ wanted.movingOut = 1;
+ CPPUNIT_ASSERT_EQUAL(wanted, tracker.forNode(0));
+ wanted.movingOut = 0;
+ CPPUNIT_ASSERT_EQUAL(wanted, tracker.forNode(1));
+
+ tracker.incMovingOut(0);
+ wanted.movingOut = 2;
+ CPPUNIT_ASSERT_EQUAL(wanted, tracker.forNode(0));
+
+ tracker.incMovingOut(1);
+ wanted.movingOut = 1;
+ CPPUNIT_ASSERT_EQUAL(wanted, tracker.forNode(1));
+
+ tracker.incSyncing(1);
+ tracker.incCopyingIn(1);
+ tracker.incCopyingOut(1);
+ wanted.syncing = 1;
+ wanted.copyingIn = 1;
+ wanted.copyingOut = 1;
+ CPPUNIT_ASSERT_EQUAL(wanted, tracker.forNode(1));
+}
+
+} // distributor
+} // storage
+