Search in sources :

Example 6 with LenEofType

use of com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType in project x-pipe by ctripcorp.

the class PsyncTest method testPsync2.

@Test
public void testPsync2() 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());
}
Also used : LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) Test(org.junit.Test) AbstractRedisKeeperTest(com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)

Example 7 with LenEofType

use of com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType in project x-pipe by ctripcorp.

the class PsyncTest method testPsyncPartialeRight.

@Test
public void testPsyncPartialeRight() throws XpipeException, IOException, InterruptedException {
    isPartial = true;
    String[] data = new String[] { "+" + DefaultPsync.PARTIAL_SYNC + "\r\n", commandContent };
    // create store
    replicationStore.beginRdb(masterId, masterOffset, new LenEofType(0));
    replicationStore.getRdbStore().endRdb();
    runData(data);
}
Also used : LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) Test(org.junit.Test) AbstractRedisKeeperTest(com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)

Example 8 with LenEofType

use of com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType in project x-pipe by ctripcorp.

the class DefaultRdbStoreTest method beforeDefaultRdbStoreTest.

@Before
public void beforeDefaultRdbStoreTest() throws IOException {
    String fileName = String.format("%s/%s.rdb", getTestFileDir(), getTestName());
    rdbFile = new File(fileName);
    rdbStore = new DefaultRdbStore(rdbFile, 1L, new LenEofType(rdbFileSize));
}
Also used : LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) File(java.io.File) Before(org.junit.Before)

Example 9 with LenEofType

use of com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType 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());
}
Also used : RdbStore(com.ctrip.xpipe.redis.core.store.RdbStore) LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) EofType(com.ctrip.xpipe.redis.core.protocal.protocal.EofType) LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) ReferenceFileRegion(com.ctrip.xpipe.netty.filechannel.ReferenceFileRegion) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FullSyncListener(com.ctrip.xpipe.redis.core.store.FullSyncListener) DefaultKeeperConfig(com.ctrip.xpipe.redis.keeper.config.DefaultKeeperConfig) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) Test(org.junit.Test) AbstractRedisKeeperTest(com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)

Example 10 with LenEofType

use of com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType 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();
}
Also used : DefaultKeeperConfig(com.ctrip.xpipe.redis.keeper.config.DefaultKeeperConfig) LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test) AbstractRedisKeeperTest(com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)

Aggregations

LenEofType (com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType)11 AbstractRedisKeeperTest (com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)9 Test (org.junit.Test)9 DefaultKeeperConfig (com.ctrip.xpipe.redis.keeper.config.DefaultKeeperConfig)3 RdbStore (com.ctrip.xpipe.redis.core.store.RdbStore)2 ByteBuf (io.netty.buffer.ByteBuf)2 File (java.io.File)2 FileSize (com.ctrip.xpipe.api.utils.FileSize)1 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)1 ReferenceFileRegion (com.ctrip.xpipe.netty.filechannel.ReferenceFileRegion)1 EofMarkType (com.ctrip.xpipe.redis.core.protocal.protocal.EofMarkType)1 EofType (com.ctrip.xpipe.redis.core.protocal.protocal.EofType)1 FullSyncListener (com.ctrip.xpipe.redis.core.store.FullSyncListener)1 MetaStore (com.ctrip.xpipe.redis.core.store.MetaStore)1 ReplicationStore (com.ctrip.xpipe.redis.core.store.ReplicationStore)1 DefaultControllableFile (com.ctrip.xpipe.utils.DefaultControllableFile)1 SizeControllableFile (com.ctrip.xpipe.utils.SizeControllableFile)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1