use of org.apache.ignite.raft.jraft.entity.LogId in project ignite-3 by apache.
the class BaseLogEntryCodecFactoryTest method testEncodeDecodeWithoutData.
@Test
public void testEncodeDecodeWithoutData() {
LogEntry entry = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_NO_OP);
entry.setId(new LogId(100, 3));
entry.setPeers(Arrays.asList(new PeerId("localhost", 99, 1), new PeerId("localhost", 100, 2)));
assertNull(entry.getData());
assertNull(entry.getOldPeers());
byte[] content = this.encoder.encode(entry);
assertNotNull(content);
assertTrue(content.length > 0);
LogEntry nentry = this.decoder.decode(content);
assertNotNull(nentry);
assertEquals(100, nentry.getId().getIndex());
assertEquals(3, nentry.getId().getTerm());
assertEquals(EnumOutter.EntryType.ENTRY_TYPE_NO_OP, nentry.getType());
assertEquals(2, nentry.getPeers().size());
assertEquals("localhost:99:1", nentry.getPeers().get(0).toString());
assertEquals("localhost:100:2", nentry.getPeers().get(1).toString());
assertNull(nentry.getData());
assertNull(nentry.getOldPeers());
}
use of org.apache.ignite.raft.jraft.entity.LogId in project ignite-3 by apache.
the class LogEntryCodecPerfTest method testEncodeDecode.
private void testEncodeDecode(final LogEntryEncoder encoder, final LogEntryDecoder decoder, final CyclicBarrier barrier) throws Exception {
ByteBuffer buf = ByteBuffer.wrap(DATA);
LogEntry entry = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_NO_OP);
entry.setData(buf);
entry.setPeers(Arrays.asList(new PeerId("localhost", 99, 1), new PeerId("localhost", 100, 2)));
if (barrier != null) {
barrier.await();
}
for (int i = 0; i < TIMES; i++) {
entry.setId(new LogId(i, i));
byte[] content = encoder.encode(entry);
assert (content.length > 0);
this.logSize.addAndGet(content.length);
LogEntry nLog = decoder.decode(content);
assertEquals(2, nLog.getPeers().size());
assertArrayEquals(DATA, nLog.getData().array());
assertEquals(i, nLog.getId().getIndex());
assertEquals(i, nLog.getId().getTerm());
}
if (barrier != null) {
barrier.await();
}
}
use of org.apache.ignite.raft.jraft.entity.LogId in project ignite-3 by apache.
the class LogManagerTest method testSetAppliedId.
@Test
public void testSetAppliedId() 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.LogId in project ignite-3 by apache.
the class LogManagerTest method testEmptyState.
@Test
public void testEmptyState() {
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(0, this.logManager.getLastLogIndex());
assertNull(this.logManager.getEntry(1));
assertEquals(0, this.logManager.getLastLogIndex(true));
LogId lastLogId = this.logManager.getLastLogId(true);
assertEquals(0, lastLogId.getIndex());
lastLogId = this.logManager.getLastLogId(false);
assertEquals(0, lastLogId.getIndex());
assertTrue(this.logManager.checkConsistency().isOk());
}
use of org.apache.ignite.raft.jraft.entity.LogId in project ignite-3 by apache.
the class LogManagerTest method testAppendEntriesBeforeAppliedIndex.
@Test
public void testAppendEntriesBeforeAppliedIndex() throws Exception {
// Append 0-10
List<LogEntry> mockEntries = TestUtils.mockEntries(10);
for (int i = 0; i < 10; i++) {
mockEntries.get(i).getId().setTerm(1);
}
final CountDownLatch latch1 = new CountDownLatch(1);
this.logManager.appendEntries(new ArrayList<>(mockEntries), new LogManager.StableClosure() {
@Override
public void run(final Status status) {
assertTrue(status.isOk());
latch1.countDown();
}
});
latch1.await();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(10, this.logManager.getLastLogIndex());
// waiting for setDiskId()
Thread.sleep(200);
this.logManager.setAppliedId(new LogId(9, 1));
for (int i = 0; i < 10; i++) {
assertNull(this.logManager.getEntryFromMemory(i));
}
// append 1-10 again, already applied, returns OK.
final CountDownLatch latch2 = new CountDownLatch(1);
mockEntries = TestUtils.mockEntries(10);
mockEntries.remove(0);
this.logManager.appendEntries(new ArrayList<>(mockEntries), new LogManager.StableClosure() {
@Override
public void run(final Status status) {
assertTrue(status.isOk());
latch2.countDown();
}
});
latch2.await();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(10, this.logManager.getLastLogIndex());
}
Aggregations