1 /*
2 Copyright (C) 2003-2006, 2008 MySQL AB
3 All rights reserved. Use is subject to license terms.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #include "NDBT_Test.hpp"
27 #include "NDBT_ReturnCodes.h"
28 #include "HugoTransactions.hpp"
29 #include "UtilTransactions.hpp"
30 #include "NdbRestarter.hpp"
31 #include <Vector.hpp>
32 #include "ScanFilter.hpp"
33 #include "ScanInterpretTest.hpp"
34
runLoadTable(NDBT_Context * ctx,NDBT_Step * step)35 int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
36
37 int records = ctx->getNumRecords();
38 HugoTransactions hugoTrans(*ctx->getTab());
39 if (hugoTrans.loadTable(GETNDB(step), records) != 0){
40 return NDBT_FAILED;
41 }
42 return NDBT_OK;
43 }
44
runClearTable(NDBT_Context * ctx,NDBT_Step * step)45 int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
46 int records = ctx->getNumRecords();
47
48 UtilTransactions utilTrans(*ctx->getTab());
49 if (utilTrans.clearTable2(GETNDB(step), records) != 0){
50 return NDBT_FAILED;
51 }
52 return NDBT_OK;
53 }
54
runClearResTable(NDBT_Context * ctx,NDBT_Step * step)55 int runClearResTable(NDBT_Context* ctx, NDBT_Step* step){
56 int records = ctx->getNumRecords();
57 const NdbDictionary::Table* pResTab =
58 GETNDB(step)->getDictionary()->getTable(ctx->getProperty("ResultTabName", "NULL"));
59
60 UtilTransactions utilTrans(*pResTab);
61 if (utilTrans.clearTable2(GETNDB(step), records) != 0){
62 return NDBT_FAILED;
63 }
64 return NDBT_OK;
65 }
66
runScanRead(NDBT_Context * ctx,NDBT_Step * step)67 int runScanRead(NDBT_Context* ctx, NDBT_Step* step){
68 int loops = ctx->getNumLoops();
69 int records = ctx->getNumRecords();
70 int parallelism = ctx->getProperty("Parallelism", 1);
71
72 int i = 0;
73 HugoTransactions hugoTrans(*ctx->getTab());
74 while (i<loops) {
75 g_info << i << ": ";
76 if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){
77 return NDBT_FAILED;
78 }
79 i++;
80 }
81 return NDBT_OK;
82 }
83
runScanReadResTable(NDBT_Context * ctx,NDBT_Step * step)84 int runScanReadResTable(NDBT_Context* ctx, NDBT_Step* step){
85 int records = ctx->getNumRecords();
86 int parallelism = ctx->getProperty("Parallelism", 1);
87 const NdbDictionary::Table* pResTab =
88 NDBT_Table::discoverTableFromDb(GETNDB(step),
89 ctx->getProperty("ResultTabName", "NULL"));
90
91 HugoTransactions hugoTrans(*pResTab);
92 if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){
93 return NDBT_FAILED;
94 }
95 return NDBT_OK;
96 }
97
runCreateResultTable(NDBT_Context * ctx,NDBT_Step * step)98 int runCreateResultTable(NDBT_Context* ctx, NDBT_Step* step){
99
100 const NdbDictionary::Table* pTab = ctx->getTab();
101 char newTabName[256];
102 BaseString::snprintf(newTabName, 256, "%s_RES", pTab->getName());
103 ctx->setProperty("ResultTabName", newTabName);
104
105 NdbDictionary::Table resTab(* pTab);
106 resTab.setName(newTabName);
107
108 if (GETNDB(step)->getDictionary()->createTable(resTab) != 0){
109 g_err << newTabName << " creation failed!"<< endl;
110 return NDBT_FAILED;
111 }else{
112 g_info << newTabName << " created!"<< endl;
113 return NDBT_OK;
114 }
115 }
116
scanWithFilter(NDBT_Context * ctx,NDBT_Step * step,ScanFilter & filt)117 int scanWithFilter(NDBT_Context* ctx, NDBT_Step* step, ScanFilter& filt){
118 int records = ctx->getNumRecords();
119 const char* resTabName = ctx->getProperty("ResultTabName", "NULL");
120 if (strcmp(resTabName, "NULL") == 0)
121 return NDBT_FAILED;
122 const NdbDictionary::Table* pTab = ctx->getTab();
123 const NdbDictionary::Table* pResTab = NDBT_Table::discoverTableFromDb(GETNDB(step), resTabName);
124 if (pResTab == NULL)
125 return NDBT_FAILED;
126
127 ScanInterpretTest interpretTest(*pTab, *pResTab);
128 if (interpretTest.scanRead(GETNDB(step),
129 records,
130 16,
131 filt) != 0){
132 return NDBT_FAILED;
133 }
134 return NDBT_OK;
135 }
runScanLessThan(NDBT_Context * ctx,NDBT_Step * step)136 int runScanLessThan(NDBT_Context* ctx, NDBT_Step* step){
137 int records = ctx->getNumRecords();
138 LessThanFilter filt(records);
139 return scanWithFilter(ctx, step, filt);
140 }
runScanEqual(NDBT_Context * ctx,NDBT_Step * step)141 int runScanEqual(NDBT_Context* ctx, NDBT_Step* step){
142 EqualFilter filt;
143 return scanWithFilter(ctx, step, filt);
144 }
145
scanVerifyWithFilter(NDBT_Context * ctx,NDBT_Step * step,ScanFilter & filt)146 int scanVerifyWithFilter(NDBT_Context* ctx, NDBT_Step* step, ScanFilter& filt){
147 int records = ctx->getNumRecords();
148 const char* resTabName = ctx->getProperty("ResultTabName", "NULL");
149 if (strcmp(resTabName, "NULL") == 0)
150 return NDBT_FAILED;
151 const NdbDictionary::Table* pTab = ctx->getTab();
152 const NdbDictionary::Table* pResTab = NDBT_Table::discoverTableFromDb(GETNDB(step), resTabName);
153 if (pResTab == NULL)
154 return NDBT_FAILED;
155
156 ScanInterpretTest interpretTest(*pTab, *pResTab);
157 if (interpretTest.scanReadVerify(GETNDB(step),
158 records,
159 16,
160 filt) != NDBT_OK){
161 return NDBT_FAILED;
162 }
163 return NDBT_OK;
164 }
runScanLessThanVerify(NDBT_Context * ctx,NDBT_Step * step)165 int runScanLessThanVerify(NDBT_Context* ctx, NDBT_Step* step){
166 int records = ctx->getNumRecords();
167 LessThanFilter filt(records);
168 return scanVerifyWithFilter(ctx, step, filt);
169 }
runScanEqualVerify(NDBT_Context * ctx,NDBT_Step * step)170 int runScanEqualVerify(NDBT_Context* ctx, NDBT_Step* step){
171 EqualFilter filt;
172 return scanVerifyWithFilter(ctx, step, filt);
173 }
174
runScanEqualLoop(NDBT_Context * ctx,NDBT_Step * step)175 int runScanEqualLoop(NDBT_Context* ctx, NDBT_Step* step){
176 int loops = ctx->getNumLoops();
177 int l = 0;
178 EqualFilter filt;
179 while(l < loops){
180 if (scanWithFilter(ctx, step, filt) != NDBT_OK)
181 return NDBT_FAILED;
182 if (runClearResTable(ctx, step) != NDBT_OK)
183 return NDBT_FAILED;
184 l++;
185 }
186 return NDBT_OK;
187 }
188
189
runScanEqualVerifyLoop(NDBT_Context * ctx,NDBT_Step * step)190 int runScanEqualVerifyLoop(NDBT_Context* ctx, NDBT_Step* step){
191 int loops = ctx->getNumLoops();
192 int l = 0;
193 EqualFilter filt;
194 while(l < loops){
195 if (scanWithFilter(ctx, step, filt) != NDBT_OK)
196 return NDBT_FAILED;
197 if (scanVerifyWithFilter(ctx, step, filt) != NDBT_OK)
198 return NDBT_FAILED;
199 if (runClearResTable(ctx, step) != NDBT_OK)
200 return NDBT_FAILED;
201 l++;
202 }
203 return NDBT_OK;
204 }
205
runScanLessThanLoop(NDBT_Context * ctx,NDBT_Step * step)206 int runScanLessThanLoop(NDBT_Context* ctx, NDBT_Step* step){
207 int loops = ctx->getNumLoops();
208 int records = ctx->getNumRecords();
209 int l = 0;
210 LessThanFilter filt(records);
211 while(l < loops){
212 if (scanWithFilter(ctx, step, filt) != NDBT_OK)
213 return NDBT_FAILED;
214 if (runClearResTable(ctx, step) != NDBT_OK)
215 return NDBT_FAILED;
216 l++;
217 }
218 return NDBT_OK;
219 }
220
221 NDBT_TESTSUITE(testScanInterpreter);
222 TESTCASE("ScanLessThan",
223 "Read all records in table TX with attrX less "\
224 "than a value and store the resultset in TX_RES."\
225 "Then compare records in TX_RES with records in TX."){
226 // TABLE("T1");
227 // TABLE("T2");
228 INITIALIZER(runLoadTable);
229 INITIALIZER(runCreateResultTable);
230 STEP(runScanLessThan);
231 VERIFIER(runScanLessThanVerify);
232 FINALIZER(runClearTable);
233 FINALIZER(runClearResTable);
234 }
235 TESTCASE("ScanEqual",
236 "Read all records in table TX with attrX equal "\
237 "to a value and store the resultset in TX_RES."\
238 "Then compare records in TX_RES with records in TX."){
239 // TABLE("T1");
240 // TABLE("T2");
241 INITIALIZER(runLoadTable);
242 INITIALIZER(runCreateResultTable);
243 STEP(runScanEqual);
244 VERIFIER(runScanEqualVerify);
245 FINALIZER(runClearTable);
246 FINALIZER(runClearResTable);
247 }
248 TESTCASE("ScanEqualLoop",
249 "Scan all records in TX equal to a value."\
250 "Do this loop number of times"){
251 // TABLE("T1");
252 // TABLE("T2");
253 INITIALIZER(runLoadTable);
254 INITIALIZER(runCreateResultTable);
255 STEP(runScanEqualLoop);
256 FINALIZER(runClearTable);
257 FINALIZER(runClearResTable);
258 }
259 TESTCASE("ScanEqualVerifyLoop",
260 "Scan all records in TX equal to a value."\
261 "Verify record in TX_RES table"\
262 "Do this loop number of times"){
263 // TABLE("T1");
264 // TABLE("T2");
265 INITIALIZER(runLoadTable);
266 INITIALIZER(runCreateResultTable);
267 STEP(runScanEqualVerifyLoop);
268 FINALIZER(runClearTable);
269 FINALIZER(runClearResTable);
270 }
271 TESTCASE("ScanLessThanLoop",
272 "Scan all records in TX less than a value."\
273 "Do this loop number of times"){
274 // TABLE("T1");
275 // TABLE("T2");
276 INITIALIZER(runLoadTable);
277 INITIALIZER(runCreateResultTable);
278 STEP(runScanLessThanLoop);
279 FINALIZER(runClearTable);
280 FINALIZER(runClearResTable);
281 }
282 NDBT_TESTSUITE_END(testScanInterpreter);
283
main(int argc,const char ** argv)284 int main(int argc, const char** argv){
285 ndb_init();
286 NDBT_TESTSUITE_INSTANCE(testScanInterpreter);
287 return testScanInterpreter.execute(argc, argv);
288 }
289
290
291
292