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 */
17
#include <NDBT_Test.hpp>
18
#include <HugoTransactions.hpp>
19
#include <UtilTransactions.hpp>
20
#include <NdbRestarter.hpp>
21
#include <NdbRestarts.hpp>
27
#define CHECK(b) if (!(b)) { \
28
ndbout << "ERR: "<< step->getName() \
29
<< " failed on line " << __LINE__ << endl; \
30
result = NDBT_FAILED; \
33
int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
34
int records = ctx->getNumRecords();
35
int batchSize = ctx->getProperty("BatchSize", 1);
37
HugoTransactions hugoTrans(*ctx->getTab());
38
if (hugoTrans.pkDelRecords(GETNDB(step), records, batchSize) != 0){
44
int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
46
int records = ctx->getNumRecords();
47
HugoTransactions hugoTrans(*ctx->getTab());
48
if (hugoTrans.loadTable(GETNDB(step), records) != 0){
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);
59
HugoTransactions hugoTrans(*ctx->getTab());
60
if (hugoTrans.pkInterpretedUpdateRecords(GETNDB(step),
66
if (hugoTrans.pkReadRecords(GETNDB(step),
75
int runTestIncValue32(NDBT_Context* ctx, NDBT_Step* step){
77
const NdbDictionary::Table * pTab = ctx->getTab();
78
Ndb* pNdb = GETNDB(step);
80
if (strcmp(pTab->getName(), "T1") != 0) {
81
g_err << "runTestBug19537: skip, table != T1" << endl;
86
NdbConnection* pTrans = pNdb->startTransaction();
88
ERR(pNdb->getNdbError());
92
NdbOperation* pOp = pTrans->getNdbOperation(pTab->getName());
94
ERR(pTrans->getNdbError());
95
pNdb->closeTransaction(pTrans);
99
int check = pOp->interpretedUpdateTuple();
101
ERR(pTrans->getNdbError());
102
pNdb->closeTransaction(pTrans);
109
check = pOp->equal("KOL1", pkVal );
111
ERR(pTrans->getNdbError());
112
pNdb->closeTransaction(pTrans);
119
Uint32 valToIncWith = 1;
120
check = pOp->incValue("KOL2", valToIncWith);
122
ERR(pTrans->getNdbError());
123
pNdb->closeTransaction(pTrans);
127
NdbRecAttr* valueRec = pOp->getValue("KOL2");
128
if( valueRec == NULL ) {
129
ERR(pTrans->getNdbError());
130
pNdb->closeTransaction(pTrans);
134
check = pTrans->execute(Commit);
136
ERR(pTrans->getNdbError());
137
pNdb->closeTransaction(pTrans);
141
Uint32 value = valueRec->u_32_value();
143
pNdb->closeTransaction(pTrans);
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);
154
if (strcmp(pTab->getName(), "T1") != 0) {
155
g_err << "runTestBug19537: skip, table != T1" << endl;
160
NdbConnection* pTrans = pNdb->startTransaction();
162
ERR(pNdb->getNdbError());
166
NdbOperation* pOp = pTrans->getNdbOperation(pTab->getName());
168
ERR(pTrans->getNdbError());
169
pNdb->closeTransaction(pTrans);
173
if (pOp->interpretedUpdateTuple() == -1) {
174
ERR(pOp->getNdbError());
175
pNdb->closeTransaction(pTrans);
181
const Uint32 pkVal = 1;
182
if (pOp->equal("KOL1", pkVal) == -1) {
183
ERR(pTrans->getNdbError());
184
pNdb->closeTransaction(pTrans);
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;
192
const Uint32* reg_ptr32 = (const Uint32*)®_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;
198
g_err << "runTestBug19537: impossible platform"
199
<< hex << " [0]=" << reg_ptr32[0] << " [1]=" <<reg_ptr32[1] << endl;
200
pNdb->closeTransaction(pTrans);
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);
211
if (pTrans->execute(Commit) == -1) {
212
ERR(pTrans->getNdbError());
213
pNdb->closeTransaction(pTrans);
217
// Read value via a new transaction
219
pTrans = pNdb->startTransaction();
221
ERR(pNdb->getNdbError());
225
pOp = pTrans->getNdbOperation(pTab->getName());
227
ERR(pTrans->getNdbError());
228
pNdb->closeTransaction(pTrans);
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);
241
if (pTrans->execute(Commit) == -1) {
242
ERR(pTrans->getNdbError());
243
pNdb->closeTransaction(pTrans);
247
// Expected conversion as in C - truncate to lower (logical) word
249
if (kol2 == 0x01020304) {
250
g_err << "runTestBug19537: the bug manifests itself !" << endl;
251
pNdb->closeTransaction(pTrans);
255
if (kol2 != 0x05060708) {
256
g_err << "runTestBug19537: impossible KOL2 " << hex << kol2 << endl;
257
pNdb->closeTransaction(pTrans);
261
pNdb->closeTransaction(pTrans);
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);
272
for (i = 0; i <= 1; i++) {
273
g_info << "bug34107:" << (i == 0 ? " small" : " too big") << endl;
275
NdbConnection* pTrans = pNdb->startTransaction();
277
ERR(pNdb->getNdbError());
281
NdbScanOperation* pOp = pTrans->getNdbScanOperation(pTab->getName());
283
ERR(pTrans->getNdbError());
284
pNdb->closeTransaction(pTrans);
288
if (pOp->readTuples() == -1) {
289
ERR(pOp->getNdbError());
290
pNdb->closeTransaction(pTrans);
294
int n = i == 0 ? 10000 : 30000;
297
for (k = 0; k < n; k++) {
299
// inserts 1 word ATTRINFO
301
if (pOp->interpret_exit_ok() == -1) {
302
ERR(pOp->getNdbError());
303
pNdb->closeTransaction(pTrans);
308
if (pTrans->execute(NoCommit) == -1) {
309
ERR(pTrans->getNdbError());
310
pNdb->closeTransaction(pTrans);
315
while ((ret = pOp->nextResult()) == 0)
317
g_info << "ret=" << ret << " err=" << pOp->getNdbError().code << endl;
319
if (i == 0 && ret != 1) {
320
ERR(pTrans->getNdbError());
321
pNdb->closeTransaction(pTrans);
325
if (i == 1 && ret != -1) {
326
g_err << "unexpected big filter success" << endl;
327
pNdb->closeTransaction(pTrans);
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);
337
pNdb->closeTransaction(pTrans);
344
NDBT_TESTSUITE(testInterpreter);
345
TESTCASE("IncValue32",
346
"Test incValue for 32 bit integer\n"){
347
INITIALIZER(runLoadTable);
348
INITIALIZER(runTestIncValue32);
349
FINALIZER(runClearTable);
351
TESTCASE("IncValue64",
352
"Test incValue for 64 bit integer\n"){
353
INITIALIZER(runLoadTable);
354
INITIALIZER(runTestIncValue64);
355
FINALIZER(runClearTable);
358
"Test big-endian write_attr of 32 bit integer\n"){
359
INITIALIZER(runLoadTable);
360
INITIALIZER(runTestBug19537);
361
FINALIZER(runClearTable);
364
"Test too big scan filter (error 874)\n"){
365
INITIALIZER(runLoadTable);
366
INITIALIZER(runTestBug34107);
367
FINALIZER(runClearTable);
370
TESTCASE("MaxTransactions",
371
"Start transactions until no more can be created\n"){
372
INITIALIZER(runTestMaxTransaction);
374
TESTCASE("MaxOperations",
375
"Get operations until no more can be created\n"){
376
INITIALIZER(runLoadTable);
377
INITIALIZER(runTestMaxOperations);
378
FINALIZER(runClearTable);
380
TESTCASE("MaxGetValue",
381
"Call getValue loads of time\n"){
382
INITIALIZER(runLoadTable);
383
INITIALIZER(runTestGetValue);
384
FINALIZER(runClearTable);
387
"Call equal loads of time\n"){
388
INITIALIZER(runTestEqual);
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);
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);
402
TESTCASE("GetOperationNoTab",
403
"Call getNdbOperation on a table that does not exist\n"){
404
INITIALIZER(runGetNdbOperationNoTab);
406
TESTCASE("MissingOperation",
407
"Missing operation request(insertTuple) should give an error code\n"){
408
INITIALIZER(runMissingOperation);
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);
416
TESTCASE("UpdateWithoutKeys",
417
"Test that it's not possible to perform update without setting\n"
419
INITIALIZER(runLoadTable);
420
INITIALIZER(runUpdateWithoutKeys);
421
FINALIZER(runClearTable);
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);
429
TESTCASE("NdbErrorOperation",
430
"Test that NdbErrorOperation is properly set"){
431
INITIALIZER(runCheckGetNdbErrorOperation);
434
NDBT_TESTSUITE_END(testInterpreter);
436
int main(int argc, const char** argv){
439
return testInterpreter.execute(argc, argv);