diff options
Diffstat (limited to 'ndb/test/include')
24 files changed, 2297 insertions, 0 deletions
diff --git a/ndb/test/include/HugoAsynchTransactions.hpp b/ndb/test/include/HugoAsynchTransactions.hpp new file mode 100644 index 00000000000..d7e6e8fc187 --- /dev/null +++ b/ndb/test/include/HugoAsynchTransactions.hpp @@ -0,0 +1,75 @@ +/* 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 */ + +#ifndef HUGO_ASYNCH_TRANSACTIONS_HPP +#define HUGO_ASYNCH_TRANSACTIONS_HPP + + +#include <NDBT.hpp> +#include <HugoCalculator.hpp> +#include <HugoTransactions.hpp> + +class HugoAsynchTransactions : private HugoTransactions { +public: + HugoAsynchTransactions(const NdbDictionary::Table&); + ~HugoAsynchTransactions(); + int loadTableAsynch(Ndb*, + int records = 0, + int batch = 1, + int trans = 1, + int operations = 1); + int pkReadRecordsAsynch(Ndb*, + int records = 0, + int batch= 1, + int trans = 1, + int operations = 1); + int pkUpdateRecordsAsynch(Ndb*, + int records = 0, + int batch= 1, + int trans = 1, + int operations = 1); + int pkDelRecordsAsynch(Ndb*, + int records = 0, + int batch = 1, + int trans = 1, + int operations = 1); + void transactionCompleted(); + + long getTransactionsCompleted(); + +private: + enum NDB_OPERATION {NO_INSERT, NO_UPDATE, NO_READ, NO_DELETE}; + + void allocTransactions(int trans); + void deallocTransactions(); + + int executeAsynchOperation(Ndb*, + int records, + int batch, + int trans, + int operations, + NDB_OPERATION theOperation, + ExecType theType = Commit); + + long transactionsCompleted; + int numTransactions; + NdbConnection** transactions; +}; + + + +#endif + diff --git a/ndb/test/include/HugoCalculator.hpp b/ndb/test/include/HugoCalculator.hpp new file mode 100644 index 00000000000..b782eb003a3 --- /dev/null +++ b/ndb/test/include/HugoCalculator.hpp @@ -0,0 +1,59 @@ +/* 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 */ + +#ifndef NDBT_CALC_HPP +#define NDBT_CALC_HPP + +#include <NDBT_ResultRow.hpp> + +/* ************************************************************* + * HugoCalculator + * + * Comon class for the Hugo test suite, provides the functions + * that is used for calculating values to load in to table and + * also knows how to verify a row that's been read from db + * + * ************************************************************/ +class HugoCalculator { +public: + HugoCalculator(const NdbDictionary::Table& tab); + Int32 calcValue(int record, int attrib, int updates) const; +#if 0 + U_Int32 calcValue(int record, int attrib, int updates) const; + U_Int64 calcValue(int record, int attrib, int updates) const; + Int64 calcValue(int record, int attrib, int updates) const; + float calcValue(int record, int attrib, int updates) const; + double calcValue(int record, int attrib, int updates) const; +#endif + const char* calcValue(int record, int attrib, int updates, char* buf) const; + + int verifyRowValues(NDBT_ResultRow* const pRow) const; + int getIdValue(NDBT_ResultRow* const pRow) const; + int getUpdatesValue(NDBT_ResultRow* const pRow) const; + int isIdCol(int colId) { return m_idCol == colId; }; + int isUpdateCol(int colId){ return m_updatesCol == colId; }; +private: + const NdbDictionary::Table& m_tab; + int m_idCol; + int m_updatesCol; +}; + + +#endif + + + + diff --git a/ndb/test/include/HugoOperations.hpp b/ndb/test/include/HugoOperations.hpp new file mode 100644 index 00000000000..7295b72b18f --- /dev/null +++ b/ndb/test/include/HugoOperations.hpp @@ -0,0 +1,149 @@ +/* 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 */ + +#ifndef HUGO_OPERATIONS_HPP +#define HUGO_OPERATIONS_HPP + +#include <NDBT.hpp> +#include <HugoCalculator.hpp> +#include <UtilTransactions.hpp> +#include <Vector.hpp> + +class HugoOperations : public UtilTransactions { +public: + HugoOperations(const NdbDictionary::Table&); + ~HugoOperations(); + int startTransaction(Ndb*); + int closeTransaction(Ndb*); + NdbConnection* getTransaction(); + void refresh(); + + int pkInsertRecord(Ndb*, + int recordNo, + int numRecords = 1, + int updatesValue = 0); + + int pkReadRecord(Ndb*, + int recordNo, + bool exclusive = false, + int numRecords = 1); + + int pkSimpleReadRecord(Ndb*, + int recordNo, + int numRecords = 1); + + int pkDirtyReadRecord(Ndb*, + int recordNo, + int numRecords = 1); + + int pkUpdateRecord(Ndb*, + int recordNo, + int numRecords = 1, + int updatesValue = 0); + + int pkDeleteRecord(Ndb*, + int recordNo, + int numRecords = 1); + + int scanReadRecords(Ndb* pNdb, + Uint32 parallelism = 240, ScanLock lock = SL_Read); + int executeScanRead(Ndb*); + + int execute_Commit(Ndb*, + AbortOption ao = AbortOnError); + int execute_NoCommit(Ndb*, + AbortOption ao = AbortOnError); + int execute_Rollback(Ndb*); + + int saveCopyOfRecord(int numRecords = 1); + int compareRecordToCopy(int numRecords = 1); + + BaseString getRecordStr(int recordNum); + int getRecordGci(int recordNum); + + int setValueForAttr(NdbOperation*, + int attrId, + int rowId, + int updateId); + int equalForAttr(NdbOperation*, + int attrId, + int rowId); + + int verifyUpdatesValue(int updatesValue, int _numRows = 0); + + int indexReadRecords(Ndb*, const char * idxName, int recordNo, + bool exclusive = false, + int records = 1); + + int indexUpdateRecord(Ndb*, + const char * idxName, + int recordNo, + int numRecords = 1, + int updatesValue = 0); + +protected: + void allocRows(int rows); + void deallocRows(); + + Vector<NDBT_ResultRow*> rows; + HugoCalculator calc; + + Vector<BaseString> savedRecords; +private: + NdbConnection* pTrans; + + struct ScanTmp { + ScanTmp() { + pTrans = 0; + m_tmpRow = 0; + m_delete = true; + m_op = DONE; + } + ScanTmp(NdbConnection* a, NDBT_ResultRow* b){ + pTrans = a; + m_tmpRow = b; + m_delete = true; + m_op = DONE; + } + ScanTmp(const ScanTmp& org){ + * this = org; + } + ScanTmp& operator=(const ScanTmp& org){ + pTrans = org.pTrans; + m_tmpRow = org.m_tmpRow; + m_delete = org.m_delete; + m_op = org.m_op; + return * this; + } + + ~ScanTmp() { + if(m_delete && pTrans) + pTrans->close(); + if(m_delete && m_tmpRow) + delete m_tmpRow; + } + + NdbConnection * pTrans; + NDBT_ResultRow * m_tmpRow; + bool m_delete; + enum { DONE, READ, UPDATE, DELETE } m_op; + }; + Vector<ScanTmp> m_scans; + int run(ScanTmp & tmp); + +}; + +#endif diff --git a/ndb/test/include/HugoTransactions.hpp b/ndb/test/include/HugoTransactions.hpp new file mode 100644 index 00000000000..5ff1fef16bc --- /dev/null +++ b/ndb/test/include/HugoTransactions.hpp @@ -0,0 +1,129 @@ +/* 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 */ + +#ifndef HUGO_TRANSACTIONS_HPP +#define HUGO_TRANSACTIONS_HPP + + +#include <NDBT.hpp> +#include <HugoCalculator.hpp> +#include <HugoOperations.hpp> + + +class HugoTransactions : public HugoOperations { +public: + HugoTransactions(const NdbDictionary::Table&); + ~HugoTransactions(); + int createEvent(Ndb*); + int eventOperation(Ndb*, void* stats, + int records); + int loadTable(Ndb*, + int records, + int batch = 512, + bool allowConstraintViolation = true, + int doSleep = 0); + int scanReadRecords(Ndb*, + int records, + int abort = 0, + int parallelism = 1, + bool committed = false); + int scanReadCommittedRecords(Ndb*, + int records, + int abort = 0, + int parallelism = 1); + int pkReadRecords(Ndb*, + int records, + int batchsize = 1, + bool dirty = false); + + int scanUpdateRecords(Ndb*, + int records, + int abort = 0, + int parallelism = 1); + + int scanUpdateRecords1(Ndb*, + int records, + int abort = 0, + int parallelism = 1); + int scanUpdateRecords2(Ndb*, + int records, + int abort = 0, + int parallelism = 1); + int scanUpdateRecords3(Ndb*, + int records, + int abort = 0, + int parallelism = 1); + + int pkUpdateRecords(Ndb*, + int records, + int batchsize = 1, + int doSleep = 0); + int pkInterpretedUpdateRecords(Ndb*, + int records, + int batchsize = 1); + int pkDelRecords(Ndb*, + int records = 0, + int batch = 1, + bool allowConstraintViolation = true, + int doSleep = 0); + int lockRecords(Ndb*, + int records, + int percentToLock = 1, + int lockTime = 1000); + int fillTable(Ndb*, + int batch=512); + + /** + * Reading using UniqHashIndex with key = pk + */ + int indexReadRecords(Ndb*, + const char * idxName, + int records, + int batchsize = 1); + + int indexUpdateRecords(Ndb*, + const char * idxName, + int records, + int batchsize = 1); + +protected: + int takeOverAndUpdateRecord(Ndb*, + NdbOperation*); +#if 0 + int setValueForAttr(NdbOperation*, + int attrId, + int rowId, + int updateId); +public: + int equalForAttr(NdbOperation*, + int attrId, + int rowId); +#endif + + int addRowToUpdate(Ndb* pNdb, + NdbConnection* pUpdTrans, + NdbOperation* pOrgOp); + + + NDBT_ResultRow row; + int m_defaultScanUpdateMethod; +}; + + + + +#endif + diff --git a/ndb/test/include/NDBT.hpp b/ndb/test/include/NDBT.hpp new file mode 100644 index 00000000000..657a9cb03b6 --- /dev/null +++ b/ndb/test/include/NDBT.hpp @@ -0,0 +1,39 @@ +/* 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 */ + +#ifndef NDB_TEST_HPP +#define NDB_TEST_HPP + +/** + * NdbTest.hpp + * This is the main include file to include in test programs + * It will include all the other include files in the NDBT-toolkit + * + */ + +#include "NDBT_ReturnCodes.h" + +#ifdef __cplusplus +#include "NDBT_Table.hpp" +#include "NDBT_Tables.hpp" +#include "NDBT_Error.hpp" +#include "NDBT_ResultRow.hpp" +#include "NDBT_Output.hpp" + +#endif + + +#endif diff --git a/ndb/test/include/NDBT_DataSet.hpp b/ndb/test/include/NDBT_DataSet.hpp new file mode 100644 index 00000000000..1a0122f617c --- /dev/null +++ b/ndb/test/include/NDBT_DataSet.hpp @@ -0,0 +1,140 @@ +/* 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 */ + +#ifndef NDBT_DATA_SET_HPP +#define NDBT_DATA_SET_HPP + +#include "NDBT_Table.hpp" +#include <NdbApi.hpp> + +class NDBT_DataSet; + +class NDBT_DataSetFactory { +public: + NDBT_DataSet * createEmpty(const NDBT_Table & table, + const char * columns[]); + + NDBT_DataSet * createRandom(const NDBT_DataSet & table, + const char * columns[], + int rows); + + NDBT_DataSet * createXXX(int noOfDS, const NDBT_DataSet ** datasets); +}; + +class NDBT_DataSet { + friend class NDBT_DataSetFactory; +public: + /** + * Rows in the data set + */ + void setRows(int rows); + void addRows(int rows); + + int getNoOfRows() const; + + /** + * Columns for a row in the data set + */ + int getNoOfColumns() const; + int getNoOfPKs() const; + + const NDBT_Attribute * getColumn(int index); + const NDBT_Attribute * getColumn(const char * name); + + /** + * Data status in dataset + */ + bool hasPK(int row); + bool hasData(int row); + + /** + * Do all rows in the dataset have a PK + */ + bool hasPK(); + + /** + * Do all rows in the dataset has data + */ + bool hasData(); + + /** + * Getters for data + */ + Uint32 getUInt(int row, int index) const; + Uint32 getUInt(int row, const char * attribute) const; + + Int32 getInt(int row, int index) const; + Int32 getInt(int row, const char * attribute) const; + + const char * getString(int row, int index) const; + const char * getString(int row, const char * attribute) const; + + bool getIsNull(int row, int index) const; + bool getIsNull(int row, const char * attribute) const; + + /** + * Setters for data + */ + void set(int row, int index, Int32 value); + void set(int row, const char * attr, Int32 value); + + void set(int row, int index, Uint32 value); + void set(int row, const char * attr, Uint32 value); + + void set(int row, int index, const char * value); + void set(int row, const char * attr, const char * value); + + /** + * Comparators + */ + + /** + * Is this dataset identical to other dataset + * + * If either of the datasets have "undefined" rows the answer is false + */ + bool equal(const NDBT_DataSet & other) const; + + /** + * Do these dataset have identical PK's + * + * I.e noOfRows equal + * + * and for each row there is a corresponding row in the other ds + * with the same pk + */ + bool equalPK(const NDBT_DataSet & other) const; + +private: + NDBT_Attribute * columns; + + Uint32 noOfRows; + Uint32 noOfPKs; + + Uint32 * pks; + Uint32 * columnSizes; + + char * pkData; + char * data; + + char * pk(int row, int pkIndex); + char * column(int row, int columnIndex); + + Uint32 * hasPK; + Uint32 * hasData; +}; + +#endif diff --git a/ndb/test/include/NDBT_DataSetTransaction.hpp b/ndb/test/include/NDBT_DataSetTransaction.hpp new file mode 100644 index 00000000000..9f250c566dd --- /dev/null +++ b/ndb/test/include/NDBT_DataSetTransaction.hpp @@ -0,0 +1,162 @@ +/* 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 */ + +#ifndef NDBT_DATA_SET_TRANSACTION_HPP +#define NDBT_DATA_SET_TRANSACTION_HPP + +#include "NDBT_Table.hpp" +#include <NdbApi.hpp> + +class NDBT_DataSet; + +/** + * This class contains a bunch a methods + * that operates on NDB together with a NDBT_DataSet + * using <b>one</b> transaction + */ +class NDBT_DataSetTransaction { +public: + /** + * Store the data into ndb + */ + static void insert(Ndb * theNdbObject, + const NDBT_DataSet *, + bool rollback = false); + + /** + * Read data (using pk) from ndb + */ + static void readByPk(Ndb * theNdbObject, + NDBT_DataSet *, + bool rollback = false); + + /** + * Update data using pk + * + */ + static void updateByPk(Ndb * theNdbObject, + const NDBT_DataSet *, + bool rollback = false); + + /** + * Delete + */ + static void deleteByPk(Ndb * theNdbObject, + const NDBT_DataSet *, + bool rollback = false); +}; + +class NDBT_DataSetAsyncTransaction { +public: + enum OperationType { + OT_Insert, + OT_ReadByPk, + OT_UpdateByPk, + OT_DeleteByPk + }; + + /** + * A callback for the NDBT_DataSetAsyncTransaction + * interface. + * + * The callback method returns: + * - the operation performed + * - the data set + * - if the transaction was commited or aborted + */ + typedef (* NDBT_DataSetAsyncTransactionCallback)(OperationType, + const NDBT_DataSet *, + bool commit, + void * anyObject); + /** + * Store the data into ndb + */ + static void insert(Ndb * theNdbObject, + const NDBT_DataSet *, + bool rollback = false, + NDBT_DataSetAsyncTransactionCallback fun, + void * anyObject); + + /** + * Read data (using pk) from ndb + */ + static void readByPk(Ndb * theNdbObject, + NDBT_DataSet *, + bool rollback = false, + NDBT_DataSetAsyncTransactionCallback fun, + void * anyObject); + + + /** + * Update data using pk + * + */ + static void updateByPk(Ndb * theNdbObject, + const NDBT_DataSet *, + bool rollback = false, + NDBT_DataSetAsyncTransactionCallback fun, + void * anyObject); + + + /** + * Delete + */ + static void deleteByPk(Ndb * theNdbObject, + const NDBT_DataSet *, + bool rollback = false, + NDBT_DataSetAsyncTransactionCallback fun, + void * anyObject); + +}; + +class NDBT_DataSetBulkOperation { +public: + /** + * Store the data into ndb + */ + static void insert(Ndb * theNdbObject, + const NDBT_DataSet *, + int parallellTransactions = 1, + int operationsPerTransaction = 10); + + /** + * Read data (using pk) from ndb + */ + static void readByPk(Ndb * theNdbObject, + NDBT_DataSet *, + int parallellTransactions = 1, + int operationsPerTransaction = 10); + + /** + * Update data using pk + * + */ + static void updateByPk(Ndb * theNdbObject, + const NDBT_DataSet *, + int parallellTransactions = 1, + int operationsPerTransaction = 10); + + /** + * Delete + */ + static void deleteByPk(Ndb * theNdbObject, + const NDBT_DataSet *, + int parallellTransactions = 1, + int operationsPerTransaction = 10); +}; + + +#endif diff --git a/ndb/test/include/NDBT_Error.hpp b/ndb/test/include/NDBT_Error.hpp new file mode 100644 index 00000000000..ef107072465 --- /dev/null +++ b/ndb/test/include/NDBT_Error.hpp @@ -0,0 +1,97 @@ +/* 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 */ + +#ifndef NDBT_Error_HPP +#define NDBT_Error_HPP + +#include <NdbOut.hpp> +#include <NdbError.hpp> + +/** + * NDBT_Error.hpp + * This is the main include file about error handling in NDBT test programs + * + */ +class ErrorData { + +public: + ErrorData(); + ~ErrorData(); + + /** + * Parse cmd line arg + * + * Return true if successeful + */ + bool parseCmdLineArg(const char ** argv, int & i); + + /** + * Print cmd line arguments + */ + void printCmdLineArgs(NdbOut & out = ndbout); + + /** + * Print settings + */ + void printSettings(NdbOut & out = ndbout); + + /** + * Print error count + */ + void printErrorCounters(NdbOut & out = ndbout) const; + + /** + * Reset error counters + */ + void resetErrorCounters(); + + /** + * + */ + int handleErrorCommon(const NdbError & error); + +private: + bool key_error; + bool temporary_resource_error; + bool insufficient_space_error; + bool node_recovery_error; + bool overload_error; + bool timeout_error; + bool internal_error; + bool user_error; + bool application_error; + + Uint32 * errorCountArray; +}; + +// +// ERR prints an NdbError object togheter with a description of where +// the error occured +// +#define ERR_OUT(where, error) \ + { where << "ERROR: " << error.code << " " \ + << error.message << endl \ + << " " << "Status: " << error.status \ + << ", Classification: " << error.classification << endl\ + << " " << "File: " << __FILE__ \ + << " (Line: " << __LINE__ << ")" << endl \ + ; \ + } + +#define ERR(error) ERR_OUT(g_err, error) +#define ERR_INFO(error) ERR_OUT(g_info, error) + +#endif diff --git a/ndb/test/include/NDBT_Output.hpp b/ndb/test/include/NDBT_Output.hpp new file mode 100644 index 00000000000..aaa619ac479 --- /dev/null +++ b/ndb/test/include/NDBT_Output.hpp @@ -0,0 +1,30 @@ +/* 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 */ + +#ifndef NDBT_Output_HPP +#define NDBT_Output_HPP + +#include <OutputStream.hpp> +#include <NdbOut.hpp> + +void setOutputLevel(int i); + +extern FilteredNdbOut g_err; +extern FilteredNdbOut g_warning; +extern FilteredNdbOut g_info; +extern FilteredNdbOut g_debug; + +#endif diff --git a/ndb/test/include/NDBT_ResultRow.hpp b/ndb/test/include/NDBT_ResultRow.hpp new file mode 100644 index 00000000000..aa54e892da3 --- /dev/null +++ b/ndb/test/include/NDBT_ResultRow.hpp @@ -0,0 +1,55 @@ +/* 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 */ + +#ifndef NDBT_RESULTROW_HPP +#define NDBT_RESULTROW_HPP + +#include <NdbApi.hpp> + +class NDBT_ResultRow { +public: + NDBT_ResultRow(const NdbDictionary::Table &tab, char attrib_delimiter='\t'); + ~NDBT_ResultRow(); + NdbRecAttr * & attributeStore(int i); + const NdbRecAttr * attributeStore(const char* name); + + BaseString c_str(); + + NdbOut & header (NdbOut &) const; + friend NdbOut & operator << (NdbOut&, const NDBT_ResultRow &); + + /** + * Make copy of NDBT_ResultRow + */ + NDBT_ResultRow * clone() const; + +private: + int cols; + char **names; + NdbRecAttr **data; + char ad[2]; + + bool m_ownData; + const NdbDictionary::Table & m_table; + + NDBT_ResultRow(const NDBT_ResultRow &); + NDBT_ResultRow& operator=(const NDBT_ResultRow &); +}; + + + + +#endif diff --git a/ndb/test/include/NDBT_ReturnCodes.h b/ndb/test/include/NDBT_ReturnCodes.h new file mode 100644 index 00000000000..0bc71ad8ceb --- /dev/null +++ b/ndb/test/include/NDBT_ReturnCodes.h @@ -0,0 +1,42 @@ +/* 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 */ + +#ifndef NDBT_RETURNCODES_H +#define NDBT_RETURNCODES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define NDBT_OK 0 +#define NDBT_FAILED 1 +#define NDBT_WRONGARGS 2 +#define NDBT_TEMPORARY 3 +/** + * NDBT_ProgramExit + * This function will print the returncode togheter with a prefix on + * the screen and then exit the test program. + * Call this function when exiting the main function in your test programs + * Returns the return code + */ +int NDBT_ProgramExit(int rcode); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ndb/test/include/NDBT_Stats.hpp b/ndb/test/include/NDBT_Stats.hpp new file mode 100644 index 00000000000..15a125dea86 --- /dev/null +++ b/ndb/test/include/NDBT_Stats.hpp @@ -0,0 +1,76 @@ +/* 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 */ + +#ifndef NDBT_STATS_HPP +#define NDBT_STATS_HPP + +#include <math.h> +#include <float.h> +#include <assert.h> + +class NDBT_Stats { +public: + NDBT_Stats() { reset(); } + + void reset() { sum = sum2 = 0.0; max = DBL_MIN; ; min = DBL_MAX; n = 0;} + + void addObservation(double t) { + sum+= t; + sum2 += (t*t); + n++; + if(min > t) min = t; + if(max < t) max = t; + } + + double getMean() const { return sum/n;} + double getStddev() const { return sqrt(getVariance()); } + double getVariance() const { return (n*sum2 - (sum*sum))/(n*n);} + double getMin() const { return min;} + double getMax() const { return max;} + int getCount() const { return n;} + + NDBT_Stats & operator+=(const NDBT_Stats & c){ + sum += c.sum; + sum2 += c.sum2; + n += c.n; + if(min > c.min) min = c.min; + if(max < c.max) max = c.max; + return * this; + } +private: + double sum; + double sum2; + int n; + double min, max; +}; + +inline +double +NDB_SQRT(double x){ + assert(x >= 0); + + double y = 0; + double s = 1; + double r = 0; + while(y <= x){ + y += s; + s += 2; + r += 1; + } + return r - 1; +} + +#endif diff --git a/ndb/test/include/NDBT_Table.hpp b/ndb/test/include/NDBT_Table.hpp new file mode 100644 index 00000000000..a4482fa8084 --- /dev/null +++ b/ndb/test/include/NDBT_Table.hpp @@ -0,0 +1,135 @@ +/* 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 */ + +#ifndef NDBT_TABLE_HPP +#define NDBT_TABLE_HPP + +#include <NdbApi.hpp> +#include <NdbOut.hpp> + +#include <string.h> + +class NDBT_Attribute : public NdbDictionary::Column { + friend class NdbOut& operator <<(class NdbOut&, const NDBT_Attribute &); +public: + NDBT_Attribute(const char* anAttrName, + AttrType type, + int sz = 4, + KeyType key = NoKey, + bool nullable = false, + StorageAttributeType indexOnly = NormalStorageAttribute, + StorageMode _sm = MMBased) : + NdbDictionary::Column(anAttrName) + { + assert(anAttrName != 0); + + setNullable(nullable); + setIndexOnlyStorage(indexOnly == IndexStorageAttribute); + setPrimaryKey(key != NoKey); + setTupleKey(key == TupleId); + setLength(1); + switch(type){ + case ::Signed: + if(sz == 8) + setType(NdbDictionary::Column::Bigint); + else if (sz == 4) + setType(NdbDictionary::Column::Int); + else { + setType(NdbDictionary::Column::Int); + setLength(sz); + } + break; + + case ::UnSigned: + if(sz == 8) + setType(NdbDictionary::Column::Bigunsigned); + else if (sz == 4) + setType(NdbDictionary::Column::Unsigned); + else { + setType(NdbDictionary::Column::Unsigned); + setLength(sz); + } + break; + + case ::Float: + if(sz == 8) + setType(NdbDictionary::Column::Double); + else if (sz == 4) + setType(NdbDictionary::Column::Float); + else{ + setType(NdbDictionary::Column::Float); + setLength(sz); + } + break; + + case ::String: + setType(NdbDictionary::Column::Char); + setLength(sz); + break; + + case ::NoAttrTypeDef: + break; + } + } + + NDBT_Attribute(const char* _name, + Column::Type _type, + int _length = 1, + bool _pk = false, + bool _nullable = false): + NdbDictionary::Column(_name) + { + assert(_name != 0); + + setNullable(_nullable); + setPrimaryKey(_pk); + setLength(_length); + setType(_type); + } +}; + +class NDBT_Table : public NdbDictionary::Table { + /** + * Print meta information about table + * (information on how it is strored, what the attributes look like etc.) + */ + friend class NdbOut& operator <<(class NdbOut&, const NDBT_Table &); +public: + + NDBT_Table(const char* name, + int noOfAttributes, + const NdbDictionary::Column attributes[], + bool stored = true) + : NdbDictionary::Table(name) + { + assert(name != 0); + + setStoredTable(stored); + for(int i = 0; i<noOfAttributes; i++) + addColumn(attributes[i]); + } + + static const NdbDictionary::Table * discoverTableFromDb(Ndb* ndb, + const char * name); +}; + +inline +const NdbDictionary::Table * +NDBT_Table::discoverTableFromDb(Ndb* ndb, const char * name){ + return ndb->getDictionary()->getTable(name); +} + +#endif diff --git a/ndb/test/include/NDBT_Tables.hpp b/ndb/test/include/NDBT_Tables.hpp new file mode 100644 index 00000000000..1da9818ee70 --- /dev/null +++ b/ndb/test/include/NDBT_Tables.hpp @@ -0,0 +1,47 @@ +/* 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 */ + +#ifndef NDBT_TABLES_HPP +#define NDBT_TABLES_HPP + + +#include <NDBT.hpp> +#include <Ndb.hpp> +#include <NdbDictionary.hpp> +#include <NDBT_Table.hpp> + +class NDBT_Tables { +public: + + static int createTable(Ndb* pNdb, const char* _name, bool _temp = false); + static int createAllTables(Ndb* pNdb, bool _temp, bool existsOK = false); + static int createAllTables(Ndb* pNdb); + + static int dropAllTables(Ndb* pNdb); + + static int print(const char * name); + static int printAll(); + + static const NdbDictionary::Table* getTable(const char* _nam); + static const NdbDictionary::Table* getTable(int _num); + static int getNumTables(); + +private: + static const NdbDictionary::Table* tableWithPkSize(const char* _nam, Uint32 pkSize); +}; +#endif + + diff --git a/ndb/test/include/NDBT_Test.hpp b/ndb/test/include/NDBT_Test.hpp new file mode 100644 index 00000000000..41332bb570c --- /dev/null +++ b/ndb/test/include/NDBT_Test.hpp @@ -0,0 +1,417 @@ +/* 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 */ + +#ifndef NDBT_TEST_HPP +#define NDBT_TEST_HPP + + +#include "NDBT_ReturnCodes.h" +#include <Properties.hpp> +#include <NdbThread.h> +#include <NdbSleep.h> +#include <NdbCondition.h> +#include <NdbTimer.hpp> +#include <assert.h> +#include <Vector.hpp> +#include <NdbDictionary.hpp> + +class NDBT_Step; +class NDBT_TestCase; +class NDBT_TestSuite; +class NDBT_TestCaseImpl1; + +class NDBT_Context { +public: + NDBT_Context(); + ~NDBT_Context(); + const NdbDictionary::Table* getTab(); + NDBT_TestSuite* getSuite(); + NDBT_TestCase* getCase(); + + // Get arguments + int getNumRecords() const; + int getNumLoops() const; + char * getRemoteMgm() const; + // Common place to store state between + // steps, for example information from one step to the + // verifier about how many records have been inserted + Uint32 getProperty(const char*, Uint32 = 0 ); + const char* getProperty(const char*, const char* ); + void setProperty(const char*, Uint32); + void setProperty(const char*, const char*); + + // Signal that a property value that another + // thread might be waiting for has changed + void broadcast(); + // Wait for the signal that a property has changed + void wait(); + void wait_timeout(int msec); + + // Wait until the property has been set to a certain value + bool getPropertyWait(const char*, Uint32); + const char* getPropertyWait(const char*, const char* ); + + // Communicate with other tests + void stopTest(); + bool isTestStopped(); + + // Communicate with tests in other API nodes + // This is done using a "system" table in the database + Uint32 getDbProperty(const char*); + bool setDbProperty(const char*, Uint32); + + void setTab(const NdbDictionary::Table*); + void setRemoteMgm(char * mgm); + + /** + * Get no of steps running/completed + */ + int getNoOfRunningSteps() const ; + int getNoOfCompletedSteps() const ; +private: + friend class NDBT_Step; + friend class NDBT_TestSuite; + friend class NDBT_TestCase; + friend class NDBT_TestCaseImpl1; + + void setSuite(NDBT_TestSuite*); + void setCase(NDBT_TestCase*); + void setNumRecords(int); + void setNumLoops(int); + const NdbDictionary::Table* tab; + NDBT_TestSuite* suite; + NDBT_TestCase* testcase; + Ndb* ndb; + int records; + int loops; + bool stopped; + char * remote_mgm; + Properties props; + NdbMutex* propertyMutexPtr; + NdbCondition* propertyCondPtr; +}; + +typedef int (NDBT_TESTFUNC)(NDBT_Context*, NDBT_Step*); + +class NDBT_Step { +public: + NDBT_Step(NDBT_TestCase* ptest, + const char* pname, + NDBT_TESTFUNC* pfunc); + int execute(NDBT_Context*); + virtual int setUp() = 0; + virtual void tearDown() = 0; + void setContext(NDBT_Context*); + NDBT_Context* getContext(); + void print(); + const char* getName() { return name; } + int getStepNo() { return step_no; } + void setStepNo(int n) { step_no = n; } +protected: + NDBT_Context* m_ctx; + const char* name; + NDBT_TESTFUNC* func; + NDBT_TestCase* testcase; + int step_no; +}; + +class NDBT_NdbApiStep : public NDBT_Step { +public: + NDBT_NdbApiStep(NDBT_TestCase* ptest, + const char* pname, + NDBT_TESTFUNC* pfunc); + int setUp(); + void tearDown(); + + Ndb* getNdb(); +protected: + Ndb* ndb; +}; + +class NDBT_ParallelStep : public NDBT_NdbApiStep { +public: + NDBT_ParallelStep(NDBT_TestCase* ptest, + const char* pname, + NDBT_TESTFUNC* pfunc); +}; + +class NDBT_Verifier : public NDBT_NdbApiStep { +public: + NDBT_Verifier(NDBT_TestCase* ptest, + const char* name, + NDBT_TESTFUNC* func); +}; + +class NDBT_Initializer : public NDBT_NdbApiStep { +public: + NDBT_Initializer(NDBT_TestCase* ptest, + const char* name, + NDBT_TESTFUNC* func); +}; + +class NDBT_Finalizer : public NDBT_NdbApiStep { +public: + NDBT_Finalizer(NDBT_TestCase* ptest, + const char* name, + NDBT_TESTFUNC* func); +}; + + +class NDBT_TestCase { +public: + NDBT_TestCase(NDBT_TestSuite* psuite, + const char* name, + const char* comment); + virtual ~NDBT_TestCase(){}; + // This is the default executor of a test case + // When a test case is executed it will need to be suplied with a number of + // different parameters and settings, these are passed to the test in the + // NDBT_Context object + virtual int execute(NDBT_Context*); + void setProperty(const char*, Uint32); + void setProperty(const char*, const char*); + virtual void print() = 0; + virtual void printHTML() = 0; + + const char* getName(){return name;}; + virtual bool tableExists(NdbDictionary::Table* aTable) = 0; + virtual bool isVerify(const NdbDictionary::Table* aTable) = 0; + + virtual void saveTestResult(const NdbDictionary::Table* ptab, int result) = 0; + virtual void printTestResult() = 0; + void initBeforeTest(){ timer.doReset();}; + + /** + * Get no of steps running/completed + */ + virtual int getNoOfRunningSteps() const = 0; + virtual int getNoOfCompletedSteps() const = 0; + +protected: + virtual int runInit(NDBT_Context* ctx) = 0; + virtual int runSteps(NDBT_Context* ctx) = 0; + virtual int runVerifier(NDBT_Context* ctx) = 0; + virtual int runFinal(NDBT_Context* ctx) = 0; + virtual void addTable(const char* aTableName, bool isVerify=true) = 0; + + void startTimer(NDBT_Context*); + void stopTimer(NDBT_Context*); + void printTimer(NDBT_Context*); + + const char* name; + const char* comment; + NDBT_TestSuite* suite; + Properties props; + NdbTimer timer; + bool isVerifyTables; +}; + +static const int FAILED_TO_CREATE = 1000; +static const int FAILED_TO_DISCOVER = 1001; + + +class NDBT_TestCaseResult{ +public: + NDBT_TestCaseResult(const char* name, int _result, NDB_TICKS _ticks): + m_result(_result){ + m_name.assign(name); + m_ticks = _ticks; + + }; + const char* getName(){return m_name.c_str(); }; + int getResult(){return m_result; }; + const char* getTimeStr(){ + // Convert to Uint32 in order to be able to print it to screen + Uint32 lapTime = (Uint32)m_ticks; + Uint32 secTime = lapTime/1000; + snprintf(buf, 255, "%d secs (%d ms)", secTime, lapTime); + return buf; + } +private: + char buf[255]; + int m_result; + BaseString m_name; + NDB_TICKS m_ticks; +}; + +class NDBT_TestCaseImpl1 : public NDBT_TestCase { +public: + NDBT_TestCaseImpl1(NDBT_TestSuite* psuite, + const char* name, + const char* comment); + virtual ~NDBT_TestCaseImpl1(); + int addStep(NDBT_Step*); + int addVerifier(NDBT_Verifier*); + int addInitializer(NDBT_Initializer*); + int addFinalizer(NDBT_Finalizer*); + void addTable(const char*, bool); + bool tableExists(NdbDictionary::Table*); + bool isVerify(const NdbDictionary::Table*); + void reportStepResult(const NDBT_Step*, int result); + // int execute(NDBT_Context* ctx); + int runInit(NDBT_Context* ctx); + int runSteps(NDBT_Context* ctx); + int runVerifier(NDBT_Context* ctx); + int runFinal(NDBT_Context* ctx); + void print(); + void printHTML(); + + virtual int getNoOfRunningSteps() const; + virtual int getNoOfCompletedSteps() const; +private: + static const int NORESULT = 999; + + void saveTestResult(const NdbDictionary::Table* ptab, int result); + void printTestResult(); + + void startStepInThread(int stepNo, NDBT_Context* ctx); + void waitSteps(); + Vector<NDBT_Step*> steps; + Vector<NdbThread*> threads; + Vector<int> results; + Vector<NDBT_Verifier*> verifiers; + Vector<NDBT_Initializer*> initializers; + Vector<NDBT_Finalizer*> finalizers; + Vector<const NdbDictionary::Table*> testTables; + Vector<NDBT_TestCaseResult*> testResults; + unsigned numStepsFail; + unsigned numStepsOk; + unsigned numStepsCompleted; + NdbMutex* waitThreadsMutexPtr; + NdbCondition* waitThreadsCondPtr; +}; + + +// A NDBT_TestSuite is a collection of TestCases +// the test suite will know how to execute the test cases +class NDBT_TestSuite { +public: + NDBT_TestSuite(const char* name); + ~NDBT_TestSuite(); + + // Default executor of a test suite + // supply argc and argv as parameters + int execute(int, const char**); + + + // These function can be used from main in the test program + // to control the behaviour of the testsuite + void setCreateTable(bool); // Create table before test func is called + void setCreateAllTables(bool); // Create all tables before testsuite is executed + + // Prints the testsuite, testcases and teststeps + void printExecutionTree(); + void printExecutionTreeHTML(); + + // Prints list of testcases + void printCases(); + + // Print summary of executed tests + void printTestCaseSummary(const char* tcname = NULL); + + /** + * Returns current date and time in the format of 2002-12-04 10:00:01 + */ + const char* getDate(); + + // Returns true if timing info should be printed + bool timerIsOn(); + + + int addTest(NDBT_TestCase* pTest); +private: + int executeOne(const char* _tabname, const char* testname = NULL); + int executeAll(const char* testname = NULL); + + void execute(Ndb*, const NdbDictionary::Table*, const char* testname = NULL); + int report(const char* _tcname = NULL); + int reportAllTables(const char* ); + const char* name; + char* remote_mgm; + int numTestsOk; + int numTestsFail; + int numTestsExecuted; + Vector<NDBT_TestCase*> tests; + NDBT_Context* ctx; + int records; + int loops; + int timer; + NdbTimer testSuiteTimer; + bool createTable; +}; + + + +#define NDBT_TESTSUITE(suitname) \ +class C##suitname : public NDBT_TestSuite { \ +public: \ +C##suitname():NDBT_TestSuite(#suitname){ \ + NDBT_TestCaseImpl1* pt; pt = NULL; \ + NDBT_Step* pts; pts = NULL; \ + NDBT_Verifier* ptv; ptv = NULL; \ + NDBT_Initializer* pti; pti = NULL; \ + NDBT_Finalizer* ptf; ptf = NULL; + +#define TESTCASE(testname, comment) \ + pt = new NDBT_TestCaseImpl1(this, testname, comment); \ + addTest(pt); + +#define TC_PROPERTY(propname, propval) \ + pt->setProperty(propname, propval); + +#define STEP(stepfunc) \ + pts = new NDBT_ParallelStep(pt, #stepfunc, stepfunc); \ + pt->addStep(pts); + +// Add a number of equal steps to the testcase +#define STEPS(stepfunc, num) \ + for (int i = 0; i < num; i++){ \ + pts = new NDBT_ParallelStep(pt, #stepfunc, stepfunc); \ + pt->addStep(pts);\ + } + +#define VERIFIER(stepfunc) \ + ptv = new NDBT_Verifier(pt, #stepfunc, stepfunc); \ + pt->addVerifier(ptv); + +#define INITIALIZER(stepfunc) \ + pti = new NDBT_Initializer(pt, #stepfunc, stepfunc); \ + pt->addInitializer(pti); + +#define FINALIZER(stepfunc) \ + ptf = new NDBT_Finalizer(pt, #stepfunc, stepfunc); \ + pt->addFinalizer(ptf); + +// Test case can be run only on this table(s), can be multiple tables +// Ex TABLE("T1") +// TABLE("T3") +// Means test will only be run on T1 and T3 +#define TABLE(tableName) \ + pt->addTable(tableName, true); + +// Test case can be run on all tables except +// Ex NOT_TABLE("T10") +// Means test will be run on all tables execept T10 +#define NOT_TABLE(tableName) \ + pt->addTable(tableName, false); + +#define NDBT_TESTSUITE_END(suitname) \ + } } ; C##suitname suitname; + +// Helper functions for retrieving variables from NDBT_Step +#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb() + +#endif diff --git a/ndb/test/include/NdbBackup.hpp b/ndb/test/include/NdbBackup.hpp new file mode 100644 index 00000000000..0a372eca7df --- /dev/null +++ b/ndb/test/include/NdbBackup.hpp @@ -0,0 +1,54 @@ +/* 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 */ + +#ifndef NDBT_BACKUP_HPP +#define NDBT_BACKUP_HPP + +#include <mgmapi.h> +#include <Vector.hpp> +#include "NdbConfig.hpp" +#include <NdbRestarter.hpp> + +class NdbBackup : public NdbConfig { +public: + NdbBackup(int _own_id, const char* _addr = 0) + : NdbConfig(_own_id, _addr) {}; + + int start(unsigned & _backup_id); + int restore(unsigned _backup_id); + + int NFMaster(NdbRestarter& _restarter); + int NFMasterAsSlave(NdbRestarter& _restarter); + int NFSlave(NdbRestarter& _restarter); + int NF(NdbRestarter& _restarter, int *NFDuringBackup_codes, const int sz, bool onMaster); + + int FailMaster(NdbRestarter& _restarter); + int FailMasterAsSlave(NdbRestarter& _restarter); + int FailSlave(NdbRestarter& _restarter); + int Fail(NdbRestarter& _restarter, int *Fail_codes, const int sz, bool onMaster); + +private: + + int execRestore(bool _restore_data, + bool _restore_meta, + int _node_id, + unsigned _backup_id); + + const char * getFileSystemPathForNode(int _node_id); + +}; + +#endif diff --git a/ndb/test/include/NdbConfig.hpp b/ndb/test/include/NdbConfig.hpp new file mode 100644 index 00000000000..f13872f4d64 --- /dev/null +++ b/ndb/test/include/NdbConfig.hpp @@ -0,0 +1,46 @@ +/* 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 */ + +#ifndef NDBT_CONFIG_HPP +#define NDBT_CONFIG_HPP + +#include <mgmapi.h> +#include <Vector.hpp> +#include <NdbRestarter.hpp> +#include <Properties.hpp> + +class NdbConfig : public NdbRestarter{ +public: + NdbConfig(int own_id, const char* addr = 0) + : NdbRestarter(addr), + ownNodeId(own_id) {}; + + bool getProperty(unsigned int node_id, const char* type, + const char * name, Uint32 * value) const; + bool getProperty(unsigned int node_id, const char* type, + const char * name, const char ** value) const; + + bool getHostName(unsigned int node_id, + const char ** hostname) const; +protected: + bool getPropsForNode(unsigned int node_id, + const char* type, + const Properties ** props) const; + + int ownNodeId; +}; + +#endif diff --git a/ndb/test/include/NdbGrep.hpp b/ndb/test/include/NdbGrep.hpp new file mode 100644 index 00000000000..31c49d1e4da --- /dev/null +++ b/ndb/test/include/NdbGrep.hpp @@ -0,0 +1,53 @@ +/* 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 */ + +#ifndef NDBT_GREP_HPP +#define NDBT_GREP_HPP + +#include <mgmapi.h> +#include <Vector.hpp> +#include "NdbConfig.hpp" +#include <NdbRestarter.hpp> +#include <NDBT.hpp> +#include <NDBT_Test.hpp> +class NdbGrep : public NdbConfig { +public: + NdbGrep(int _own_id, const char* _addr = 0) + : NdbConfig(_own_id, _addr) {}; + + int start(); + int stop(); + int query(); + + + int verify(NDBT_Context* ctx); + + + int NFMaster(NdbRestarter& _restarter); + int NFMasterAsSlave(NdbRestarter& _restarter); + int NFSlave(NdbRestarter& _restarter); + int NF(NdbRestarter& _restarter, int *NFDuringGrep_codes, const int sz, bool onMaster); + + int FailMaster(NdbRestarter& _restarter); + int FailMasterAsSlave(NdbRestarter& _restarter); + int FailSlave(NdbRestarter& _restarter); + int Fail(NdbRestarter& _restarter, int *Fail_codes, const int sz, bool onMaster); + +private: + +}; + +#endif diff --git a/ndb/test/include/NdbRestarter.hpp b/ndb/test/include/NdbRestarter.hpp new file mode 100644 index 00000000000..cfd5409bb69 --- /dev/null +++ b/ndb/test/include/NdbRestarter.hpp @@ -0,0 +1,95 @@ +/* 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 */ + +#ifndef NDBT_RESTARTER_HPP +#define NDBT_RESTARTER_HPP + +#include <mgmapi.h> +#include <Vector.hpp> + +class NdbRestarter { +public: + NdbRestarter(const char* _addr = 0); + ~NdbRestarter(); + + int getDbNodeId(int _i); + + int restartOneDbNode(int _nodeId, + bool initial = false, + bool nostart = false, + bool abort = false); + + int restartAll(bool initial = false, + bool nostart = false, + bool abort = false); + + int startAll(); + int startNodes(int * _nodes, int _num_nodes); + int waitClusterStarted(unsigned int _timeout = 120); + int waitClusterSingleUser(unsigned int _timeout = 120); + int waitClusterStartPhase(int _startphase, unsigned int _timeout = 120); + int waitClusterNoStart(unsigned int _timeout = 120); + int waitNodesStarted(int * _nodes, int _num_nodes, + unsigned int _timeout = 120); + int waitNodesStartPhase(int * _nodes, int _num_nodes, + int _startphase, unsigned int _timeout = 120); + int waitNodesNoStart(int * _nodes, int _num_nodes, + unsigned int _timeout = 120); + + + int getNumDbNodes(); + int insertErrorInNode(int _nodeId, int error); + int insertErrorInAllNodes(int error); + + int enterSingleUserMode(int _nodeId); + int exitSingleUserMode(); + + int dumpStateOneNode(int _nodeId, int * _args, int _num_args); + int dumpStateAllNodes(int * _args, int _num_args); + + int getMasterNodeId(); + int getRandomNodeOtherNodeGroup(int nodeId, int randomNumber); + int getRandomNotMasterNodeId(int randomNumber); + +protected: + + int waitClusterState(ndb_mgm_node_status _status, + unsigned int _timeout, + int _startphase = -1); + + int waitNodesState(int * _nodes, int _num_nodes, + ndb_mgm_node_status _status, + unsigned int _timeout, + int _startphase = -1); + + bool isConnected(); + int connect(); + void disconnect(); + int getStatus(); + + Vector<ndb_mgm_node_state> ndbNodes; + Vector<ndb_mgm_node_state> mgmNodes; + Vector<ndb_mgm_node_state> apiNodes; + + bool connected; + const char* addr; + const char* host; + int port; + NdbMgmHandle handle; + +}; + +#endif diff --git a/ndb/test/include/NdbRestarts.hpp b/ndb/test/include/NdbRestarts.hpp new file mode 100644 index 00000000000..aabcd7b9975 --- /dev/null +++ b/ndb/test/include/NdbRestarts.hpp @@ -0,0 +1,120 @@ +/* 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 */ + +#ifndef NDBT_RESTARTS_HPP +#define NDBT_RESTARTS_HPP + +#include <NdbRestarter.hpp> +#include <NdbTick.h> +#include <random.h> + +/** + * This class is used to test Ndb's ability to handle + * node- and system-restarts. + * For example: + * Node restart: Restart one node in the cluster. + * System restart: Restart all nodes in the cluster. + * Node crash: Crash one node in the middle of execution and bring it up again. + * Multiple node crash: Crash multiple nodes with a few seconds or milliseconds delay between. + * Initial node restart: Restart one node in the cluster without a filesystem on disk. + * + * Each restart type is represented by a NdbRestart class and a collection of these are stored + * in the NdbRestarts class. + * + * This class may be used from other programs to execute a particular restart. + * + */ + + +class NdbRestarts { +public: + NdbRestarts(const char* _addr = 0): + m_restarter(_addr) + { + myRandom48Init(NdbTick_CurrentMillisecond()); + } + + enum NdbRestartType{ + NODE_RESTART, + MULTIPLE_NODE_RESTART, + SYSTEM_RESTART + }; + + struct NdbRestart { + typedef int (restartFunc)(NdbRestarter&, const NdbRestart*); + + NdbRestart(const char* _name, + NdbRestartType _type, + restartFunc* _func, + int _requiredNodes, + int _arg1 = -1); + + const char * m_name; + NdbRestartType m_type; + restartFunc* m_restartFunc; + int m_numRequiredNodes; + int m_arg1; + + }; + + int getNumRestarts(); + + int executeRestart(int _num, unsigned int _timeout = 120); + int executeRestart(const char* _name, unsigned int _timeout = 120); + + void listRestarts(); + void listRestarts(NdbRestartType _type); +private: + int executeRestart(const NdbRestart*, unsigned int _timeout); + + struct NdbErrorInsert { + NdbErrorInsert(const char* _name, + int _errorNo); + + const char * m_name; + int m_errorNo; + + public: + const char* getName(); + }; + + int getNumErrorInserts(); + const NdbErrorInsert* getError(int _num); + const NdbErrorInsert* getRandomError(); + + static const NdbErrorInsert m_errors[]; + static const int m_NoOfErrors; + + const NdbRestart* getRestart(int _num); + const NdbRestart* getRestart(const char* _name); + + static const NdbRestart m_restarts[]; + static const int m_NoOfRestarts; + + NdbRestarter m_restarter; +}; + + + + + + + + + + + +#endif diff --git a/ndb/test/include/NdbTest.hpp b/ndb/test/include/NdbTest.hpp new file mode 100644 index 00000000000..a2e612b7ffa --- /dev/null +++ b/ndb/test/include/NdbTest.hpp @@ -0,0 +1,35 @@ +/* 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 */ + +#ifndef NDB_TEST_HPP +#define NDB_TEST_HPP + +/** + * NdbTest.hpp + * This is the main include file to include in test programs + * It will include all the other include files in the NDBT-toolkit + * + */ + +#include "NDBT_ReturnCodes.h" + +#ifdef __cplusplus +#include "NDBT_Table.hpp" +#include "NDBT_Error.hpp" +#endif + + +#endif diff --git a/ndb/test/include/NdbTimer.hpp b/ndb/test/include/NdbTimer.hpp new file mode 100644 index 00000000000..8d9a088b7b5 --- /dev/null +++ b/ndb/test/include/NdbTimer.hpp @@ -0,0 +1,110 @@ +/* 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 */ + +#ifndef NDBTIMER_H +#define NDBTIMER_H + +#include <NdbStdio.h> +#include <NdbTick.h> +#include <NdbOut.hpp> + +// +// Class used for measuring time and priting the results +// +// Currently measures time in milliseconds +// + +class NdbTimer +{ +public: + + NdbTimer(); + ~NdbTimer() {}; + + void doStart(); + void doStop(); + void doReset(); + NDB_TICKS elapsedTime(); + void printTransactionStatistics(const char* text, + int numTransactions, + int numOperations); + void printTestTimer(int numLoops, + int numRecords); + void printTotalTime(void); +private: + NDB_TICKS startTime; + NDB_TICKS stopTime; +}; + +inline NdbTimer::NdbTimer(){ + doReset(); +} + +inline void NdbTimer::doReset(void){ + startTime = 0; + stopTime = 0; +} + +inline void NdbTimer::doStart(void){ + startTime = NdbTick_CurrentMillisecond(); +} + +inline void NdbTimer::doStop(void){ + stopTime = NdbTick_CurrentMillisecond(); +} + +inline NDB_TICKS NdbTimer::elapsedTime(void){ + return (stopTime - startTime); +} + +inline void NdbTimer::printTransactionStatistics(const char* text, + int numTransactions, + int numOperations){ + + // Convert to Uint32 in order to be able to print it to screen + Uint32 lapTime = (Uint32)elapsedTime(); + ndbout_c("%i transactions, %i %s total time = %d ms\nAverage %f ms/transaction, %f ms/%s.\n%f transactions/second, %f %ss/second.\n", + numTransactions, numTransactions*numOperations, text, lapTime, + ((double)lapTime/numTransactions), ((double)lapTime/(numTransactions*numOperations)), text, + 1000.0/((double)lapTime/numOperations), 1000.0/((double)lapTime/(numTransactions*numOperations)), text); +} + + + +inline void NdbTimer::printTestTimer(int numLoops, + int numRecords){ + // Convert to Uint32 in order to be able to print it to screen + Uint32 lapTime = (Uint32)elapsedTime(); + ndbout_c("%i loop * %i records, total time = %d ms\nAverage %f ms/loop, %f ms/record.\n%f looop/second, %f records/second.\n", + numLoops, numRecords, lapTime, + ((double)lapTime/numLoops), ((double)lapTime/(numLoops*numRecords)), + 1000.0/((double)lapTime/numLoops), 1000.0/((double)lapTime/(numLoops*numRecords))); +} + + +inline void NdbTimer::printTotalTime(void){ + // Convert to Uint32 in order to be able to print it to screen + Uint32 lapTime = (Uint32)elapsedTime(); + Uint32 secTime = lapTime/1000; + ndbout_c("Total time : %d seconds (%d ms)\n", secTime, lapTime); +} + + + + + + +#endif diff --git a/ndb/test/include/TestNdbEventOperation.hpp b/ndb/test/include/TestNdbEventOperation.hpp new file mode 100644 index 00000000000..307b0e0089b --- /dev/null +++ b/ndb/test/include/TestNdbEventOperation.hpp @@ -0,0 +1,24 @@ +/* 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 */ + +struct EventOperationStats { + int n_inserts; + int n_deletes; + int n_updates; + int n_duplicates; + int n_consecutive; + int n_inconsistent_gcis; +}; diff --git a/ndb/test/include/UtilTransactions.hpp b/ndb/test/include/UtilTransactions.hpp new file mode 100644 index 00000000000..b16ab74455e --- /dev/null +++ b/ndb/test/include/UtilTransactions.hpp @@ -0,0 +1,108 @@ +/* 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 */ + +#ifndef UTIL_TRANSACTIONS_HPP +#define UTIL_TRANSACTIONS_HPP + +#include <NDBT.hpp> + +typedef int (ReadCallBackFn)(NDBT_ResultRow*); + +class UtilTransactions { +public: + enum ScanLock { + SL_Read = 0, + SL_ReadHold = 1, + SL_Exclusive = 2 + }; + + UtilTransactions(const NdbDictionary::Table&); + UtilTransactions(Ndb* ndb, const char * tableName); + + int clearTable(Ndb*, + int records = 0, + int parallelism = 240); + + // Delete all records from the table using a scan + int clearTable1(Ndb*, + int records = 0, + int parallelism = 16); + // Delete all records from the table using a scan + // Using batching + int clearTable2(Ndb*, + int records = 0, + int parallelism = 240); + + int clearTable3(Ndb*, + int records = 0, + int parallelism = 240); + + int selectCount(Ndb*, + int parallelism = 16, + int* count_rows = NULL, + ScanLock lock = SL_Read, + NdbConnection* pTrans = NULL); + int scanReadRecords(Ndb*, + int parallelism, + bool exclusive, + int records, + int noAttribs, + int* attrib_list, + ReadCallBackFn* fn = NULL); + int verifyIndex(Ndb*, + const char* indexName, + int parallelism = 240, + bool transactional = false); + + int copyTableData(Ndb*, + const char* destName); + + +private: + static int takeOverAndDeleteRecord(Ndb*, + NdbOperation*); + + int addRowToDelete(Ndb* pNdb, + NdbConnection* pDelTrans, + NdbOperation* pOrgOp); + + + int addRowToInsert(Ndb* pNdb, + NdbConnection* pInsTrans, + NDBT_ResultRow & row, + const char* insertTabName); + + + int verifyUniqueIndex(Ndb*, + const char* indexName, + int parallelism = 240, + bool transactional = false); + + int scanAndCompareUniqueIndex(Ndb* pNdb, + const char * indexName, + int parallelism, + bool transactional); + + int readRowFromTableAndIndex(Ndb* pNdb, + NdbConnection* pTrans, + const char * indexName, + NDBT_ResultRow& row ); +protected: + int m_defaultClearMethod; + const NdbDictionary::Table& tab; +}; + +#endif |