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