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));
}
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));
}
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());
}
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();
}
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));
}
}
}
}
}
Aggregations