2004-04-14 10:53:21 +02:00
|
|
|
/* 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; }
|
|
|
|
|
|
|
|
|
2004-05-26 15:36:55 +00:00
|
|
|
#include "Bank.hpp"
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
int runCreateBank(NDBT_Context* ctx, NDBT_Step* step){
|
|
|
|
Bank bank;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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){
|
2004-09-15 11:49:18 +02:00
|
|
|
ndb_init();
|
2004-04-14 10:53:21 +02:00
|
|
|
// Tables should not be auto created
|
|
|
|
testBank.setCreateTable(false);
|
|
|
|
|
|
|
|
return testBank.execute(argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|