use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class BaseLogStorageTest method testLoadWithConfigManager.
@Test
public void testLoadWithConfigManager() {
assertTrue(this.confManager.getLastConfiguration().isEmpty());
final LogEntry confEntry1 = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION);
confEntry1.setId(new LogId(99, 1));
confEntry1.setPeers(JRaftUtils.getConfiguration("localhost:8081,localhost:8082").listPeers());
final LogEntry confEntry2 = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION);
confEntry2.setId(new LogId(100, 2));
confEntry2.setPeers(JRaftUtils.getConfiguration("localhost:8081,localhost:8082,localhost:8083").listPeers());
assertTrue(this.logStorage.appendEntry(confEntry1));
assertEquals(1, this.logStorage.appendEntries(Arrays.asList(confEntry2)));
// reload log storage.
if (this.logStorage instanceof RocksDBLogStorage) {
this.logStorage.shutdown();
this.logStorage = newLogStorage();
this.logStorage.init(newLogStorageOptions());
ConfigurationEntry conf = this.confManager.getLastConfiguration();
assertNotNull(conf);
assertFalse(conf.isEmpty());
assertEquals("localhost:8081,localhost:8082,localhost:8083", conf.getConf().toString());
conf = this.confManager.get(99);
assertNotNull(conf);
assertFalse(conf.isEmpty());
assertEquals("localhost:8081,localhost:8082", conf.getConf().toString());
}
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class LogManagerTest method testAppendOneEntry.
@Test
public void testAppendOneEntry() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final LogEntry entry = TestUtils.mockEntry(1, 1);
final List<LogEntry> entries = new ArrayList<>();
entries.add(entry);
this.logManager.appendEntries(entries, new LogManager.StableClosure() {
@Override
public void run(final Status status) {
assertTrue(status.isOk());
latch.countDown();
}
});
latch.await();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(1, this.logManager.getLastLogIndex());
assertEquals(entry, this.logManager.getEntry(1));
assertEquals(1, this.logManager.getLastLogIndex(true));
LogId lastLogId = this.logManager.getLastLogId(true);
assertEquals(1, lastLogId.getIndex());
lastLogId = this.logManager.getLastLogId(false);
assertEquals(1, lastLogId.getIndex());
assertTrue(this.logManager.checkConsistency().isOk());
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class LogManagerTest method mockAddEntries.
private List<LogEntry> mockAddEntries() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final List<LogEntry> mockEntries = TestUtils.mockEntries(10);
this.logManager.appendEntries(new ArrayList<>(mockEntries), new LogManager.StableClosure() {
@Override
public void run(final Status status) {
assertTrue(status.isOk());
latch.countDown();
}
});
latch.await();
return mockEntries;
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class LogManagerTest method testSetAppliedId2.
@Test
public void testSetAppliedId2() throws Exception {
final List<LogEntry> mockEntries = mockAddEntries();
for (int i = 0; i < 10; i++) {
// it's in memory
assertEquals(mockEntries.get(i), this.logManager.getEntryFromMemory(i + 1));
}
// waiting for setDiskId()
Thread.sleep(200);
this.logManager.setAppliedId(new LogId(10, 10));
for (int i = 0; i < 10; i++) {
assertNull(this.logManager.getEntryFromMemory(i + 1));
assertEquals(mockEntries.get(i), this.logManager.getEntry(i + 1));
}
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class LogManagerTest method testAppendEntries.
@Test
public void testAppendEntries() throws Exception {
final List<LogEntry> mockEntries = mockAddEntries();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(10, this.logManager.getLastLogIndex());
for (int i = 0; i < 10; i++) {
assertEquals(mockEntries.get(i), this.logManager.getEntry(i + 1));
}
assertEquals(10, this.logManager.getLastLogIndex(true));
LogId lastLogId = this.logManager.getLastLogId(true);
assertEquals(10, lastLogId.getIndex());
lastLogId = this.logManager.getLastLogId(false);
assertEquals(10, lastLogId.getIndex());
assertTrue(this.logManager.checkConsistency().isOk());
}
Aggregations