MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
testBank.cpp
1 /*
2  Copyright (C) 2003-2006, 2008 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <NDBT.hpp>
20 #include <NDBT_Test.hpp>
21 #include <HugoTransactions.hpp>
22 #include <UtilTransactions.hpp>
23 #include <NdbRestarter.hpp>
24 #include <NdbBackup.hpp>
25 
26 
27 #define CHECK(b) if (!(b)) { \
28  g_err << "ERR: "<< step->getName() \
29  << " failed on line " << __LINE__ << endl; \
30  result = NDBT_FAILED; \
31  continue; }
32 
33 
34 #include "Bank.hpp"
35 
36 const char* _database = "BANK";
37 
38 int runCreateBank(NDBT_Context* ctx, NDBT_Step* step){
39  Bank bank(ctx->m_cluster_connection, _database);
40  int overWriteExisting = true;
41  if (bank.createAndLoadBank(overWriteExisting) != NDBT_OK)
42  return NDBT_FAILED;
43  return NDBT_OK;
44 }
45 
46 int runBankTimer(NDBT_Context* ctx, NDBT_Step* step){
47  Bank bank(ctx->m_cluster_connection, _database);
48  int wait = 30; // Max seconds between each "day"
49  int yield = 1; // Loops before bank returns
50 
51  while (ctx->isTestStopped() == false) {
52  bank.performIncreaseTime(wait, yield);
53  }
54  return NDBT_OK;
55 }
56 
57 int runBankTransactions(NDBT_Context* ctx, NDBT_Step* step){
58  Bank bank(ctx->m_cluster_connection, _database);
59  int wait = 10; // Max ms between each transaction
60  int yield = 100; // Loops before bank returns
61 
62  while (ctx->isTestStopped() == false) {
63  bank.performTransactions(wait, yield);
64  }
65  return NDBT_OK;
66 }
67 
68 int runBankGL(NDBT_Context* ctx, NDBT_Step* step){
69  Bank bank(ctx->m_cluster_connection, _database);
70  int yield = 20; // Loops before bank returns
71  int result = NDBT_OK;
72 
73  while (ctx->isTestStopped() == false) {
74  if (bank.performMakeGLs(yield) != NDBT_OK){
75  ndbout << "bank.performMakeGLs FAILED" << endl;
76  result = NDBT_FAILED;
77  }
78  }
79  return NDBT_OK;
80 }
81 
82 int runBankSum(NDBT_Context* ctx, NDBT_Step* step){
83  Bank bank(ctx->m_cluster_connection, _database);
84  int wait = 2000; // Max ms between each sum of accounts
85  int yield = 1; // Loops before bank returns
86  int result = NDBT_OK;
87 
88  while (ctx->isTestStopped() == false) {
89  if (bank.performSumAccounts(wait, yield) != NDBT_OK){
90  ndbout << "bank.performSumAccounts FAILED" << endl;
91  result = NDBT_FAILED;
92  }
93  }
94  return result ;
95 }
96 
97 int runDropBank(NDBT_Context* ctx, NDBT_Step* step){
98  Bank bank(ctx->m_cluster_connection, _database);
99  if (bank.dropBank() != NDBT_OK)
100  return NDBT_FAILED;
101  return NDBT_OK;
102 }
103 
104 int runBankController(NDBT_Context* ctx, NDBT_Step* step){
105  Ndb* pNdb = GETNDB(step);
106  int loops = ctx->getNumLoops();
107  int records = ctx->getNumRecords();
108  int l = 0;
109  int result = NDBT_OK;
110 
111  while (l < loops && result != NDBT_FAILED){
112 
113  if (pNdb->waitUntilReady() != 0){
114  result = NDBT_FAILED;
115  continue;
116  }
117 
118  // Sleep for a while
119  NdbSleep_SecSleep(records);
120 
121  l++;
122  }
123 
124  if (pNdb->waitUntilReady() != 0){
125  result = NDBT_FAILED;
126  }
127 
128  ctx->stopTest();
129 
130  return result;
131 }
132 
133 NDBT_TESTSUITE(testBank);
134 TESTCASE("Bank",
135  "Run the bank\n"){
136  INITIALIZER(runCreateBank);
137  STEP(runBankTimer);
138  STEP(runBankTransactions);
139  STEP(runBankGL);
140  // TODO STEP(runBankSum);
141  STEP(runBankController);
142  FINALIZER(runDropBank);
143 
144 }
145 NDBT_TESTSUITE_END(testBank);
146 
147 int main(int argc, const char** argv){
148  ndb_init();
149  // Tables should not be auto created
150  NDBT_TESTSUITE_INSTANCE(testBank);
151  testBank.setCreateTable(false);
152 
153  return testBank.execute(argc, argv);
154 }
155 
156