Search in sources :

Example 16 with RaftOptions

use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.

the class LogManagerTest method setup.

@Override
@Before
public void setup() throws Exception {
    super.setup();
    this.confManager = new ConfigurationManager();
    final RaftOptions raftOptions = new RaftOptions();
    this.logStorage = newLogStorage(raftOptions);
    this.logManager = new LogManagerImpl();
    final LogManagerOptions opts = new LogManagerOptions();
    opts.setConfigurationManager(this.confManager);
    opts.setLogEntryCodecFactory(LogEntryV2CodecFactory.getInstance());
    opts.setFsmCaller(this.fsmCaller);
    opts.setNodeMetrics(new NodeMetrics(false));
    opts.setLogStorage(this.logStorage);
    opts.setRaftOptions(raftOptions);
    assertTrue(this.logManager.init(opts));
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) NodeMetrics(com.alipay.sofa.jraft.core.NodeMetrics) LogManagerOptions(com.alipay.sofa.jraft.option.LogManagerOptions) ConfigurationManager(com.alipay.sofa.jraft.conf.ConfigurationManager) Before(org.junit.Before)

Example 17 with RaftOptions

use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.

the class LocalSnapshotReaderTest method setup.

@Override
@Before
public void setup() throws Exception {
    super.setup();
    this.path = this.path + File.separator + Snapshot.JRAFT_SNAPSHOT_PREFIX + snapshotIndex;
    FileUtils.forceMkdir(new File(path));
    this.table = new LocalSnapshotMetaTable(new RaftOptions());
    this.table.addFile("testFile", LocalFileMetaOutter.LocalFileMeta.newBuilder().setChecksum("test").build());
    table.saveToFile(path + File.separator + Snapshot.JRAFT_SNAPSHOT_META_FILE);
    this.reader = new LocalSnapshotReader(snapshotStorage, null, new Endpoint("localhost", 8081), new RaftOptions(), path);
    assertTrue(this.reader.init(null));
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) Endpoint(com.alipay.sofa.jraft.util.Endpoint) File(java.io.File) Before(org.junit.Before)

Example 18 with RaftOptions

use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.

the class LocalSnapshotWriterTest method testSyncInit.

@Test
public void testSyncInit() throws Exception {
    LocalFileMetaOutter.LocalFileMeta meta = LocalFileMetaOutter.LocalFileMeta.newBuilder().setChecksum("test").setSource(LocalFileMetaOutter.FileSource.FILE_SOURCE_LOCAL).build();
    assertTrue(this.writer.addFile("data1", meta));
    assertTrue(this.writer.addFile("data2"));
    assertEquals(meta, this.writer.getFileMeta("data1"));
    assertFalse(((LocalFileMetaOutter.LocalFileMeta) this.writer.getFileMeta("data2")).hasChecksum());
    assertFalse(((LocalFileMetaOutter.LocalFileMeta) this.writer.getFileMeta("data2")).hasUserMeta());
    this.writer.sync();
    // create a new writer
    LocalSnapshotWriter newWriter = new LocalSnapshotWriter(path, snapshotStorage, new RaftOptions());
    assertTrue(newWriter.init(null));
    assertNotSame(writer, newWriter);
    assertEquals(meta, newWriter.getFileMeta("data1"));
    assertFalse(((LocalFileMetaOutter.LocalFileMeta) newWriter.getFileMeta("data2")).hasChecksum());
    assertFalse(((LocalFileMetaOutter.LocalFileMeta) newWriter.getFileMeta("data2")).hasUserMeta());
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) LocalFileMetaOutter(com.alipay.sofa.jraft.entity.LocalFileMetaOutter) Test(org.junit.Test) BaseStorageTest(com.alipay.sofa.jraft.storage.BaseStorageTest)

Example 19 with RaftOptions

use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.

the class LogStorageBenchmark method main.

