19 #include <NDBT_Test.hpp>
21 #include <AtrtClient.hpp>
23 #include <NdbRestarts.hpp>
29 if (!sql.doQuery(
"CREATE TABLE reconnect ("
32 "b varchar(32) NOT NULL, "
33 "PRIMARY KEY(pk, thread)"
42 if (!sql.doQuery(
"DROP TABLE IF EXISTS reconnect"))
56 unsigned shutdown_counter= 0;
61 if (!sql.doQuery(query, args))
63 switch(sql.last_errno()){
65 g_err <<
"Fatal error: " << sql.last_error() << endl;
66 g_err.print(
"query: %s", query);
76 g_info << query << endl;
80 if (ctx->isTestStopped())
85 if (shutdown_counter == 0)
91 unsigned extra_loops= i - shutdown_counter;
96 if (sql.last_errno() != 0)
98 g_err <<
"Fatal error during shutdown queries: "
99 << sql.last_error() << endl;
100 g_err.print(
"query: %s", query);
101 result = NDBT_FAILED;
114 g_info << i - failed <<
" queries completed and "
115 << failed <<
" failed" << endl;
122 query.
assfmt(
"INSERT INTO reconnect "
123 "(pk, thread, b) VALUES (?, %d, 'data%d')",
124 step->getStepNo(), step->getStepNo());
125 return runSQLQueries(ctx, step, query.
c_str());
131 return runSQLQueries(ctx, step,
"SELECT * FROM reconnect");
137 query.
assfmt(
"DELETE from reconnect WHERE thread=%d LIMIT 10",
139 return runSQLQueries(ctx, step, query.
c_str());
144 int result = NDBT_OK;
145 int loops = ctx->getNumLoops();
150 while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
152 ndbout <<
"Loop " << i <<
"/"<< loops <<
" started" << endl;
154 if(restarts.executeRestart(ctx,
"RestartAllNodesAbort", timeout) != 0){
155 g_err <<
"Failed to restart all nodes with abort" << endl;
156 result = NDBT_FAILED;
160 NdbSleep_SecSleep(10);
168 NDBT_TESTSUITE(testReconnect);
169 TESTCASE(
"InsertAndRestart",
170 "Run INSERTs while cluster restart"){
171 INITIALIZER(runDropTable);
172 INITIALIZER(runCreateTable);
174 STEP(runRestartCluster);
176 TESTCASE(
"SelectAndRestart",
177 "Run SELECTs while cluster restart"){
178 INITIALIZER(runDropTable);
179 INITIALIZER(runCreateTable);
181 STEP(runRestartCluster);
183 TESTCASE(
"DeleteAndRestart",
184 "Run DELETEs while cluster restart"){
185 INITIALIZER(runDropTable);
186 INITIALIZER(runCreateTable);
188 STEP(runRestartCluster);
190 TESTCASE(
"AllAndRestart",
191 "Run all kind of statements while cluster restart"){
192 INITIALIZER(runDropTable);
193 INITIALIZER(runCreateTable);
195 STEPS(runINSERT, 25);
197 STEP(runRestartCluster);
200 NDBT_TESTSUITE_END(testReconnect);
202 int main(
int argc,
const char** argv){
204 NDBT_TESTSUITE_INSTANCE(testReconnect);
205 return testReconnect.execute(argc, argv);