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 ebaeaae commit 78568c9
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -38,7 +36,7 @@
import com.moilioncircle.redis.replicator.event.Event;
import com.moilioncircle.redis.replicator.event.EventListener;
import com.moilioncircle.redis.replicator.event.PostRdbSyncEvent;
import com.moilioncircle.redis.replicator.rdb.datatype.AuxField;
import com.moilioncircle.redis.replicator.event.PreRdbSyncEvent;
import com.moilioncircle.redis.replicator.util.Strings;

import redis.clients.jedis.Jedis;
Expand Down Expand Up @@ -67,16 +65,19 @@ public void psync() throws IOException {
@SuppressWarnings("resource")
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();

final AtomicInteger acc1 = new AtomicInteger();
r.addEventListener(new EventListener() {
@Override
public void onEvent(Replicator replicator, Event event) {
if (event instanceof AuxField) {
set.add((AuxField) event);
if (event instanceof PreRdbSyncEvent) {
acc1.incrementAndGet();
}
if (event instanceof PostRdbSyncEvent) {
if (flag.compareAndSet(false, true)) {
// will trigger full sync at this time
close(replicator);
Thread thread = new Thread(new JRun());
thread.setDaemon(true);
thread.start();
Expand All @@ -88,6 +89,7 @@ public void onEvent(Replicator replicator, Event event) {
if (acc.get() == 500) {
//close current process port;
//that will auto trigger psync command
r.getLogger().info("id:{}, offset:{}", configuration.getReplId(), configuration.getReplOffset());
close(replicator);
}

Expand All @@ -110,6 +112,7 @@ public void onEvent(Replicator replicator, Event event) {
}
});
r.open();
assertEquals(2, acc1.get());
assertEquals(1500, acc.get());
}

Expand Down

0 comments on commit 78568c9

Please sign in to comment.