hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxReduceJobTest.cpp
Go to the documentation of this file.
1 /*
2  * SphinxReduceJobTest.cpp
3  *
4  * Created on: May 1, 2013
5  * Author: igor
6  */
7 
8 #include <gtest/gtest.h>
9 #include "SphinxReduceJob.hpp"
12 #include <vector>
13 
14 using namespace HCE::reduce::core;
15 using namespace HCE::sphinx;
16 using namespace HCE::sphinx::reduce_task;
17 using namespace std;
18 using namespace Poco;
19 
20 class SphinxReduceJobTest: public ::testing::Test{
21  protected:
22  virtual void SetUp(){
23  sphinxDataStorage.assign(new SphinxReduceDataStorage());
24  sphinxReduceTask.assign(new SphinxReduceTask());
25  sphinxReduceResult.assign(new SphinxReduceResult());
26  sphinxReduceJob.assign(
27  new SphinxReduceJob(sphinxDataStorage, sphinxReduceTask, sphinxReduceResult));
28  }
29 
30  virtual void TearDown(){
31  }
32 
33  static SharedPtr<SphinxReduceDataStorage>sphinxDataStorage;
34  static SharedPtr<SphinxReduceTask>sphinxReduceTask;
35  static SharedPtr<SphinxReduceResult>sphinxReduceResult;
36  static SharedPtr<SphinxReduceJob>sphinxReduceJob;
37 };
38 SharedPtr<SphinxReduceDataStorage>SphinxReduceJobTest::sphinxDataStorage;
39 SharedPtr<SphinxReduceTask>SphinxReduceJobTest::sphinxReduceTask;
40 SharedPtr<SphinxReduceResult>SphinxReduceJobTest::sphinxReduceResult;
41 SharedPtr<SphinxReduceJob>SphinxReduceJobTest::sphinxReduceJob;
42 
43 
45 {
46  ScheduleStrategySingle scheduleStrategySingle;
47 
48  scheduleStrategySingle.executeJob(sphinxReduceJob);
49 
50  sphinxReduceResult->reset();
51  ASSERT_TRUE(sphinxReduceResult->hasNext() == false);
52 }
53 
55 {
56  string id;
57  string weight;
58  vector<SphinxMatchInfo> resources;
59 
60  resources.push_back(buildSimpleMatchInfo(22, 1234LLU));
61  resources.push_back(buildSimpleMatchInfo(25LLU, 4565646LLU));
62  resources.push_back(buildSimpleMatchInfo(22LLU, 4565646LLU));
63  resources.push_back(buildSimpleMatchInfo(13LLU, 456564645LLU));
64 
65  for (size_t resIndex = 0; resIndex < resources.size(); ++resIndex){
66  sphinxDataStorage->addData(resources[resIndex]);
67  }
68 
69  ScheduleStrategySingle scheduleStrategySingle;
70 
71  scheduleStrategySingle.executeJob(sphinxReduceJob);
72 
73  int resNumber = 0;
74  sphinxReduceResult->reset();
75  while (sphinxReduceResult->hasNext()){
76  sphinxReduceResult->getNext(id, weight);
77 
78  bool isFind = (
79  (id == to_string(resources[1].getDocId()) && weight == resources[1].getWeight()) ||
80  (id == to_string(resources[2].getDocId()) && weight == resources[2].getWeight()) ||
81  (id == to_string(resources[3].getDocId()) && weight == resources[3].getWeight()));
82  ASSERT_TRUE(isFind);
83  resNumber++;
84  }
85  EXPECT_EQ(resNumber, 3);
86  ASSERT_TRUE(sphinxReduceResult->hasNext() == false);
87 }