-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtestReconnect.cpp
More file actions
207 lines (172 loc) · 5.09 KB
/
Copy pathtestReconnect.cpp
File metadata and controls
207 lines (172 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <NDBT.hpp>
#include <NDBT_Test.hpp>
#include <DbUtil.hpp>
#include <AtrtClient.hpp>
#include <NdbRestarts.hpp>
int runCreateTable(NDBT_Context* ctx, NDBT_Step* step){
DbUtil sql("test");
if (!sql.doQuery("CREATE TABLE reconnect ("
"pk bigint, "
"thread int, "
"b varchar(32) NOT NULL, "
"PRIMARY KEY(pk, thread)"
") engine = NDB;"))
return NDBT_FAILED;
return NDBT_OK;
}
int runDropTable(NDBT_Context* ctx, NDBT_Step* step){
DbUtil sql("test");
if (!sql.doQuery("DROP TABLE IF EXISTS reconnect"))
return NDBT_FAILED;
return NDBT_OK;
}
int runSQLQueries(NDBT_Context* ctx, NDBT_Step* step,
const char* query)
{
int result = -1;
DbUtil sql("test");
unsigned failed = 0;
unsigned i = 0;
unsigned shutdown_counter= 0;
while (result == -1)
{
Properties args;
args.put("0", i);
if (!sql.doQuery(query, args))
{
switch(sql.last_errno()){
case 2006: // MySQL server has gone away(ie. crash)
g_err << "Fatal error: " << sql.last_error() << endl;
g_err.print("query: %s", query);
result = NDBT_FAILED;
break;
default:
// Ignore
failed++;
break;
}
}
else
g_info << query << endl;
sql.silent(); // Late, to catch any SQL syntax errors
i++;
if (ctx->isTestStopped())
{
// When the test is stopped we run additional queries
// that all should work
if (shutdown_counter == 0)
{
shutdown_counter = i;
}
else
{
unsigned extra_loops= i - shutdown_counter;
if (extra_loops < 10)
{
// Check that last query suceeded
if (sql.last_errno() != 0)
{
g_err << "Fatal error during shutdown queries: "
<< sql.last_error() << endl;
g_err.print("query: %s", query);
result = NDBT_FAILED;
}
}
else
{
// We are done, signal sucess
result= NDBT_OK;
}
}
}
}
ctx->stopTest();
g_info << i - failed << " queries completed and "
<< failed << " failed" << endl;
return result;
}
int runINSERT(NDBT_Context* ctx, NDBT_Step* step){
BaseString query;
query.assfmt("INSERT INTO reconnect "
"(pk, thread, b) VALUES (?, %d, 'data%d')",
step->getStepNo(), step->getStepNo());
return runSQLQueries(ctx, step, query.c_str());
}
int runSELECT(NDBT_Context* ctx, NDBT_Step* step){
return runSQLQueries(ctx, step, "SELECT * FROM reconnect");
}
int runDELETE(NDBT_Context* ctx, NDBT_Step* step){
BaseString query;
query.assfmt("DELETE from reconnect WHERE thread=%d LIMIT 10",
step->getStepNo());
return runSQLQueries(ctx, step, query.c_str());
}
int runRestartCluster(NDBT_Context* ctx, NDBT_Step* step){
int result = NDBT_OK;
int loops = ctx->getNumLoops();
NdbRestarts restarts;
int i = 0;
int timeout = 240;
while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
ndbout << "Loop " << i << "/"<< loops <<" started" << endl;
if(restarts.executeRestart(ctx, "RestartAllNodesAbort", timeout) != 0){
g_err << "Failed to restart all nodes with abort" << endl;
result = NDBT_FAILED;
break;
}
NdbSleep_SecSleep(10);
i++;
}
ctx->stopTest();
return result;
}
NDBT_TESTSUITE(testReconnect);
TESTCASE("InsertAndRestart",
"Run INSERTs while cluster restart"){
INITIALIZER(runDropTable);
INITIALIZER(runCreateTable);
STEP(runINSERT);
STEP(runRestartCluster);
}
TESTCASE("SelectAndRestart",
"Run SELECTs while cluster restart"){
INITIALIZER(runDropTable);
INITIALIZER(runCreateTable);
STEP(runSELECT);
STEP(runRestartCluster);
}
TESTCASE("DeleteAndRestart",
"Run DELETEs while cluster restart"){
INITIALIZER(runDropTable);
INITIALIZER(runCreateTable);
STEP(runDELETE);
STEP(runRestartCluster);
}
TESTCASE("AllAndRestart",
"Run all kind of statements while cluster restart"){
INITIALIZER(runDropTable);
INITIALIZER(runCreateTable);
STEPS(runSELECT, 5);
STEPS(runINSERT, 25);
STEPS(runDELETE, 2);
STEP(runRestartCluster);
}
NDBT_TESTSUITE_END(testReconnect);
int main(int argc, const char** argv){
ndb_init();
NDBT_TESTSUITE_INSTANCE(testReconnect);
return testReconnect.execute(argc, argv);
}