1 /*
2 Copyright (C) 2003-2006, 2008 MySQL AB
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_Test.hpp"
27 #include "NDBT_ReturnCodes.h"
28 #include "HugoTransactions.hpp"
29 #include "HugoAsynchTransactions.hpp"
30 #include "UtilTransactions.hpp"
31
runLoadTable(NDBT_Context * ctx,NDBT_Step * step)32 int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
33
34 int records = ctx->getNumRecords();
35 int batchSize = ctx->getProperty("BatchSize", 1);
36 int transactions = (records / 100) + 1;
37 int operations = (records / transactions) + 1;
38
39 HugoAsynchTransactions hugoTrans(*ctx->getTab());
40 if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
41 transactions, operations) != 0){
42 return NDBT_FAILED;
43 }
44 return NDBT_OK;
45 }
46
runInsert(NDBT_Context * ctx,NDBT_Step * step)47 int runInsert(NDBT_Context* ctx, NDBT_Step* step){
48
49 int records = ctx->getNumRecords();
50 int batchSize = ctx->getProperty("BatchSize", 1);
51 int transactions = (records / 100) + 1;
52 int operations = (records / transactions) + 1;
53
54 HugoAsynchTransactions hugoTrans(*ctx->getTab());
55 // Insert records, dont allow any
56 // errors(except temporary) while inserting
57 if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
58 transactions, operations) != 0){
59 return NDBT_FAILED;
60 }
61 return NDBT_OK;
62 }
63
runVerifyInsert(NDBT_Context * ctx,NDBT_Step * step)64 int runVerifyInsert(NDBT_Context* ctx, NDBT_Step* step){
65 int records = ctx->getNumRecords();
66 int batchSize = ctx->getProperty("BatchSize", 1);
67 int transactions = (records / 100) + 1;
68 int operations = (records / transactions) + 1;
69
70 HugoAsynchTransactions hugoTrans(*ctx->getTab());
71 if (hugoTrans.pkDelRecordsAsynch(GETNDB(step), records, batchSize,
72 transactions, operations) != 0){
73 return NDBT_FAILED;
74 }
75 return NDBT_OK;
76 }
77
runClearTable(NDBT_Context * ctx,NDBT_Step * step)78 int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
79 int records = ctx->getNumRecords();
80 int batchSize = ctx->getProperty("BatchSize", 1);
81 int transactions = (records / 100) + 1;
82 int operations = (records / transactions) + 1;
83
84 HugoAsynchTransactions hugoTrans(*ctx->getTab());
85 if (hugoTrans.pkDelRecordsAsynch(GETNDB(step), records, batchSize,
86 transactions, operations) != 0){
87 return NDBT_FAILED;
88 }
89 return NDBT_OK;
90 }
91
runPkDelete(NDBT_Context * ctx,NDBT_Step * step)92 int runPkDelete(NDBT_Context* ctx, NDBT_Step* step){
93
94 int loops = ctx->getNumLoops();
95 int records = ctx->getNumRecords();
96 int batchSize = ctx->getProperty("BatchSize", 1);
97 int transactions = (records / 100) + 1;
98 int operations = (records / transactions) + 1;
99
100 int i = 0;
101 HugoAsynchTransactions hugoTrans(*ctx->getTab());
102 while (i<loops) {
103 ndbout << i << ": ";
104 if (hugoTrans.pkDelRecordsAsynch(GETNDB(step), records, batchSize,
105 transactions, operations) != 0){
106 return NDBT_FAILED;
107 }
108 // Load table, don't allow any primary key violations
109 if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
110 transactions, operations) != 0){
111 return NDBT_FAILED;
112 }
113 i++;
114 }
115 return NDBT_OK;
116 }
117
118
runPkRead(NDBT_Context * ctx,NDBT_Step * step)119 int runPkRead(NDBT_Context* ctx, NDBT_Step* step){
120 int loops = ctx->getNumLoops();
121 int records = ctx->getNumRecords();
122 int batchSize = ctx->getProperty("BatchSize", 1);
123 int transactions = (records / 100) + 1;
124 int operations = (records / transactions) + 1;
125
126 int i = 0;
127 HugoAsynchTransactions hugoTrans(*ctx->getTab());
128 while (i<loops) {
129 ndbout << i << ": ";
130 if (hugoTrans.pkReadRecordsAsynch(GETNDB(step), records, batchSize,
131 transactions, operations) != NDBT_OK){
132 return NDBT_FAILED;
133 }
134 i++;
135 }
136 return NDBT_OK;
137 }
138
runPkUpdate(NDBT_Context * ctx,NDBT_Step * step)139 int runPkUpdate(NDBT_Context* ctx, NDBT_Step* step){
140 int loops = ctx->getNumLoops();
141 int records = ctx->getNumRecords();
142 int batchSize = ctx->getProperty("BatchSize", 1);
143 int transactions = (records / 100) + 1;
144 int operations = (records / transactions) + 1;
145
146 int i = 0;
147 HugoAsynchTransactions hugoTrans(*ctx->getTab());
148 while (i<loops) {
149 ndbout << i << ": ";
150 if (hugoTrans.pkUpdateRecordsAsynch(GETNDB(step), records,
151 batchSize, transactions,
152 operations) != 0){
153 return NDBT_FAILED;
154 }
155 i++;
156 }
157 return NDBT_OK;
158 }
159
160 NDBT_TESTSUITE(testBasicAsynch);
161 TESTCASE("PkInsertAsynch",
162 "Verify that we can insert and delete from this table using PK"
163 " NOTE! No errors are allowed!" ){
164 INITIALIZER(runInsert);
165 VERIFIER(runVerifyInsert);
166 }
167 TESTCASE("PkReadAsynch",
168 "Verify that we can insert, read and delete from this table"
169 " using PK"){
170 INITIALIZER(runLoadTable);
171 STEP(runPkRead);
172 FINALIZER(runClearTable);
173 }
174 TESTCASE("PkUpdateAsynch",
175 "Verify that we can insert, update and delete from this table"
176 " using PK"){
177 INITIALIZER(runLoadTable);
178 STEP(runPkUpdate);
179 FINALIZER(runClearTable);
180 }
181 TESTCASE("PkDeleteAsynch",
182 "Verify that we can delete from this table using PK"){
183 INITIALIZER(runLoadTable);
184 STEP(runPkDelete);
185 FINALIZER(runClearTable);
186 }
187
188 NDBT_TESTSUITE_END(testBasicAsynch);
189
main(int argc,const char ** argv)190 int main(int argc, const char** argv){
191 ndb_init();
192 NDBT_TESTSUITE_INSTANCE(testBasicAsynch);
193 return testBasicAsynch.execute(argc, argv);
194 }
195
196