Skip to content

Commit

Permalink
Update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sandynz committed Feb 17, 2025
1 parent f65ec96 commit 16f3db6
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.Attribute;
import io.netty.util.concurrent.Promise;
import lombok.SneakyThrows;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
import org.apache.shardingsphere.db.protocol.mysql.packet.command.binlog.MySQLComBinlogDumpCommandPacket;
import org.apache.shardingsphere.db.protocol.mysql.packet.command.binlog.MySQLComRegisterSlaveCommandPacket;
Expand All @@ -40,6 +41,7 @@

import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -131,9 +133,11 @@ private void mockChannelResponse(final Object response) {
new Thread(() -> mockChannelResponseInThread(response)).start();
}

@SneakyThrows(InterruptedException.class)
@SuppressWarnings("unchecked")
private void mockChannelResponseInThread(final Object response) {
while (true) {
long t1 = System.currentTimeMillis();
do {
Promise<Object> responseCallback;
try {
responseCallback = (Promise<Object>) Plugins.getMemberAccessor().get(MySQLBinlogClient.class.getDeclaredField("responseCallback"), client);
Expand All @@ -142,9 +146,9 @@ private void mockChannelResponseInThread(final Object response) {
}
if (null != responseCallback) {
responseCallback.setSuccess(response);
break;
}
}
TimeUnit.SECONDS.sleep(1L);
} while (System.currentTimeMillis() - t1 <= TimeUnit.SECONDS.toMillis(20L));
}

@Test
Expand Down

0 comments on commit 16f3db6

Please sign in to comment.