@@ -0,0 +1,3444 @@
+package com.moilioncircle.redis.replicator;%0A%0Aimport com.moilioncircle.redis.replicator.cmd.Command;%0Aimport com.moilioncircle.redis.replicator.cmd.CommandListener;%0Aimport com.moilioncircle.redis.replicator.cmd.impl.SetCommand;%0Aimport com.moilioncircle.redis.replicator.rdb.RdbListener;%0Aimport com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair;%0Aimport org.junit.Test;%0Aimport redis.clients.jedis.Jedis;%0A%0Aimport java.io.IOException;%0Aimport java.util.concurrent.atomic.AtomicBoolean;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A%0Aimport static junit.framework.TestCase.assertEquals;%0A%0A/**%0A * Created by Baoyi Chen on 2017/2/9.%0A */%0Apublic class PsyncTest %7B%0A%0A    //@Test%0A    public void psync() throws IOException %7B%0A%0A        Replicator replicator = new RedisReplicator(%22127.0.0.1%22, 6380, Configuration.defaultSetting().setAuthPassword(%22test%22).setConnectionTimeout(2000));%0A        final AtomicBoolean flag = new AtomicBoolean(false);%0A        replicator.addRdbListener(new RdbListener() %7B%0A            @Override%0A            public void preFullSync(Replicator replicator) %7B%0A            %7D%0A%0A            @Override%0A            public void handle(Replicator replicator, KeyValuePair%3C?%3E kv) %7B%0A%0A            %7D%0A%0A            @Override%0A            public void postFullSync(Replicator replicator, long checksum) %7B%0A                if (!flag.get()) %7B%0A                    Thread thread = new Thread(new JRun());%0A                    thread.setDaemon(true);%0A                    thread.start();%0A                    flag.compareAndSet(false, true);%0A                %7D%0A            %7D%0A        %7D);%0A        final AtomicInteger acc = new AtomicInteger();%0A        replicator.addCommandListener(new CommandListener() %7B%0A            @Override%0A            public void handle(Replicator replicator, Command command) %7B%0A                if (command instanceof SetCommand && ((SetCommand) command).getKey().startsWith(%22psync%22)) %7B%0A                    SetCommand setCommand = (SetCommand) command;%0A                    int num = Integer.parseInt(setCommand.getKey().split(%22 %22)%5B1%5D);%0A                    acc.incrementAndGet();%0A                    if (acc.get() == 200) %7B%0A                        //close current process port;%0A                        //that will auto trigger psync command%0A                        //TODO how to get the current process port and kill that port using java?%0A                    %7D%0A                    if (acc.get() == 1000) %7B%0A                        try %7B%0A                            replicator.close();%0A                        %7D catch (IOException e) %7B%0A                            e.printStackTrace();%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A        %7D);%0A        replicator.addCloseListener(new CloseListener() %7B%0A            @Override%0A            public void handle(Replicator replicator) %7B%0A                assertEquals(1000, acc.get());%0A            %7D%0A        %7D);%0A        replicator.open();%0A    %7D%0A%0A    private static class JRun implements Runnable %7B%0A%0A        @Override%0A        public void run() %7B%0A            Jedis jedis = new Jedis(%22127.0.0.1%22, 6380);%0A            jedis.auth(%22test%22);%0A            for (int i = 0; i %3C 1000; i++) %7B%0A                jedis.set(%22psync %22 + i, %22psync%22 + i);%0A                try %7B%0A                    Thread.sleep(20);%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A            jedis.close();%0A        %7D%0A    %7D%0A%0A%7D%0A

add testcase