Skip to content

Commit

Permalink
Merge pull request shyiko#103 from janickr/fix-build-on-ci
Browse files Browse the repository at this point in the history
Fix circleci build, in the integration test suite multiple events could be in the binary log
  • Loading branch information
osheroff authored Feb 15, 2023
2 parents 74103e2 + 2ca98a1 commit 6905f82
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,15 @@ public void testGTIDAdvancesStatementBased() throws Exception {
public void testGTIDAdvances() throws Exception {
master.execute("CREATE TABLE if not exists foo (i int)");

final String[] initialGTIDSet = new String[1];
master.query("show master status", new Callback<ResultSet>() {
@Override
public void execute(ResultSet rs) throws SQLException {
rs.next();
initialGTIDSet[0] = rs.getString("Executed_Gtid_Set");
}
});
String initialGTIDSet = getExecutedGtidSet(master);

EventDeserializer eventDeserializer = new EventDeserializer();
try {
client.disconnect();
final BinaryLogClient clientWithKeepAlive = new BinaryLogClient(slave.hostname(), slave.port(),
slave.username(), slave.password());

clientWithKeepAlive.setGtidSet(initialGTIDSet[0]);
clientWithKeepAlive.setGtidSet(initialGTIDSet);
clientWithKeepAlive.registerEventListener(eventListener);
clientWithKeepAlive.setEventDeserializer(eventDeserializer);
try {
Expand Down Expand Up @@ -130,6 +123,8 @@ public void execute(Statement statement) throws SQLException {
public void testGtidServerId() throws Exception {
master.execute("CREATE TABLE if not exists foo (i int)");

String initialGTIDSet = getExecutedGtidSet(master);

final String[] expectedServerId = new String[1];
master.query("select @@server_uuid", new Callback<ResultSet>() {
@Override
Expand All @@ -144,12 +139,10 @@ public void execute(ResultSet rs) throws SQLException {
EventDeserializer eventDeserializer = new EventDeserializer();
try {
client.disconnect();
final BinaryLogClient clientWithKeepAlive = new BinaryLogClient(slave.hostname(), slave.port(),
slave.username(), slave.password());

clientWithKeepAlive.setGtidSet("");
clientWithKeepAlive.registerEventListener(eventListener);
final BinaryLogClient clientWithKeepAlive = new BinaryLogClient(master.hostname(), master.port(),
master.username(), master.password());

clientWithKeepAlive.setGtidSet(initialGTIDSet);

clientWithKeepAlive.registerEventListener(new BinaryLogClient.EventListener() {
@Override
Expand All @@ -159,6 +152,7 @@ public void onEvent(Event event) {
}
}
});
clientWithKeepAlive.registerEventListener(eventListener);
clientWithKeepAlive.setEventDeserializer(eventDeserializer);
try {
eventListener.reset();
Expand All @@ -171,7 +165,7 @@ public void execute(Statement statement) throws SQLException {
}
});

eventListener.waitFor(XidEventData.class, 1, TimeUnit.SECONDS.toMillis(4));
eventListener.waitForAtLeast(EventType.GTID, 1, TimeUnit.SECONDS.toMillis(4));
assertEquals(actualServerId[0], expectedServerId[0]);


Expand All @@ -183,4 +177,16 @@ public void execute(Statement statement) throws SQLException {
}
}

private String getExecutedGtidSet(MySQLConnection master) throws SQLException {
final String[] initialGTIDSet = new String[1];
master.query("show master status", new Callback<ResultSet>() {
@Override
public void execute(ResultSet rs) throws SQLException {
rs.next();
initialGTIDSet[0] = rs.getString("Executed_Gtid_Set");
}
});
return initialGTIDSet[0];
}

}

0 comments on commit 6905f82

Please sign in to comment.