1 /* Copyright (C) 2014 InfiniDB, Inc.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 MA 02110-1301, USA. */
17
18 /*****************************************************************************
19 * $Id: tdriver-pdict.cpp 9210 2013-01-21 14:10:42Z rdempsey $
20 *
21 ****************************************************************************/
22
23 #include <iostream>
24
25 #include <cppunit/extensions/HelperMacros.h>
26 #include <cppunit/extensions/TestFactoryRegistry.h>
27 #include <cppunit/ui/text/TestRunner.h>
28
29 #include "joblist.h"
30 #include "jobstep.h"
31 #include "distributedenginecomm.h"
32 #include "calpontsystemcatalog.h"
33 #include "we_type.h"
34 #include "dbrm.h"
35
36 using namespace std;
37 using namespace joblist;
38 using namespace execplan;
39
40 class JobStepDriver : public CppUnit::TestFixture
41 {
42
43 CPPUNIT_TEST_SUITE(JobStepDriver);
44
45 CPPUNIT_TEST(pDictStep_1);
46
47 CPPUNIT_TEST_SUITE_END();
48
49 private:
50 public:
51
pDictStep_1()52 void pDictStep_1()
53 {
54 DistributedEngineComm* dec;
55 boost::shared_ptr<CalpontSystemCatalog> cat;
56 ElementType e;
57 uint32_t i, it;
58 bool more;
59 BRM::DBRM dbrm;
60 const uint32_t dictOID = 2064;
61 ResourceManager rm;
62 dec = DistributedEngineComm::instance(rm);
63 cat = CalpontSystemCatalog::makeCalpontSystemCatalog();
64
65 JobStepAssociation inJs;
66 JobStepAssociation outJs;
67
68 // create request list
69 AnyDataListSPtr spdl1(new AnyDataList());
70 FifoDataList* dl1 = new FifoDataList(1, 128);
71 spdl1->fifoDL(dl1);
72 inJs.outAdd(spdl1);
73
74 AnyDataListSPtr spdl2(new AnyDataList());
75 StringFifoDataList* dl2 = new StringFifoDataList(1, 128);
76 spdl2->stringDL(dl2);
77 outJs.outAdd(spdl2);
78
79 int64_t lbid;
80 int err = dbrm.lookup(dictOID, 0, lbid);
81 CPPUNIT_ASSERT(err == 0);
82
83 // populate the element pair
84 UintRowGroup rw;
85
86 const uint32_t tcount = 10;
87
88 for (i = 1; i <= tcount; i++)
89 {
90 WriteEngine::Token token; // rid
91 token.op = i; // index of sig in block
92 token.fbo = lbid; // lbid of sig block to search
93 token.spare = 0;
94 // cast for ElementType second value
95 uint64_t* u = reinterpret_cast<uint64_t*>(&token);
96 CPPUNIT_ASSERT(u);
97 rw.et[rw.count].first = i;
98 rw.et[rw.count++].second = *u;
99
100 if (rw.count == rw.ElementsPerGroup)
101 {
102 dl1->insert(rw);
103 }
104
105 }
106
107 if (rw.count > 0)
108 dl1->insert(rw);
109
110 // close input set
111 dl1->endOfInput();
112
113 pDictionaryStep p(inJs, outJs, dec, cat, dictOID, 1000, 12346, 32000, 32000, 1, 0, rm);
114 p.dec(dec);
115 p.run();
116 p.join();
117 // StringElementType s;
118 it = dl2->getIterator();
119 // dump the result set
120 StringRowGroup s;
121
122
123 for (more = dl2->next(it, &s), i = 0; more; more = dl2->next(it, &s), i++)
124 {
125
126 for (uint64_t i = 0; i < s.count; ++i )
127 cout << i << " <rid = " << s.et[i].first << ", value = " << s.et[i].second << ">" << endl;
128 }
129
130 CPPUNIT_ASSERT(s.count == tcount);
131
132 }
133
134 };
135
136 CPPUNIT_TEST_SUITE_REGISTRATION(JobStepDriver);
137
main(int argc,char ** argv)138 int main( int argc, char** argv)
139 {
140 CppUnit::TextUi::TestRunner runner;
141 CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
142
143 runner.addTest( registry.makeTest() );
144 bool wasSuccessful = runner.run( "", false );
145
146 return (wasSuccessful ? 0 : 1);
147
148 }
149