Search in sources :

Example 1 with Command

use of com.ctrip.xpipe.api.command.Command in project x-pipe by ctripcorp.

the class DefaultRedisMasterReplicationTest method testCancelScheduleWhenConnected.

@Test
public void testCancelScheduleWhenConnected() throws IOException {
    AtomicInteger replConfCount = new AtomicInteger();
    defaultRedisMasterReplication = new DefaultRedisMasterReplication(redisMaster, redisKeeperServer, nioEventLoopGroup, scheduled, replTimeoutMilli) {

        @Override
        protected Command<Object> createReplConf() {
            replConfCount.incrementAndGet();
            return super.createReplConf();
        }
    };
    defaultRedisMasterReplication.onContinue(RunidGenerator.DEFAULT.generateRunid(), RunidGenerator.DEFAULT.generateRunid());
    Channel channel = mock(Channel.class);
    when(channel.closeFuture()).thenReturn(new DefaultChannelPromise(channel));
    defaultRedisMasterReplication.masterConnected(channel);
    int countBefore = replConfCount.get();
    sleep(DefaultRedisMasterReplication.REPLCONF_INTERVAL_MILLI * 2);
    int countAfter = replConfCount.get();
    Assert.assertEquals(countBefore, countAfter);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Command(com.ctrip.xpipe.api.command.Command) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) Channel(io.netty.channel.Channel) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) AbstractRedisKeeperTest(com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest) Test(org.junit.Test)

Aggregations

Command (com.ctrip.xpipe.api.command.Command)1 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)1 AbstractRedisKeeperTest (com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)1 Channel (io.netty.channel.Channel)1 DefaultChannelPromise (io.netty.channel.DefaultChannelPromise)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1