use of com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType 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.redis.core.protocal.protocal.LenEofType 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.core.protocal.protocal.LenEofType in project x-pipe by ctripcorp.
the class PsyncTest method testPsync2Spaces.
@Test
public void testPsync2Spaces() throws XpipeException, IOException, InterruptedException {
isPartial = true;
String newReplId = RunidGenerator.DEFAULT.generateRunid();
String[] data = new String[] { "+" + DefaultPsync.PARTIAL_SYNC + " " + newReplId + " \r\n", commandContent };
// create store
replicationStore.beginRdb(masterId, masterOffset, new LenEofType(0));
replicationStore.getRdbStore().endRdb();
Long secondReplIdOffset = replicationStore.getEndOffset() + 1;
runData(data);
Assert.assertEquals(newReplId, replicationStore.getMetaStore().getReplId());
Assert.assertEquals(masterId, replicationStore.getMetaStore().getReplId2());
Assert.assertEquals(secondReplIdOffset, replicationStore.getMetaStore().getSecondReplIdOffset());
}
use of com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType in project x-pipe by ctripcorp.
the class PsyncTest method testPsync2SplitTcp.
@Test
public void testPsync2SplitTcp() throws XpipeException, IOException, InterruptedException {
isPartial = true;
String newReplId = RunidGenerator.DEFAULT.generateRunid();
String[] data = new String[] { "+" + DefaultPsync.PARTIAL_SYNC, " " + newReplId + " \r\n", commandContent };
// create store
replicationStore.beginRdb(masterId, masterOffset, new LenEofType(0));
replicationStore.getRdbStore().endRdb();
Long secondReplIdOffset = replicationStore.getEndOffset() + 1;
runData(data);
Assert.assertEquals(newReplId, replicationStore.getMetaStore().getReplId());
Assert.assertEquals(masterId, replicationStore.getMetaStore().getReplId2());
Assert.assertEquals(secondReplIdOffset, replicationStore.getMetaStore().getSecondReplIdOffset());
}
use of com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType in project x-pipe by ctripcorp.
the class DefaultRdbStore method createControllableFile.
private ControllableFile createControllableFile() throws IOException {
if (eofType instanceof LenEofType) {
return new DefaultControllableFile(file);
} else if (eofType instanceof EofMarkType) {
return new SizeControllableFile(file, new FileSize() {
@Override
public long getSize(LongSupplier realSizeProvider) {
long realSize = 0;
synchronized (truncateLock) {
// truncate may make size wrong
realSize = realSizeProvider.getAsLong();
}
if (status.get() == Status.Writing) {
long ret = realSize - ((EofMarkType) eofType).getTag().length();
logger.debug("[getSize][writing]{}, {}", DefaultRdbStore.this, ret);
return ret < 0 ? 0 : ret;
}
return realSize;
}
});
} else {
throw new IllegalStateException("unknown eoftype:" + eofType.getClass() + "," + eofType);
}
}
Aggregations