X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Ftesting%2FTestManager.hpp;fp=example%2Fdiameter%2Flauncher%2Ftesting%2FTestManager.hpp;h=313e15f94a07097ad3bc317d7fa9f26727384e66;hb=4c3f0a4d7e4db76996404d80c6f939548fca656f;hp=0000000000000000000000000000000000000000;hpb=c82a3818b279727e943a76343f3cf1a278ac9e19;p=anna.git diff --git a/example/diameter/launcher/testing/TestManager.hpp b/example/diameter/launcher/testing/TestManager.hpp new file mode 100644 index 0000000..313e15f --- /dev/null +++ b/example/diameter/launcher/testing/TestManager.hpp @@ -0,0 +1,134 @@ +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // + + +#ifndef example_diameter_launcher_TestManager_hpp +#define example_diameter_launcher_TestManager_hpp + +// Project +#include +#include +#include +#include +#include +#include + +// Process +#include + + +namespace anna { + class Millisecond; + + namespace timex { + class Engine; + } + namespace diameter { + namespace comm { + class ClientSession; + class ServerSession; + } + } +} + + +class TestClock; +class TestCase; +class TestCaseStep; + +typedef std::map test_pool_t; +typedef std::map::const_iterator test_pool_it; +typedef std::map::iterator test_pool_nc_it; + + +/** + Timer Manager for testing system +*/ +class TestManager : public anna::timex::TimeEventObserver, public anna::Singleton { + typedef anna::Recycler timer_container; + + anna::timex::Engine* a_timeController; + + // reports + std::string a_reportsDirectory; + bool a_dumpReports; + + // Pool of test cases + test_pool_t a_testPool; + test_pool_it a_currentTestIt; + bool a_poolRepeat; // repeat pool when finish + unsigned int a_inProgressCount; + unsigned int a_inProgressLimit; // limit load to have this value + + // Test clock + int a_synchronousAmount; + TestClock *a_clock; + bool tick() throw(); + bool nextTestCase() throw(); + + // Test timers + timer_container a_timers; + + // Session-Id's + std::map a_sessionIdTestCaseMap; // stores used Session-Id values within a test case. + // No other can use them, but a test case could use more than one. + + + TestManager(); + TestManager(const TestManager&); + + TestTimer* createTimer(TestCaseStep*, const anna::Millisecond &, const TestTimer::Type::_v type) throw(anna::RuntimeException); + void cancelTimer(TestTimer*) throw(); + void release(anna::timex::TimeEvent*) throw(); + + public: + + void registerSessionId(const std::string &sessionId, const TestCase *testCase) throw(anna::RuntimeException); + + int tests() const throw() { return a_testPool.size(); } + void setTimerController(anna::timex::Engine *engine) throw() { a_timeController = engine; } + + void setReportsDirectory(const std::string &rd) throw() { a_reportsDirectory = rd; } + const std::string &getReportsDirectory() const throw() { return a_reportsDirectory; } + + void setDumpReports(bool dr) throw() { a_dumpReports = dr; } + bool getDumpReports() const throw() { return a_dumpReports; } + + // Helper to calculate time interval and synchronous amount of execution tests to guarantee the input rate (tests per second) + // through the time manager which has a minimum resolution of ADML minimum resolution. The first call to this method will + // start the time trigger system and check for new test cases to be launched. + bool configureTTPS(int testTicksPerSecond) throw(); + + bool clearPool() throw(); + bool resetPool(bool hard /* hard reset includes in-progress test cases */) throw(); + void setPoolRepeat(bool repeat) throw() { a_poolRepeat = repeat; } + bool getPoolRepeat() const throw() { return a_poolRepeat; } + unsigned int getInProgressCount() const throw() { return a_inProgressCount; } + void setInProgressCountDelta(unsigned int delta) throw() { a_inProgressCount += delta; } + unsigned int getInProgressLimit() const throw() { return a_inProgressLimit; } + void setInProgressLimit(unsigned int limit) throw() { a_inProgressLimit = limit; } // 0 = UINT_MAX (no limit) + + bool gotoTestCase(unsigned int id) throw(); + TestCase *findTestCase(unsigned int id) const throw(); // id = -1 provides current test case triggered + TestCase *getTestCase(unsigned int id) throw(); // creates/reuses a test case + + // Main logic + TestCase *getTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) throw(anna::RuntimeException); + void receiveMessage(const anna::DataBlock &message, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException); + void receiveMessage(const anna::DataBlock &message, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException); + + anna::xml::Node* asXML(anna::xml::Node* parent) const throw(); + std::string asXMLString() const throw(); + + + friend class anna::Singleton ; + friend class TestStepTimeout; // createTimer + friend class TestStepDelay; // createTimer + friend class TestClock; // tick +}; + +#endif