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