From: Eduardo Ramos Testillano (eramedu) Date: Tue, 2 Jul 2019 08:32:07 +0000 (+0200) Subject: Abstract testing a little more X-Git-Url: https://git.teslayout.com/public/public/public/?p=anna.git;a=commitdiff_plain;h=303d3e2584497a05fc715fbf32b57dcf81805f38 Abstract testing a little more --- diff --git a/example/diameter/launcher/MyDiameterEntity.cpp b/example/diameter/launcher/MyDiameterEntity.cpp index 35ff50f..f0864df 100644 --- a/example/diameter/launcher/MyDiameterEntity.cpp +++ b/example/diameter/launcher/MyDiameterEntity.cpp @@ -134,7 +134,7 @@ throw(anna::RuntimeException) { } // Testing: - anna::testing::TestManager::instantiate().receiveMessage(message, clientSession); + anna::testing::TestManager::instantiate().receiveDiameterMessage(message, clientSession); } void MyDiameterEntity::eventResponse(const anna::diameter::comm::Response &response) @@ -227,7 +227,7 @@ throw(anna::RuntimeException) { if(isOK || contextExpired) my_node->sendBurstMessage(); // Testing: - if(isOK) anna::testing::TestManager::instantiate().receiveMessage(*message, clientSession); + if(isOK) anna::testing::TestManager::instantiate().receiveDiameterMessage(*message, clientSession); } void MyDiameterEntity::eventUnknownResponse(anna::diameter::comm::ClientSession *clientSession, const anna::DataBlock &message) @@ -276,5 +276,5 @@ throw(anna::RuntimeException) { if(my_node->logEnabled()) my_node->writeLogFile(message, "recvfe", clientSession->asString()); // Testing: - anna::testing::TestManager::instantiate().receiveMessage(message, clientSession); + anna::testing::TestManager::instantiate().receiveDiameterMessage(message, clientSession); } diff --git a/example/diameter/launcher/MyLocalServer.cpp b/example/diameter/launcher/MyLocalServer.cpp index 383db73..50ab634 100644 --- a/example/diameter/launcher/MyLocalServer.cpp +++ b/example/diameter/launcher/MyLocalServer.cpp @@ -71,7 +71,7 @@ throw(anna::RuntimeException) { // Testing: - anna::testing::TestManager::instantiate().receiveMessage(message, serverSession); + anna::testing::TestManager::instantiate().receiveDiameterMessage(message, serverSession); return; } @@ -103,7 +103,7 @@ throw(anna::RuntimeException) { } else { // Testing: - anna::testing::TestManager::instantiate().receiveMessage(message, serverSession); + anna::testing::TestManager::instantiate().receiveDiameterMessage(message, serverSession); return; // nothing done } @@ -136,7 +136,7 @@ throw(anna::RuntimeException) { if(analysisOK && programmed) a_reactingAnswers.nextMessage(code); // Testing: - anna::testing::TestManager::instantiate().receiveMessage(message, serverSession); + anna::testing::TestManager::instantiate().receiveDiameterMessage(message, serverSession); } void MyLocalServer::eventResponse(const anna::diameter::comm::Response &response) @@ -227,7 +227,7 @@ throw(anna::RuntimeException) { } // Testing: - if(isOK) anna::testing::TestManager::instantiate().receiveMessage(*message, serverSession); + if(isOK) anna::testing::TestManager::instantiate().receiveDiameterMessage(*message, serverSession); } void MyLocalServer::eventUnknownResponse(anna::diameter::comm::ServerSession *serverSession, const anna::DataBlock &message) @@ -275,5 +275,5 @@ throw(anna::RuntimeException) { if(my_node->logEnabled()) my_node->writeLogFile(message, "recvfc", serverSession->asString()); // Testing: - anna::testing::TestManager::instantiate().receiveMessage(message, serverSession); + anna::testing::TestManager::instantiate().receiveDiameterMessage(message, serverSession); } diff --git a/include/anna/testing/TestManager.hpp b/include/anna/testing/TestManager.hpp index 979941f..82fdf99 100644 --- a/include/anna/testing/TestManager.hpp +++ b/include/anna/testing/TestManager.hpp @@ -95,14 +95,12 @@ class TestManager : public anna::timex::TimeEventObserver, public anna::Singleto // Test timers timer_container a_timers; - // Test case identifiers: - // 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. - // Subscriber's - std::map a_subscriberIdTestCaseMap; // stores used Subscriber-Id values within a test case. - + // Test case identifiers: key1 (strong); key2 (alternative) + std::map a_key1TestCaseMap; + std::map a_key2TestCaseMap; + // Diameter shall use: key1 -> sessionId, key2 -> subscriberId + // StatSummary a_statSummary; // general statistics @@ -118,8 +116,8 @@ class TestManager : public anna::timex::TimeEventObserver, public anna::Singleto public: - void registerSessionId(const std::string &sessionId, const TestCase *testCase) throw(anna::RuntimeException); - void registerSubscriberId(const std::string &subscriberId, const TestCase *testCase) throw(anna::RuntimeException); + void registerKey1(const std::string &key, const TestCase *testCase) throw(anna::RuntimeException); + void registerKey2(const std::string &key, const TestCase *testCase) throw(anna::RuntimeException); int tests() const throw() { return a_testPool.size(); } void setTimerController(anna::timex::Engine *engine) throw() { a_timeController = engine; } @@ -169,11 +167,15 @@ class TestManager : public anna::timex::TimeEventObserver, public anna::Singleto 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(); - TestCase *getTestCaseFromSubscriberId(const anna::DataBlock &message, std::string &subscriberId) throw(); - 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); + // Diameter + TestCase *getDiameterTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) throw(); + TestCase *getDiameterTestCaseFromSubscriberId(const anna::DataBlock &message, std::string &subscriberId) throw(); + void receiveDiameterMessage(const anna::DataBlock &message, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException); + void receiveDiameterMessage(const anna::DataBlock &message, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException); + + // Non-trasactional (kafka) + // + // bool execTestCases(int sync_amount) throw(); diff --git a/source/testing/TestCase.cpp b/source/testing/TestCase.cpp index 455c61b..818093b 100644 --- a/source/testing/TestCase.cpp +++ b/source/testing/TestCase.cpp @@ -256,7 +256,7 @@ void TestCase::assertMessage(const anna::DataBlock &db, bool toEntity) throw(ann if (registerKeys) { TestManager &testManager = TestManager::instantiate(); - testManager.registerSessionId(anna::diameter::helpers::base::functions::getSessionId(db), this); + testManager.registerKey1(anna::diameter::helpers::base::functions::getSessionId(db), this); std::string subscriberId = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(db, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164); @@ -264,7 +264,7 @@ void TestCase::assertMessage(const anna::DataBlock &db, bool toEntity) throw(ann subscriberId = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(db, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_IMSI); if (subscriberId != "") - testManager.registerSubscriberId(subscriberId, this); + testManager.registerKey2(subscriberId, this); } } diff --git a/source/testing/TestManager.cpp b/source/testing/TestManager.cpp index 6aeae9f..5f0f6f6 100644 --- a/source/testing/TestManager.cpp +++ b/source/testing/TestManager.cpp @@ -104,33 +104,33 @@ TestManager::TestManager() : a_currentTestIt = a_testPool.end(); } -void TestManager::registerSessionId(const std::string &sessionId, const TestCase *testCase) throw(anna::RuntimeException) { +void TestManager::registerKey1(const std::string &key, const TestCase *testCase) throw(anna::RuntimeException) { - std::map::const_iterator it = a_sessionIdTestCaseMap.find(sessionId); - if (it != a_sessionIdTestCaseMap.end()) { // found + auto it = a_key1TestCaseMap.find(key); + if (it != a_key1TestCaseMap.end()) { // found unsigned int id = it->second->getId(); if (id != testCase->getId()) { - throw anna::RuntimeException(anna::functions::asString("There is another test case (id = %llu) which registered such sessionId: %s", id, sessionId.c_str()), ANNA_FILE_LOCATION); + throw anna::RuntimeException(anna::functions::asString("There is another test case (id = %llu) which registered such key1: %s", id, key.c_str()), ANNA_FILE_LOCATION); } } else { - a_sessionIdTestCaseMap[sessionId] = const_cast(testCase); - LOGDEBUG(anna::Logger::debug(anna::functions::asString("TestManager::registerSessionId for test case (id = %llu): %s)", testCase->getId(), sessionId.c_str()), ANNA_FILE_LOCATION)); + a_key1TestCaseMap[key] = const_cast(testCase); + LOGDEBUG(anna::Logger::debug(anna::functions::asString("TestManager::registerKey1 for test case (id = %llu): %s)", testCase->getId(), key.c_str()), ANNA_FILE_LOCATION)); } } -void TestManager::registerSubscriberId(const std::string &subscriberId, const TestCase *testCase) throw(anna::RuntimeException) { +void TestManager::registerKey2(const std::string &key, const TestCase *testCase) throw(anna::RuntimeException) { - std::map::const_iterator it = a_subscriberIdTestCaseMap.find(subscriberId); - if (it != a_subscriberIdTestCaseMap.end()) { // found + auto it = a_key2TestCaseMap.find(key); + if (it != a_key2TestCaseMap.end()) { // found unsigned int id = it->second->getId(); if (id != testCase->getId()) { - throw anna::RuntimeException(anna::functions::asString("There is another test case (id = %llu) which registered such subscriberId: %s", id, subscriberId.c_str()), ANNA_FILE_LOCATION); + throw anna::RuntimeException(anna::functions::asString("There is another test case (id = %llu) which registered such key2: %s", id, key.c_str()), ANNA_FILE_LOCATION); } } else { - a_subscriberIdTestCaseMap[subscriberId] = const_cast(testCase); - LOGDEBUG(anna::Logger::debug(anna::functions::asString("TestManager::registerSubscriberId for test case (id = %llu): %s)", testCase->getId(), subscriberId.c_str()), ANNA_FILE_LOCATION)); + a_key2TestCaseMap[key] = const_cast(testCase); + LOGDEBUG(anna::Logger::debug(anna::functions::asString("TestManager::registerKey2 for test case (id = %llu): %s)", testCase->getId(), key.c_str()), ANNA_FILE_LOCATION)); } } @@ -282,8 +282,8 @@ bool TestManager::clearPool() throw() { // TODO: stop the possible command threads or there will be a core dump a_testPool.clear(); - a_sessionIdTestCaseMap.clear(); - a_subscriberIdTestCaseMap.clear(); + a_key1TestCaseMap.clear(); + a_key2TestCaseMap.clear(); a_currentTestIt = a_testPool.end(); a_poolCycle = 1; configureTTPS(0); // stop @@ -299,8 +299,8 @@ bool TestManager::resetPool(bool hard) throw() { if (it->second->reset(hard)) result = true; } - //a_sessionIdTestCaseMap.clear(); - //a_subscriberIdTestCaseMap.clear(); + //a_key1TestCaseMap.clear(); + //a_key2TestCaseMap.clear(); return result; } @@ -375,7 +375,7 @@ bool TestManager::nextTestCase() throw() { } } -TestCase *TestManager::getTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) throw() { +TestCase *TestManager::getDiameterTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) throw() { try { sessionId = anna::diameter::helpers::base::functions::getSessionId(message); } @@ -384,15 +384,15 @@ TestCase *TestManager::getTestCaseFromSessionId(const anna::DataBlock &message, LOGDEBUG(anna::Logger::debug("Cannot get the Session-Id from received DataBlock in order to identify the Test Case", ANNA_FILE_LOCATION)); return NULL; } - std::map::const_iterator sessionIdIt = a_sessionIdTestCaseMap.find(sessionId); - if (sessionIdIt != a_sessionIdTestCaseMap.end()) + auto sessionIdIt = a_key1TestCaseMap.find(sessionId); + if (sessionIdIt != a_key1TestCaseMap.end()) return sessionIdIt->second; LOGDEBUG(anna::Logger::debug(anna::functions::asString("Cannot identify the Test Case for received Session-Id: %s", sessionId.c_str()), ANNA_FILE_LOCATION)); return NULL; } -TestCase *TestManager::getTestCaseFromSubscriberId(const anna::DataBlock &message, std::string &subscriberId) throw() { +TestCase *TestManager::getDiameterTestCaseFromSubscriberId(const anna::DataBlock &message, std::string &subscriberId) throw() { try { subscriberId = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(message, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164); if (subscriberId == "") // try with IMSI @@ -403,15 +403,15 @@ TestCase *TestManager::getTestCaseFromSubscriberId(const anna::DataBlock &messag LOGDEBUG(anna::Logger::debug("Cannot get the Subscriber-Id from received DataBlock in order to identify the Test Case", ANNA_FILE_LOCATION)); return NULL; } - std::map::const_iterator subscriberIdIt = a_subscriberIdTestCaseMap.find(subscriberId); - if (subscriberIdIt != a_subscriberIdTestCaseMap.end()) + auto subscriberIdIt = a_key2TestCaseMap.find(subscriberId); + if (subscriberIdIt != a_key2TestCaseMap.end()) return subscriberIdIt->second; LOGDEBUG(anna::Logger::debug(anna::functions::asString("Cannot identify the Test Case for received Subscriber-Id: %s", subscriberId.c_str()), ANNA_FILE_LOCATION)); return NULL; } -void TestManager::receiveMessage(const anna::DataBlock &message, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException) { +void TestManager::receiveDiameterMessage(const anna::DataBlock &message, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException) { // Testing disabled: if (!tests()) return; @@ -419,9 +419,9 @@ void TestManager::receiveMessage(const anna::DataBlock &message, const anna::dia // Identify the test case: std::string sessionId, subscriberId; TestCase *tc; - tc = getTestCaseFromSessionId(message, sessionId); + tc = getDiameterTestCaseFromSessionId(message, sessionId); if (!tc) - tc = getTestCaseFromSubscriberId(message, subscriberId); + tc = getDiameterTestCaseFromSubscriberId(message, subscriberId); if (!tc) { LOGWARNING(anna::Logger::warning(anna::comm::functions::asText("Cannot identify the Test Case for the message received from server: ", message), ANNA_FILE_LOCATION)); // this should not appear return; @@ -452,7 +452,7 @@ void TestManager::receiveMessage(const anna::DataBlock &message, const anna::dia } } -void TestManager::receiveMessage(const anna::DataBlock &message, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException) { +void TestManager::receiveDiameterMessage(const anna::DataBlock &message, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException) { // Testing disabled: if (!tests()) return; @@ -460,9 +460,9 @@ void TestManager::receiveMessage(const anna::DataBlock &message, const anna::dia // Identify the test case: std::string sessionId, subscriberId; TestCase *tc; - tc = getTestCaseFromSessionId(message, sessionId); + tc = getDiameterTestCaseFromSessionId(message, sessionId); if (!tc) - tc = getTestCaseFromSubscriberId(message, subscriberId); + tc = getDiameterTestCaseFromSubscriberId(message, subscriberId); if (!tc) { LOGWARNING(anna::Logger::warning(anna::comm::functions::asText("Cannot identify the Test Case for the message received from client: ", message), ANNA_FILE_LOCATION)); // this should not appear return;