summaryrefslogtreecommitdiffstats
path: root/storage/src/tests/distributor/garbagecollectiontest.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/garbagecollectiontest.cpp
Publish
Diffstat (limited to 'storage/src/tests/distributor/garbagecollectiontest.cpp')
-rw-r--r--storage/src/tests/distributor/garbagecollectiontest.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/storage/src/tests/distributor/garbagecollectiontest.cpp b/storage/src/tests/distributor/garbagecollectiontest.cpp
new file mode 100644
index 00000000000..399222f0e34
--- /dev/null
+++ b/storage/src/tests/distributor/garbagecollectiontest.cpp
@@ -0,0 +1,77 @@
+// 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 <cppunit/extensions/HelperMacros.h>
+#include <vespa/storageapi/message/removelocation.h>
+#include <vespa/storage/distributor/operations/idealstate/garbagecollectionoperation.h>
+#include <vespa/storage/distributor/idealstatemanager.h>
+#include <tests/distributor/distributortestutil.h>
+
+namespace storage {
+namespace distributor {
+
+class GarbageCollectionOperationTest : public CppUnit::TestFixture, public DistributorTestUtil
+{
+ CPPUNIT_TEST_SUITE(GarbageCollectionOperationTest);
+ CPPUNIT_TEST(testSimple);
+ CPPUNIT_TEST_SUITE_END();
+
+protected:
+ void testSimple();
+
+public:
+ void setUp() {
+ createLinks();
+ };
+
+ void tearDown() {
+ close();
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(GarbageCollectionOperationTest);
+
+void
+GarbageCollectionOperationTest::testSimple()
+{
+ _distributor->enableClusterState(lib::ClusterState("distributor:1 storage:2"));
+ addNodesToBucketDB(document::BucketId(16, 1), "0=250/50/300,1=250/50/300");
+ getConfig().setGarbageCollection("music.date < 34", 3600);
+
+ GarbageCollectionOperation op("storage",
+ BucketAndNodes(document::BucketId(16, 1),
+ toVector<uint16_t>(0, 1)));
+
+ op.setIdealStateManager(&getIdealStateManager());
+ op.start(_sender, framework::MilliSecTime(0));
+
+ CPPUNIT_ASSERT_EQUAL((size_t)2, _sender.commands.size());
+
+ getClock().setAbsoluteTimeInSeconds(34);
+
+ for (uint32_t i = 0; i < 2; ++i) {
+ std::shared_ptr<api::StorageCommand> msg = _sender.commands[i];
+ CPPUNIT_ASSERT(msg->getType() == api::MessageType::REMOVELOCATION);
+
+ api::RemoveLocationCommand* tmp = (api::RemoveLocationCommand*)msg.get();
+ CPPUNIT_ASSERT_EQUAL(vespalib::string("music.date < 34"),
+ tmp->getDocumentSelection());
+
+ std::shared_ptr<api::StorageReply> reply(tmp->makeReply().release());
+ api::RemoveLocationReply* sreply = (api::RemoveLocationReply*)reply.get();
+ sreply->setBucketInfo(api::BucketInfo(666, 90, 500));
+
+ op.receive(_sender, reply);
+ }
+
+ BucketDatabase::Entry entry = getBucket(document::BucketId(16, 1));
+ CPPUNIT_ASSERT(entry.valid());
+ CPPUNIT_ASSERT_EQUAL(2, (int)entry->getNodeCount());
+ CPPUNIT_ASSERT_EQUAL(34, (int)entry->getLastGarbageCollectionTime());
+ CPPUNIT_ASSERT_EQUAL(api::BucketInfo(666, 90, 500),
+ entry->getNodeRef(0).getBucketInfo());
+ CPPUNIT_ASSERT_EQUAL(api::BucketInfo(666, 90, 500),
+ entry->getNodeRef(1).getBucketInfo());
+}
+
+} // distributor
+} // storage