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

« back to all changes in this revision

Viewing changes to storage/ndb/test/ndbapi/testInterpreter.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.hpp>
 
17
#include <NDBT_Test.hpp>
 
18
#include <HugoTransactions.hpp>
 
19
#include <UtilTransactions.hpp>
 
20
#include <NdbRestarter.hpp>
 
21
#include <NdbRestarts.hpp>
 
22
#include <Vector.hpp>
 
23
#include <random.h>
 
24
#include <NdbTick.h>
 
25
 
 
26
 
 
27
#define CHECK(b) if (!(b)) { \
 
28
  ndbout << "ERR: "<< step->getName() \
 
29
         << " failed on line " << __LINE__ << endl; \
 
30
  result = NDBT_FAILED; \
 
31
  continue; } 
 
32
 
 
33
int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
 
34
  int records = ctx->getNumRecords();
 
35
  int batchSize = ctx->getProperty("BatchSize", 1);
 
36
  
 
37
  HugoTransactions hugoTrans(*ctx->getTab());
 
38
  if (hugoTrans.pkDelRecords(GETNDB(step),  records, batchSize) != 0){
 
39
    return NDBT_FAILED;
 
40
  }
 
41
  return NDBT_OK;
 
42
}
 
43
 
 
44
int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
 
45
 
 
46
  int records = ctx->getNumRecords();
 
47
  HugoTransactions hugoTrans(*ctx->getTab());
 
48
  if (hugoTrans.loadTable(GETNDB(step), records) != 0){
 
49
    return NDBT_FAILED;
 
50
  }
 
51
  return NDBT_OK;
 
52
}
 
53
 
 
54
int runTestIncValue64(NDBT_Context* ctx, NDBT_Step* step){
 
55
  int records = ctx->getNumRecords();
 
56
  //  NDBT_Table* pTab = ctx->getTab();
 
57
  //Ndb* pNdb = GETNDB(step);
 
58
 
 
59
  HugoTransactions hugoTrans(*ctx->getTab());
 
60
  if (hugoTrans.pkInterpretedUpdateRecords(GETNDB(step), 
 
61
                                           records) != 0){
 
62
    return NDBT_FAILED;
 
63
  }
 
64
 
 
65
  // Verify the update  
 
66
  if (hugoTrans.pkReadRecords(GETNDB(step), 
 
67
                              records) != 0){
 
68
    return NDBT_FAILED;
 
69
  }
 
70
  
 
71
  return NDBT_OK;
 
72
 
 
73
}
 
74
 
 
75
int runTestIncValue32(NDBT_Context* ctx, NDBT_Step* step){
 
76
  int result = NDBT_OK;
 
77
  const NdbDictionary::Table * pTab = ctx->getTab();
 
78
  Ndb* pNdb = GETNDB(step);
 
79
 
 
80
  if (strcmp(pTab->getName(), "T1") != 0) {
 
81
    g_err << "runTestBug19537: skip, table != T1" << endl;
 
82
    return NDBT_OK;
 
83
  }
 
84
 
 
85
 
 
86
  NdbConnection* pTrans = pNdb->startTransaction();
 
87
  if (pTrans == NULL){
 
88
    ERR(pNdb->getNdbError());
 
89
    return NDBT_FAILED;
 
90
  }
 
91
  
 
92
  NdbOperation* pOp = pTrans->getNdbOperation(pTab->getName());
 
93
  if (pOp == NULL) {
 
94
    ERR(pTrans->getNdbError());
 
95
    pNdb->closeTransaction(pTrans);
 
96
    return NDBT_FAILED;
 
97
  }
 
98
  
 
99
  int check = pOp->interpretedUpdateTuple();
 
100
  if( check == -1 ) {
 
101
    ERR(pTrans->getNdbError());
 
102
    pNdb->closeTransaction(pTrans);
 
103
    return NDBT_FAILED;
 
104
  }
 
105
  
 
106
  
 
107
  // Primary keys
 
108
  Uint32 pkVal = 1;
 
109
  check = pOp->equal("KOL1", pkVal );
 
110
  if( check == -1 ) {
 
111
    ERR(pTrans->getNdbError());
 
112
    pNdb->closeTransaction(pTrans);
 
113
    return NDBT_FAILED;
 
114
  }
 
115
  
 
116
  // Attributes
 
117
  
 
118
  // Update column
 
119
  Uint32 valToIncWith = 1;
 
120
  check = pOp->incValue("KOL2", valToIncWith);
 
121
  if( check == -1 ) {
 
122
    ERR(pTrans->getNdbError());
 
123
    pNdb->closeTransaction(pTrans);
 
124
    return NDBT_FAILED;
 
125
  }
 
126
 
 
127
  NdbRecAttr* valueRec = pOp->getValue("KOL2");
 
128
  if( valueRec == NULL ) {
 
129
    ERR(pTrans->getNdbError());
 
130
    pNdb->closeTransaction(pTrans);
 
131
    return NDBT_FAILED;
 
132
  }
 
133
  
 
134
  check = pTrans->execute(Commit);
 
135
  if( check == -1 ) {
 
136
    ERR(pTrans->getNdbError());
 
137
    pNdb->closeTransaction(pTrans);
 
138
    return NDBT_FAILED;
 
139
  }
 
140
 
 
141
  Uint32 value = valueRec->u_32_value();
 
142
    
 
143
  pNdb->closeTransaction(pTrans);
 
144
 
 
145
 
 
146
  return NDBT_OK;
 
147
}
 
