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