18 #include <ndb_global.h>
24 static int _loop = 25;
25 static int _sleep = 25;
27 static int _subloop = 5;
28 static int _wait_all = 0;
32 static struct my_option my_long_options[] =
34 NDB_STD_OPTS(
"ndb_desc"),
35 {
"loop",
'l',
"loops",
36 (gptr*) &_loop, (gptr*) &_loop, 0,
37 GET_INT, REQUIRED_ARG, _loop, 0, 0, 0, 0, 0 },
38 {
"sleep",
's',
"Sleep (ms) between connection attempt",
39 (gptr*) &_sleep, (gptr*) &_sleep, 0,
40 GET_INT, REQUIRED_ARG, _sleep, 0, 0, 0, 0, 0 },
42 "Drop event operations before disconnect (0 = no, 1 = yes, else rand",
43 (gptr*) &_drop, (gptr*) &_drop, 0,
44 GET_INT, REQUIRED_ARG, _drop, 0, 0, 0, 0, 0 },
45 {
"subscribe-loop", NDB_OPT_NOSHORT,
46 "Loop in subscribe/unsubscribe",
47 (uchar**) &_subloop, (uchar**) &_subloop, 0,
48 GET_INT, REQUIRED_ARG, _subloop, 0, 0, 0, 0, 0 },
49 {
"wait-all", NDB_OPT_NOSHORT,
50 "Wait for all ndb-nodes (i.e not only some)",
51 (uchar**) &_wait_all, (uchar**) &_wait_all, 0,
52 GET_INT, REQUIRED_ARG, _wait_all, 0, 0, 0, 0, 0 },
53 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
56 int main(
int argc,
char** argv){
59 const char *load_default_groups[]= {
"mysql_cluster",0 };
60 load_defaults(
"my",load_default_groups,&argc,&argv);
63 opt_debug=
"d:t:O,/tmp/ndb_desc.trace";
65 if ((ho_error=handle_options(&argc, &argv, my_long_options,
66 ndb_std_get_one_option)))
67 return NDBT_ProgramExit(NDBT_WRONGARGS);
69 for (
int i = 0;
i<_loop;
i++)
74 ndbout <<
"Unable to connect to management server." << endl;
75 return NDBT_ProgramExit(NDBT_FAILED);
79 if (res < 0 || (_wait_all && res != 0))
81 ndbout <<
"Cluster nodes not ready in 30 seconds." << endl;
82 return NDBT_ProgramExit(NDBT_FAILED);
85 Ndb MyNdb(&con,
"TEST_DB");
86 if(MyNdb.init() != 0){
87 ERR(MyNdb.getNdbError());
88 return NDBT_ProgramExit(NDBT_FAILED);
91 for (
int k = _subloop; k >= 1; k--)
93 if (k > 1 && ((k % 25) == 0))
95 ndbout_c(
"subscribe/unsubscribe: %u", _subloop - k);
99 for (
int j = 0; j < argc; j++)
104 ndbout_c(
"Failed to retreive table: \"%s\"", argv[j]);
108 tmp.
appfmt(
"EV-%s", argv[j]);
112 ndbout <<
"Event operation creation failed: " <<
113 MyNdb.getNdbError() << endl;
114 return NDBT_ProgramExit(NDBT_FAILED);
126 ndbout <<
"operation execution failed: " << pOp->
getNdbError()
134 NdbSleep_MilliSleep(10 + rand() % _sleep);
138 ndbout_c(
"NDBT_ProgramExit: SLEEPING OK");
139 while(
true) NdbSleep_SecSleep(5);
142 for (Uint32
i = 0;
i<ops.size();
i++)
144 switch(k == 1 ? _drop : 1){
149 if (MyNdb.dropEventOperation(ops[
i]))
151 ndbout <<
"drop event operation failed "
152 << MyNdb.getNdbError() << endl;
153 return NDBT_ProgramExit(NDBT_FAILED);
157 if ((rand() % 100) > 50)
164 return NDBT_ProgramExit(NDBT_OK);