📄 testndbapi.cpp
字号:
} while (errors < maxErrors && i < maxLimit); if (pOp->getValue(pTab->getColumn(1)->getName()) == NULL) { const NdbError err = pCon->getNdbError(); ERR(pCon->getNdbError()); pNdb->closeTransaction(pCon); delete pNdb; if (err.code == 4225) { return NDBT_OK; } else { return NDBT_FAILED; }//if } ndbout << i << " equal called" << endl; int check = pCon->execute(Commit); if (check != 0){ ERR(pCon->getNdbError()); } pNdb->closeTransaction(pCon); }// m l++; }// l delete pNdb; return result;}int runTestDeleteNdb(NDBT_Context* ctx, NDBT_Step* step){ Uint32 loops = ctx->getNumLoops(); Uint32 l = 0; int result = NDBT_OK; NdbRestarts restarts; Vector<Ndb*> ndbVector; const NdbDictionary::Table* pTab = ctx->getTab(); HugoTransactions hugoTrans(*pTab); int records = ctx->getNumRecords(); while (l < loops && result == NDBT_OK){ // Create 5 ndb objects for( int i = 0; i < 5; i++){ Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB"); if (pNdb == NULL){ ndbout << "pNdb == NULL" << endl; result = NDBT_FAILED; goto end_test; } ndbVector.push_back(pNdb); if (pNdb->init()){ ERR(pNdb->getNdbError()); result = NDBT_FAILED; goto end_test; } if (pNdb->waitUntilReady() != 0){ ERR(pNdb->getNdbError()); result = NDBT_FAILED; goto end_test; } if (hugoTrans.pkReadRecords(pNdb, records) != 0){ result = NDBT_FAILED; goto end_test; } } if ((l % 2) == 0){ // Restart random node ndbout << "Restart random node " << endl; if(restarts.executeRestart("RestartRandomNodeAbort", 120) != 0){ g_err << "Failed to executeRestart(RestartRandomNode)"<<endl; result = NDBT_FAILED; goto end_test; } } else { // Restart all nodes ndbout << "Restart all nodes " << endl; if(restarts.executeRestart("RestartAllNodesAbort", 120) != 0){ g_err << "Failed to executeRestart(RestartAllNodes)"<<endl; result = NDBT_FAILED; goto end_test; } } // Delete the ndb objects for(size_t j = 0; j < ndbVector.size(); j++) delete ndbVector[j]; ndbVector.clear(); l++; } end_test: for(size_t i = 0; i < ndbVector.size(); i++) delete ndbVector[i]; ndbVector.clear(); return result;}int runClearTable(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); UtilTransactions utilTrans(*ctx->getTab()); if (utilTrans.clearTable2(GETNDB(step), records) != 0){ return NDBT_FAILED; } return NDBT_OK;}int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){ int records = ctx->getNumRecords(); HugoTransactions hugoTrans(*ctx->getTab()); if (hugoTrans.loadTable(GETNDB(step), records) != 0){ return NDBT_FAILED; } return NDBT_OK;}int runTestWaitUntilReady(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB"); // Forget about calling pNdb->init(); if (pNdb->waitUntilReady() == 0){ ndbout << "waitUntilReady returned OK" << endl; delete pNdb; return NDBT_FAILED; } const NdbError err = pNdb->getNdbError(); delete pNdb; ERR(err); if (err.code != 4256) return NDBT_FAILED; return NDBT_OK;}int runGetNdbOperationNoTab(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB"); if (pNdb == NULL){ ndbout << "pNdb == NULL" << endl; return NDBT_FAILED; } if (pNdb->init()){ ERR(pNdb->getNdbError()); delete pNdb; return NDBT_FAILED; } NdbConnection* pCon = pNdb->startTransaction(); if (pCon == NULL){ delete pNdb; return NDBT_FAILED; } // Call getNdbOperation on an unknown table NdbOperation* pOp = pCon->getNdbOperation("HUPP76"); if (pOp == NULL){ NdbError err = pCon->getNdbError(); ERR(err); if (err.code == 0){ pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } } pNdb->closeTransaction(pCon); delete pNdb; return NDBT_OK;}int runMissingOperation(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; const NdbDictionary::Table* pTab = ctx->getTab(); Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB"); if (pNdb == NULL){ ndbout << "pNdb == NULL" << endl; return NDBT_FAILED; } if (pNdb->init()){ ERR(pNdb->getNdbError()); delete pNdb; return NDBT_FAILED; } NdbConnection* pCon = pNdb->startTransaction(); if (pCon == NULL){ pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } NdbOperation* pOp = pCon->getNdbOperation(pTab->getName()); if (pOp == NULL){ ERR(pCon->getNdbError()); pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } // Forget about calling pOp->insertTuple(); // Call getValue should not work if (pOp->getValue(pTab->getColumn(1)->getName()) == NULL) { const NdbError err = pCon->getNdbError(); ERR(err); if (err.code == 0){ ndbout << "hupp" << endl; result = NDBT_FAILED; } } else { ndbout << "hupp2" << endl; result = NDBT_FAILED; } pNdb->closeTransaction(pCon); delete pNdb; return result;}int runGetValueInUpdate(NDBT_Context* ctx, NDBT_Step* step){ const NdbDictionary::Table* pTab = ctx->getTab(); Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB"); if (pNdb == NULL){ ndbout << "pNdb == NULL" << endl; return NDBT_FAILED; } if (pNdb->init()){ ERR(pNdb->getNdbError()); delete pNdb; return NDBT_FAILED; } NdbConnection* pCon = pNdb->startTransaction(); if (pCon == NULL){ pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } NdbOperation* pOp = pCon->getNdbOperation(pTab->getName()); if (pOp == NULL){ ERR(pCon->getNdbError()); pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } if (pOp->updateTuple() != 0){ pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } // Call getValue should not work if (pOp->getValue(pTab->getColumn(1)->getName()) == NULL) { // It didn't work const NdbError err = pCon->getNdbError(); ERR(err); if (err.code == 0){ pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } } else { // It worked, not good! pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } int check = pCon->execute(Commit); if (check != 0){ ERR(pCon->getNdbError()); } pNdb->closeTransaction(pCon); delete pNdb; return NDBT_OK;}int runUpdateWithoutValues(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; const NdbDictionary::Table* pTab = ctx->getTab(); HugoOperations hugoOps(*pTab); Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB"); if (pNdb == NULL){ ndbout << "pNdb == NULL" << endl; return NDBT_FAILED; } if (pNdb->init()){ ERR(pNdb->getNdbError()); delete pNdb; return NDBT_FAILED; } NdbConnection* pCon = pNdb->startTransaction(); if (pCon == NULL){ pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } NdbOperation* pOp = pCon->getNdbOperation(pTab->getName()); if (pOp == NULL){ ERR(pCon->getNdbError()); pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } if (pOp->updateTuple() != 0){ pNdb->closeTransaction(pCon); ERR(pOp->getNdbError()); delete pNdb; return NDBT_FAILED; } for(int a = 0; a<pTab->getNoOfColumns(); a++){ if (pTab->getColumn(a)->getPrimaryKey() == true){ if(hugoOps.equalForAttr(pOp, a, 1) != 0){ ERR(pCon->getNdbError()); pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } } } // Dont' call any setValues // Execute should work int check = pCon->execute(Commit); if (check == 0){ ndbout << "execute worked" << endl; } else { ERR(pCon->getNdbError()); result = NDBT_FAILED; } pNdb->closeTransaction(pCon); delete pNdb; return result;}int runUpdateWithoutKeys(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; const NdbDictionary::Table* pTab = ctx->getTab(); Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB"); if (pNdb == NULL){ ndbout << "pNdb == NULL" << endl; return NDBT_FAILED; } if (pNdb->init()){ ERR(pNdb->getNdbError()); delete pNdb; return NDBT_FAILED; } NdbConnection* pCon = pNdb->startTransaction(); if (pCon == NULL){ pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } NdbOperation* pOp = pCon->getNdbOperation(pTab->getName()); if (pOp == NULL){ ERR(pCon->getNdbError()); pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } if (pOp->updateTuple() != 0){ pNdb->closeTransaction(pCon); ERR(pOp->getNdbError()); delete pNdb; return NDBT_FAILED; } // Dont' call any equal or setValues // Execute should not work int check = pCon->execute(Commit); if (check == 0){ ndbout << "execute worked" << endl; result = NDBT_FAILED; } else { ERR(pCon->getNdbError()); } pNdb->closeTransaction(pCon); delete pNdb; return result;}int runReadWithoutGetValue(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; const NdbDictionary::Table* pTab = ctx->getTab(); HugoOperations hugoOps(*pTab); Ndb* pNdb = GETNDB(step); Uint32 lm; for(Uint32 cm= 0; cm < 2; cm++) { for(lm= 0; lm <= NdbOperation::LM_CommittedRead; lm++) { NdbConnection* pCon = pNdb->startTransaction(); if (pCon == NULL){ pNdb->closeTransaction(pCon); return NDBT_FAILED; } NdbOperation* pOp = pCon->getNdbOperation(pTab->getName()); if (pOp == NULL){ ERR(pCon->getNdbError()); pNdb->closeTransaction(pCon);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -