1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "NDBT_Test.hpp"
17
#include "NDBT_ReturnCodes.h"
18
#include "HugoTransactions.hpp"
19
#include "UtilTransactions.hpp"
20
#include "NdbRestarter.hpp"
22
#include "ScanFilter.hpp"
23
#include "ScanInterpretTest.hpp"
25
int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
27
int records = ctx->getNumRecords();
28
HugoTransactions hugoTrans(*ctx->getTab());
29
if (hugoTrans.loadTable(GETNDB(step), records) != 0){
35
int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
36
int records = ctx->getNumRecords();
38
UtilTransactions utilTrans(*ctx->getTab());
39
if (utilTrans.clearTable2(GETNDB(step), records) != 0){
45
int runClearResTable(NDBT_Context* ctx, NDBT_Step* step){
46
int records = ctx->getNumRecords();
47
const NdbDictionary::Table* pResTab =
48
GETNDB(step)->getDictionary()->getTable(ctx->getProperty("ResultTabName", "NULL"));
50
UtilTransactions utilTrans(*pResTab);
51
if (utilTrans.clearTable2(GETNDB(step), records) != 0){
57
int runScanRead(NDBT_Context* ctx, NDBT_Step* step){
58
int loops = ctx->getNumLoops();
59
int records = ctx->getNumRecords();
60
int parallelism = ctx->getProperty("Parallelism", 1);
63
HugoTransactions hugoTrans(*ctx->getTab());
66
if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){
74
int runScanReadResTable(NDBT_Context* ctx, NDBT_Step* step){
75
int records = ctx->getNumRecords();
76
int parallelism = ctx->getProperty("Parallelism", 1);
77
const NdbDictionary::Table* pResTab =
78
NDBT_Table::discoverTableFromDb(GETNDB(step),
79
ctx->getProperty("ResultTabName", "NULL"));
81
HugoTransactions hugoTrans(*pResTab);
82
if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){
88
int runCreateResultTable(NDBT_Context* ctx, NDBT_Step* step){
90
const NdbDictionary::Table* pTab = ctx->getTab();
92
BaseString::snprintf(newTabName, 256, "%s_RES", pTab->getName());
93
ctx->setProperty("ResultTabName", newTabName);
95
NdbDictionary::Table resTab(* pTab);
96
resTab.setName(newTabName);
98
if (GETNDB(step)->getDictionary()->createTable(resTab) != 0){
99
g_err << newTabName << " creation failed!"<< endl;
102
g_info << newTabName << " created!"<< endl;
107
int scanWithFilter(NDBT_Context* ctx, NDBT_Step* step, ScanFilter& filt){
108
int records = ctx->getNumRecords();
109
const char* resTabName = ctx->getProperty("ResultTabName", "NULL");
110
if (strcmp(resTabName, "NULL") == 0)
112
const NdbDictionary::Table* pTab = ctx->getTab();
113
const NdbDictionary::Table* pResTab = NDBT_Table::discoverTableFromDb(GETNDB(step), resTabName);
117
ScanInterpretTest interpretTest(*pTab, *pResTab);
118
if (interpretTest.scanRead(GETNDB(step),
126
int runScanLessThan(NDBT_Context* ctx, NDBT_Step* step){
127
int records = ctx->getNumRecords();
128
LessThanFilter filt(records);
129
return scanWithFilter(ctx, step, filt);
131
int runScanEqual(NDBT_Context* ctx, NDBT_Step* step){
133
return scanWithFilter(ctx, step, filt);
136
int scanVerifyWithFilter(NDBT_Context* ctx, NDBT_Step* step, ScanFilter& filt){
137
int records = ctx->getNumRecords();
138
const char* resTabName = ctx->getProperty("ResultTabName", "NULL");
139
if (strcmp(resTabName, "NULL") == 0)
141
const NdbDictionary::Table* pTab = ctx->getTab();
142
const NdbDictionary::Table* pResTab = NDBT_Table::discoverTableFromDb(GETNDB(step), resTabName);
146
ScanInterpretTest interpretTest(*pTab, *pResTab);
147
if (interpretTest.scanReadVerify(GETNDB(step),
155
int runScanLessThanVerify(NDBT_Context* ctx, NDBT_Step* step){
156
int records = ctx->getNumRecords();
157
LessThanFilter filt(records);
158
return scanVerifyWithFilter(ctx, step, filt);
160
int runScanEqualVerify(NDBT_Context* ctx, NDBT_Step* step){
162
return scanVerifyWithFilter(ctx, step, filt);
165
int runScanEqualLoop(NDBT_Context* ctx, NDBT_Step* step){
166
int loops = ctx->getNumLoops();
170
if (scanWithFilter(ctx, step, filt) != NDBT_OK)
172
if (runClearResTable(ctx, step) != NDBT_OK)
180
int runScanEqualVerifyLoop(NDBT_Context* ctx, NDBT_Step* step){
181
int loops = ctx->getNumLoops();
185
if (scanWithFilter(ctx, step, filt) != NDBT_OK)
187
if (scanVerifyWithFilter(ctx, step, filt) != NDBT_OK)
189
if (runClearResTable(ctx, step) != NDBT_OK)
196
int runScanLessThanLoop(NDBT_Context* ctx, NDBT_Step* step){
197
int loops = ctx->getNumLoops();
198
int records = ctx->getNumRecords();
200
LessThanFilter filt(records);
202
if (scanWithFilter(ctx, step, filt) != NDBT_OK)
204
if (runClearResTable(ctx, step) != NDBT_OK)
211
NDBT_TESTSUITE(testScanInterpreter);
212
TESTCASE("ScanLessThan",
213
"Read all records in table TX with attrX less "\
214
"than a value and store the resultset in TX_RES."\
215
"Then compare records in TX_RES with records in TX."){
218
INITIALIZER(runLoadTable);
219
INITIALIZER(runCreateResultTable);
220
STEP(runScanLessThan);
221
VERIFIER(runScanLessThanVerify);
222
FINALIZER(runClearTable);
223
FINALIZER(runClearResTable);
225
TESTCASE("ScanEqual",
226
"Read all records in table TX with attrX equal "\
227
"to a value and store the resultset in TX_RES."\
228
"Then compare records in TX_RES with records in TX."){
231
INITIALIZER(runLoadTable);
232
INITIALIZER(runCreateResultTable);
234
VERIFIER(runScanEqualVerify);
235
FINALIZER(runClearTable);
236
FINALIZER(runClearResTable);
238
TESTCASE("ScanEqualLoop",
239
"Scan all records in TX equal to a value."\
240
"Do this loop number of times"){
243
INITIALIZER(runLoadTable);
244
INITIALIZER(runCreateResultTable);
245
STEP(runScanEqualLoop);
246
FINALIZER(runClearTable);
247
FINALIZER(runClearResTable);
249
TESTCASE("ScanEqualVerifyLoop",
250
"Scan all records in TX equal to a value."\
251
"Verify record in TX_RES table"\
252
"Do this loop number of times"){
255
INITIALIZER(runLoadTable);
256
INITIALIZER(runCreateResultTable);
257
STEP(runScanEqualVerifyLoop);
258
FINALIZER(runClearTable);
259
FINALIZER(runClearResTable);
261
TESTCASE("ScanLessThanLoop",
262
"Scan all records in TX less than a value."\
263
"Do this loop number of times"){
266
INITIALIZER(runLoadTable);
267
INITIALIZER(runCreateResultTable);
268
STEP(runScanLessThanLoop);
269
FINALIZER(runClearTable);
270
FINALIZER(runClearResTable);
272
NDBT_TESTSUITE_END(testScanInterpreter);
274
int main(int argc, const char** argv){
276
return testScanInterpreter.execute(argc, argv);