48
void binlog_error(drizzle_return_t ret, void *context)
51
ASSERT_EQ_(DRIZZLE_RETURN_EOF, ret, "%s(%s)", drizzle_error(con), drizzle_strerror(ret));
54
void binlog_event(drizzle_binlog_event_st *event, void *context)
58
timestamp= drizzle_binlog_event_timestamp(event);
59
/* Test to see if timestamp is greater than 2012-01-01 00:00:00, corrupted
60
* timestamps will have weird values that shoud fail this after several
61
* events. Also rotate event doesn't have a timestamp so need to add 0
63
ASSERT_FALSE_(((timestamp < 1325376000) && (timestamp != 0)), "Bad timestamp retrieved: %u", timestamp);
65
/* An event higher than the max known is bad, either we don't know about
66
* new events or type is corrupted */
67
ASSERT_FALSE_((drizzle_binlog_event_type(event) >= DRIZZLE_EVENT_TYPE_END), "Bad event type: %d", drizzle_binlog_event_type(event));
48
70
int main(int argc, char *argv[])
74
drizzle_binlog_st *binlog;
53
76
con= drizzle_create_tcp(getenv("MYSQL_SERVER"),
54
77
getenv("MYSQL_PORT") ? atoi("MYSQL_PORT") : DRIZZLE_DEFAULT_TCP_PORT,
62
85
drizzle_return_t ret= drizzle_connect(con);
63
86
SKIP_IF_(ret == DRIZZLE_RETURN_COULD_NOT_CONNECT, "%s(%s)", drizzle_error(con), drizzle_strerror(ret));
64
87
ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "%s(%s)", drizzle_error(con), drizzle_strerror(ret));
66
drizzle_result_st *result= drizzle_start_binlog(con, 0, "", 0, true, &ret);
88
binlog= drizzle_binlog_init(con, binlog_event, binlog_error, NULL, true);
89
ret= drizzle_binlog_start(binlog, 0, "", 0);
68
90
SKIP_IF_(ret == DRIZZLE_RETURN_ERROR_CODE, "Binlog is not open?: %s(%s)", drizzle_error(con), drizzle_strerror(ret));
69
ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "Drizzle binlog start failure: %s(%s)", drizzle_error(con), drizzle_strerror(ret));
71
while (ret == DRIZZLE_RETURN_OK)
74
ret= drizzle_binlog_get_next_event(result);
75
if (ret == DRIZZLE_RETURN_EOF)
79
ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "Binlog error %s\n", drizzle_error(con));
80
timestamp= drizzle_binlog_event_timestamp(result);
81
/* Test to see if timestamp is greater than 2012-01-01 00:00:00, corrupted
82
* timestamps will have weird values that shoud fail this after several
83
* events. Also rotate event doesn't have a timestamp so need to add 0
85
ASSERT_FALSE_(((timestamp < 1325376000) && (timestamp != 0)), "Bad timestamp retrieved: %u", timestamp);
87
/* An event higher than the max known is bad, either we don't know about
88
* new events or type is corrupted */
89
ASSERT_FALSE_((drizzle_binlog_event_type(result) >= DRIZZLE_EVENT_TYPE_END), "Bad event type: %d", drizzle_binlog_event_type(result));
91
ASSERT_EQ_(DRIZZLE_RETURN_EOF, ret, "Drizzle binlog start failure: %s(%s)", drizzle_error(con), drizzle_strerror(ret));
92
92
return EXIT_SUCCESS;