summaryrefslogtreecommitdiffstats
path: root/storage/src/tests/distributor/blockingoperationstartertest.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/blockingoperationstartertest.cpp
Publish
Diffstat (limited to 'storage/src/tests/distributor/blockingoperationstartertest.cpp')
-rw-r--r--storage/src/tests/distributor/blockingoperationstartertest.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/storage/src/tests/distributor/blockingoperationstartertest.cpp b/storage/src/tests/distributor/blockingoperationstartertest.cpp
new file mode 100644
index 00000000000..ee0058643d9
--- /dev/null
+++ b/storage/src/tests/distributor/blockingoperationstartertest.cpp
@@ -0,0 +1,78 @@
+// 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 <string>
+#include <sstream>
+#include <memory>
+#include <vespa/storage/frameworkimpl/component/storagecomponentregisterimpl.h>
+#include <vespa/storage/distributor/blockingoperationstarter.h>
+#include <vespa/storage/distributor/pendingmessagetracker.h>
+#include <tests/distributor/maintenancemocks.h>
+
+namespace storage {
+
+namespace distributor {
+
+using document::BucketId;
+
+class BlockingOperationStarterTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(BlockingOperationStarterTest);
+ CPPUNIT_TEST(testOperationNotBlockedWhenNoMessagesPending);
+ CPPUNIT_TEST(testOperationBlockedWhenMessagesPending);
+ CPPUNIT_TEST_SUITE_END();
+
+ std::shared_ptr<Operation> createMockOperation() {
+ return std::shared_ptr<Operation>(new MockOperation(BucketId(16, 1)));
+ }
+ std::shared_ptr<Operation> createBlockingMockOperation() {
+ std::shared_ptr<MockOperation> op(new MockOperation(BucketId(16, 1)));
+ op->setShouldBlock(true);
+ return op;
+ }
+
+ framework::defaultimplementation::FakeClock _clock;
+ std::unique_ptr<MockOperationStarter> _starterImpl;
+ std::unique_ptr<StorageComponentRegisterImpl> _compReg;
+ std::unique_ptr<PendingMessageTracker> _messageTracker;
+ std::unique_ptr<BlockingOperationStarter> _operationStarter;
+
+public:
+ void testOperationNotBlockedWhenNoMessagesPending();
+ void testOperationBlockedWhenMessagesPending();
+
+ void setUp();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(BlockingOperationStarterTest);
+
+void
+BlockingOperationStarterTest::setUp()
+{
+ _starterImpl.reset(new MockOperationStarter());
+ _compReg.reset(new StorageComponentRegisterImpl());
+ _compReg->setClock(_clock);
+ _clock.setAbsoluteTimeInSeconds(1);
+ _messageTracker.reset(new PendingMessageTracker(*_compReg));
+ _operationStarter.reset(new BlockingOperationStarter(*_messageTracker, *_starterImpl));
+}
+
+void
+BlockingOperationStarterTest::testOperationNotBlockedWhenNoMessagesPending()
+{
+ CPPUNIT_ASSERT(_operationStarter->start(createMockOperation(),
+ OperationStarter::Priority(0)));
+ CPPUNIT_ASSERT_EQUAL(std::string("BucketId(0x4000000000000001), pri 0\n"),
+ _starterImpl->toString());
+}
+
+void
+BlockingOperationStarterTest::testOperationBlockedWhenMessagesPending()
+{
+ // start should return true but not forward message to underlying starter.
+ CPPUNIT_ASSERT(_operationStarter->start(createBlockingMockOperation(),
+ OperationStarter::Priority(0)));
+ CPPUNIT_ASSERT_EQUAL(std::string(""), _starterImpl->toString());
+}
+
+}
+}