Search in sources :

Example 1 with FakeRedisServer

use of com.ctrip.xpipe.redis.core.server.FakeRedisServer in project x-pipe by ctripcorp.

the class FakeRedis method main.

public static void main(String[] args) throws Exception {
    int port = Integer.parseInt(System.getProperty("port", "6379"));
    FakeRedisServer fakeRedisServer = new FakeRedisServer(port);
    fakeRedisServer.setSendHalfRdbAndCloseConnectionCount(1);
    fakeRedisServer.initialize();
    fakeRedisServer.start();
}
Also used : FakeRedisServer(com.ctrip.xpipe.redis.core.server.FakeRedisServer)

Example 2 with FakeRedisServer

use of com.ctrip.xpipe.redis.core.server.FakeRedisServer in project x-pipe by ctripcorp.

the class DefaultPsyncTest method beforeDefaultPsyncTest.

@Before
public void beforeDefaultPsyncTest() throws Exception {
    FakeRedisServer fakeRedisServer = startFakeRedisServer();
    Endpoint masterEndPoint = new DefaultEndPoint("localhost", fakeRedisServer.getPort());
    SimpleObjectPool<NettyClient> pool = NettyPoolUtil.createNettyPool(new InetSocketAddress("localhost", fakeRedisServer.getPort()));
    when(replicationStoreManager.createIfNotExist()).thenReturn(replicationStore);
    when(replicationStore.getMetaStore()).thenReturn(metaStore);
    when(metaStore.getReplId()).thenReturn("?");
    when(replicationStore.getEndOffset()).thenReturn(-1L);
    defaultPsync = new DefaultPsync(pool, masterEndPoint, replicationStoreManager, scheduled);
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Endpoint(com.ctrip.xpipe.api.endpoint.Endpoint) InetSocketAddress(java.net.InetSocketAddress) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) FakeRedisServer(com.ctrip.xpipe.redis.core.server.FakeRedisServer) Before(org.junit.Before)

Example 3 with FakeRedisServer

use of com.ctrip.xpipe.redis.core.server.FakeRedisServer in project x-pipe by ctripcorp.

the class AbstractRedisTest method startFakeRedisServer.

protected FakeRedisServer startFakeRedisServer(int serverPort) throws Exception {
    FakeRedisServer fakeRedisServer = new FakeRedisServer(serverPort);
    fakeRedisServer.initialize();
    fakeRedisServer.start();
    add(fakeRedisServer);
    return fakeRedisServer;
}
Also used : FakeRedisServer(com.ctrip.xpipe.redis.core.server.FakeRedisServer)

Example 4 with FakeRedisServer

use of com.ctrip.xpipe.redis.core.server.FakeRedisServer in project x-pipe by ctripcorp.

the class PingCommandTest method testPing.

@Test
public void testPing() throws Exception {
    FakeRedisServer fakeRedisServer = startFakeRedisServer();
    PingCommand command = new PingCommand(getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress("localhost", fakeRedisServer.getPort())), scheduled);
    String result = command.execute().get();
    Assert.assertEquals(PingCommand.PONG, result);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) FakeRedisServer(com.ctrip.xpipe.redis.core.server.FakeRedisServer) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 5 with FakeRedisServer

use of com.ctrip.xpipe.redis.core.server.FakeRedisServer in project x-pipe by ctripcorp.

the class DefaultRedisKeeperServerTest method testKeeperStopNoConnectMaster.

@Test
public void testKeeperStopNoConnectMaster() throws Exception {
    FakeRedisServer server1 = startFakeRedisServer();
    FakeRedisServer server2 = startFakeRedisServer();
    FakeRedisServer server3 = startFakeRedisServer();
    RedisKeeperServer redisKeeperServer = createRedisKeeperServer();
    redisKeeperServer.initialize();
    redisKeeperServer.start();
    redisKeeperServer.setRedisKeeperServerState(new RedisKeeperServerStateActive(redisKeeperServer, localhostInetAddress(server1.getPort())));
    redisKeeperServer.reconnectMaster();
    waitConditionUntilTimeOut(() -> server1.getConnected() == 1);
    sleep(100);
    redisKeeperServer.stop();
    redisKeeperServer.setRedisKeeperServerState(new RedisKeeperServerStateActive(redisKeeperServer, localhostInetAddress(server2.getPort())));
    redisKeeperServer.reconnectMaster();
    waitConditionUntilTimeOut(() -> server1.getConnected() == 0);
    Assert.assertEquals(0, server2.getConnected());
    redisKeeperServer.dispose();
    redisKeeperServer.setRedisKeeperServerState(new RedisKeeperServerStateActive(redisKeeperServer, localhostInetAddress(server3.getPort())));
    redisKeeperServer.reconnectMaster();
    sleep(100);
    Assert.assertEquals(0, server1.getConnected());
    Assert.assertEquals(0, server2.getConnected());
    Assert.assertEquals(0, server3.getConnected());
}
Also used : FakeRedisServer(com.ctrip.xpipe.redis.core.server.FakeRedisServer) Test(org.junit.Test)

Aggregations

FakeRedisServer (com.ctrip.xpipe.redis.core.server.FakeRedisServer)5 InetSocketAddress (java.net.InetSocketAddress)2 Test (org.junit.Test)2 Endpoint (com.ctrip.xpipe.api.endpoint.Endpoint)1 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)1 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)1 Before (org.junit.Before)1