Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix typo #1125

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public void testEmptyState() {
assertEquals(1, this.logStorage.getFirstLogIndex());
assertEquals(0, this.logStorage.getLastLogIndex());
assertNull(this.logStorage.getEntry(100));
assertEquals(0, this.logStorage.getTerm(100));
}

@Test
Expand All @@ -96,18 +95,27 @@ public void testAddOneEntryState() {

assertEquals(100, this.logStorage.getFirstLogIndex());
assertEquals(100, this.logStorage.getLastLogIndex());
Assert.assertEquals(entry1, this.logStorage.getEntry(100));
assertEquals(1, this.logStorage.getTerm(100));
LogEntry logEntry1 = this.logStorage.getEntry(100);
assertNotNull(logEntry1);
assertEquals(entry1, logEntry1);
assertEquals(1, logEntry1.getId().getTerm());

final LogEntry entry2 = TestUtils.mockEntry(200, 2);
assertTrue(this.logStorage.appendEntry(entry2));

assertEquals(100, this.logStorage.getFirstLogIndex());
assertEquals(200, this.logStorage.getLastLogIndex());
Assert.assertEquals(entry1, this.logStorage.getEntry(100));
Assert.assertEquals(entry2, this.logStorage.getEntry(200));
assertEquals(1, this.logStorage.getTerm(100));
assertEquals(2, this.logStorage.getTerm(200));

logEntry1 = this.logStorage.getEntry(100);
final LogEntry logEntry2 = this.logStorage.getEntry(200);
assertNotNull(logEntry1);
assertNotNull(logEntry2);

Assert.assertEquals(entry1, logEntry1);
Assert.assertEquals(entry2, logEntry2);

assertEquals(1, logEntry1.getId().getTerm());
assertEquals(2, logEntry2.getId().getTerm());
}

@Test
Expand Down Expand Up @@ -149,10 +157,10 @@ public void testAddManyEntries() {
assertEquals(0, this.logStorage.getFirstLogIndex());
assertEquals(9, this.logStorage.getLastLogIndex());
for (int i = 0; i < 10; i++) {
assertEquals(i, this.logStorage.getTerm(i));
final LogEntry entry = this.logStorage.getEntry(i);
assertNotNull(entry);
assertEquals(entries.get(i), entry);
final LogEntry logEntry = this.logStorage.getEntry(i);
flaymes marked this conversation as resolved.
Show resolved Hide resolved
assertNotNull(logEntry);
assertEquals(entries.get(i), logEntry);
assertEquals(i, logEntry.getId().getTerm());
}
}

Expand All @@ -162,7 +170,9 @@ public void testReset() {
this.logStorage.reset(5);
assertEquals(5, this.logStorage.getFirstLogIndex());
assertEquals(5, this.logStorage.getLastLogIndex());
assertEquals(5, this.logStorage.getTerm(5));
final LogEntry logEntry = this.logStorage.getEntry(5);
assertNotNull(logEntry);
assertEquals(5, logEntry.getId().getTerm());
}

@Test
Expand All @@ -187,7 +197,7 @@ public void testTruncatePrefix() throws Exception {
}

@Test
public void testAppendMantyLargeEntries() {
public void testAppendManyLargeEntries() {
final long start = Utils.monotonicMs();
final int totalLogs = 100000;
final int logSize = 16 * 1024;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void run(final Status status) {
}

@Test
public void testAppendEntresConflicts() throws Exception {
public void testAppendEntriesConflicts() throws Exception {
//Append 0-10
List<LogEntry> mockEntries = TestUtils.mockEntries(10);
for (int i = 0; i < 10; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public void testEmptyState() {
assertEquals(1, this.logStorage.getFirstLogIndex());
assertEquals(0, this.logStorage.getLastLogIndex());
assertNull(this.logStorage.getEntry(100));
assertEquals(0, this.logStorage.getTerm(100));
}

@Test
Expand All @@ -95,17 +94,27 @@ public void testAddOneEntryState() {
assertEquals(100, this.logStorage.getFirstLogIndex());
assertEquals(100, this.logStorage.getLastLogIndex());
Assert.assertEquals(entry1, this.logStorage.getEntry(100));
assertEquals(1, this.logStorage.getTerm(100));
LogEntry logEntry1 = this.logStorage.getEntry(100);
assertNotNull(logEntry1);
assertEquals(entry1, logEntry1);
assertEquals(1, logEntry1.getId().getTerm());

final LogEntry entry2 = TestUtils.mockEntry(200, 2);
assertTrue(this.logStorage.appendEntry(entry2));

assertEquals(100, this.logStorage.getFirstLogIndex());
assertEquals(200, this.logStorage.getLastLogIndex());
Assert.assertEquals(entry1, this.logStorage.getEntry(100));
Assert.assertEquals(entry2, this.logStorage.getEntry(200));
assertEquals(1, this.logStorage.getTerm(100));
assertEquals(2, this.logStorage.getTerm(200));

logEntry1 = this.logStorage.getEntry(100);
final LogEntry logEntry2 = this.logStorage.getEntry(200);
assertNotNull(logEntry1);
assertNotNull(logEntry2);

Assert.assertEquals(entry1, logEntry1);
Assert.assertEquals(entry2, logEntry2);

assertEquals(1, logEntry1.getId().getTerm());
assertEquals(2, logEntry2.getId().getTerm());
}

@Test
Expand Down Expand Up @@ -147,8 +156,8 @@ public void testAddManyEntries() {
assertEquals(0, this.logStorage.getFirstLogIndex());
assertEquals(9, this.logStorage.getLastLogIndex());
for (int i = 0; i < 10; i++) {
assertEquals(i, this.logStorage.getTerm(i));
final LogEntry entry = this.logStorage.getEntry(i);
assertEquals(i, entry.getId().getTerm());
assertNotNull(entry);
assertEquals(entries.get(i), entry);
}
Expand All @@ -160,7 +169,9 @@ public void testReset() {
this.logStorage.reset(5);
assertEquals(5, this.logStorage.getFirstLogIndex());
assertEquals(5, this.logStorage.getLastLogIndex());
assertEquals(5, this.logStorage.getTerm(5));
final LogEntry logEntry = this.logStorage.getEntry(5);
assertNotNull(logEntry);
assertEquals(5, logEntry.getId().getTerm());
}

@Test
Expand All @@ -181,7 +192,7 @@ public void testTruncatePrefix() {
}

@Test
public void testAppendMantyLargeEntries() {
public void testAppendManyLargeEntries() {
final long start = Utils.monotonicMs();
final int totalLogs = 100000;
final int logSize = 16 * 1024;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ public LogEntry getEntry(final long index) {

@Override
public long getTerm(final long index) {
if (index >= this.thresholdIndex) {
return this.newLogStorage.getTerm(index);
}
if (isOldStorageExist()) {
return this.oldLogStorage.getTerm(index);
final LogEntry entry = getEntry(index);
if (entry != null) {
return entry.getId().getTerm();
}
return 0;
}
Expand Down
Loading