diff options
Diffstat (limited to 'ndb/test/ndbapi/testBlobs.cpp')
-rw-r--r-- | ndb/test/ndbapi/testBlobs.cpp | 224 |
1 files changed, 172 insertions, 52 deletions
diff --git a/ndb/test/ndbapi/testBlobs.cpp b/ndb/test/ndbapi/testBlobs.cpp index 41bb82f3e06..efa0811aa39 100644 --- a/ndb/test/ndbapi/testBlobs.cpp +++ b/ndb/test/ndbapi/testBlobs.cpp @@ -42,13 +42,14 @@ struct Opt { bool m_core; bool m_dbg; bool m_dbgall; + const char* m_dbug; bool m_full; unsigned m_loop; unsigned m_parts; unsigned m_rows; unsigned m_seed; const char* m_skip; - const char* m_style; + const char* m_test; // metadata const char* m_tname; const char* m_x1name; // hash index @@ -66,13 +67,14 @@ struct Opt { m_core(false), m_dbg(false), m_dbgall(false), + m_dbug(0), m_full(false), m_loop(1), m_parts(10), m_rows(100), m_seed(0), - m_skip(""), - m_style("012"), + m_skip(0), + m_test(0), // metadata m_tname("TBLOB1"), m_x1name("TBLOB1X1"), @@ -100,46 +102,46 @@ printusage() << " -core dump core on error" << endl << " -dbg print debug" << endl << " -dbgall print also NDB API debug (if compiled in)" << endl + << " -dbug opt dbug options" << endl << " -full read/write only full blob values" << endl - << " -inline read/write only blobs which fit inline" << endl << " -loop N loop N times 0=forever [" << d.m_loop << "]" << endl << " -parts N max parts in blob value [" << d.m_parts << "]" << endl << " -rows N number of rows [" << d.m_rows << "]" << endl << " -seed N random seed 0=loop number [" << d.m_seed << "]" << endl - << " -skip xxx skip these tests (see list) [" << d.m_skip << endl - << " -style xxx access styles to test (see list) [" << d.m_style << "]" << endl + << " -skip xxx skip given tests (see list) [no tests]" << endl + << " -test xxx only given tests (see list) [all tests]" << endl << "metadata" << endl << " -pk2len N length of PK2 [" << d.m_pk2len << "/" << g_max_pk2len <<"]" << endl << " -oneblob only 1 blob attribute [default 2]" << endl - << "testcases for -skip" << endl + << "testcases for test/skip" << endl << " k primary key ops" << endl << " i hash index ops" << endl << " s table scans" << endl << " r ordered index scans" << endl - << " u update blob value" << endl - << "access styles for -style" << endl + << "additional flags for test/skip" << endl + << " u update existing blob value" << endl + << " n normal insert and update" << endl + << " w insert and update using writeTuple" << endl << " 0 getValue / setValue" << endl << " 1 setActiveHook" << endl << " 2 readData / writeData" << endl << "bug tests (no blob test)" << endl << " -bug 4088 ndb api hang with mixed ops on index table" << endl - << " -bug 2222 delete + write gives 626" << endl - << " -bug 3333 acc crash on delete and long key" << endl + << " -bug nnnn delete + write gives 626" << endl + << " -bug nnnn acc crash on delete and long key" << endl ; } static Opt g_opt; static bool -skipcase(int x) +testcase(char x) { - return strchr(g_opt.m_skip, x) != 0; -} - -static bool -skipstyle(int x) -{ - return strchr(g_opt.m_style, '0' + x) == 0; + if (x < 10) + x += '0'; + return + (g_opt.m_test == 0 || strchr(g_opt.m_test, x) != 0) && + (g_opt.m_skip == 0 || strchr(g_opt.m_skip, x) == 0); } static Ndb* g_ndb = 0; @@ -435,7 +437,9 @@ getBlobLength(NdbBlob* h, unsigned& len) CHK(h->getLength(len2) == 0); len = (unsigned)len2; assert(len == len2); - DBG("getBlobLength " << h->getColumn()->getName() << " len=" << len); + bool isNull; + CHK(h->getNull(isNull) == 0); + DBG("getBlobLength " << h->getColumn()->getName() << " len=" << len << " null=" << isNull); return 0; } @@ -912,6 +916,41 @@ updatePk(int style) } static int +writePk(int style) +{ + DBG("--- writePk " << stylename[style] << " ---"); + for (unsigned k = 0; k < g_opt.m_rows; k++) { + Tup& tup = g_tups[k]; + DBG("writePk pk1=" << hex << tup.m_pk1); + CHK((g_con = g_ndb->startTransaction()) != 0); + CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0); + CHK(g_opr->writeTuple() == 0); + CHK(g_opr->equal("PK1", tup.m_pk1) == 0); + if (g_opt.m_pk2len != 0) + CHK(g_opr->equal("PK2", tup.m_pk2) == 0); + CHK(getBlobHandles(g_opr) == 0); + if (style == 0) { + CHK(setBlobValue(tup) == 0); + } else if (style == 1) { + // non-nullable must be set + CHK(g_bh1->setValue("", 0) == 0); + CHK(setBlobWriteHook(tup) == 0); + } else { + // non-nullable must be set + CHK(g_bh1->setValue("", 0) == 0); + CHK(g_con->execute(NoCommit) == 0); + CHK(writeBlobData(tup) == 0); + } + CHK(g_con->execute(Commit) == 0); + g_ndb->closeTransaction(g_con); + g_opr = 0; + g_con = 0; + tup.m_exists = true; + } + return 0; +} + +static int deletePk() { DBG("--- deletePk ---"); @@ -996,6 +1035,39 @@ updateIdx(int style) } static int +writeIdx(int style) +{ + DBG("--- writeIdx " << stylename[style] << " ---"); + for (unsigned k = 0; k < g_opt.m_rows; k++) { + Tup& tup = g_tups[k]; + DBG("writeIdx pk1=" << hex << tup.m_pk1); + CHK((g_con = g_ndb->startTransaction()) != 0); + CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0); + CHK(g_opx->writeTuple() == 0); + CHK(g_opx->equal("PK2", tup.m_pk2) == 0); + CHK(getBlobHandles(g_opx) == 0); + if (style == 0) { + CHK(setBlobValue(tup) == 0); + } else if (style == 1) { + // non-nullable must be set + CHK(g_bh1->setValue("", 0) == 0); + CHK(setBlobWriteHook(tup) == 0); + } else { + // non-nullable must be set + CHK(g_bh1->setValue("", 0) == 0); + CHK(g_con->execute(NoCommit) == 0); + CHK(writeBlobData(tup) == 0); + } + CHK(g_con->execute(Commit) == 0); + g_ndb->closeTransaction(g_con); + g_opx = 0; + g_con = 0; + tup.m_exists = true; + } + return 0; +} + +static int deleteIdx() { DBG("--- deleteIdx ---"); @@ -1167,10 +1239,16 @@ deleteScan(bool idx) // main +// from here on print always +#undef DBG +#define DBG(x) \ + do { \ + ndbout << "line " << __LINE__ << " " << x << endl; \ + } while (0) + static int testmain() { - int style; g_ndb = new Ndb("TEST_DB"); CHK(g_ndb->init() == 0); CHK(g_ndb->waitUntilReady() == 0); @@ -1194,55 +1272,88 @@ testmain() if (g_opt.m_seed != 0) srandom(g_opt.m_seed); for (g_loop = 0; g_opt.m_loop == 0 || g_loop < g_opt.m_loop; g_loop++) { + int style; DBG("=== loop " << g_loop << " ==="); if (g_opt.m_seed == 0) srandom(g_loop); // pk for (style = 0; style <= 2; style++) { - if (skipcase('k') || skipstyle(style)) + if (! testcase('k') || ! testcase(style)) continue; DBG("--- pk ops " << stylename[style] << " ---"); - calcTups(false); - CHK(insertPk(style) == 0); - CHK(verifyBlob() == 0); - CHK(readPk(style) == 0); - if (! skipcase('u')) { - calcTups(style); - CHK(updatePk(style) == 0); + if (testcase('n')) { + calcTups(false); + CHK(insertPk(style) == 0); + CHK(verifyBlob() == 0); + CHK(readPk(style) == 0); + if (testcase('u')) { + calcTups(style); + CHK(updatePk(style) == 0); + CHK(verifyBlob() == 0); + CHK(readPk(style) == 0); + } + CHK(deletePk() == 0); + CHK(verifyBlob() == 0); + } + if (testcase('w')) { + calcTups(false); + CHK(writePk(style) == 0); + CHK(verifyBlob() == 0); + CHK(readPk(style) == 0); + if (testcase('u')) { + calcTups(style); + CHK(writePk(style) == 0); + CHK(verifyBlob() == 0); + CHK(readPk(style) == 0); + } + CHK(deletePk() == 0); CHK(verifyBlob() == 0); } - CHK(readPk(style) == 0); - CHK(deletePk() == 0); - CHK(verifyBlob() == 0); } // hash index for (style = 0; style <= 2; style++) { - if (skipcase('i') || skipstyle(style)) + if (! testcase('i') || ! testcase(style)) continue; DBG("--- idx ops " << stylename[style] << " ---"); - calcTups(false); - CHK(insertPk(style) == 0); - CHK(verifyBlob() == 0); - CHK(readIdx(style) == 0); - calcTups(style); - if (! skipcase('u')) { - CHK(updateIdx(style) == 0); + if (testcase('n')) { + calcTups(false); + CHK(insertPk(style) == 0); + CHK(verifyBlob() == 0); + CHK(readIdx(style) == 0); + if (testcase('u')) { + calcTups(style); + CHK(updateIdx(style) == 0); + CHK(verifyBlob() == 0); + CHK(readIdx(style) == 0); + } + CHK(deleteIdx() == 0); + CHK(verifyBlob() == 0); + } + if (testcase('w')) { + calcTups(false); + CHK(writePk(style) == 0); CHK(verifyBlob() == 0); CHK(readIdx(style) == 0); + if (testcase('u')) { + calcTups(style); + CHK(writeIdx(style) == 0); + CHK(verifyBlob() == 0); + CHK(readIdx(style) == 0); + } + CHK(deleteIdx() == 0); + CHK(verifyBlob() == 0); } - CHK(deleteIdx() == 0); - CHK(verifyBlob() == 0); } // scan table for (style = 0; style <= 2; style++) { - if (skipcase('s') || skipstyle(style)) + if (! testcase('s') || ! testcase(style)) continue; DBG("--- table scan " << stylename[style] << " ---"); calcTups(false); CHK(insertPk(style) == 0); CHK(verifyBlob() == 0); CHK(readScan(style, false) == 0); - if (! skipcase('u')) { + if (testcase('u')) { CHK(updateScan(style, false) == 0); CHK(verifyBlob() == 0); } @@ -1251,14 +1362,14 @@ testmain() } // scan index for (style = 0; style <= 2; style++) { - if (skipcase('r') || skipstyle(style)) + if (! testcase('r') || ! testcase(style)) continue; DBG("--- index scan " << stylename[style] << " ---"); calcTups(false); CHK(insertPk(style) == 0); CHK(verifyBlob() == 0); CHK(readScan(style, true) == 0); - if (! skipcase('u')) { + if (testcase('u')) { CHK(updateScan(style, true) == 0); CHK(verifyBlob() == 0); } @@ -1331,9 +1442,7 @@ static struct { int m_bug; int (*m_test)(); } g_bugtest[] = { - { 4088, bugtest_4088 }, - { 2222, bugtest_2222 }, - { 3333, bugtest_3333 } + { 4088, bugtest_4088 } }; NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535) @@ -1361,6 +1470,12 @@ NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535) putenv(strdup("NDB_BLOB_DEBUG=1")); continue; } + if (strcmp(arg, "-dbug") == 0) { + if (++argv, --argc > 0) { + g_opt.m_dbug = strdup(argv[0]); + continue; + } + } if (strcmp(arg, "-full") == 0) { g_opt.m_full = true; continue; @@ -1395,9 +1510,9 @@ NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535) continue; } } - if (strcmp(arg, "-style") == 0) { + if (strcmp(arg, "-test") == 0) { if (++argv, --argc > 0) { - g_opt.m_style = strdup(argv[0]); + g_opt.m_test = strdup(argv[0]); continue; } } @@ -1431,9 +1546,14 @@ NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535) printusage(); return NDBT_ProgramExit(NDBT_WRONGARGS); } + if (g_opt.m_dbug != 0) { + DBUG_PUSH(g_opt.m_dbug); + } if (g_opt.m_pk2len == 0) { char b[100]; - strcpy(b, g_opt.m_skip); + b[0] = 0; + if (g_opt.m_skip != 0) + strcpy(b, g_opt.m_skip); strcat(b, "i"); strcat(b, "r"); g_opt.m_skip = strdup(b); |