use of com.ctrip.xpipe.netty.filechannel.ReferenceFileRegion 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.netty.filechannel.ReferenceFileRegion in project x-pipe by ctripcorp.
the class AbstractRedisKeeperTest method readRdbFileTilEnd.
protected String readRdbFileTilEnd(RdbStore rdbStore) throws IOException, InterruptedException {
final ByteArrayWritableByteChannel bachannel = new ByteArrayWritableByteChannel();
final CountDownLatch latch = new CountDownLatch(1);
rdbStore.readRdbFile(new RdbFileListener() {
@Override
public void setRdbFileInfo(EofType eofType, long rdbFileOffset) {
}
@Override
public void onFileData(ReferenceFileRegion referenceFileRegion) throws IOException {
if (referenceFileRegion == null) {
latch.countDown();
return;
}
referenceFileRegion.transferTo(bachannel, 0L);
}
@Override
public boolean isOpen() {
return true;
}
@Override
public void exception(Exception e) {
latch.countDown();
}
@Override
public void beforeFileData() {
}
});
latch.await(5, TimeUnit.SECONDS);
return new String(bachannel.getResult());
}
Aggregations