Skip to content

Commit 8fdc781

Browse files
author
mskold/marty@mysql.com/linux.site
committed
Fixed ndbapi-examples, and added tests for mysql-test-run.pl
1 parent 6bac3b8 commit 8fdc781

28 files changed

+1016
-80
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--require r/have_ndbapi_examples.require
2+
disable_query_log;
3+
eval select LENGTH("$MY_NDB_EXAMPLES_BINARY") > 0 as "have_ndb_example";
4+
enable_query_log;

mysql-test/mysql-test-run.pl

+24
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@
323323
our $exe_ndb_mgm;
324324
our $exe_ndb_waiter;
325325
our $path_ndb_tools_dir;
326+
our $path_ndb_examples_dir;
327+
our $exe_ndb_example;
326328
our $file_ndb_testrun_log;
327329

328330
our @data_dir_lst;
@@ -1233,6 +1235,9 @@ ()
12331235
mtr_script_exists("$glob_basedir/scripts/mysql_fix_privilege_tables",
12341236
"/usr/bin/false");
12351237
$path_ndb_tools_dir= mtr_path_exists("$glob_basedir/storage/ndb/tools");
1238+
$path_ndb_examples_dir= mtr_path_exists("$glob_basedir/storage/ndb/ndbapi-examples");
1239+
$exe_ndb_example= mtr_exe_exists("$path_ndb_examples_dir/ndbapi_simple/ndbapi_simple",
1240+
$exe_mysqld);
12361241
$exe_ndb_mgm= "$glob_basedir/storage/ndb/src/mgmclient/ndb_mgm";
12371242
$exe_ndb_waiter= "$glob_basedir/storage/ndb/tools/ndb_waiter";
12381243
$exe_ndbd= "$glob_basedir/storage/ndb/src/kernel/ndbd";
@@ -1297,6 +1302,7 @@ ()
12971302
}
12981303

12991304
$path_ndb_tools_dir= "$glob_basedir/bin";
1305+
$path_ndb_examples_dir= "$glob_basedir/ndbapi-examples";
13001306
$exe_ndb_mgm= "$glob_basedir/bin/ndb_mgm";
13011307
$exe_ndb_waiter= "$glob_basedir/bin/ndb_waiter";
13021308
$exe_ndbd= "$glob_basedir/bin/ndbd";
@@ -1344,6 +1350,20 @@ ()
13441350
($lib_udf_example ? dirname($lib_udf_example) : "") .
13451351
($ENV{'LD_LIBRARY_PATH'} ? ":$ENV{'LD_LIBRARY_PATH'}" : "");
13461352

1353+
# --------------------------------------------------------------------------
1354+
# Add the path where libndbclient can be found
1355+
# --------------------------------------------------------------------------
1356+
$ENV{'LD_LIBRARY_PATH'}=
1357+
(mtr_path_exists("$glob_basedir/storage/ndb/src/.libs") ? "$glob_basedir/storage/ndb/src/.libs" : "") .
1358+
($ENV{'LD_LIBRARY_PATH'} ? ":$ENV{'LD_LIBRARY_PATH'}" : "");
1359+
1360+
# --------------------------------------------------------------------------
1361+
# Add the path where libmysqlclient can be found
1362+
# --------------------------------------------------------------------------
1363+
$ENV{'LD_LIBRARY_PATH'}=
1364+
(mtr_path_exists("$glob_basedir/libmysql_r/.libs") ? "$glob_basedir/libmysql_r/.libs" : "") .
1365+
($ENV{'LD_LIBRARY_PATH'} ? ":$ENV{'LD_LIBRARY_PATH'}" : "");
1366+
13471367

