📄 testndbapi.cpp
字号:
return NDBT_FAILED; } if (pOp->readTuple((NdbOperation::LockMode)lm) != 0){ pNdb->closeTransaction(pCon); ERR(pOp->getNdbError()); 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); return NDBT_FAILED; } } } // Dont' call any getValues // Execute should work int check = pCon->execute(cm == 0 ? NoCommit : Commit); if (check == 0){ ndbout << "execute worked" << endl; } else { ERR(pCon->getNdbError()); result = NDBT_FAILED; } pNdb->closeTransaction(pCon); } } /** * Now test scans */ for(lm= 0; lm <= NdbOperation::LM_CommittedRead; lm++) { NdbConnection* pCon = pNdb->startTransaction(); if (pCon == NULL){ pNdb->closeTransaction(pCon); return NDBT_FAILED; } NdbScanOperation* pOp = pCon->getNdbScanOperation(pTab->getName()); if (pOp == NULL){ ERR(pCon->getNdbError()); pNdb->closeTransaction(pCon); return NDBT_FAILED; } if ((pOp->readTuples((NdbOperation::LockMode)lm)) != 0){ pNdb->closeTransaction(pCon); ERR(pOp->getNdbError()); return NDBT_FAILED; } // Dont' call any getValues // Execute should work int check = pCon->execute(NoCommit); if (check == 0){ ndbout << "execute worked" << endl; } else { ERR(pCon->getNdbError()); result = NDBT_FAILED; } int res; while((res = pOp->nextResult()) == 0); pNdb->closeTransaction(pCon); if(res != 1) result = NDBT_FAILED; } return result;}int runCheckGetNdbErrorOperation(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(2048)){ ERR(pNdb->getNdbError()); delete pNdb; return NDBT_FAILED; } HugoOperations hugoOps(*pTab); NdbConnection* pCon = pNdb->startTransaction(); if (pCon == NULL){ ndbout << "Could not start transaction" << endl; 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; } // Dont call readTuple here // That's the error! for(int a = 0; a<pTab->getNoOfColumns(); a++){ if (pTab->getColumn(a)->getPrimaryKey() == true){ if(hugoOps.equalForAttr(pOp, a, 1) != 0){ // An error has occured, check that // it's possible to get the NdbErrorOperation const NdbError err = pCon->getNdbError(); ERR(err); if (err.code == 0) result = NDBT_FAILED; NdbOperation* pOp2 = pCon->getNdbErrorOperation(); if (pOp2 == NULL) result = NDBT_FAILED; else { const NdbError err2 = pOp2->getNdbError(); ERR(err2); if (err.code == 0) result = NDBT_FAILED; } } } } pNdb->closeTransaction(pCon); delete pNdb; return result;}#define C2(x) { int _x= (x); if(_x == 0){ ndbout << "line: " << __LINE__ << endl; return NDBT_FAILED;} }int runBug_11133(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; const NdbDictionary::Table* pTab = ctx->getTab(); HugoOperations hugoOps(*pTab); Ndb* pNdb = GETNDB(step); C2(hugoOps.startTransaction(pNdb) == 0); C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_Commit(pNdb) == 0); C2(hugoOps.closeTransaction(pNdb) == 0); C2(hugoOps.startTransaction(pNdb) == 0); C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_Commit(pNdb) == 0); C2(hugoOps.closeTransaction(pNdb) == 0); C2(hugoOps.startTransaction(pNdb) == 0); C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_Commit(pNdb) == 0); C2(hugoOps.closeTransaction(pNdb) == 0); C2(hugoOps.startTransaction(pNdb) == 0); C2(hugoOps.pkReadRecord(pNdb, 0, 1, NdbOperation::LM_Exclusive) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_Commit(pNdb) == 0); C2(hugoOps.closeTransaction(pNdb) == 0); Ndb ndb2(&ctx->m_cluster_connection, "TEST_DB"); C2(ndb2.init() == 0); C2(ndb2.waitUntilReady() == 0); HugoOperations hugoOps2(*pTab); C2(hugoOps.startTransaction(pNdb) == 0); C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps2.startTransaction(&ndb2) == 0); C2(hugoOps2.pkWritePartialRecord(&ndb2, 0) == 0); C2(hugoOps2.execute_async(&ndb2, NdbTransaction::NoCommit) == 0); C2(hugoOps.execute_Commit(pNdb) == 0); C2(hugoOps2.wait_async(&ndb2) == 0); C2(hugoOps.closeTransaction(pNdb) == 0); C2(hugoOps2.closeTransaction(&ndb2) == 0); C2(hugoOps.startTransaction(pNdb) == 0); C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps2.startTransaction(&ndb2) == 0); C2(hugoOps2.pkWriteRecord(&ndb2, 0, 1) == 0); C2(hugoOps2.execute_async(&ndb2, NdbTransaction::NoCommit) == 0); C2(hugoOps.execute_Commit(pNdb) == 0); C2(hugoOps2.wait_async(&ndb2) == 0); C2(hugoOps2.execute_Commit(pNdb) == 0); C2(hugoOps.closeTransaction(pNdb) == 0); C2(hugoOps2.closeTransaction(&ndb2) == 0); C2(hugoOps.startTransaction(pNdb) == 0); C2(hugoOps.pkUpdateRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps2.startTransaction(&ndb2) == 0); C2(hugoOps2.pkWritePartialRecord(&ndb2, 0) == 0); C2(hugoOps2.execute_async(&ndb2, NdbTransaction::NoCommit) == 0); C2(hugoOps.execute_Commit(pNdb) == 0); C2(hugoOps2.wait_async(&ndb2) == 0); C2(hugoOps.closeTransaction(pNdb) == 0); C2(hugoOps2.closeTransaction(&ndb2) == 0); C2(hugoOps.startTransaction(pNdb) == 0); C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0); C2(hugoOps.execute_NoCommit(pNdb) == 0); C2(hugoOps2.startTransaction(&ndb2) == 0); C2(hugoOps2.pkWritePartialRecord(&ndb2, 0) == 0); C2(hugoOps2.execute_async(&ndb2, NdbTransaction::NoCommit) == 0); C2(hugoOps.execute_Commit(pNdb) == 0); C2(hugoOps2.wait_async(&ndb2) != 0); C2(hugoOps.closeTransaction(pNdb) == 0); C2(hugoOps2.closeTransaction(&ndb2) == 0); return result;}int runScan_4006(NDBT_Context* ctx, NDBT_Step* step){ int result = NDBT_OK; const Uint32 max= 5; 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(max)){ ERR(pNdb->getNdbError()); delete pNdb; return NDBT_FAILED; } NdbConnection* pCon = pNdb->startTransaction(); if (pCon == NULL){ pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } Uint32 i; Vector<NdbScanOperation*> scans; for(i = 0; i<10*max; i++) { NdbScanOperation* pOp = pCon->getNdbScanOperation(pTab->getName()); if (pOp == NULL){ ERR(pCon->getNdbError()); pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } if (pOp->readTuples() != 0){ pNdb->closeTransaction(pCon); ERR(pOp->getNdbError()); delete pNdb; return NDBT_FAILED; } scans.push_back(pOp); } // Dont' call any equal or setValues // Execute should not work int check = pCon->execute(NoCommit); if (check == 0){ ndbout << "execute worked" << endl; } else { ERR(pCon->getNdbError()); } for(i= 0; i<scans.size(); i++) { NdbScanOperation* pOp= scans[i]; while((check= pOp->nextResult()) == 0); if(check != 1) { ERR(pOp->getNdbError()); pNdb->closeTransaction(pCon); delete pNdb; return NDBT_FAILED; } } pNdb->closeTransaction(pCon); Vector<NdbConnection*> cons; for(i= 0; i<10*max; i++) { pCon= pNdb->startTransaction(); if(pCon) cons.push_back(pCon); else break; } for(i= 0; i<cons.size(); i++) { cons[i]->close(); } if(cons.size() != max) { result= NDBT_FAILED; } delete pNdb; return result;}template class Vector<NdbScanOperation*>;NDBT_TESTSUITE(testNdbApi);TESTCASE("MaxNdb", "Create Ndb objects until no more can be created\n"){ INITIALIZER(runTestMaxNdb);}TESTCASE("MaxTransactions", "Start transactions until no more can be created\n"){ INITIALIZER(runTestMaxTransaction);}TESTCASE("MaxOperations", "Get operations until no more can be created\n"){ INITIALIZER(runLoadTable); INITIALIZER(runTestMaxOperations); FINALIZER(runClearTable);}TESTCASE("MaxGetValue", "Call getValue loads of time\n"){ INITIALIZER(runLoadTable); INITIALIZER(runTestGetValue); FINALIZER(runClearTable);}TESTCASE("MaxEqual", "Call equal loads of time\n"){ INITIALIZER(runTestEqual);}TESTCASE("DeleteNdb", "Make sure that a deleted Ndb object is properly deleted\n" "and removed from transporter\n"){ INITIALIZER(runLoadTable); INITIALIZER(runTestDeleteNdb); FINALIZER(runClearTable);}TESTCASE("WaitUntilReady", "Make sure you get an error message when calling waitUntilReady\n" "without an init'ed Ndb\n"){ INITIALIZER(runTestWaitUntilReady);}TESTCASE("GetOperationNoTab", "Call getNdbOperation on a table that does not exist\n"){ INITIALIZER(runGetNdbOperationNoTab);}TESTCASE("MissingOperation", "Missing operation request(insertTuple) should give an error code\n"){ INITIALIZER(runMissingOperation);}TESTCASE("GetValueInUpdate", "Test that it's not possible to perform getValue in an update\n"){ INITIALIZER(runLoadTable); INITIALIZER(runGetValueInUpdate); FINALIZER(runClearTable);}TESTCASE("UpdateWithoutKeys", "Test that it's not possible to perform update without setting\n" "PKs"){ INITIALIZER(runLoadTable); INITIALIZER(runUpdateWithoutKeys); FINALIZER(runClearTable);}TESTCASE("UpdateWithoutValues", "Test that it's not possible to perform update without setValues\n"){ INITIALIZER(runLoadTable); INITIALIZER(runUpdateWithoutValues); FINALIZER(runClearTable);}TESTCASE("NdbErrorOperation", "Test that NdbErrorOperation is properly set"){ INITIALIZER(runCheckGetNdbErrorOperation);}TESTCASE("ReadWithoutGetValue", "Test that it's possible to perform read wo/ getvalue's\n"){ INITIALIZER(runLoadTable); INITIALIZER(runReadWithoutGetValue); FINALIZER(runClearTable);}TESTCASE("Bug_11133", "Test ReadEx-Delete-Write\n"){ INITIALIZER(runBug_11133); FINALIZER(runClearTable);}TESTCASE("Scan_4006", "Check that getNdbScanOperation does not get 4006\n"){ INITIALIZER(runLoadTable); INITIALIZER(runScan_4006); FINALIZER(runClearTable);}NDBT_TESTSUITE_END(testNdbApi);int main(int argc, const char** argv){ ndb_init(); // TABLE("T1"); return testNdbApi.execute(argc, argv);}template class Vector<Ndb*>;template class Vector<NdbConnection*>;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -