use of com.ctrip.xpipe.endpoint.DefaultEndPoint in project x-pipe by ctripcorp.
the class RedisFakeSlaveTest method startKeeperCreateReplicationLogClient.
private void startKeeperCreateReplicationLogClient() throws UnknownHostException, IOException {
try {
Endpoint endpoint = new DefaultEndPoint(redisMasterUri);
socket = new Socket(endpoint.getHost(), endpoint.getPort());
if (logger.isInfoEnabled()) {
logger.info("[startKeeperClient]" + socket);
}
final OutputStream ous = socket.getOutputStream();
InputStream ins = socket.getInputStream();
ous.write(("replconf listening-port " + fakeSlavePort + "\r\n").getBytes());
ous.flush();
readLine(ins);
ous.write("fsync\r\n".getBytes());
ous.flush();
readLine(ins);
scheduled.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
ous.write("replconf ack 0\r\n".getBytes());
ous.flush();
} catch (IOException e) {
closeSocket();
logger.error("[run]", e);
}
}
}, 0, 1, TimeUnit.SECONDS);
} catch (IOException e) {
closeSocket();
logger.error("[startKeeperCreateReplicationLogClient]" + socket, e);
}
}
use of com.ctrip.xpipe.endpoint.DefaultEndPoint in project x-pipe by ctripcorp.
the class DefaultRedisMasterReplicationTest method testTimeout.
@Test
public void testTimeout() throws Exception {
Server server = startEmptyServer();
when(redisMaster.masterEndPoint()).thenReturn(new DefaultEndPoint("localhost", server.getPort()));
AtomicInteger connectingCount = new AtomicInteger(0);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
connectingCount.incrementAndGet();
return null;
}
}).when(redisMaster).setMasterState(MASTER_STATE.REDIS_REPL_CONNECTING);
defaultRedisMasterReplication.setMasterConnectRetryDelaySeconds(0);
defaultRedisMasterReplication.initialize();
defaultRedisMasterReplication.start();
waitConditionUntilTimeOut(() -> connectingCount.get() >= 2);
}
use of com.ctrip.xpipe.endpoint.DefaultEndPoint in project x-pipe by ctripcorp.
the class DefaultReplicationStoreManagerTest method test.
@Test
public void test() throws Exception {
String keeperRunid = randomKeeperRunid();
File baseDir = new File(getTestFileDir());
String clusterId = "cluster1";
String shardId = "shard1";
DefaultReplicationStoreManager mgr = (DefaultReplicationStoreManager) createReplicationStoreManager(clusterId, shardId, keeperRunid, baseDir);
LifecycleHelper.initializeIfPossible(mgr);
ReplicationStore currentStore = mgr.getCurrent();
assertNull(currentStore);
currentStore = mgr.create();
assertEquals(clusterId, mgr.getClusterName());
assertEquals(shardId, mgr.getShardName());
assertEquals(currentStore, mgr.getCurrent());
DefaultReplicationStore newCurrentStore = (DefaultReplicationStore) mgr.create();
assertEquals(newCurrentStore, mgr.getCurrent());
assertNotEquals(currentStore, mgr.getCurrent());
MetaStore metaStore = newCurrentStore.getMetaStore();
metaStore.setMasterAddress(new DefaultEndPoint("redis://127.0.0.1:6379"));
newCurrentStore.beginRdb("masterRunid", 0, new LenEofType(100));
ByteBuf cmdBuf = Unpooled.buffer();
cmdBuf.writeByte(9);
newCurrentStore.getCommandStore().appendCommands(cmdBuf);
DefaultReplicationStoreManager mgr2 = (DefaultReplicationStoreManager) createReplicationStoreManager(clusterId, shardId, keeperRunid, baseDir);
assertEquals(metaStore.getReplId(), mgr2.getCurrent().getMetaStore().getReplId());
assertEquals(metaStore.beginOffset(), mgr2.getCurrent().getMetaStore().beginOffset());
assertEquals(metaStore.getMasterAddress(), mgr2.getCurrent().getMetaStore().getMasterAddress());
assertEquals(metaStore.beginOffset(), mgr2.getCurrent().getMetaStore().beginOffset());
}
use of com.ctrip.xpipe.endpoint.DefaultEndPoint 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);
}
use of com.ctrip.xpipe.endpoint.DefaultEndPoint in project x-pipe by ctripcorp.
the class RoleCommandHandlerTest method beforeRoleCommandHandlerTest.
@Before
public void beforeRoleCommandHandlerTest() {
host = "localhost";
port = randomPort();
when(redisClient.getRedisKeeperServer()).thenReturn(redisKeeperServer);
when(redisKeeperServer.getRedisMaster()).thenReturn(redisMaster);
when(redisKeeperServer.role()).thenReturn(SERVER_ROLE.KEEPER);
when(redisMaster.masterEndPoint()).thenReturn(new DefaultEndPoint(host, port));
when(redisMaster.getMasterState()).thenReturn(masterState);
}
Aggregations