diff options
Diffstat (limited to 'storage/ndb/test/ndbapi/bank/testBank.cpp')
-rw-r--r-- | storage/ndb/test/ndbapi/bank/testBank.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/storage/ndb/test/ndbapi/bank/testBank.cpp b/storage/ndb/test/ndbapi/bank/testBank.cpp new file mode 100644 index 00000000000..6be66d528b1 --- /dev/null +++ b/storage/ndb/test/ndbapi/bank/testBank.cpp @@ -0,0 +1,151 @@ +/* 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 <NdbBackup.hpp> + + +#define CHECK(b) if (!(b)) { \ + g_err << "ERR: "<< step->getName() \ + << " failed on line " << __LINE__ << endl; \ + result = NDBT_FAILED; \ + continue; } + + +#include "Bank.hpp" + +int runCreateBank(NDBT_Context* ctx, NDBT_Step* step){ + Bank bank(ctx->m_cluster_connection); + int overWriteExisting = true; + if (bank.createAndLoadBank(overWriteExisting) != NDBT_OK) + return NDBT_FAILED; + return NDBT_OK; +} + +int runBankTimer(NDBT_Context* ctx, NDBT_Step* step){ + Bank bank(ctx->m_cluster_connection); + int wait = 30; // Max seconds between each "day" + int yield = 1; // Loops before bank returns + + while (ctx->isTestStopped() == false) { + bank.performIncreaseTime(wait, yield); + } + return NDBT_OK; +} + +int runBankTransactions(NDBT_Context* ctx, NDBT_Step* step){ + Bank bank(ctx->m_cluster_connection); + int wait = 10; // Max ms between each transaction + int yield = 100; // Loops before bank returns + + while (ctx->isTestStopped() == false) { + bank.performTransactions(wait, yield); + } + return NDBT_OK; +} + +int runBankGL(NDBT_Context* ctx, NDBT_Step* step){ + Bank bank(ctx->m_cluster_connection); + int yield = 20; // Loops before bank returns + int result = NDBT_OK; + + while (ctx->isTestStopped() == false) { + if (bank.performMakeGLs(yield) != NDBT_OK){ + ndbout << "bank.performMakeGLs FAILED" << endl; + result = NDBT_FAILED; + } + } + return NDBT_OK; +} + +int runBankSum(NDBT_Context* ctx, NDBT_Step* step){ + Bank bank(ctx->m_cluster_connection); + int wait = 2000; // Max ms between each sum of accounts + int yield = 1; // Loops before bank returns + int result = NDBT_OK; + + while (ctx->isTestStopped() == false) { + if (bank.performSumAccounts(wait, yield) != NDBT_OK){ + ndbout << "bank.performSumAccounts FAILED" << endl; + result = NDBT_FAILED; + } + } + return result ; +} + +int runDropBank(NDBT_Context* ctx, NDBT_Step* step){ + Bank bank(ctx->m_cluster_connection); + if (bank.dropBank() != NDBT_OK) + return NDBT_FAILED; + return NDBT_OK; +} + +int runBankController(NDBT_Context* ctx, NDBT_Step* step){ + Ndb* pNdb = GETNDB(step); + int loops = ctx->getNumLoops(); + int records = ctx->getNumRecords(); + int l = 0; + int result = NDBT_OK; + + while (l < loops && result != NDBT_FAILED){ + + if (pNdb->waitUntilReady() != 0){ + result = NDBT_FAILED; + continue; + } + + // Sleep for a while + NdbSleep_SecSleep(records); + + l++; + } + + if (pNdb->waitUntilReady() != 0){ + result = NDBT_FAILED; + } + + ctx->stopTest(); + + return result; +} + +NDBT_TESTSUITE(testBank); +TESTCASE("Bank", + "Run the bank\n"){ + INITIALIZER(runCreateBank); + STEP(runBankTimer); + STEP(runBankTransactions); + STEP(runBankGL); + // TODO STEP(runBankSum); + STEP(runBankController); + FINALIZER(runDropBank); + +} +NDBT_TESTSUITE_END(testBank); + +int main(int argc, const char** argv){ + ndb_init(); + // Tables should not be auto created + testBank.setCreateTable(false); + + return testBank.execute(argc, argv); +} + + |