148
 
 
149
int runTestBug19537(NDBT_Context* ctx, NDBT_Step* step){
 
150
  int result = NDBT_OK;
 
151
  const NdbDictionary::Table * pTab = ctx->getTab();
 
152
  Ndb* pNdb = GETNDB(step);
 
153
 
 
154
  if (strcmp(pTab->getName(), "T1") != 0) {
 
155
    g_err << "runTestBug19537: skip, table != T1" << endl;
 
156
    return NDBT_OK;
 
157
  }
 
158
 
 
159
 
 
160
  NdbConnection* pTrans = pNdb->startTransaction();
 
161
  if (pTrans == NULL){
 
162
    ERR(pNdb->getNdbError());
 
163
    return NDBT_FAILED;
 
164
  }
 
165
  
 
166
  NdbOperation* pOp = pTrans->getNdbOperation(pTab->getName());
 
167
  if (pOp == NULL) {
 
168
    ERR(pTrans->getNdbError());
 
169
    pNdb->closeTransaction(pTrans);
 
170
    return NDBT_FAILED;
 
171
  }
 
172
  
 
173
  if (pOp->interpretedUpdateTuple() == -1) {
 
174
    ERR(pOp->getNdbError());
 
175
    pNdb->closeTransaction(pTrans);
 
176
    return NDBT_FAILED;
 
177
  }
 
178
  
 
179
  
 
180
  // Primary keys
 
181
  const Uint32 pkVal = 1;
 
182
  if (pOp->equal("KOL1", pkVal) == -1) {
 
183
    ERR(pTrans->getNdbError());
 
184
    pNdb->closeTransaction(pTrans);
 
185
    return NDBT_FAILED;
 
186
  }
 
187
  
 
188
  // Load 64-bit constant into register 1 and
 
189
  // write from register 1 to 32-bit column KOL2
 
190
  const Uint64 reg_val = 0x0102030405060708ULL;
 
191
 
 
192
  const Uint32* reg_ptr32 = (const Uint32*)&reg_val;
 
193
  if (reg_ptr32[0] == 0x05060708 && reg_ptr32[1] == 0x01020304) {
 
194
    g_err << "runTestBug19537: platform is LITTLE endian" << endl;
 
195
  } else if (reg_ptr32[0] == 0x01020304 && reg_ptr32[1] == 0x05060708) {
 
196
    g_err << "runTestBug19537: platform is BIG endian" << endl;
 
197
  } else {
 
198
    g_err << "runTestBug19537: impossible platform"
 
199
          << hex << " [0]=" << reg_ptr32[0] << " [1]=" <<reg_ptr32[1] << endl;
 
200
    pNdb->closeTransaction(pTrans);
 
201
    return NDBT_FAILED;
 
202
  }
 
203
 
 
204
  if (pOp->load_const_u64(1, reg_val) == -1 ||
 
205
      pOp->write_attr("KOL2", 1) == -1) {
 
206
    ERR(pOp->getNdbError());
 
207
    pNdb->closeTransaction(pTrans);
 
208
    return NDBT_FAILED;
 
209
  }
 
210
 
 
211
  if (pTrans->execute(Commit) == -1) {
 
212
    ERR(pTrans->getNdbError());
 
213
    pNdb->closeTransaction(pTrans);
 
214
    return NDBT_FAILED;
 
215
  }
 
216
 
 
217
  // Read value via a new transaction
 
218
 
 
219
  pTrans = pNdb->startTransaction();
 
220
  if (pTrans == NULL){
 
221
    ERR(pNdb->getNdbError());
 
222
    return NDBT_FAILED;
 
223
  }
 
224
  
 
225
  pOp = pTrans->getNdbOperation(pTab->getName());
 
226
  if (pOp == NULL) {
 
227
    ERR(pTrans->getNdbError());
 
228
    pNdb->closeTransaction(pTrans);
 
229
    return NDBT_FAILED;
 
230
  }
 
231
  
 
232
  Uint32 kol2 = 0x09090909;
 
233
  if (pOp->readTuple() == -1 ||
 
234
      pOp->equal("KOL1", pkVal) == -1 ||
 
235
      pOp->getValue("KOL2", (char*)&kol2) == 0) {
 
236
    ERR(pOp->getNdbError());
 
237
    pNdb->closeTransaction(pTrans);
 
238
    return NDBT_FAILED;
 
239
  }
 
240
 
 
241
  if (pTrans->execute(Commit) == -1) {
 
242
    ERR(pTrans->getNdbError());
 
243
    pNdb->closeTransaction(pTrans);
 
244
    return NDBT_FAILED;
 
245
  }
 
246
 
 
247
  // Expected conversion as in C - truncate to lower (logical) word
 
248
 
 
249
  if (kol2 == 0x01020304) {
 
250
    g_err << "runTestBug19537: the bug manifests itself !" << endl;
 
251
    pNdb->closeTransaction(pTrans);
 
252
    return NDBT_FAILED;
 
253
  }
 
254
 
 
255
  if (kol2 != 0x05060708) {
 
256
    g_err << "runTestBug19537: impossible KOL2 " << hex << kol2 << endl;
 
257
    pNdb->closeTransaction(pTrans);
 
258
    return NDBT_FAILED;
 
259
  }
 
260
 
 
261
  pNdb->closeTransaction(pTrans);
 
262
  return NDBT_OK;
 
263
}
 
