📄 testdict.cpp
字号:
/* Copyright (C) 2003 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <NDBT.hpp>#include <NDBT_Test.hpp>#include <HugoTransactions.hpp>#include <UtilTransactions.hpp>#include <NdbRestarter.hpp>#include <Vector.hpp>#include <signaldata/DumpStateOrd.hpp>#include <../../include/kernel/ndb_limits.h>#include <random.h>#include <NdbAutoPtr.hpp> #define CHECK(b) if (!(b)) { \ g_err << "ERR: "<< step->getName() \ << " failed on line " << __LINE__ << endl; \ result = NDBT_FAILED; \ break; } #define CHECK2(b, c) if (!(b)) { \ g_err << "ERR: "<< step->getName() \ << " failed on line " << __LINE__ << ": " << c << endl; \ result = NDBT_FAILED; \ goto end; }int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int records = ctx->getNumRecords(); HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.loadTable(pNdb, records) != 0){ return NDBT_FAILED; } return NDBT_OK;}int runCreateInvalidTables(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int result = NDBT_OK; char failTabName[256]; for (int i = 0; i < 10; i++){ BaseString::snprintf(failTabName, 256, "F%d", i); const NdbDictionary::Table* pFailTab = NDBT_Tables::getTable(failTabName); if (pFailTab != NULL){ ndbout << "|- " << failTabName << endl; // Try to create table in db if (pFailTab->createTableInDb(pNdb) == 0){ ndbout << failTabName << " created, this was not expected"<< endl; result = NDBT_FAILED; } // Verify that table is not in db const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, failTabName) ; if (pTab2 != NULL){ ndbout << failTabName << " was found in DB, this was not expected"<< endl; result = NDBT_FAILED; if (pFailTab->equal(*pTab2) == true){ ndbout << "It was equal" << endl; } else { ndbout << "It was not equal" << endl; } int records = 1000; HugoTransactions hugoTrans(*pTab2); if (hugoTrans.loadTable(pNdb, records) != 0){ ndbout << "It can NOT be loaded" << endl; } else{ ndbout << "It can be loaded" << endl; UtilTransactions utilTrans(*pTab2); if (utilTrans.clearTable(pNdb, records, 64) != 0){ ndbout << "It can NOT be cleared" << endl; } else{ ndbout << "It can be cleared" << endl; } } if (pNdb->getDictionary()->dropTable(pTab2->getName()) == -1){ ndbout << "It can NOT be dropped" << endl; } else { ndbout << "It can be dropped" << endl; } } } } return result;}int runCreateTheTable(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); const NdbDictionary::Table* pTab = ctx->getTab(); // Try to create table in db if (pTab->createTableInDb(pNdb) != 0){ return NDBT_FAILED; } // Verify that table is in db const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab2 == NULL){ ndbout << pTab->getName() << " was not found in DB"<< endl; return NDBT_FAILED; } ctx->setTab(pTab2); return NDBT_OK;}int runDropTheTable(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); const NdbDictionary::Table* pTab = ctx->getTab(); // Try to create table in db pNdb->getDictionary()->dropTable(pTab->getName()); return NDBT_OK;}int runCreateTableWhenDbIsFull(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int result = NDBT_OK; const char* tabName = "TRANSACTION"; //Use a util table const NdbDictionary::Table* pTab = NDBT_Tables::getTable(tabName); if (pTab != NULL){ ndbout << "|- " << tabName << endl; // Verify that table is not in db if (NDBT_Table::discoverTableFromDb(pNdb, tabName) != NULL){ ndbout << tabName << " was found in DB"<< endl; return NDBT_FAILED; } // Try to create table in db if (pTab->createTableInDb(pNdb) == 0){ result = NDBT_FAILED; } // Verify that table is in db if (NDBT_Table::discoverTableFromDb(pNdb, tabName) != NULL){ ndbout << tabName << " was found in DB"<< endl; result = NDBT_FAILED; } } return result;}int runDropTableWhenDbIsFull(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int result = NDBT_OK; const char* tabName = "TRANSACTION"; //Use a util table const NdbDictionary::Table* pTab = NDBT_Table::discoverTableFromDb(pNdb, tabName); if (pTab != NULL){ ndbout << "|- TRANSACTION" << endl; // Try to drop table in db if (pNdb->getDictionary()->dropTable(pTab->getName()) == -1){ result = NDBT_FAILED; } // Verify that table is not in db if (NDBT_Table::discoverTableFromDb(pNdb, tabName) != NULL){ ndbout << tabName << " was found in DB"<< endl; result = NDBT_FAILED; } } return result;}int runCreateAndDrop(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int loops = ctx->getNumLoops(); int i = 0; const NdbDictionary::Table* pTab = ctx->getTab(); ndbout << "|- " << pTab->getName() << endl; while (i < loops){ ndbout << i << ": "; // Try to create table in db if (pTab->createTableInDb(pNdb) != 0){ return NDBT_FAILED; } // Verify that table is in db const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab2 == NULL){ ndbout << pTab->getName() << " was not found in DB"<< endl; return NDBT_FAILED; } if (pNdb->getDictionary()->dropTable(pTab2->getName())){ ndbout << "Failed to drop "<<pTab2->getName()<<" in db" << endl; return NDBT_FAILED; } // Verify that table is not in db const NdbDictionary::Table* pTab3 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab3 != NULL){ ndbout << pTab3->getName() << " was found in DB"<< endl; return NDBT_FAILED; } i++; } return NDBT_OK;}int runCreateAndDropWithData(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int loops = ctx->getNumLoops(); int records = ctx->getNumRecords(); int i = 0; NdbRestarter restarter; int val = DumpStateOrd::DihMinTimeBetweenLCP; if(restarter.dumpStateAllNodes(&val, 1) != 0){ int result; do { CHECK(0); } while (0); g_err << "Unable to change timebetween LCP" << endl; return NDBT_FAILED; } const NdbDictionary::Table* pTab = ctx->getTab(); ndbout << "|- " << pTab->getName() << endl; while (i < loops){ ndbout << i << ": "; // Try to create table in db if (pTab->createTableInDb(pNdb) != 0){ return NDBT_FAILED; } // Verify that table is in db const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab2 == NULL){ ndbout << pTab->getName() << " was not found in DB"<< endl; return NDBT_FAILED; } HugoTransactions hugoTrans(*pTab2); if (hugoTrans.loadTable(pNdb, records) != 0){ return NDBT_FAILED; } int count = 0; UtilTransactions utilTrans(*pTab2); if (utilTrans.selectCount(pNdb, 64, &count) != 0){ return NDBT_FAILED; } if (count != records){ ndbout << count <<" != "<<records << endl; return NDBT_FAILED; } if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){ ndbout << "Failed to drop "<<pTab2->getName()<<" in db" << endl; return NDBT_FAILED; } // Verify that table is not in db const NdbDictionary::Table* pTab3 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab3 != NULL){ ndbout << pTab3->getName() << " was found in DB"<< endl; return NDBT_FAILED; } i++; } return NDBT_OK;}int runFillTable(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.fillTable(pNdb) != 0){ return NDBT_FAILED; } return NDBT_OK;}int runClearTable(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = GETNDB(step); int records = ctx->getNumRecords(); UtilTransactions utilTrans(*ctx->getTab()); if (utilTrans.clearTable(pNdb, records) != 0){ return NDBT_FAILED; } return NDBT_OK;}int runCreateAndDropDuring(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; int loops = ctx->getNumLoops(); int i = 0; const NdbDictionary::Table* pTab = ctx->getTab(); ndbout << "|- " << pTab->getName() << endl; while (i < loops && result == NDBT_OK){ ndbout << i << ": " << endl; // Try to create table in db Ndb* pNdb = GETNDB(step); g_debug << "Creating table" << endl; if (pTab->createTableInDb(pNdb) != 0){ g_err << "createTableInDb failed" << endl; result = NDBT_FAILED; continue; } g_debug << "Verifying creation of table" << endl; // Verify that table is in db const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab2 == NULL){ g_err << pTab->getName() << " was not found in DB"<< endl; result = NDBT_FAILED; continue; } NdbSleep_MilliSleep(3000); g_debug << "Dropping table" << endl; if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){ g_err << "Failed to drop "<<pTab2->getName()<<" in db" << endl; result = NDBT_FAILED; continue; } g_debug << "Verifying dropping of table" << endl; // Verify that table is not in db const NdbDictionary::Table* pTab3 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab3 != NULL){ g_err << pTab3->getName() << " was found in DB"<< endl; result = NDBT_FAILED; continue; } i++; } ctx->stopTest(); return result;}int runUseTableUntilStopped(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); const NdbDictionary::Table* pTab = ctx->getTab(); while (ctx->isTestStopped() == false) { // g_info << i++ << ": "; // Delete and recreate Ndb object // Otherwise you always get Invalid Schema Version // It would be a nice feature to remove this two lines //step->tearDown(); //step->setUp(); Ndb* pNdb = GETNDB(step); const NdbDictionary::Table* pTab2 = NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()); if (pTab2 == NULL) continue; int res; HugoTransactions hugoTrans(*pTab2); if ((res = hugoTrans.loadTable(pNdb, records)) != 0){ NdbError err = pNdb->getNdbError(res); if(err.classification == NdbError::SchemaError){ pNdb->getDictionary()->invalidateTable(pTab->getName()); } continue; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -