diff options
Diffstat (limited to 'storage/src/tests')
-rw-r--r-- | storage/src/tests/common/testnodestateupdater.h | 17 | ||||
-rw-r--r-- | storage/src/tests/storageserver/statemanagertest.cpp | 32 |
2 files changed, 38 insertions, 11 deletions
diff --git a/storage/src/tests/common/testnodestateupdater.h b/storage/src/tests/common/testnodestateupdater.h index 1e898e84b18..49f6b4f27b2 100644 --- a/storage/src/tests/common/testnodestateupdater.h +++ b/storage/src/tests/common/testnodestateupdater.h @@ -20,18 +20,23 @@ struct TestNodeStateUpdater : public NodeStateUpdater std::vector<StateListener*> _listeners; public: - TestNodeStateUpdater(const lib::NodeType& type); - ~TestNodeStateUpdater(); + explicit TestNodeStateUpdater(const lib::NodeType& type); + ~TestNodeStateUpdater() override; lib::NodeState::CSP getReportedNodeState() const override { return _reported; } lib::NodeState::CSP getCurrentNodeState() const override { return _current; } std::shared_ptr<const lib::ClusterStateBundle> getClusterStateBundle() const override; void addStateListener(StateListener& s) override { _listeners.push_back(&s); } void removeStateListener(StateListener&) override {} - Lock::SP grabStateChangeLock() override { return Lock::SP(new Lock); } - void setReportedNodeState(const lib::NodeState& state) override { _reported.reset(new lib::NodeState(state)); } - - void setCurrentNodeState(const lib::NodeState& state) { _current.reset(new lib::NodeState(state)); } + Lock::SP grabStateChangeLock() override { return std::make_shared<Lock>(); } + void setReportedNodeState(const lib::NodeState& state) override { + _reported = std::make_shared<lib::NodeState>(state); + } + void immediately_send_get_node_state_replies() override {} + + void setCurrentNodeState(const lib::NodeState& state) { + _current = std::make_shared<lib::NodeState>(state); + } void setClusterState(lib::ClusterState::CSP c); }; diff --git a/storage/src/tests/storageserver/statemanagertest.cpp b/storage/src/tests/storageserver/statemanagertest.cpp index 8821d271e52..5c201f86f90 100644 --- a/storage/src/tests/storageserver/statemanagertest.cpp +++ b/storage/src/tests/storageserver/statemanagertest.cpp @@ -33,12 +33,14 @@ struct StateManagerTest : public CppUnit::TestFixture { void testSystemState(); void testReportedNodeState(); - void testClusterStateVersion(); + void current_cluster_state_version_is_included_in_host_info_json(); + void can_explicitly_send_get_node_state_reply(); CPPUNIT_TEST_SUITE(StateManagerTest); CPPUNIT_TEST(testSystemState); CPPUNIT_TEST(testReportedNodeState); - CPPUNIT_TEST(testClusterStateVersion); + CPPUNIT_TEST(current_cluster_state_version_is_included_in_host_info_json); + CPPUNIT_TEST(can_explicitly_send_get_node_state_reply); CPPUNIT_TEST_SUITE_END(); }; @@ -223,9 +225,7 @@ StateManagerTest::testReportedNodeState() CPPUNIT_ASSERT_EQUAL(expectedEvents, stateListener.ost.str()); } -void -StateManagerTest::testClusterStateVersion() -{ +void StateManagerTest::current_cluster_state_version_is_included_in_host_info_json() { ClusterState state(*_manager->getClusterStateBundle()->getBaselineClusterState()); state.setVersion(123); _manager->setClusterStateBundle(lib::ClusterStateBundle(state)); @@ -255,4 +255,26 @@ StateManagerTest::testClusterStateVersion() CPPUNIT_ASSERT_EQUAL(123, version); } +void StateManagerTest::can_explicitly_send_get_node_state_reply() { + { + auto lock = _manager->grabStateChangeLock(); + _manager->setReportedNodeState(NodeState(NodeType::STORAGE, State::UP)); + } + // Send down a GetNodeState with the same state as we currently have. This + // ensures that the StateManager doesn't auto-reply with the current state + // to inform the caller that the state has changed. + auto cmd = std::make_shared<api::GetNodeStateCommand>( + std::make_unique<NodeState>(NodeType::STORAGE, State::UP)); + cmd->setTimeout(10000000); + _upper->sendDown(cmd); + + CPPUNIT_ASSERT_EQUAL(size_t(0), _upper->getNumReplies()); + + _manager->immediately_send_get_node_state_replies(); + + std::shared_ptr<api::StorageReply> reply; + GET_ONLY_OK_REPLY(reply); + CPPUNIT_ASSERT_EQUAL(api::MessageType::GETNODESTATE_REPLY, reply->getType()); +} + } // storage |