264
 
 
265
 
 
266
int runTestBug34107(NDBT_Context* ctx, NDBT_Step* step){
 
267
  int result = NDBT_OK;
 
268
  const NdbDictionary::Table * pTab = ctx->getTab();
 
269
  Ndb* pNdb = GETNDB(step);
 
270
 
 
271
  int i;
 
272
  for (i = 0; i <= 1; i++) {
 
273
    g_info << "bug34107:" << (i == 0 ? " small" : " too big") << endl;
 
274
 
 
275
    NdbConnection* pTrans = pNdb->startTransaction();
 
276
    if (pTrans == NULL){
 
277
      ERR(pNdb->getNdbError());
 
278
      return NDBT_FAILED;
 
279
    }
 
280
    
 
281
    NdbScanOperation* pOp = pTrans->getNdbScanOperation(pTab->getName());
 
282
    if (pOp == NULL) {
 
283
      ERR(pTrans->getNdbError());
 
284
      pNdb->closeTransaction(pTrans);
 
285
      return NDBT_FAILED;
 
286
    }
 
287
    
 
288
    if (pOp->readTuples() == -1) {
 
289
      ERR(pOp->getNdbError());
 
290
      pNdb->closeTransaction(pTrans);
 
291
      return NDBT_FAILED;
 
292
    }
 
293
 
 
294
    int n = i == 0 ? 10000 : 30000;
 
295
    int k;
 
296
 
 
297
    for (k = 0; k < n; k++) {
 
298
 
 
299
      // inserts 1 word ATTRINFO
 
300
 
 
301
      if (pOp->interpret_exit_ok() == -1) {
 
302
        ERR(pOp->getNdbError());
 
303
        pNdb->closeTransaction(pTrans);
 
304
        return NDBT_FAILED;
 
305
      }
 
306
    }
 
307
      
 
308
    if (pTrans->execute(NoCommit) == -1) {
 
309
      ERR(pTrans->getNdbError());
 
310
      pNdb->closeTransaction(pTrans);
 
311
      return NDBT_FAILED;
 
312
    }
 
313
 
 
314
    int ret;
 
315
    while ((ret = pOp->nextResult()) == 0)
 
316
      ;
 
317
    g_info << "ret=" << ret << " err=" << pOp->getNdbError().code << endl;
 
318
 
 
319
    if (i == 0 && ret != 1) {
 
320
      ERR(pTrans->getNdbError());
 
321
      pNdb->closeTransaction(pTrans);
 
322
      return NDBT_FAILED;
 
323
    }
 
324
 
 
325
    if (i == 1 && ret != -1) {
 
326
      g_err << "unexpected big filter success" << endl;
 
327
      pNdb->closeTransaction(pTrans);
 
328
      return NDBT_FAILED;
 
329
    }
 
330
    if (i == 1 && pOp->getNdbError().code != 874) {
 
331
      g_err << "unexpected big filter error code, wanted 874" << endl;
 
332
      ERR(pTrans->getNdbError());
 
333
      pNdb->closeTransaction(pTrans);
 
334
      return NDBT_FAILED;
 
335
    }
 
336
 
 
337
    pNdb->closeTransaction(pTrans);
 
338
  }
 
339
 
 
340
  return NDBT_OK;
 
341
}
 
