// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include #include #include #include #include #include using document::test::makeDocumentBucket; using document::BucketId; using namespace ::testing; namespace storage::distributor { struct BlockingOperationStarterTest : Test { std::shared_ptr createMockOperation() { return std::make_shared(makeDocumentBucket(BucketId(16, 1))); } std::shared_ptr createBlockingMockOperation() { auto op = std::make_shared(makeDocumentBucket(BucketId(16, 1))); op->setShouldBlock(true); return op; } framework::defaultimplementation::FakeClock _clock; std::unique_ptr _starterImpl; std::unique_ptr _compReg; std::unique_ptr _messageTracker; std::unique_ptr _operation_sequencer; std::unique_ptr _operationStarter; void SetUp() override; }; void BlockingOperationStarterTest::SetUp() { _starterImpl = std::make_unique(); _compReg = std::make_unique(); _compReg->setClock(_clock); _clock.setAbsoluteTimeInSeconds(1); _messageTracker = std::make_unique(*_compReg); _operation_sequencer = std::make_unique(); _operationStarter = std::make_unique(*_messageTracker, *_operation_sequencer, *_starterImpl); } TEST_F(BlockingOperationStarterTest, operation_not_blocked_when_no_messages_pending) { ASSERT_TRUE(_operationStarter->start(createMockOperation(), OperationStarter::Priority(0))); EXPECT_EQ("Bucket(BucketSpace(0x0000000000000001), BucketId(0x4000000000000001)), pri 0\n", _starterImpl->toString()); } TEST_F(BlockingOperationStarterTest, operation_blocked_when_messages_pending) { // start should return true but not forward message to underlying starter. ASSERT_TRUE(_operationStarter->start(createBlockingMockOperation(), OperationStarter::Priority(0))); EXPECT_EQ("", _starterImpl->toString()); } }