public static void main(final String[] args) {
    String testPath = Paths.get(SystemPropertyUtil.get("user.dir"), "log_storage").toString();
    System.out.println("Test log storage path: " + testPath);
    int batchSize = 100;
    int logSize = 16 * 1024;
    int totalLogs = 1024 * 1024;
    // LogStorage logStorage = new RocksDBLogStorage(testPath, new RaftOptions());
    LogStorage logStorage = new RocksDBSegmentLogStorage(testPath, new RaftOptions());
    LogStorageOptions opts = new LogStorageOptions();
    opts.setConfigurationManager(new ConfigurationManager());
    opts.setLogEntryCodecFactory(LogEntryV2CodecFactory.getInstance());
    logStorage.init(opts);
    new LogStorageBenchmark(logStorage, logSize, totalLogs, batchSize).doTest();
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) LogStorageOptions(com.alipay.sofa.jraft.option.LogStorageOptions) LogStorage(com.alipay.sofa.jraft.storage.LogStorage) RocksDBSegmentLogStorage(com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage) ConfigurationManager(com.alipay.sofa.jraft.conf.ConfigurationManager) RocksDBSegmentLogStorage(com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage)

Example 20 with RaftOptions

use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.

the class RocksDBSegmentLogStorageTest method testTruncateChaos.

@Test
public void testTruncateChaos() throws Exception {
    int times = 100;
    int n = 100;
    for (int i = 0; i < times; i++) {
        this.logStorage.shutdown();
        FileUtils.deleteDirectory(new File(this.path));
        this.path = TestUtils.mkTempDir();
        FileUtils.forceMkdir(new File(this.path));
        this.logStorage = new RocksDBSegmentLogStorage(this.path, new RaftOptions(), 32, 256);
        final LogStorageOptions opts = newLogStorageOptions();
        this.logStorage.init(opts);
        for (int j = 0; j < n; j++) {
            this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(j, 1, ThreadLocalRandom.current().nextInt(180))));
        }
        int index = ThreadLocalRandom.current().nextInt(n);
        boolean truncatePrefix = ThreadLocalRandom.current().nextBoolean();
        if (truncatePrefix) {
            this.logStorage.truncatePrefix(index);
            for (int j = 0; j < n; j++) {
                if (j < index) {
                    assertNull(this.logStorage.getEntry(j));
                } else {
                    assertNotNull(this.logStorage.getEntry(j));
                }
            }
        } else {
            this.logStorage.truncateSuffix(index);
            for (int j = 0; j < n; j++) {
                if (j <= index) {
                    assertNotNull(this.logStorage.getEntry(j));
                } else {
                    assertNull(this.logStorage.getEntry(j));
                }
            }
        }
    }
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) LogStorageOptions(com.alipay.sofa.jraft.option.LogStorageOptions) File(java.io.File) RocksDBSegmentLogStorage(com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage) Test(org.junit.Test)

Aggregations

RaftOptions (com.alipay.sofa.jraft.option.RaftOptions)25 Test (org.junit.Test)11 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)9 Endpoint (com.alipay.sofa.jraft.util.Endpoint)9 Before (org.junit.Before)8 File (java.io.File)6 PeerId (com.alipay.sofa.jraft.entity.PeerId)5 LocalFileMetaOutter (com.alipay.sofa.jraft.entity.LocalFileMetaOutter)4 TimerManager (com.alipay.sofa.jraft.core.TimerManager)3 CopyOptions (com.alipay.sofa.jraft.option.CopyOptions)3 LogStorageOptions (com.alipay.sofa.jraft.option.LogStorageOptions)3 SnapshotCopierOptions (com.alipay.sofa.jraft.option.SnapshotCopierOptions)3 BaseStorageTest (com.alipay.sofa.jraft.storage.BaseStorageTest)3 RocksDBSegmentLogStorage (com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage)3 ByteBuffer (java.nio.ByteBuffer)3 Node (com.alipay.sofa.jraft.Node)2 Configuration (com.alipay.sofa.jraft.conf.Configuration)2 ConfigurationManager (com.alipay.sofa.jraft.conf.ConfigurationManager)2 CliServiceImpl (com.alipay.sofa.jraft.core.CliServiceImpl)2 CliOptions (com.alipay.sofa.jraft.option.CliOptions)2