13481368
# --------------------------------------------------------------------------
13491369
# Also command lines in .opt files may contain env vars
@@ -1360,6 +1380,7 @@ ()
13601380
$ENV{'MASTER_MYSOCK1'}= $master->[1]->{'path_sock'};
13611381
$ENV{'MASTER_MYPORT'}= $master->[0]->{'port'};
13621382
$ENV{'MASTER_MYPORT1'}= $master->[1]->{'port'};
1383+
$ENV{'SLAVE_MYSOCK'}= $slave->[0]->{'path_sock'};
13631384
$ENV{'SLAVE_MYPORT'}= $slave->[0]->{'port'};
13641385
$ENV{'SLAVE_MYPORT1'}= $slave->[1]->{'port'};
13651386
$ENV{'SLAVE_MYPORT2'}= $slave->[2]->{'port'};
@@ -3802,7 +3823,10 @@ ($)
38023823
$ENV{'NDB_BACKUP_DIR'}= $clusters->[0]->{'data_dir'};
38033824
$ENV{'NDB_DATA_DIR'}= $clusters->[0]->{'data_dir'};
38043825
$ENV{'NDB_TOOLS_DIR'}= $path_ndb_tools_dir;
3826+
$ENV{'NDB_EXAMPLES_DIR'}= $path_ndb_examples_dir;
3827+
$ENV{'MY_NDB_EXAMPLES_BINARY'}= ($exe_ndb_example eq "$path_ndb_examples_dir/ndbapi_simple/ndbapi_simple")?$exe_ndb_example:"";
38053828
$ENV{'NDB_TOOLS_OUTPUT'}= $file_ndb_testrun_log;
3829+
$ENV{'NDB_EXAMPLES_OUTPUT'}= $file_ndb_testrun_log;
38063830
$ENV{'NDB_CONNECTSTRING'}= $opt_ndbconnectstring;
38073831

38083832
my $exe= $exe_mysqltest;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
have_ndb_example
2+
1

mysql-test/r/ndbapi.result

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
DROP TABLE IF EXISTS t0;
2+
drop database if exists mysqltest;
3+
Running ndbapi_simple, results in /windows/Linux_space/MySQL/mysql-5.1/mysql-test/var/log/ndb_testrun.log
4+
Running ndbapi_simple_index, results in /windows/Linux_space/MySQL/mysql-5.1/mysql-test/var/log/ndb_testrun.log
5+
Running ndbapi_scan, results in /windows/Linux_space/MySQL/mysql-5.1/mysql-test/var/log/ndb_testrun.log
6+
Running ndbapi_retries, results in /windows/Linux_space/MySQL/mysql-5.1/mysql-test/var/log/ndb_testrun.log
7+
Running ndbapi_async, results in /windows/Linux_space/MySQL/mysql-5.1/mysql-test/var/log/ndb_testrun.log
8+
Running ndbapi_async1, results in /windows/Linux_space/MySQL/mysql-5.1/mysql-test/var/log/ndb_testrun.log
9+
use TEST_DB;
10+
create table t0(c0 int, c1 int, c2 char(4), c3 char(4), c4 text,
11+
primary key(c0, c2)) engine ndb charset latin1;
12+
insert into t0 values (1, 2, 'a', 'b', null);
13+
insert into t0 values (3, 4, 'c', 'd', null);
14+
update t0 set c3 = 'e' where c0 = 1 and c2 = 'a';
15+
update t0 set c3 = 'f';
16+
update t0 set c3 = 'F';
17+
update t0 set c2 = 'g' where c0 = 1;
18+
update t0 set c2 = 'G' where c0 = 1;
19+
update t0 set c0 = 5, c2 = 'H' where c0 = 3;
20+
delete from t0;
21+
drop table t0;
22+
Running mgmapi_logevent, results in /windows/Linux_space/MySQL/mysql-5.1/mysql-test/var/log/ndb_testrun.log

mysql-test/r/rpl_ndbapi_multi.result

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
stop slave;
2+
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
3+
reset master;
4+
reset slave;
5+
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
6+
start slave;
7+
Running mgmapi_logevent, results in /windows/Linux_space/MySQL/mysql-5.1/mysql-test/var/log/ndb_testrun.log

