use of com.ctrip.xpipe.api.endpoint.Endpoint 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.api.endpoint.Endpoint 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.api.endpoint.Endpoint in project x-pipe by ctripcorp.
the class DefaultEndPointTest method testEndPoint.
@Test
public void testEndPoint() {
String url = "redis://:password@10.2.58.242:6379";
Endpoint endpoint = new DefaultEndPoint(url);
Assert.assertEquals("redis", endpoint.getScheme());
Assert.assertEquals("", endpoint.getUser());
Assert.assertEquals("password", endpoint.getPassword());
Assert.assertEquals("10.2.58.242", endpoint.getHost());
Assert.assertEquals(6379, endpoint.getPort());
}
use of com.ctrip.xpipe.api.endpoint.Endpoint in project x-pipe by ctripcorp.
the class AbstractRedisMasterReplication method tryConnect.
protected ChannelFuture tryConnect(Bootstrap b) {
Endpoint endpoint = redisMaster.masterEndPoint();
logger.info("[tryConnect][begin]{}", endpoint);
return b.connect(endpoint.getHost(), endpoint.getPort());
}
use of com.ctrip.xpipe.api.endpoint.Endpoint in project x-pipe by ctripcorp.
the class DefaultRedisKeeperServer method reconnectMaster.
@Override
public synchronized void reconnectMaster() {
Endpoint target = redisKeeperServerState.getMaster();
logger.info("[reconnectMaster]{} -> {}", this, target);
if (keeperRedisMaster != null && target != null && keeperRedisMaster.getLifecycleState().isStarted()) {
Endpoint current = keeperRedisMaster.masterEndPoint();
if (current != null && current.getHost().equals(target.getHost()) && current.getPort() == target.getPort()) {
logger.info("[reconnectMaster][master the same]{},{}", current, target);
return;
}
}
stopAndDisposeMaster();
if (target == null) {
logger.info("[reconnectMaster][target null][close master connection]{}, {}", this, redisKeeperServerState);
return;
}
initAndStartMaster(target);
}
Aggregations