use of org.apache.ignite.raft.jraft.option.RaftOptions in project ignite-3 by apache.
the class ItNodeTest method testNodeTaskOverload.
@Test
public void testNodeTaskOverload() throws Exception {
Endpoint addr = new Endpoint(TestUtils.getLocalAddress(), TestUtils.INIT_PORT);
PeerId peer = new PeerId(addr, 0);
NodeOptions nodeOptions = createNodeOptions();
RaftOptions raftOptions = new RaftOptions();
raftOptions.setDisruptorBufferSize(2);
nodeOptions.setRaftOptions(raftOptions);
MockStateMachine fsm = new MockStateMachine(addr);
nodeOptions.setFsm(fsm);
nodeOptions.setLogUri(dataPath + File.separator + "log");
nodeOptions.setRaftMetaUri(dataPath + File.separator + "meta");
nodeOptions.setSnapshotUri(dataPath + File.separator + "snapshot");
nodeOptions.setInitialConf(new Configuration(Collections.singletonList(peer)));
RaftGroupService service = createService("unittest", new PeerId(addr, 0), nodeOptions);
Node node = service.start();
assertEquals(1, node.listPeers().size());
assertTrue(node.listPeers().contains(peer));
while (!node.isLeader()) ;
List<Task> tasks = new ArrayList<>();
AtomicInteger c = new AtomicInteger(0);
for (int i = 0; i < 10; i++) {
ByteBuffer data = ByteBuffer.wrap(("hello" + i).getBytes(UTF_8));
int finalI = i;
Task task = new Task(data, new JoinableClosure(status -> {
LOG.info("{} i={}", status, finalI);
if (!status.isOk()) {
assertTrue(status.getRaftError() == RaftError.EBUSY || status.getRaftError() == RaftError.EPERM);
}
c.incrementAndGet();
}));
node.apply(task);
tasks.add(task);
}
Task.joinAll(tasks, TimeUnit.SECONDS.toMillis(30));
assertEquals(10, c.get());
}
use of org.apache.ignite.raft.jraft.option.RaftOptions in project ignite-3 by apache.
the class LocalSnapshotMetaTableTest method testSaveLoadIoBuffer.
@Test
public void testSaveLoadIoBuffer() throws Exception {
LocalFileMetaOutter.LocalFileMeta meta1 = msgFactory.localFileMeta().checksum("data1").source(LocalFileMetaOutter.FileSource.FILE_SOURCE_LOCAL).build();
assertTrue(this.table.addFile("data1", meta1));
LocalFileMetaOutter.LocalFileMeta meta2 = msgFactory.localFileMeta().checksum("data2").source(LocalFileMetaOutter.FileSource.FILE_SOURCE_LOCAL).build();
assertTrue(this.table.addFile("data2", meta2));
ByteBuffer buf = this.table.saveToByteBufferAsRemote();
assertNotNull(buf);
assertTrue(buf.hasRemaining());
LocalSnapshotMetaTable newTable = new LocalSnapshotMetaTable(new RaftOptions());
assertNull(newTable.getFileMeta("data1"));
assertNull(newTable.getFileMeta("data2"));
assertTrue(newTable.loadFromIoBufferAsRemote(buf));
assertEquals(meta1, newTable.getFileMeta("data1"));
assertEquals(meta2, newTable.getFileMeta("data2"));
}
use of org.apache.ignite.raft.jraft.option.RaftOptions in project ignite-3 by apache.
the class LocalSnapshotMetaTableTest method setup.
@BeforeEach
public void setup() {
RaftOptions opts = new RaftOptions();
this.table = new LocalSnapshotMetaTable(opts);
this.msgFactory = opts.getRaftMessagesFactory();
}
use of org.apache.ignite.raft.jraft.option.RaftOptions in project ignite-3 by apache.
the class LocalSnapshotMetaTableTest method testSaveLoadFile.
@Test
public void testSaveLoadFile(@WorkDirectory Path workDir) throws IOException {
LocalFileMetaOutter.LocalFileMeta meta1 = msgFactory.localFileMeta().checksum("data1").source(LocalFileMetaOutter.FileSource.FILE_SOURCE_LOCAL).build();
assertTrue(this.table.addFile("data1", meta1));
LocalFileMetaOutter.LocalFileMeta meta2 = msgFactory.localFileMeta().checksum("data2").source(LocalFileMetaOutter.FileSource.FILE_SOURCE_LOCAL).build();
assertTrue(this.table.addFile("data2", meta2));
RaftOutter.SnapshotMeta meta = msgFactory.snapshotMeta().lastIncludedIndex(1).lastIncludedTerm(1).build();
this.table.setMeta(meta);
assertTrue(table.listFiles().contains("data1"));
assertTrue(table.listFiles().contains("data2"));
assertTrue(table.hasMeta());
String filePath = workDir.resolve("table").toString();
table.saveToFile(filePath);
LocalSnapshotMetaTable newTable = new LocalSnapshotMetaTable(new RaftOptions());
assertNull(newTable.getFileMeta("data1"));
assertNull(newTable.getFileMeta("data2"));
assertTrue(newTable.loadFromFile(filePath));
assertEquals(meta1, newTable.getFileMeta("data1"));
assertEquals(meta2, newTable.getFileMeta("data2"));
assertEquals(meta, newTable.getMeta());
}
use of org.apache.ignite.raft.jraft.option.RaftOptions in project ignite-3 by apache.
the class LocalSnapshotStorageTest method setup.
@BeforeEach
public void setup() throws Exception {
String snapshotPath = this.path + File.separator + Snapshot.JRAFT_SNAPSHOT_PREFIX + lastSnapshotIndex;
new File(snapshotPath).mkdirs();
opts = new RaftOptions();
this.table = new LocalSnapshotMetaTable(opts);
this.table.setMeta(opts.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(this.lastSnapshotIndex).lastIncludedTerm(1).build());
this.table.saveToFile(snapshotPath + File.separator + Snapshot.JRAFT_SNAPSHOT_META_FILE);
this.snapshotStorage = new LocalSnapshotStorage(path.toString(), new RaftOptions());
assertTrue(this.snapshotStorage.init(null));
}
Aggregations