use of com.ctrip.xpipe.redis.keeper.config.DefaultKeeperConfig in project x-pipe by ctripcorp.
the class AbstractIntegratedTest method createMetaService.
protected MetaServerKeeperService createMetaService(final List<MetaServerMeta> metaServerMetas) {
DefaultMetaServerLocator metaServerLocator = new DefaultMetaServerLocator(new MetaServerAddressAware() {
@Override
public String getMetaServerUrl() {
return String.format("http://%s:%d", "localhost", metaServerMetas.get(0).getPort());
}
});
DefaultMetaService metaService = new DefaultMetaService();
metaService.setConfig(new DefaultKeeperConfig());
metaService.setMetaServerLocator(metaServerLocator);
return metaService;
}
use of com.ctrip.xpipe.redis.keeper.config.DefaultKeeperConfig in project x-pipe by ctripcorp.
the class DefaultReplicationStoreTest method testInterruptedException.
@Test
public void testInterruptedException() throws IOException {
String keeperRunid = randomKeeperRunid();
int dataLen = 100;
store = new DefaultReplicationStore(baseDir, new DefaultKeeperConfig(), keeperRunid, createkeeperMonitor());
RdbStore rdbStore = store.beginRdb(randomKeeperRunid(), -1, new LenEofType(dataLen));
rdbStore.writeRdb(Unpooled.wrappedBuffer(randomString(dataLen).getBytes()));
rdbStore.endRdb();
Thread.currentThread().interrupt();
store = new DefaultReplicationStore(baseDir, new DefaultKeeperConfig(), keeperRunid, createkeeperMonitor());
// clear interrupt
Thread.interrupted();
store.appendCommands(Unpooled.wrappedBuffer(randomString(dataLen).getBytes()));
store = new DefaultReplicationStore(baseDir, new DefaultKeeperConfig(), keeperRunid, createkeeperMonitor());
}
use of com.ctrip.xpipe.redis.keeper.config.DefaultKeeperConfig in project x-pipe by ctripcorp.
the class DefaultReplicationStoreTest method testReadWhileDestroy.
@Test
public void testReadWhileDestroy() throws Exception {
store = new DefaultReplicationStore(baseDir, new DefaultKeeperConfig(), randomKeeperRunid(), createkeeperMonitor());
store.getMetaStore().becomeActive();
int dataLen = 1000;
RdbStore rdbStore = store.beginRdb(randomKeeperRunid(), -1, new LenEofType(dataLen));
rdbStore.writeRdb(Unpooled.wrappedBuffer(randomString(dataLen).getBytes()));
rdbStore.endRdb();
CountDownLatch latch = new CountDownLatch(2);
AtomicBoolean result = new AtomicBoolean(true);
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try {
sleep(2);
store.close();
store.destroy();
} finally {
latch.countDown();
}
}
});
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try {
store.fullSyncIfPossible(new FullSyncListener() {
@Override
public ChannelFuture onCommand(ReferenceFileRegion referenceFileRegion) {
return null;
}
@Override
public void beforeCommand() {
}
@Override
public void setRdbFileInfo(EofType eofType, long rdbFileKeeperOffset) {
}
@Override
public void onFileData(ReferenceFileRegion referenceFileRegion) throws IOException {
sleep(10);
}
@Override
public boolean isOpen() {
return true;
}
@Override
public void exception(Exception e) {
logger.info("[exception][fail]" + e.getMessage());
result.set(false);
}
@Override
public void beforeFileData() {
}
});
} catch (Exception e) {
logger.info("[exception][fail]" + e.getMessage());
result.set(false);
} finally {
latch.countDown();
}
}
});
latch.await(100, TimeUnit.MILLISECONDS);
Assert.assertFalse(result.get());
}
use of com.ctrip.xpipe.redis.keeper.config.DefaultKeeperConfig in project x-pipe by ctripcorp.
the class DefaultReplicationStoreTest method testReadWrite.
@Test
public void testReadWrite() throws Exception {
store = new DefaultReplicationStore(baseDir, new DefaultKeeperConfig(), randomKeeperRunid(), createkeeperMonitor());
store.getMetaStore().becomeActive();
StringBuffer exp = new StringBuffer();
int cmdCount = 4;
int cmdLen = 10;
store.beginRdb("master", -1, new LenEofType(-1));
for (int j = 0; j < cmdCount; j++) {
ByteBuf buf = Unpooled.buffer();
String cmd = UUID.randomUUID().toString().substring(0, cmdLen);
exp.append(cmd);
buf.writeBytes(cmd.getBytes());
store.getCommandStore().appendCommands(buf);
}
String result = readCommandFileTilEnd(store, exp.length());
assertEquals(exp.toString(), result);
store.close();
}
Aggregations