mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / test / ndbapi / testBasicAsynch.cpp
blobd9114c9015102ff4803286d27fab9213a6c111fe
1 /* Copyright (c) 2003-2005 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_Test.hpp"
17 #include "NDBT_ReturnCodes.h"
18 #include "HugoTransactions.hpp"
19 #include "HugoAsynchTransactions.hpp"
20 #include "UtilTransactions.hpp"
22 #define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
24 int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
26 int records = ctx->getNumRecords();
27 int batchSize = ctx->getProperty("BatchSize", 1);
28 int transactions = (records / 100) + 1;
29 int operations = (records / transactions) + 1;
31 HugoAsynchTransactions hugoTrans(*ctx->getTab());
32 if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
33 transactions, operations) != 0){
34 return NDBT_FAILED;
36 return NDBT_OK;
39 int runInsert(NDBT_Context* ctx, NDBT_Step* step){
41 int records = ctx->getNumRecords();
42 int batchSize = ctx->getProperty("BatchSize", 1);
43 int transactions = (records / 100) + 1;
44 int operations = (records / transactions) + 1;
46 HugoAsynchTransactions hugoTrans(*ctx->getTab());
47 // Insert records, dont allow any
48 // errors(except temporary) while inserting
49 if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
50 transactions, operations) != 0){
51 return NDBT_FAILED;
53 return NDBT_OK;
56 int runVerifyInsert(NDBT_Context* ctx, NDBT_Step* step){
57 int records = ctx->getNumRecords();
58 int batchSize = ctx->getProperty("BatchSize", 1);
59 int transactions = (records / 100) + 1;
60 int operations = (records / transactions) + 1;
62 HugoAsynchTransactions hugoTrans(*ctx->getTab());
63 if (hugoTrans.pkDelRecordsAsynch(GETNDB(step), records, batchSize,
64 transactions, operations) != 0){
65 return NDBT_FAILED;
67 return NDBT_OK;
70 int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
71 int records = ctx->getNumRecords();
72 int batchSize = ctx->getProperty("BatchSize", 1);
73 int transactions = (records / 100) + 1;
74 int operations = (records / transactions) + 1;
76 HugoAsynchTransactions hugoTrans(*ctx->getTab());
77 if (hugoTrans.pkDelRecordsAsynch(GETNDB(step), records, batchSize,
78 transactions, operations) != 0){
79 return NDBT_FAILED;
81 return NDBT_OK;
84 int runPkDelete(NDBT_Context* ctx, NDBT_Step* step){
86 int loops = ctx->getNumLoops();
87 int records = ctx->getNumRecords();
88 int batchSize = ctx->getProperty("BatchSize", 1);
89 int transactions = (records / 100) + 1;
90 int operations = (records / transactions) + 1;
92 int i = 0;
93 HugoAsynchTransactions hugoTrans(*ctx->getTab());
94 while (i<loops) {
95 ndbout << i << ": ";
96 if (hugoTrans.pkDelRecordsAsynch(GETNDB(step), records, batchSize,
97 transactions, operations) != 0){
98 return NDBT_FAILED;
100 // Load table, don't allow any primary key violations
101 if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
102 transactions, operations) != 0){
103 return NDBT_FAILED;
105 i++;
107 return NDBT_OK;
111 int runPkRead(NDBT_Context* ctx, NDBT_Step* step){
112 int loops = ctx->getNumLoops();
113 int records = ctx->getNumRecords();
114 int batchSize = ctx->getProperty("BatchSize", 1);
115 int transactions = (records / 100) + 1;
116 int operations = (records / transactions) + 1;
118 int i = 0;
119 HugoAsynchTransactions hugoTrans(*ctx->getTab());
120 while (i<loops) {
121 ndbout << i << ": ";
122 if (hugoTrans.pkReadRecordsAsynch(GETNDB(step), records, batchSize,
123 transactions, operations) != NDBT_OK){
124 return NDBT_FAILED;
126 i++;
128 return NDBT_OK;
131 int runPkUpdate(NDBT_Context* ctx, NDBT_Step* step){
132 int loops = ctx->getNumLoops();
133 int records = ctx->getNumRecords();
134 int batchSize = ctx->getProperty("BatchSize", 1);
135 int transactions = (records / 100) + 1;
136 int operations = (records / transactions) + 1;
138 int i = 0;
139 HugoAsynchTransactions hugoTrans(*ctx->getTab());
140 while (i<loops) {
141 ndbout << i << ": ";
142 if (hugoTrans.pkUpdateRecordsAsynch(GETNDB(step), records,
143 batchSize, transactions,
144 operations) != 0){
145 return NDBT_FAILED;
147 i++;
149 return NDBT_OK;
152 NDBT_TESTSUITE(testBasicAsynch);
153 TESTCASE("PkInsertAsynch",
154 "Verify that we can insert and delete from this table using PK"
155 " NOTE! No errors are allowed!" ){
156 INITIALIZER(runInsert);
157 VERIFIER(runVerifyInsert);
159 TESTCASE("PkReadAsynch",
160 "Verify that we can insert, read and delete from this table"
161 " using PK"){
162 INITIALIZER(runLoadTable);
163 STEP(runPkRead);
164 FINALIZER(runClearTable);
166 TESTCASE("PkUpdateAsynch",
167 "Verify that we can insert, update and delete from this table"
168 " using PK"){
169 INITIALIZER(runLoadTable);
170 STEP(runPkUpdate);
171 FINALIZER(runClearTable);
173 TESTCASE("PkDeleteAsynch",
174 "Verify that we can delete from this table using PK"){
175 INITIALIZER(runLoadTable);
176 STEP(runPkDelete);
177 FINALIZER(runClearTable);
180 NDBT_TESTSUITE_END(testBasicAsynch);
182 int main(int argc, const char** argv){
183 ndb_init();
184 return testBasicAsynch.execute(argc, argv);