mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / test / ndbapi / bank / Bank.hpp
blob68336899179b47e61a7f614e89e436f29c00690d
1 /* Copyright (c) 2003-2007 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #ifndef BANK_HPP
17 #define BANK_HPP
19 #include <NdbOut.hpp>
20 #include <NdbApi.hpp>
21 #include <NDBT.hpp>
22 #include <NdbTick.h>
23 #include <random.h>
26 class Bank {
27 public:
29 Bank(Ndb_cluster_connection&, bool init = true, const char *dbase="BANK");
31 void setSkipCreate(bool skip) { m_skip_create = skip; }
32 int createAndLoadBank(bool overWrite, bool disk= false, int num_accounts=10);
33 int dropBank();
35 int performTransactions(int maxSleepBetweenTrans = 20, int yield=0);
36 int performMakeGLs(int yield=0);
37 int performValidateAllGLs();
38 int performSumAccounts(int maxSleepBetweenSums = 2000, int yield=0);
39 int performIncreaseTime(int maxSleepBetweenDays = 30, int yield=0);
40 private:
42 int init();
44 enum TransactionTypes{
45 WithDrawal = 2000,
46 Deposit = 3000
49 static const int NOT_ENOUGH_FUNDS = 1000;
50 static const int VERIFICATION_FAILED = 1001;
52 int performTransaction();
53 int performTransaction(int fromAccountId,
54 int toAccountId,
55 int amount );
56 int performTransactionImpl1(int fromAccountId,
57 int toAccountId,
58 int amount );
60 int performValidateGLs(Uint64 age = 20);
61 int performValidateGL(Uint64 GLTime);
62 int performValidatePurged();
64 int performMakeGL(int time);
65 int performMakeGLForAccountType(NdbConnection* pTrans,
66 Uint64 time,
67 Uint32 accountTypeId);
68 int sumTransactionsForGL(const Uint64 time,
69 const Uint32 accountType,
70 Uint32& balance,
71 Uint32& withdrawalCount,
72 Uint32& withdrawalSum,
73 Uint32& depositSum,
74 Uint32& depositCount,
75 Uint32& transactionsCount,
76 NdbConnection* pTrans);
77 int getBalanceForAccountType(const Uint32 accountType,
78 Uint32& balance);
79 int getBalanceForGL(const Uint64 glTime,
80 const Uint32 accountType,
81 Uint32 &balance);
83 int checkNoTransactionsOlderThan(const Uint32 accountType,
84 const Uint64 oldest);
85 int getOldestPurgedGL(const Uint32 accountType,
86 Uint64 &oldest);
87 int getOldestNotPurgedGL(Uint64 &oldest,
88 Uint32 &accountTypeId,
89 bool &found);
90 int findLastGL(Uint64 &lastTime);
91 int purgeOldGLTransactions(Uint64 currTime, Uint32 age);
93 int purgeTransactions(const Uint64 glTime,
94 const Uint32 accountTypeId);
95 int findTransactionsToPurge(const Uint64 glTime,
96 const Uint32 accountType,
97 NdbConnection* pTrans);
100 int getSumAccounts(Uint32 &sumAccounts,
101 Uint32 &numAccounts);
102 int getNumAccounts();
103 int getNumAccountTypes();
104 int getMaxAmount();
107 enum SystemValueId {
108 LastTransactionId = 0,
109 CurrentTime = 1
113 int readSystemValue(SystemValueId sysValId, Uint64 & value);
114 int increaseSystemValue(SystemValueId sysValId, Uint64 &value);
115 int increaseSystemValue2(SystemValueId sysValId, Uint64 &value);
116 int writeSystemValue(SystemValueId sysValId, Uint64 value);
117 int getNextTransactionId(Uint64 &value);
118 int incCurrTime(Uint64 &value);
119 int getCurrTime(Uint64 &time);
121 int prepareReadSystemValueOp(NdbConnection*, SystemValueId sysValId, Uint64 &time);
122 int prepareGetCurrTimeOp(NdbConnection*, Uint64 &time);
124 int createTables(bool disk);
125 int createTable(const char* tabName, bool disk);
127 int dropTables();
128 int dropTable(const char* tabName);
130 int clearTables();
131 int clearTable(const char* tabName);
133 int loadGl();
134 int loadAccountType();
135 int loadAccount (int numAccounts);
136 int loadSystemValues();
138 private:
140 Ndb m_ndb;
141 int m_maxAccount;
142 bool m_initialized;
143 bool m_skip_create;
146 #endif