Skip to content

Commit ce8800c

Browse files
committed
fix failed UT
1 parent c455b2f commit ce8800c

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ CorruptionPolicy getLogCorruptionPolicy() {
353353
return CorruptionPolicy.get(storage, RaftStorage::getLogCorruptionPolicy);
354354
}
355355

356-
void appendToOpenSegment(LogEntryProto entry, Op op) {
356+
void appendToOpenSegment(LogEntryProto entry, Op op, boolean verifyEntryIndex) {
357357
Preconditions.assertTrue(isOpen(), "The log segment %s is not open for append", this);
358-
append(true, entry, op, false);
358+
append(true, entry, op, verifyEntryIndex);
359359
}
360360

361361
public static final String APPEND_RECORD = LogSegment.class.getSimpleName() + ".append";

ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ void appendEntry(LogEntryProto entry, LogSegment.Op op) {
632632
// SegmentedRaftLog does the segment creation/rolling work. Here we just
633633
// simply append the entry into the open segment.
634634
Objects.requireNonNull(openSegment, "openSegment == null");
635-
openSegment.appendToOpenSegment(entry, op);
635+
openSegment.appendToOpenSegment(entry, op, false);
636636
}
637637

638638
/**

ratis-test/src/test/java/org/apache/ratis/server/raftlog/segmented/TestLogSegment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void testAppendEntries() throws Exception {
206206
SimpleOperation op = new SimpleOperation("m" + i);
207207
LogEntryProto entry = LogProtoUtils.toLogEntryProto(op.getLogEntryContent(), term, i++ + start);
208208
size += getEntrySize(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE);
209-
segment.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE);
209+
segment.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE, true);
210210
}
211211

212212
Assertions.assertTrue(segment.getTotalFileSize() >= max);
@@ -238,18 +238,18 @@ public void testAppendWithGap() throws Exception {
238238
final StateMachineLogEntryProto m = op.getLogEntryContent();
239239
try {
240240
LogEntryProto entry = LogProtoUtils.toLogEntryProto(m, 0, 1001);
241-
segment.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE);
241+
segment.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE, true);
242242
Assertions.fail("should fail since the entry's index needs to be 1000");
243243
} catch (IllegalStateException e) {
244244
// the exception is expected.
245245
}
246246

247247
LogEntryProto entry = LogProtoUtils.toLogEntryProto(m, 0, 1000);
248-
segment.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE);
248+
segment.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE, true);
249249

250250
try {
251251
entry = LogProtoUtils.toLogEntryProto(m, 0, 1002);
252-
segment.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE);
252+
segment.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE, true);
253253
Assertions.fail("should fail since the entry's index needs to be 1001");
254254
} catch (IllegalStateException e) {
255255
// the exception is expected.
@@ -264,7 +264,7 @@ public void testTruncate() throws Exception {
264264
for (int i = 0; i < 100; i++) {
265265
LogEntryProto entry = LogProtoUtils.toLogEntryProto(
266266
new SimpleOperation("m" + i).getLogEntryContent(), term, i + start);
267-
segment.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE);
267+
segment.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE, true);
268268
}
269269

270270
// truncate an open segment (remove 1080~1099)

ratis-test/src/test/java/org/apache/ratis/server/raftlog/segmented/TestSegmentedRaftLogCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private LogSegment prepareLogSegment(long start, long end, boolean isOpen) {
6363
for (long i = start; i <= end; i++) {
6464
SimpleOperation m = new SimpleOperation("m" + i);
6565
LogEntryProto entry = LogProtoUtils.toLogEntryProto(m.getLogEntryContent(), 0, i);
66-
s.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE);
66+
s.appendToOpenSegment(entry, LogSegment.Op.WRITE_CACHE_WITHOUT_STATE_MACHINE_CACHE, true);
6767
}
6868
if (!isOpen) {
6969
s.close();

0 commit comments

Comments
 (0)