mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / test / ndbapi / testSRBank.cpp
blobe7f6a6965602c47044929325a3aea718ee9aefff
1 /* Copyright (c) 2003, 2005-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 #include <NDBT.hpp>
17 #include <NDBT_Test.hpp>
18 #include <HugoTransactions.hpp>
19 #include <UtilTransactions.hpp>
20 #include <NdbBackup.hpp>
22 #include "bank/Bank.hpp"
23 #include <NdbMixRestarter.hpp>
25 bool disk = false;
27 #define CHECK(b) if (!(b)) { \
28 g_err << "ERR: "<< step->getName() \
29 << " failed on line " << __LINE__ << endl; \
30 result = NDBT_FAILED; \
31 continue; }
33 int runCreateBank(NDBT_Context* ctx, NDBT_Step* step){
34 Bank bank(ctx->m_cluster_connection);
35 int overWriteExisting = true;
36 if (bank.createAndLoadBank(overWriteExisting, disk, 10) != NDBT_OK)
37 return NDBT_FAILED;
38 return NDBT_OK;
41 /**
43 * SR 0 - normal
44 * SR 1 - shutdown in progress
45 * SR 2 - restart in progress
47 int
48 runBankTimer(NDBT_Context* ctx, NDBT_Step* step){
49 int wait = 5; // Max seconds between each "day"
50 int yield = 1; // Loops before bank returns
52 ctx->incProperty(NMR_SR_THREADS);
53 while (!ctx->isTestStopped())
55 Bank bank(ctx->m_cluster_connection);
56 while(!ctx->isTestStopped() &&
57 ctx->getProperty(NMR_SR) <= NdbMixRestarter::SR_STOPPING)
59 if(bank.performIncreaseTime(wait, yield) == NDBT_FAILED)
60 break;
63 ndbout_c("runBankTimer is stopped");
64 ctx->incProperty(NMR_SR_THREADS_STOPPED);
65 if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
66 break;
68 return NDBT_OK;
71 int runBankTransactions(NDBT_Context* ctx, NDBT_Step* step){
72 int wait = 0; // Max ms between each transaction
73 int yield = 1; // Loops before bank returns
75 ctx->incProperty(NMR_SR_THREADS);
76 while (!ctx->isTestStopped())
78 Bank bank(ctx->m_cluster_connection);
79 while(!ctx->isTestStopped() &&
80 ctx->getProperty(NMR_SR) <= NdbMixRestarter::SR_STOPPING)
81 if(bank.performTransactions(0, 1) == NDBT_FAILED)
82 break;
84 ndbout_c("runBankTransactions is stopped");
85 ctx->incProperty(NMR_SR_THREADS_STOPPED);
86 if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
87 break;
89 return NDBT_OK;
92 int runBankGL(NDBT_Context* ctx, NDBT_Step* step){
93 int yield = 1; // Loops before bank returns
94 int result = NDBT_OK;
96 ctx->incProperty(NMR_SR_THREADS);
97 while (ctx->isTestStopped() == false)
99 Bank bank(ctx->m_cluster_connection);
100 while(!ctx->isTestStopped() &&
101 ctx->getProperty(NMR_SR) <= NdbMixRestarter::SR_STOPPING)
102 if (bank.performMakeGLs(yield) != NDBT_OK)
104 if(ctx->getProperty(NMR_SR) != NdbMixRestarter::SR_RUNNING)
105 break;
106 ndbout << "bank.performMakeGLs FAILED" << endl;
107 abort();
108 return NDBT_FAILED;
111 ndbout_c("runBankGL is stopped");
112 ctx->incProperty(NMR_SR_THREADS_STOPPED);
113 if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
114 break;
116 return NDBT_OK;
119 int
120 runBankSrValidator(NDBT_Context* ctx, NDBT_Step* step)
123 ctx->incProperty(NMR_SR_VALIDATE_THREADS);
125 while(!ctx->isTestStopped())
127 if (ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_VALIDATING))
128 break;
130 int wait = 0;
131 int yield = 1;
132 Bank bank(ctx->m_cluster_connection);
133 if (bank.performSumAccounts(wait, yield) != 0)
135 ndbout << "bank.performSumAccounts FAILED" << endl;
136 abort();
137 return NDBT_FAILED;
140 if (bank.performValidateAllGLs() != 0)
142 ndbout << "bank.performValidateAllGLs FAILED" << endl;
143 abort();
144 return NDBT_FAILED;
147 ctx->incProperty(NMR_SR_VALIDATE_THREADS_DONE);
149 if (ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
150 break;
153 return NDBT_OK;
156 #if 0
157 int runBankSum(NDBT_Context* ctx, NDBT_Step* step){
158 Bank bank(ctx->m_cluster_connection);
159 int wait = 2000; // Max ms between each sum of accounts
160 int yield = 1; // Loops before bank returns
161 int result = NDBT_OK;
163 while (ctx->isTestStopped() == false)
165 if (bank.performSumAccounts(wait, yield) != NDBT_OK){
166 ndbout << "bank.performSumAccounts FAILED" << endl;
167 result = NDBT_FAILED;
170 return result ;
172 #endif
176 runMixRestart(NDBT_Context* ctx, NDBT_Step* step)
178 int result = NDBT_OK;
179 NdbMixRestarter res;
180 int runtime = ctx->getNumLoops();
181 int sleeptime = ctx->getNumRecords();
182 Uint32 mask = ctx->getProperty("Type", ~(Uint32)0);
183 res.setRestartTypeMask(mask);
185 if (res.runPeriod(ctx, step, runtime, sleeptime))
187 abort();
188 return NDBT_FAILED;
191 ctx->stopTest();
192 return NDBT_OK;
195 int
196 runDropBank(NDBT_Context* ctx, NDBT_Step* step){
197 Bank bank(ctx->m_cluster_connection);
198 if (bank.dropBank() != NDBT_OK)
199 return NDBT_FAILED;
200 return NDBT_OK;
204 NDBT_TESTSUITE(testSRBank);
205 TESTCASE("SR",
206 " Test that a consistent bank is restored after graceful shutdown\n"
207 "1. Create bank\n"
208 "2. Start bank and let it run\n"
209 "3. Restart ndb and verify consistency\n"
210 "4. Drop bank\n")
212 TC_PROPERTY("Type", NdbMixRestarter::RTM_SR);
213 INITIALIZER(runCreateBank);
214 STEP(runBankTimer);
215 STEP(runBankTransactions);
216 STEP(runBankTransactions);
217 STEP(runBankTransactions);
218 STEP(runBankTransactions);
219 STEP(runBankTransactions);
220 STEP(runBankTransactions);
221 STEP(runBankTransactions);
222 STEP(runBankTransactions);
223 STEP(runBankTransactions);
224 STEP(runBankTransactions);
225 STEP(runBankGL);
226 STEP(runBankSrValidator);
227 STEP(runMixRestart);
229 TESTCASE("NR",
230 " Test that a consistent bank is restored after graceful shutdown\n"
231 "1. Create bank\n"
232 "2. Start bank and let it run\n"
233 "3. Restart ndb and verify consistency\n"
234 "4. Drop bank\n")
236 TC_PROPERTY("Type", NdbMixRestarter::RTM_NR);
237 INITIALIZER(runCreateBank);
238 STEP(runBankTimer);
239 STEP(runBankTransactions);
240 STEP(runBankTransactions);
241 STEP(runBankTransactions);
242 STEP(runBankTransactions);
243 STEP(runBankTransactions);
244 STEP(runBankTransactions);
245 STEP(runBankTransactions);
246 STEP(runBankTransactions);
247 STEP(runBankTransactions);
248 STEP(runBankTransactions);
249 STEP(runBankGL);
250 STEP(runMixRestart);
251 FINALIZER(runDropBank);
253 TESTCASE("Mix",
254 " Test that a consistent bank is restored after graceful shutdown\n"
255 "1. Create bank\n"
256 "2. Start bank and let it run\n"
257 "3. Restart ndb and verify consistency\n"
258 "4. Drop bank\n")
260 TC_PROPERTY("Type", NdbMixRestarter::RTM_ALL);
261 INITIALIZER(runCreateBank);
262 STEP(runBankTimer);
263 STEP(runBankTransactions);
264 STEP(runBankTransactions);
265 STEP(runBankTransactions);
266 STEP(runBankTransactions);
267 STEP(runBankTransactions);
268 STEP(runBankTransactions);
269 STEP(runBankTransactions);
270 STEP(runBankTransactions);
271 STEP(runBankTransactions);
272 STEP(runBankTransactions);
273 STEP(runBankGL);
274 STEP(runMixRestart);
275 STEP(runBankSrValidator);
276 FINALIZER(runDropBank);
278 NDBT_TESTSUITE_END(testSRBank);
280 int
281 main(int argc, const char** argv){
282 ndb_init();
283 for (int i = 0; i<argc; i++)
285 if (strcmp(argv[i], "--disk") == 0)
287 argc--;
288 disk = true;
289 for (; i<argc; i++)
290 argv[i] = argv[i+1];
291 break;
294 return testSRBank.execute(argc, argv);
297 template class Vector<ndb_mgm_node_state*>;