Skip to content

Commit

Permalink
feat: fix typo (sofastack#1125)
Browse files Browse the repository at this point in the history
* (typo) fix some typo

* (chore) adjust the test code order and method of obtaining term id

* fix typo

* chore: update getTerm calls
  • Loading branch information
flaymes authored Jul 9, 2024
1 parent d82b30b commit 38c0867
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
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);
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

0 comments on commit 38c0867

Please sign in to comment.