~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/test/ndbapi/testScanInterpreter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
 
16
#include "NDBT_Test.hpp"
 
17
#include "NDBT_ReturnCodes.h"
 
18
#include "HugoTransactions.hpp"
 
19
#include "UtilTransactions.hpp"
 
20
#include "NdbRestarter.hpp"
 
21
#include <Vector.hpp>
 
22
#include "ScanFilter.hpp"
 
23
#include "ScanInterpretTest.hpp"
 
24
 
 
25
int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
 
26
 
 
27
  int records = ctx->getNumRecords();
 
28
  HugoTransactions hugoTrans(*ctx->getTab());
 
29
  if (hugoTrans.loadTable(GETNDB(step), records) != 0){
 
30
    return NDBT_FAILED;
 
31
  }
 
32
  return NDBT_OK;
 
33
}
 
34
 
 
35
int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
 
36
  int records = ctx->getNumRecords();
 
37
  
 
38
  UtilTransactions utilTrans(*ctx->getTab());
 
39
  if (utilTrans.clearTable2(GETNDB(step),  records) != 0){
 
40
    return NDBT_FAILED;
 
41
  }
 
42
  return NDBT_OK;
 
43
}
 
44
 
 
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"));
 
49
  
 
50
  UtilTransactions utilTrans(*pResTab);
 
51
  if (utilTrans.clearTable2(GETNDB(step), records) != 0){
 
52
    return NDBT_FAILED;
 
53
  }
 
54
  return NDBT_OK;
 
55
}
 
56
 
 
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);
 
61
  
 
62
  int i = 0;
 
63
  HugoTransactions hugoTrans(*ctx->getTab());
 
64
  while (i<loops) {
 
65
    g_info << i << ": ";
 
66
    if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){
 
67
      return NDBT_FAILED;
 
68
    }
 
69
    i++;
 
70
  }
 
71
  return NDBT_OK;
 
72
}
 
73
 
 
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"));
 
80
  
 
81
  HugoTransactions hugoTrans(*pResTab);
 
82
  if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){
 
83
    return NDBT_FAILED;
 
84
  }
 
85
  return NDBT_OK;
 
86
}
 
87
 
 
88
int runCreateResultTable(NDBT_Context* ctx, NDBT_Step* step){
 
89
 
 
90
  const NdbDictionary::Table* pTab = ctx->getTab();
 
91
  char newTabName[256];
 
92
  BaseString::snprintf(newTabName, 256, "%s_RES", pTab->getName());
 
93
  ctx->setProperty("ResultTabName", newTabName);
 
94
 
 
95
  NdbDictionary::Table resTab(* pTab);
 
96
  resTab.setName(newTabName);
 
97
  
 
98
  if (GETNDB(step)->getDictionary()->createTable(resTab) != 0){
 
99
    g_err << newTabName << " creation failed!"<< endl;
 
100
    return NDBT_FAILED;
 
101
  }else{
 
102
    g_info << newTabName << " created!"<< endl;
 
103
    return NDBT_OK;
 
104
  }
 
105
}
 
106
 
 
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)
 
111
    return NDBT_FAILED;
 
112
  const NdbDictionary::Table* pTab = ctx->getTab();
 
113
  const NdbDictionary::Table* pResTab = NDBT_Table::discoverTableFromDb(GETNDB(step), resTabName);
 
114
  if (pResTab == NULL)
 
115
    return NDBT_FAILED;
 
116
  
 
117
  ScanInterpretTest interpretTest(*pTab, *pResTab);
 
118
  if (interpretTest.scanRead(GETNDB(step), 
 
119
                             records, 
 
120
                             16, 
 
121
                             filt) != 0){
 
122
    return NDBT_FAILED;
 
123
  }
 
124
  return NDBT_OK;
 
125
}
 
126
int runScanLessThan(NDBT_Context* ctx, NDBT_Step* step){
 
127
  int records = ctx->getNumRecords();
 
128
  LessThanFilter filt(records);
 
129
  return scanWithFilter(ctx, step, filt);
 
130
}
 
131
int runScanEqual(NDBT_Context* ctx, NDBT_Step* step){
 
132
  EqualFilter filt;
 
133
  return scanWithFilter(ctx, step, filt);
 
134
}
 
135
 
 
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)
 
140
    return NDBT_FAILED;
 
141
  const NdbDictionary::Table* pTab = ctx->getTab();
 
142
  const NdbDictionary::Table* pResTab = NDBT_Table::discoverTableFromDb(GETNDB(step), resTabName);
 
143
  if (pResTab == NULL)
 
144
    return NDBT_FAILED;
 
145
  
 
146
  ScanInterpretTest interpretTest(*pTab, *pResTab);
 
147
  if (interpretTest.scanReadVerify(GETNDB(step), 
 
148
                                   records, 
 
149
                                   16, 
 
150
                                   filt) != NDBT_OK){
 
151
    return NDBT_FAILED;
 
152
  }
 
153
  return NDBT_OK;
 
154
}
 
155
int runScanLessThanVerify(NDBT_Context* ctx, NDBT_Step* step){
 
156
  int records = ctx->getNumRecords();
 
157
  LessThanFilter filt(records);
 
158
  return scanVerifyWithFilter(ctx, step, filt);
 
159
}
 
160
int runScanEqualVerify(NDBT_Context* ctx, NDBT_Step* step){
 
161
  EqualFilter filt;
 
162
  return scanVerifyWithFilter(ctx, step, filt);
 
163
}
 
164
 
 
165
int runScanEqualLoop(NDBT_Context* ctx, NDBT_Step* step){
 
166
  int loops = ctx->getNumLoops();
 
167
  int l = 0;
 
168
  EqualFilter filt;
 
169
  while(l < loops){
 
170
    if (scanWithFilter(ctx, step, filt) != NDBT_OK)
 
171
      return NDBT_FAILED;
 
172
    if (runClearResTable(ctx, step) != NDBT_OK)
 
173
      return NDBT_FAILED;
 
174
    l++;
 
175
  }
 
176
  return NDBT_OK;
 
177
}
 
178
 
 
179
 
 
180
int runScanEqualVerifyLoop(NDBT_Context* ctx, NDBT_Step* step){
 
181
  int loops = ctx->getNumLoops();
 
182
  int l = 0;
 
183
  EqualFilter filt;
 
184
  while(l < loops){
 
185
    if (scanWithFilter(ctx, step, filt) != NDBT_OK)
 
186
      return NDBT_FAILED;
 
187
    if (scanVerifyWithFilter(ctx, step, filt) != NDBT_OK)
 
188
      return NDBT_FAILED;
 
189
    if (runClearResTable(ctx, step) != NDBT_OK)
 
190
      return NDBT_FAILED;
 
191
    l++;
 
192
  }
 
193
  return NDBT_OK;
 
194
}
 
195
 
 
196
int runScanLessThanLoop(NDBT_Context* ctx, NDBT_Step* step){
 
197
  int loops = ctx->getNumLoops();
 
198
  int records = ctx->getNumRecords();
 
199
  int l = 0;
 
200
  LessThanFilter filt(records);
 
201
  while(l < loops){
 
202
    if (scanWithFilter(ctx, step, filt) != NDBT_OK)
 
203
      return NDBT_FAILED;
 
204
    if (runClearResTable(ctx, step) != NDBT_OK)
 
205
      return NDBT_FAILED;
 
206
    l++;
 
207
  }
 
208
  return NDBT_OK;
 
209
}
 
210
 
 
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."){
 
216
  //  TABLE("T1");
 
217
  //  TABLE("T2");
 
218
  INITIALIZER(runLoadTable);
 
219
  INITIALIZER(runCreateResultTable);
 
220
  STEP(runScanLessThan);
 
221
  VERIFIER(runScanLessThanVerify);
 
222
  FINALIZER(runClearTable);
 
223
  FINALIZER(runClearResTable);
 
224
}
 
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."){
 
229
  //  TABLE("T1");
 
230
  //  TABLE("T2");
 
231
  INITIALIZER(runLoadTable);
 
232
  INITIALIZER(runCreateResultTable);
 
233
  STEP(runScanEqual);
 
234
  VERIFIER(runScanEqualVerify);
 
235
  FINALIZER(runClearTable);
 
236
  FINALIZER(runClearResTable);
 
237
}
 
238
TESTCASE("ScanEqualLoop", 
 
239
         "Scan all records in TX equal to a value."\
 
240
         "Do this loop number of times"){
 
241
  //  TABLE("T1");
 
242
  //  TABLE("T2");
 
243
  INITIALIZER(runLoadTable);
 
244
  INITIALIZER(runCreateResultTable);
 
245
  STEP(runScanEqualLoop);
 
246
  FINALIZER(runClearTable);
 
247
  FINALIZER(runClearResTable);
 
248
}
 
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"){
 
253
  //  TABLE("T1");
 
254
  //  TABLE("T2");
 
255
  INITIALIZER(runLoadTable);
 
256
  INITIALIZER(runCreateResultTable);
 
257
  STEP(runScanEqualVerifyLoop);
 
258
  FINALIZER(runClearTable);
 
259
  FINALIZER(runClearResTable);
 
260
}
 
261
TESTCASE("ScanLessThanLoop", 
 
262
         "Scan all records in TX less than a value."\
 
263
         "Do this loop number of times"){
 
264
  //  TABLE("T1");
 
265
  //  TABLE("T2");
 
266
  INITIALIZER(runLoadTable);
 
267
  INITIALIZER(runCreateResultTable);
 
268
  STEP(runScanLessThanLoop);
 
269
  FINALIZER(runClearTable);
 
270
  FINALIZER(runClearResTable);
 
271
}
 
272
NDBT_TESTSUITE_END(testScanInterpreter);
 
273
 
 
274
int main(int argc, const char** argv){
 
275
  ndb_init();
 
276
  return testScanInterpreter.execute(argc, argv);
 
277
}
 
278
 
 
279
 
 
280