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