use of com.alipay.sofa.jraft.entity.LogId in project sofa-jraft by sofastack.
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++) {
Assert.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());
}
use of com.alipay.sofa.jraft.entity.LogId in project sofa-jraft by sofastack.
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
Assert.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));
Assert.assertEquals(mockEntries.get(i), this.logManager.getEntry(i + 1));
}
}
use of com.alipay.sofa.jraft.entity.LogId in project sofa-jraft by sofastack.
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());
Assert.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 com.alipay.sofa.jraft.entity.LogId in project sofa-jraft by sofastack.
the class LogManagerImpl method setDiskId.
private void setDiskId(final LogId id) {
if (id == null) {
return;
}
LogId clearId;
this.writeLock.lock();
try {
if (id.compareTo(this.diskId) < 0) {
return;
}
this.diskId = id;
clearId = this.diskId.compareTo(this.appliedId) <= 0 ? this.diskId : this.appliedId;
} finally {
this.writeLock.unlock();
}
if (clearId != null) {
clearMemoryLogs(clearId);
}
}
use of com.alipay.sofa.jraft.entity.LogId in project sofa-jraft by sofastack.
the class LogManagerImpl method setAppliedId.
@Override
public void setAppliedId(final LogId appliedId) {
LogId clearId;
this.writeLock.lock();
try {
if (appliedId.compareTo(this.appliedId) < 0) {
return;
}
this.appliedId = appliedId.copy();
clearId = this.diskId.compareTo(this.appliedId) <= 0 ? this.diskId : this.appliedId;
} finally {
this.writeLock.unlock();
}
if (clearId != null) {
clearMemoryLogs(clearId);
}
}
Aggregations