MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
testBasicAsynch.cpp
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 as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "NDBT_Test.hpp"
20 #include "NDBT_ReturnCodes.h"
21 #include "HugoTransactions.hpp"
22 #include "HugoAsynchTransactions.hpp"
23 #include "UtilTransactions.hpp"
24 
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 
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 
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 
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 
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 
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 
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 
183 int main(int argc, const char** argv){
184  ndb_init();
185  NDBT_TESTSUITE_INSTANCE(testBasicAsynch);
186  return testBasicAsynch.execute(argc, argv);
187 }
188