Fixes and improvs. Basic DRA feature.
[anna.git] / example / diameter / launcher / testing / TestStep.cpp
index 076a227..c4ec2e5 100644 (file)
@@ -75,20 +75,20 @@ std::string TestStep::asXMLString() const throw() {
 }
 
 bool TestStep::execute() throw() {
-  LOGDEBUG(anna::Logger::debug(anna::functions::asString("EXECUTING %s for Test Case %llu (%p) (%p)", asText(a_type), a_testCase->getId(), (TestCaseStep*)this, this), ANNA_FILE_LOCATION));
+  LOGDEBUG(anna::Logger::debug(anna::functions::asString("EXECUTING %s (step number %d) for Test Case %llu (%p) (%p)", asText(a_type), a_number, a_testCase->getId(), (TestCaseStep*)this, this), ANNA_FILE_LOCATION));
   setBeginTimestamp(anna::functions::millisecond());
   return do_execute();
 }
 
 void TestStep::complete() throw() {
-  LOGDEBUG(anna::Logger::debug(anna::functions::asString("COMPLETE %s for Test Case %llu (%p) (%p)", asText(a_type), a_testCase->getId(), (TestCaseStep*)this, this), ANNA_FILE_LOCATION));
+  LOGDEBUG(anna::Logger::debug(anna::functions::asString("COMPLETE %s (step number %d) for Test Case %llu (%p) (%p)", asText(a_type), a_number, a_testCase->getId(), (TestCaseStep*)this, this), ANNA_FILE_LOCATION));
   a_completed = true;
   setEndTimestamp(anna::functions::millisecond());
   do_complete();
 }
 
 void TestStep::reset() throw() {
-  LOGDEBUG(anna::Logger::debug(anna::functions::asString("RESET %s for Test Case %llu (%p) (%p)", asText(a_type), a_testCase->getId(), (TestCaseStep*)this, this), ANNA_FILE_LOCATION));
+  LOGDEBUG(anna::Logger::debug(anna::functions::asString("RESET %s (step number %d) for Test Case %llu (%p) (%p)", asText(a_type), a_number, a_testCase->getId(), (TestCaseStep*)this, this), ANNA_FILE_LOCATION));
   // type and testCase kept
   a_completed = false;
   a_beginTimestamp = 0;
@@ -193,62 +193,56 @@ bool TestStepSendxml::do_execute() throw() {
   bool success = false;
   std::string failReason, s_warn;
 
-  // Update sequence for answers:
-  if (a_waitForRequestStepNumber != -1) { // is an answer: try to copy sequence information; alert about Session-Id discrepance
-    // Request which was received:
-    const TestStepWait *tsw = (const TestStepWait*)(a_testCase->getStep(a_waitForRequestStepNumber));
-    const anna::DataBlock &request = tsw->getMsgDataBlock();
-    anna::diameter::HopByHop hbh = anna::diameter::codec::functions::getHopByHop(request);
-    anna::diameter::EndToEnd ete = anna::diameter::codec::functions::getEndToEnd(request);
-    // Update sequence:
-    anna::diameter::codec::functions::setHopByHop(a_message, hbh);
-    anna::diameter::codec::functions::setEndToEnd(a_message, ete);
-
-    // Check Session-Id for warning ...
-    std::string sessionIdAnswer = anna::diameter::helpers::base::functions::getSessionId(a_message);
-    std::string sessionIdRequest = anna::diameter::helpers::base::functions::getSessionId(request);
-    if (sessionIdRequest != sessionIdAnswer) {
-      s_warn = anna::functions::asString("Sending an answer which Session-Id (%s) is different than supposed corresponding request (%s)", sessionIdAnswer.c_str(), sessionIdRequest.c_str());
-      LOGWARNING(anna::Logger::warning(s_warn, ANNA_FILE_LOCATION));
-      a_testCase->addDebugSummaryHint(s_warn);
+  try {
+    // Update sequence for answers:
+    if (a_waitForRequestStepNumber != -1) { // is an answer: try to copy sequence information; alert about Session-Id discrepance
+      // Request which was received:
+      const TestStepWait *tsw = (const TestStepWait*)(a_testCase->getStep(a_waitForRequestStepNumber));
+      const anna::DataBlock &request = tsw->getMsgDataBlock();
+      anna::diameter::HopByHop hbh = anna::diameter::codec::functions::getHopByHop(request);
+      anna::diameter::EndToEnd ete = anna::diameter::codec::functions::getEndToEnd(request);
+      // Update sequence:
+      anna::diameter::codec::functions::setHopByHop(a_message, hbh);
+      anna::diameter::codec::functions::setEndToEnd(a_message, ete);
+
+      // Check Session-Id for warning ...
+      std::string sessionIdAnswer = anna::diameter::helpers::base::functions::getSessionId(a_message);
+      std::string sessionIdRequest = anna::diameter::helpers::base::functions::getSessionId(request);
+      if (sessionIdRequest != sessionIdAnswer) {
+        s_warn = anna::functions::asString("Sending an answer which Session-Id (%s) is different than supposed corresponding request (%s)", sessionIdAnswer.c_str(), sessionIdRequest.c_str());
+        LOGWARNING(anna::Logger::warning(s_warn, ANNA_FILE_LOCATION));
+        a_testCase->addDebugSummaryHint(s_warn);
+      }
     }
-  }
 
-  if (getType() == Type::Sendxml2e) {
-    MyDiameterEntity *entity = a_realmNode->getEntity();
-    if (entity) {
-      try {
+    if (getType() == Type::Sendxml2e) {
+      MyDiameterEntity *entity = a_realmNode->getEntity();
+      if (entity) {
         //msg->clearBody();
         msg->setBody(a_message);
         /* response = NULL =*/entity->send(msg);
         success = true;
-      } catch(anna::RuntimeException &ex) {
-        ex.trace();
-        failReason = ex.asString();
+      }
+      else {
+        failReason = "There is no diameter entity currently configured. Unable to send the message";
+        LOGWARNING(anna::Logger::warning(failReason, ANNA_FILE_LOCATION));
       }
     }
-    else {
-      failReason = "There is no diameter entity currently configured. Unable to send the message";
-      LOGWARNING(anna::Logger::warning(failReason, ANNA_FILE_LOCATION));
-    }
-  }
-  else if (getType() == Type::Sendxml2c) {
-    MyLocalServer *localServer = a_realmNode->getDiameterServer();
-    if (localServer) {
-      try {
+    else if (getType() == Type::Sendxml2c) {
+      MyLocalServer *localServer = a_realmNode->getDiameterServer();
+      if (localServer) {
         //msg->clearBody();
         msg->setBody(a_message);
         /* response = NULL =*/localServer->send(msg);
         success = true;
-      } catch(anna::RuntimeException &ex) {
-        ex.trace();
-        failReason = ex.asString();
+      }
+      else {
+        failReason = "There is no diameter local server currently configured. Unable to send the message";
+        LOGWARNING(anna::Logger::warning(failReason, ANNA_FILE_LOCATION));
       }
     }
-    else {
-      failReason = "There is no diameter local server currently configured. Unable to send the message";
-      LOGWARNING(anna::Logger::warning(failReason, ANNA_FILE_LOCATION));
-    }
+  } catch(anna::RuntimeException &ex) {
+    failReason = ex.asString();
   }
 
   // release msg
@@ -265,10 +259,6 @@ bool TestStepSendxml::do_execute() throw() {
   return success; // go next if sent was OK
 }
 
-void TestStepSendxml::do_complete() throw() {
-  next();
-}
-
 void TestStepSendxml::do_reset() throw() {
   a_expired = false;
   //a_message.clear();
@@ -302,7 +292,7 @@ bool TestStepDelay::do_execute() throw() {
 
 void TestStepDelay::do_complete() throw() {
   a_timer = NULL;
-  next();
+  next(); // next() invoked here because execute() is always false for delay and never dvance the iterator
 }
 
 void TestStepDelay::do_reset() throw() {
@@ -371,7 +361,7 @@ bool TestStepWait::do_execute() throw() {
 }
 
 void TestStepWait::do_complete() throw() {
-  next();
+  next(); // next() invoked here because execute() never do this.
 }
 
 bool TestStepWait::fulfilled(const anna::DataBlock &db/*, bool matchSessionId*/) throw() {