342
 
 
343
 
 
344
NDBT_TESTSUITE(testInterpreter);
 
345
TESTCASE("IncValue32", 
 
346
         "Test incValue for 32 bit integer\n"){ 
 
347
  INITIALIZER(runLoadTable);
 
348
  INITIALIZER(runTestIncValue32);
 
349
  FINALIZER(runClearTable);
 
350
}
 
351
TESTCASE("IncValue64", 
 
352
         "Test incValue for 64 bit integer\n"){ 
 
353
  INITIALIZER(runLoadTable);
 
354
  INITIALIZER(runTestIncValue64);
 
355
  FINALIZER(runClearTable);
 
356
}
 
357
TESTCASE("Bug19537",
 
358
         "Test big-endian write_attr of 32 bit integer\n"){
 
359
  INITIALIZER(runLoadTable);
 
360
  INITIALIZER(runTestBug19537);
 
361
  FINALIZER(runClearTable);
 
362
}
 
363
TESTCASE("Bug34107",
 
364
         "Test too big scan filter (error 874)\n"){
 
365
  INITIALIZER(runLoadTable);
 
366
  INITIALIZER(runTestBug34107);
 
367
  FINALIZER(runClearTable);
 
368
}
 
369
#if 0
 
370
TESTCASE("MaxTransactions", 
 
371
         "Start transactions until no more can be created\n"){ 
 
372
  INITIALIZER(runTestMaxTransaction);
 
373
}
 
374
TESTCASE("MaxOperations", 
 
375
        "Get operations until no more can be created\n"){ 
 
376
  INITIALIZER(runLoadTable);
 
377
  INITIALIZER(runTestMaxOperations);
 
378
  FINALIZER(runClearTable);
 
379
}
 
380
TESTCASE("MaxGetValue", 
 
381
        "Call getValue loads of time\n"){ 
 
382
  INITIALIZER(runLoadTable);
 
383
  INITIALIZER(runTestGetValue);
 
384
  FINALIZER(runClearTable);
 
385
}
 
386
TESTCASE("MaxEqual", 
 
387
        "Call equal loads of time\n"){ 
 
388
  INITIALIZER(runTestEqual);
 
389
}
 
390
TESTCASE("DeleteNdb", 
 
391
        "Make sure that a deleted Ndb object is properly deleted\n"
 
392
        "and removed from transporter\n"){ 
 
393
  INITIALIZER(runLoadTable);
 
394
  INITIALIZER(runTestDeleteNdb);
 
395
  FINALIZER(runClearTable);
 
396
}
 
397
TESTCASE("WaitUntilReady", 
 
398
        "Make sure you get an error message when calling waitUntilReady\n"
 
399
        "without an init'ed Ndb\n"){ 
 
400
  INITIALIZER(runTestWaitUntilReady);
 
401
}
 
402
TESTCASE("GetOperationNoTab", 
 
403
        "Call getNdbOperation on a table that does not exist\n"){ 
 
404
  INITIALIZER(runGetNdbOperationNoTab);
 
405
}
 
406
TESTCASE("MissingOperation", 
 
407
        "Missing operation request(insertTuple) should give an error code\n"){ 
 
408
  INITIALIZER(runMissingOperation);
 
409
}
 
410
TESTCASE("GetValueInUpdate", 
 
411
        "Test that it's not possible to perform getValue in an update\n"){ 
 
412
  INITIALIZER(runLoadTable);
 
413
  INITIALIZER(runGetValueInUpdate);
 
414
  FINALIZER(runClearTable);
 
415
}
 
416
TESTCASE("UpdateWithoutKeys", 
 
417
        "Test that it's not possible to perform update without setting\n"
 
418
         "PKs"){ 
 
419
  INITIALIZER(runLoadTable);
 
420
  INITIALIZER(runUpdateWithoutKeys);
 
421
  FINALIZER(runClearTable);
 
422
}
 
423
TESTCASE("UpdateWithoutValues", 
 
424
        "Test that it's not possible to perform update without setValues\n"){ 
 
425
  INITIALIZER(runLoadTable);
 
426
  INITIALIZER(runUpdateWithoutValues);
 
427
  FINALIZER(runClearTable);
 
428
}
 
429
TESTCASE("NdbErrorOperation", 
 
430
         "Test that NdbErrorOperation is properly set"){
 
431
  INITIALIZER(runCheckGetNdbErrorOperation);
 
432
}
 
433
#endif
 
434
NDBT_TESTSUITE_END(testInterpreter);
 
435
 
 
436
int main(int argc, const char** argv){
 
437
  ndb_init();
 
438
  //  TABLE("T1");
 
439
  return testInterpreter.execute(argc, argv);
 
440
}
 
441
 
 
442