1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include <ndb_global.h>
24
static int _loop = 25;
25
static int _sleep = 25;
30
static struct my_option my_long_options[] =
32
NDB_STD_OPTS("ndb_desc"),
33
{ "loop", 'l', "loops",
34
(gptr*) &_loop, (gptr*) &_loop, 0,
35
GET_INT, REQUIRED_ARG, _loop, 0, 0, 0, 0, 0 },
36
{ "sleep", 's', "Sleep (ms) between connection attempt",
37
(gptr*) &_sleep, (gptr*) &_sleep, 0,
38
GET_INT, REQUIRED_ARG, _sleep, 0, 0, 0, 0, 0 },
40
"Drop event operations before disconnect (0 = no, 1 = yes, else rand",
41
(gptr*) &_drop, (gptr*) &_drop, 0,
42
GET_INT, REQUIRED_ARG, _drop, 0, 0, 0, 0, 0 },
43
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
48
char desc[] = "This program connects to ndbd, and then disconnects\n";
49
ndb_std_print_version();
50
my_print_help(my_long_options);
51
my_print_variables(my_long_options);
54
int main(int argc, char** argv){
57
const char *load_default_groups[]= { "mysql_cluster",0 };
58
load_defaults("my",load_default_groups,&argc,&argv);
61
opt_debug= "d:t:O,/tmp/ndb_desc.trace";
63
if ((ho_error=handle_options(&argc, &argv, my_long_options,
64
ndb_std_get_one_option)))
65
return NDBT_ProgramExit(NDBT_WRONGARGS);
67
for (int i = 0; i<_loop; i++)
69
Ndb_cluster_connection con(opt_connect_str);
70
if(con.connect(12, 5, 1) != 0)
72
ndbout << "Unable to connect to management server." << endl;
73
return NDBT_ProgramExit(NDBT_FAILED);
75
if (con.wait_until_ready(30,30) != 0)
77
ndbout << "Cluster nodes not ready in 30 seconds." << endl;
78
return NDBT_ProgramExit(NDBT_FAILED);
81
Ndb MyNdb(&con, "TEST_DB");
82
if(MyNdb.init() != 0){
83
ERR(MyNdb.getNdbError());
84
return NDBT_ProgramExit(NDBT_FAILED);
87
Vector<NdbEventOperation*> ops;
88
const NdbDictionary::Dictionary * dict= MyNdb.getDictionary();
89
for (int j = 0; j < argc; j++)
91
const NdbDictionary::Table * pTab = dict->getTable(argv[j]);
94
ndbout_c("Failed to retreive table: \"%s\"", argv[j]);
98
tmp.appfmt("EV-%s", argv[j]);
99
NdbEventOperation* pOp = MyNdb.createEventOperation(tmp.c_str());
102
ndbout << "Event operation creation failed: " <<
103
MyNdb.getNdbError() << endl;
104
return NDBT_ProgramExit(NDBT_FAILED);
107
for (int a = 0; a < pTab->getNoOfColumns(); a++)
109
pOp->getValue(pTab->getColumn(a)->getName());
110
pOp->getPreValue(pTab->getColumn(a)->getName());
115
ndbout << "operation execution failed: " << pOp->getNdbError()
117
return NDBT_ProgramExit(NDBT_FAILED);
124
NdbSleep_MilliSleep(10 + rand() % _sleep);
127
for (Uint32 i = 0; i<ops.size(); i++)
134
if (MyNdb.dropEventOperation(ops[i]))
136
ndbout << "drop event operation failed "
137
<< MyNdb.getNdbError() << endl;
138
return NDBT_ProgramExit(NDBT_FAILED);
142
if ((rand() % 100) > 50)
148
return NDBT_ProgramExit(NDBT_OK);
151
template class Vector<NdbEventOperation*>;