mysql-test/t/ndbapi.test

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- source include/have_ndb.inc
2+
-- source include/have_ndbapi_examples.inc
3+
4+
--disable_warnings
5+
DROP TABLE IF EXISTS t0;
6+
drop database if exists mysqltest;
7+
--enable_warnings
8+
9+
--exec echo Running ndbapi_simple, results in $NDB_EXAMPLES_OUTPUT
10+
--exec $NDB_EXAMPLES_DIR/ndbapi_simple/ndbapi_simple $MASTER_MYSOCK "localhost:$NDBCLUSTER_PORT" >> $NDB_EXAMPLES_OUTPUT
11+
12+
--exec echo Running ndbapi_simple_index, results in $NDB_EXAMPLES_OUTPUT
13+
--exec $NDB_EXAMPLES_DIR/ndbapi_simple_index/ndbapi_simple_index $MASTER_MYSOCK "localhost:$NDBCLUSTER_PORT" >> $NDB_EXAMPLES_OUTPUT
14+
15+
--exec echo Running ndbapi_scan, results in $NDB_EXAMPLES_OUTPUT
16+
--exec $NDB_EXAMPLES_DIR/ndbapi_scan/ndbapi_scan $MASTER_MYSOCK "localhost:$NDBCLUSTER_PORT" >> $NDB_EXAMPLES_OUTPUT
17+
18+
--exec echo Running ndbapi_retries, results in $NDB_EXAMPLES_OUTPUT
19+
--exec $NDB_EXAMPLES_DIR/ndbapi_retries/ndbapi_retries $MASTER_MYSOCK "localhost:$NDBCLUSTER_PORT" >> $NDB_EXAMPLES_OUTPUT
20+
21+
--exec echo Running ndbapi_async, results in $NDB_EXAMPLES_OUTPUT
22+
--exec $NDB_EXAMPLES_DIR/ndbapi_async/ndbapi_async $MASTER_MYSOCK "localhost:$NDBCLUSTER_PORT" >> $NDB_EXAMPLES_OUTPUT
23+
24+
--exec echo Running ndbapi_async1, results in $NDB_EXAMPLES_OUTPUT
25+
--exec $NDB_EXAMPLES_DIR/ndbapi_async1/ndbapi_async1 $MASTER_MYSOCK "localhost:$NDBCLUSTER_PORT" >> $NDB_EXAMPLES_OUTPUT
26+
27+
use TEST_DB;
28+
create table t0(c0 int, c1 int, c2 char(4), c3 char(4), c4 text,
29+
primary key(c0, c2)) engine ndb charset latin1;
30+
#--exec echo Running ndbapi_event, results in $NDB_EXAMPLES_OUTPUT
31+
#--exec $NDB_EXAMPLES_DIR/ndbapi_event/ndbapi_event "localhost:$NDBCLUSTER_PORT" 1 >> $NDB_EXAMPLES_OUTPUT
32+
insert into t0 values (1, 2, 'a', 'b', null);
33+
insert into t0 values (3, 4, 'c', 'd', null);
34+
update t0 set c3 = 'e' where c0 = 1 and c2 = 'a'; -- use pk
35+
update t0 set c3 = 'f'; -- use scan
36+
update t0 set c3 = 'F'; -- use scan update to 'same'
37+
update t0 set c2 = 'g' where c0 = 1; -- update pk part
38+
update t0 set c2 = 'G' where c0 = 1; -- update pk part to 'same'
39+
update t0 set c0 = 5, c2 = 'H' where c0 = 3; -- update full PK
40+
delete from t0;
41+
drop table t0;
42+
43+
--exec echo Running mgmapi_logevent, results in $NDB_EXAMPLES_OUTPUT
44+
--exec $NDB_EXAMPLES_DIR/mgmapi_logevent/mgmapi_logevent "localhost:$NDBCLUSTER_PORT" 1 >> $NDB_EXAMPLES_OUTPUT

