1 /* Copyright (c) 2003-2005 MySQL AB
2    Use is subject to license terms
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; version 2 of the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */
16 
17 #include "NDBT_Test.hpp"
18 #include "NDBT_ReturnCodes.h"
19 #include "HugoTransactions.hpp"
20 #include "HugoAsynchTransactions.hpp"
21 #include "UtilTransactions.hpp"
22 
23 #define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
24 
runLoadTable(NDBT_Context * ctx,NDBT_Step * step)25 int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
26 
27   int records = ctx->getNumRecords();
28   int batchSize = ctx->getProperty("BatchSize", 1);
29   int transactions = (records / 100) + 1;
30   int operations = (records / transactions) + 1;
31 
32   HugoAsynchTransactions hugoTrans(*ctx->getTab());
33   if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
34 				transactions, operations) != 0){
35     return NDBT_FAILED;
36   }
37   return NDBT_OK;
38 }
39 
runInsert(NDBT_Context * ctx,NDBT_Step * step)40 int runInsert(NDBT_Context* ctx, NDBT_Step* step){
41 
42   int records = ctx->getNumRecords();
43   int batchSize = ctx->getProperty("BatchSize", 1);
44   int transactions = (records / 100) + 1;
45   int operations = (records / transactions) + 1;
46 
47   HugoAsynchTransactions hugoTrans(*ctx->getTab());
48   // Insert records, dont allow any
49   // errors(except temporary) while inserting
50   if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
51 				transactions, operations) != 0){
52     return NDBT_FAILED;
53   }
54   return NDBT_OK;
55 }
56 
runVerifyInsert(NDBT_Context * ctx,NDBT_Step * step)57 int runVerifyInsert(NDBT_Context* ctx, NDBT_Step* step){
58   int records = ctx->getNumRecords();
59   int batchSize = ctx->getProperty("BatchSize", 1);
60   int transactions = (records / 100) + 1;
61   int operations = (records / transactions) + 1;
62 
63   HugoAsynchTransactions hugoTrans(*ctx->getTab());
64   if (hugoTrans.pkDelRecordsAsynch(GETNDB(step),  records, batchSize,
65 				   transactions, operations) != 0){
66     return NDBT_FAILED;
67   }
68   return NDBT_OK;
69 }
70 
runClearTable(NDBT_Context * ctx,NDBT_Step * step)71 int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
72   int records = ctx->getNumRecords();
73   int batchSize = ctx->getProperty("BatchSize", 1);
74   int transactions = (records / 100) + 1;
75   int operations = (records / transactions) + 1;
76 
77   HugoAsynchTransactions hugoTrans(*ctx->getTab());
78   if (hugoTrans.pkDelRecordsAsynch(GETNDB(step),  records, batchSize,
79 				   transactions, operations) != 0){
80     return NDBT_FAILED;
81   }
82   return NDBT_OK;
83 }
84 
runPkDelete(NDBT_Context * ctx,NDBT_Step * step)85 int runPkDelete(NDBT_Context* ctx, NDBT_Step* step){
86 
87   int loops = ctx->getNumLoops();
88   int records = ctx->getNumRecords();
89   int batchSize = ctx->getProperty("BatchSize", 1);
90   int transactions = (records / 100) + 1;
91   int operations = (records / transactions) + 1;
92 
93   int i = 0;
94   HugoAsynchTransactions hugoTrans(*ctx->getTab());
95   while (i<loops) {
96     ndbout << i << ": ";
97     if (hugoTrans.pkDelRecordsAsynch(GETNDB(step),  records, batchSize,
98 				     transactions, operations) != 0){
99       return NDBT_FAILED;
100     }
101     // Load table, don't allow any primary key violations
102     if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
103 				  transactions, operations) != 0){
104       return NDBT_FAILED;
105     }
106     i++;
107   }
108   return NDBT_OK;
109 }
110 
111 
runPkRead(NDBT_Context * ctx,NDBT_Step * step)112 int runPkRead(NDBT_Context* ctx, NDBT_Step* step){
113   int loops = ctx->getNumLoops();
114   int records = ctx->getNumRecords();
115   int batchSize = ctx->getProperty("BatchSize", 1);
116   int transactions = (records / 100) + 1;
117   int operations = (records / transactions) + 1;
118 
119   int i = 0;
120   HugoAsynchTransactions hugoTrans(*ctx->getTab());
121   while (i<loops) {
122     ndbout << i << ": ";
123     if (hugoTrans.pkReadRecordsAsynch(GETNDB(step), records, batchSize,
124 				      transactions, operations) != NDBT_OK){
125       return NDBT_FAILED;
126     }
127     i++;
128   }
129   return NDBT_OK;
130 }
131 
runPkUpdate(NDBT_Context * ctx,NDBT_Step * step)132 int runPkUpdate(NDBT_Context* ctx, NDBT_Step* step){
133   int loops = ctx->getNumLoops();
134   int records = ctx->getNumRecords();
135   int batchSize = ctx->getProperty("BatchSize", 1);
136   int transactions = (records / 100) + 1;
137   int operations = (records / transactions) + 1;
138 
139   int i = 0;
140   HugoAsynchTransactions hugoTrans(*ctx->getTab());
141   while (i<loops) {
142     ndbout << i << ": ";
143     if (hugoTrans.pkUpdateRecordsAsynch(GETNDB(step), records,
144 					batchSize, transactions,
145 					operations) != 0){
146       return NDBT_FAILED;
147     }
148     i++;
149   }
150   return NDBT_OK;
151 }
152 
153 NDBT_TESTSUITE(testBasicAsynch);
154 TESTCASE("PkInsertAsynch",
155 	 "Verify that we can insert and delete from this table using PK"
156 	 " NOTE! No errors are allowed!" ){
157   INITIALIZER(runInsert);
158   VERIFIER(runVerifyInsert);
159 }
160 TESTCASE("PkReadAsynch",
161 	 "Verify that we can insert, read and delete from this table"
162 	 " using PK"){
163   INITIALIZER(runLoadTable);
164   STEP(runPkRead);
165   FINALIZER(runClearTable);
166 }
167 TESTCASE("PkUpdateAsynch",
168 	 "Verify that we can insert, update and delete from this table"
169 	 " using PK"){
170   INITIALIZER(runLoadTable);
171   STEP(runPkUpdate);
172   FINALIZER(runClearTable);
173 }
174 TESTCASE("PkDeleteAsynch",
175 	 "Verify that we can delete from this table using PK"){
176   INITIALIZER(runLoadTable);
177   STEP(runPkDelete);
178   FINALIZER(runClearTable);
179 }
180 
181 NDBT_TESTSUITE_END(testBasicAsynch);
182 
main(int argc,const char ** argv)183 int main(int argc, const char** argv){
184   ndb_init();
185   return testBasicAsynch.execute(argc, argv);
186 }
187 
188