⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testndbapi.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* 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 <NdbRestarts.hpp>#include <Vector.hpp>#include <random.h>#include <NdbTick.h>#define MAX_NDB_OBJECTS 32678#define CHECK(b) if (!(b)) { \  ndbout << "ERR: "<< step->getName() \         << " failed on line " << __LINE__ << endl; \  result = NDBT_FAILED; \  continue; } #define CHECKE(b) if (!(b)) { \  errors++; \  ndbout << "ERR: "<< step->getName() \         << " failed on line " << __LINE__ << endl; \  result = NDBT_FAILED; \  continue; } int runTestMaxNdb(NDBT_Context* ctx, NDBT_Step* step){  Uint32 loops = ctx->getNumLoops();  Uint32 l = 0;  int oldi = 0;  int result = NDBT_OK;  while (l < loops && result == NDBT_OK){    ndbout_c("loop %d", l + 1);    int errors = 0;    int maxErrors = 5;        Vector<Ndb*> ndbVector;    int i = 0;    int init = 0;    do {                  Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");      if (pNdb == NULL){	ndbout << "pNdb == NULL" << endl;      	errors++;	continue;	      }      i++;      ndbVector.push_back(pNdb);            if (pNdb->init()){	ERR(pNdb->getNdbError());	errors++;	continue;      }            init++;    } while (errors == 0);        ndbout << i << " ndb objects created" << endl;        if (l > 0 && i != oldi && init != MAX_NDB_OBJECTS){      ndbout << l << ": not as manyNdb objects created" << endl	     << i << " != " << oldi << endl;      result =  NDBT_FAILED;    }    oldi = i;              for(size_t j = 0;  j < ndbVector.size(); j++){      delete ndbVector[j];      if(((j+1) % 250) == 0){	ndbout << "Deleted " << (Uint64) j << " ndb objects " << endl;      }    }    ndbVector.clear();    l++;  }  return result;}int runTestMaxTransaction(NDBT_Context* ctx, NDBT_Step* step){  Uint32 loops = ctx->getNumLoops();  Uint32 l = 0;  int oldi = 0;  int result = NDBT_OK;  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;  }  const NdbDictionary::Table* pTab = ctx->getTab();  if (pTab == 0) abort();  while (l < loops && result == NDBT_OK){    int errors = 0;    int maxErrors = 5;        Vector<NdbConnection*> conVector;    int i = 0;    do {            NdbConnection* pCon;            int type = i%2;      switch (type){      case 0:	pCon = pNdb->startTransaction();	break;      case 1:      {	BaseString key;	key.appfmt("DATA-%d", i);	ndbout_c("%s", key.c_str());	pCon = pNdb->startTransaction(pTab,				      key.c_str(),				      key.length());      }      break;      default:	abort();      }            if (pCon == NULL){	ERR(pNdb->getNdbError());	errors++;	continue;      }	        conVector.push_back(pCon);	              i++;          } while (errors < maxErrors);    ndbout << i << " connections created" << endl;    if (l > 0 && i != oldi){      ndbout << l << ": not as many transactions created" << endl	     << i << " != " << oldi << endl;      result =  NDBT_FAILED;    }    oldi = i;              for(size_t j = 0; j < conVector.size(); j++){      pNdb->closeTransaction(conVector[j]);    }    conVector.clear();    l++;  }  // BONUS Test closeTransaction with null trans  pNdb->closeTransaction(NULL);  delete pNdb;  return result;}int runTestMaxOperations(NDBT_Context* ctx, NDBT_Step* step){  Uint32 l = 1;  int result = NDBT_OK;  int maxOpsLimit = 1;  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);  bool endTest = false;  while (!endTest && result == NDBT_OK){    int errors = 0;    int maxErrors = 5;    maxOpsLimit = l*1000;               if (hugoOps.startTransaction(pNdb) != NDBT_OK){      delete pNdb;      return NDBT_FAILED;    }        int i = 0;    while (errors < maxErrors){            if(hugoOps.pkReadRecord(pNdb,1, 1) != NDBT_OK){	errors++;	continue;      }	              i++;            if (i >= maxOpsLimit){	errors = maxErrors;      }	    }    ndbout << i << " operations used" << endl;    int execResult = hugoOps.execute_Commit(pNdb);    switch(execResult){    case NDBT_OK:      break;    case 233: // Out of operation records in transaction coordinator            // OK - end test      endTest = true;      break;    default:      result = NDBT_FAILED;      break;    }        hugoOps.closeTransaction(pNdb);    l++;  }  delete pNdb;  return result;}int runTestGetValue(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);    for (int m = 1; m < 100; m++){    int errors = 0;    int maxErrors = 5;          NdbConnection* pCon = pNdb->startTransaction();    if (pCon == NULL){      delete pNdb;      return NDBT_FAILED;    }          NdbOperation* pOp = pCon->getNdbOperation(pTab->getName());    if (pOp == NULL){      pNdb->closeTransaction(pCon);      delete pNdb;      return NDBT_FAILED;    }          if (pOp->readTuple() != 0){      pNdb->closeTransaction(pCon);      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;	}      }    }          int i = 0;    int maxLimit = 1000*m;    do {      	      if (pOp->getValue(pTab->getColumn(1)->getName()) == NULL) {	const NdbError err = pCon->getNdbError();	ERR(err);	if (err.code == 0)	  result = NDBT_FAILED;		errors++;	continue;      }	      i++;             	    } while (errors < maxErrors && i < maxLimit);          ndbout << i << " getValues called" << endl;          if (pCon->execute(Commit) != 0){      const NdbError err = pCon->getNdbError();      switch(err.code){      case 880: // TUP - Read too much      case 823: // TUP - Too much AI      case 4257: // NDBAPI - Too much AI	// OK errors	ERR(pCon->getNdbError());	break;      default:	ERR(pCon->getNdbError());	ndbout << "Illegal error" << endl;	result= NDBT_FAILED;	break;      }    }          pNdb->closeTransaction(pCon);  }// m  delete pNdb;  return result;}int runTestEqual(NDBT_Context* ctx, NDBT_Step* step){  Uint32 loops = ctx->getNumLoops();  Uint32 l = 0;  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);    while (l < loops){    for(int m = 1; m < 10; m++){      int errors = 0;      int maxErrors = 5;            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;      }            if (pOp->readTuple() != 0){	ERR(pCon->getNdbError());	pNdb->closeTransaction(pCon);	delete pNdb;	return NDBT_FAILED;      }            int i = 0;      int maxLimit = 1000*m;            do {      		if ((l%2)!=0){	  // Forward	  for(int a = 0; a<pTab->getNoOfColumns(); a++){	    if (pTab->getColumn(a)->getPrimaryKey() == true){	      if(hugoOps.equalForAttr(pOp, a, 1) != 0){		const NdbError err = pCon->getNdbError();		ERR(err);		if (err.code == 0)		  result = NDBT_FAILED;		errors++;	      }	    }	  }	} else {	  // Backward	  for(int a = pTab->getNoOfColumns()-1; a>=0; a--){	    if (pTab->getColumn(a)->getPrimaryKey() == true){	      if(hugoOps.equalForAttr(pOp, a, 1) != 0){		const NdbError err = pCon->getNdbError();		ERR(err);		if (err.code == 0)		  result = NDBT_FAILED;		errors++;	      }	    }	  }	}		i++;      	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -