quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbdeshm...@apache.org
Subject [08/11] incubator-quickstep git commit: Added test for adding completion message feedback.
Date Sat, 25 Jun 2016 14:40:41 GMT
Added test for adding completion message feedback.


Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/cb519ebd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/cb519ebd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/cb519ebd

Branch: refs/heads/scheduler++
Commit: cb519ebd639ecdab512cb17e13740c06e5c19a4d
Parents: 9ad3281
Author: Harshad Deshmukh <hbdeshmukh@apache.org>
Authored: Fri Jun 24 12:09:22 2016 -0500
Committer: Harshad Deshmukh <hbdeshmukh@apache.org>
Committed: Sat Jun 25 09:40:02 2016 -0500

----------------------------------------------------------------------
 query_execution/CMakeLists.txt             |  1 +
 query_execution/Learner.cpp                |  4 +-
 query_execution/tests/Learner_unittest.cpp | 82 ++++++++++++++++++++++++-
 3 files changed, 82 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/cb519ebd/query_execution/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_execution/CMakeLists.txt b/query_execution/CMakeLists.txt
index 3904185..ef1ce99 100644
--- a/query_execution/CMakeLists.txt
+++ b/query_execution/CMakeLists.txt
@@ -274,6 +274,7 @@ target_link_libraries(Learner_unittest
                       gtest
                       gtest_main
                       quickstep_queryexecution_Learner
+                      quickstep_queryexecution_QueryExecutionMessages_proto             
        
                       quickstep_queryoptimizer_QueryHandle)
 add_test(Learner_unittest Learner_unittest) 
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/cb519ebd/query_execution/Learner.cpp
----------------------------------------------------------------------
diff --git a/query_execution/Learner.cpp b/query_execution/Learner.cpp
index 0f17e7a..c7a7064 100644
--- a/query_execution/Learner.cpp
+++ b/query_execution/Learner.cpp
@@ -51,10 +51,11 @@ void Learner::addCompletionFeedback(
       workorder_completion_proto.execution_time_in_microseconds(),
       workorder_completion_proto.operator_index());
 
-  // updateProbability();
   if (!hasFeedbackFromAllQueriesInPriorityLevel(priority_level)) {
     updateFeedbackFromQueriesInPriorityLevel(priority_level);
   }
+  updateProbabilitiesForQueriesInPriorityLevel(priority_level, query_id);
+  updateProbabilitiesOfAllPriorityLevels();
 }
 
 void Learner::updateProbabilitiesForQueriesInPriorityLevel(
@@ -67,7 +68,6 @@ void Learner::updateProbabilitiesForQueriesInPriorityLevel(
     return;
   } else if (execution_stats_[priority_level].size() == 1u) {
     DCHECK(current_probabilities_[priority_level] != nullptr);
-    DCHECK(current_probabilities_[priority_level]->getNumObjects() == 1u);
     // As we want the probability of the lone query in this priority level as
     // 1, we set the numerator same as denominator.
     const std::size_t numerator =

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/cb519ebd/query_execution/tests/Learner_unittest.cpp
----------------------------------------------------------------------
diff --git a/query_execution/tests/Learner_unittest.cpp b/query_execution/tests/Learner_unittest.cpp
index a1a144d..556c984 100644
--- a/query_execution/tests/Learner_unittest.cpp
+++ b/query_execution/tests/Learner_unittest.cpp
@@ -20,11 +20,26 @@
 #include "gtest/gtest.h"
 
 #include "query_execution/Learner.hpp"
+#include "query_execution/QueryExecutionMessages.pb.h"
 #include "query_optimizer/QueryHandle.hpp"
 
 namespace quickstep {
 
-TEST(LearnerTest, AddAndRemoveQueryTest) {
+class LearnerTest : public ::testing::Test {
+ protected:
+  serialization::NormalWorkOrderCompletionMessage createMockCompletionMessage(
+      const std::size_t query_id, const std::size_t operator_id) {
+    serialization::NormalWorkOrderCompletionMessage mock_proto_message;
+    mock_proto_message.set_operator_index(operator_id);
+    mock_proto_message.set_query_id(query_id);
+    mock_proto_message.set_worker_thread_index(0);
+    mock_proto_message.set_execution_time_in_microseconds(10);
+
+    return mock_proto_message;
+  }
+};
+
+TEST_F(LearnerTest, AddAndRemoveQueryTest) {
   Learner learner;
   std::unique_ptr<QueryHandle> handle;
   const std::size_t kPriorityLevel = 1;
@@ -53,7 +68,7 @@ TEST(LearnerTest, AddAndRemoveQueryTest) {
   EXPECT_FALSE(learner.hasActiveQueries());
 }
 
-TEST(LearnerTest, MultipleQueriesSamePriorityAddRemoveTest) {
+TEST_F(LearnerTest, MultipleQueriesSamePriorityAddRemoveTest) {
   Learner learner;
   std::unique_ptr<QueryHandle> handle1, handle2;
   const std::size_t kPriorityLevel = 1;
@@ -85,7 +100,7 @@ TEST(LearnerTest, MultipleQueriesSamePriorityAddRemoveTest) {
   EXPECT_EQ(0u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel));
 }
 
-TEST(LearnerTest, MultipleQueriesDifferentPrioritiesAddRemoveTest) {
+TEST_F(LearnerTest, MultipleQueriesDifferentPrioritiesAddRemoveTest) {
   Learner learner;
   std::unique_ptr<QueryHandle> handle1, handle2;
   const std::size_t kPriorityLevel1 = 1;
@@ -123,4 +138,65 @@ TEST(LearnerTest, MultipleQueriesDifferentPrioritiesAddRemoveTest) {
   EXPECT_EQ(0u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel2));
 }
 
+TEST_F(LearnerTest, AddCompletionFeedbackSamePriorityLevelTest) {
+  Learner learner;
+  std::unique_ptr<QueryHandle> handle1, handle2;
+  const std::size_t kPriorityLevel = 1;
+  handle1.reset(new QueryHandle(1, kPriorityLevel));
+
+  EXPECT_FALSE(learner.hasActiveQueries());
+  EXPECT_EQ(0u, learner.getTotalNumActiveQueries());
+  learner.addQuery(*handle1);
+  serialization::NormalWorkOrderCompletionMessage completion_message =
+      createMockCompletionMessage(handle1->query_id(), 0);
+
+  learner.addCompletionFeedback(completion_message);
+  EXPECT_TRUE(learner.hasActiveQueries());
+  EXPECT_EQ(1u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(1u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel));
+
+  handle2.reset(new QueryHandle(2, kPriorityLevel));
+  learner.addQuery(*handle2);
+  completion_message = createMockCompletionMessage(handle2->query_id(), 0);
+  learner.addCompletionFeedback(completion_message);
+
+  EXPECT_TRUE(learner.hasActiveQueries());
+  EXPECT_EQ(2u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(2u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel));
+}
+
+TEST_F(LearnerTest, AddCompletionFeedbackMultiplePriorityLevelsTest) {
+  Learner learner;
+  std::unique_ptr<QueryHandle> handle1, handle2;
+  const std::size_t kPriorityLevel1 = 1;
+  const std::size_t kPriorityLevel2 = 2;
+  handle1.reset(new QueryHandle(1, kPriorityLevel1));
+
+  EXPECT_FALSE(learner.hasActiveQueries());
+  EXPECT_EQ(0u, learner.getTotalNumActiveQueries());
+  learner.addQuery(*handle1);
+
+  handle2.reset(new QueryHandle(2, kPriorityLevel2));
+  learner.addQuery(*handle2);
+
+  EXPECT_EQ(2u, learner.getTotalNumActiveQueries());
+  EXPECT_EQ(1u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel1));
+  EXPECT_EQ(1u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel2));
+
+  const std::size_t kNumIterations = 10;
+  std::vector<QueryHandle*> handles;
+  handles.emplace_back(handle1.get());
+  handles.emplace_back(handle2.get());
+  for (std::size_t iter_num = 0; iter_num < kNumIterations; ++iter_num) {
+    for (std::size_t index = 0; index < handles.size(); ++index) {
+      EXPECT_TRUE(learner.hasActiveQueries());
+      serialization::NormalWorkOrderCompletionMessage completion_message =
+        createMockCompletionMessage(handles[index]->query_id(), 0);
+      learner.addCompletionFeedback(completion_message);
+      EXPECT_EQ(2u, learner.getTotalNumActiveQueries());
+      EXPECT_EQ(1u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel1));
+      EXPECT_EQ(1u, learner.getNumActiveQueriesInPriorityLevel(kPriorityLevel2));
+    }
+  }
+}
 }  // namespace quickstep


Mime
View raw message