mysql-test/t/rpl_ndbapi_multi.test

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- source include/have_ndb.inc
2+
-- source include/have_binlog_format_row.inc
3+
-- source include/master-slave.inc
4+
-- source include/have_ndbapi_examples.inc
5+
6+
--exec $NDB_EXAMPLES_DIR/ndbapi_simple_dual/ndbapi_simple_dual $MASTER_MYSOCK "localhost:$NDBCLUSTER_PORT" $SLAVE_MYSOCK "localhost:$NDBCLUSTER_PORT_SLAVE" >> $NDB_EXAMPLES_OUTPUT
7+
8+
--exec echo Running mgmapi_logevent, results in $NDB_EXAMPLES_OUTPUT
9+
--exec $NDB_EXAMPLES_DIR/mgmapi_logevent/mgmapi_logevent "localhost:$NDBCLUSTER_PORT" "localhost:$NDBCLUSTER_PORT_SLAVE" 1 >> $NDB_EXAMPLES_OUTPUT
10+

storage/ndb/ndbapi-examples/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ BIN_DIRS := ndbapi_simple \
55
ndbapi_simple_index \
66
ndbapi_event \
77
ndbapi_scan \
8-
mgmapi_logevent
8+
mgmapi_logevent \
9+
ndbapi_simple_dual \
10+
mgmapi_logevent_dual
911

1012
bins: $(patsubst %, _bins_%, $(BIN_DIRS))
1113

storage/ndb/ndbapi-examples/mgmapi_logevent/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ TOP_SRCDIR = ../../../..
1010
INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include
1111
LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \
1212
-L$(TOP_SRCDIR)/libmysql_r/.libs \
13+
-L$(TOP_SRCDIR)/zlib/.libs \
1314
-L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings
1415
SYS_LIB =
1516

storage/ndb/ndbapi-examples/mgmapi_logevent/mgmapi_logevent.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
exit(-1); \
4040
}
4141

42-
int main()
42+
int main(int argc, char** argv)
4343
{
4444
NdbMgmHandle h;
4545
NdbLogEventHandle le;
@@ -51,22 +51,36 @@ int main()
5151
0 };
5252
struct ndb_logevent event;
5353

54+
if (argc < 2)
55+
{
56+
printf("Arguments are <connect_string cluster> [<iterations>].\n");
57+
exit(-1);
58+
}
59+
const char *connectstring = argv[1];
60+
int iterations = -1;
61+
if (argc > 2)
62+
iterations = atoi(argv[2]);
5463
ndb_init();
55-
64+
5665
h= ndb_mgm_create_handle();
5766
if ( h == 0)
5867
{
5968
printf("Unable to create handle\n");
6069
exit(-1);
6170
}
71+
if (ndb_mgm_set_connectstring(h, connectstring) == -1)
72+
{
73+
printf("Unable to set connectstring\n");
74+
exit(-1);
75+
}
6276
if (ndb_mgm_connect(h,0,0,0)) MGMERROR(h);
6377

6478
le= ndb_mgm_create_logevent_handle(h, filter);
6579
if ( le == 0 ) MGMERROR(h);
6680

67-
while (1)
81+
while (iterations-- != 0)
6882
{
69-
int timeout= 5000;
83+
int timeout= 1000;
7084
int r= ndb_logevent_get_next(le,&event,timeout);
7185
if (r == 0)
7286
printf("No event within %d milliseconds\n", timeout);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
TARGET = mgmapi_logevent_dual
2+
SRCS = $(TARGET).cpp
3+
OBJS = $(TARGET).o
4+
CXX = g++
5+
CFLAGS = -c -Wall -fno-rtti -fno-exceptions
6+
CXXFLAGS =
7+
DEBUG =
8+
LFLAGS = -Wall
9+
TOP_SRCDIR = ../../../..
10+
INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include
11+
LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \
12+
-L$(TOP_SRCDIR)/libmysql_r/.libs \
13+
-L$(TOP_SRCDIR)/zlib/.libs \
14+
-L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings
15+
SYS_LIB =
16+
17+
$(TARGET): $(OBJS)
18+
$(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lmystrings -lz $(SYS_LIB) -o $(TARGET)
19+
20+
$(TARGET).o: $(SRCS)
21+
$(CXX) $(CFLAGS) -I$(TOP_SRCDIR)/include -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/mgmapi -I$(INCLUDE_DIR)/ndbapi $(SRCS)
22+
23+
clean:
24+
rm -f *.o $(TARGET)

0 commit comments

Comments
 (0)