Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Baoyi Chen committed Dec 9, 2023
1 parent 5212235 commit 6ba02aa
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.Test;
import org.slf4j.Logger;

import com.moilioncircle.redis.replicator.Configuration;
import com.moilioncircle.redis.replicator.RedisSocketReplicator;
Expand Down Expand Up @@ -64,11 +65,11 @@ public void psync() throws IOException {
setRetryTimeInterval(1000).
setUseDefaultExceptionListener(false);
@SuppressWarnings("resource")
Replicator replicator = new TestRedisSocketReplicator("127.0.0.1", 6380, configuration);
TestRedisSocketReplicator r = new TestRedisSocketReplicator("127.0.0.1", 6380, configuration);
final AtomicBoolean flag = new AtomicBoolean(false);
final Set<AuxField> set = new LinkedHashSet<>();
final AtomicInteger acc = new AtomicInteger();
replicator.addEventListener(new EventListener() {
r.addEventListener(new EventListener() {
@Override
public void onEvent(Replicator replicator, Event event) {
if (event instanceof AuxField) {
Expand All @@ -93,6 +94,7 @@ public void onEvent(Replicator replicator, Event event) {
if (acc.get() == 1010) {
//close current process port;
//that will auto trigger psync command
r.getLogger().info("id:{}, offset:{}", configuration.getReplId(), configuration.getReplOffset());
close(replicator);
}
if (acc.get() == 1480) {
Expand All @@ -107,7 +109,7 @@ public void onEvent(Replicator replicator, Event event) {
}
}
});
replicator.open();
r.open();
assertEquals(1500, acc.get());
}

Expand Down Expand Up @@ -146,6 +148,10 @@ private static class TestRedisSocketReplicator extends RedisSocketReplicator {
public TestRedisSocketReplicator(String host, int port, Configuration configuration) {
super(host, port, configuration);
}

public Logger getLogger() {
return TestRedisSocketReplicator.logger;
}

public Socket getSocket() {
return super.socket;
Expand Down

0 comments on commit 6ba02aa

Please sign in to comment.