|
|
@ -38,9 +38,8 @@ class LogSegmentTest { |
|
|
|
/* create a segment with the given base offset */ |
|
|
|
/* create a segment with the given base offset */ |
|
|
|
def createSegment(offset: Long, |
|
|
|
def createSegment(offset: Long, |
|
|
|
indexIntervalBytes: Int = 10, |
|
|
|
indexIntervalBytes: Int = 10, |
|
|
|
maxSegmentMs: Int = Int.MaxValue, |
|
|
|
|
|
|
|
time: Time = Time.SYSTEM): LogSegment = { |
|
|
|
time: Time = Time.SYSTEM): LogSegment = { |
|
|
|
val seg = LogUtils.createSegment(offset, logDir, indexIntervalBytes, maxSegmentMs, time) |
|
|
|
val seg = LogUtils.createSegment(offset, logDir, indexIntervalBytes, time) |
|
|
|
segments += seg |
|
|
|
segments += seg |
|
|
|
seg |
|
|
|
seg |
|
|
|
} |
|
|
|
} |
|
|
@ -163,10 +162,10 @@ class LogSegmentTest { |
|
|
|
|
|
|
|
|
|
|
|
val maxSegmentMs = 300000 |
|
|
|
val maxSegmentMs = 300000 |
|
|
|
val time = new MockTime |
|
|
|
val time = new MockTime |
|
|
|
val seg = createSegment(0, maxSegmentMs = maxSegmentMs, time = time) |
|
|
|
val seg = createSegment(0, time = time) |
|
|
|
seg.close() |
|
|
|
seg.close() |
|
|
|
|
|
|
|
|
|
|
|
val reopened = createSegment(0, maxSegmentMs = maxSegmentMs, time = time) |
|
|
|
val reopened = createSegment(0, time = time) |
|
|
|
assertEquals(0, seg.timeIndex.sizeInBytes) |
|
|
|
assertEquals(0, seg.timeIndex.sizeInBytes) |
|
|
|
assertEquals(0, seg.offsetIndex.sizeInBytes) |
|
|
|
assertEquals(0, seg.offsetIndex.sizeInBytes) |
|
|
|
|
|
|
|
|
|
|
@ -176,24 +175,21 @@ class LogSegmentTest { |
|
|
|
assertFalse(reopened.timeIndex.isFull) |
|
|
|
assertFalse(reopened.timeIndex.isFull) |
|
|
|
assertFalse(reopened.offsetIndex.isFull) |
|
|
|
assertFalse(reopened.offsetIndex.isFull) |
|
|
|
|
|
|
|
|
|
|
|
assertFalse(reopened.shouldRoll(messagesSize = 1024, |
|
|
|
var rollParams = RollParams(maxSegmentMs, maxSegmentBytes = Int.MaxValue, RecordBatch.NO_TIMESTAMP, |
|
|
|
maxTimestampInMessages = RecordBatch.NO_TIMESTAMP, |
|
|
|
maxOffsetInMessages = 100L, messagesSize = 1024, time.milliseconds()) |
|
|
|
maxOffsetInMessages = 100L, |
|
|
|
assertFalse(reopened.shouldRoll(rollParams)) |
|
|
|
now = time.milliseconds())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The segment should not be rolled even if maxSegmentMs has been exceeded |
|
|
|
// The segment should not be rolled even if maxSegmentMs has been exceeded |
|
|
|
time.sleep(maxSegmentMs + 1) |
|
|
|
time.sleep(maxSegmentMs + 1) |
|
|
|
assertEquals(maxSegmentMs + 1, reopened.timeWaitedForRoll(time.milliseconds(), RecordBatch.NO_TIMESTAMP)) |
|
|
|
assertEquals(maxSegmentMs + 1, reopened.timeWaitedForRoll(time.milliseconds(), RecordBatch.NO_TIMESTAMP)) |
|
|
|
assertFalse(reopened.shouldRoll(messagesSize = 1024, |
|
|
|
rollParams = RollParams(maxSegmentMs, maxSegmentBytes = Int.MaxValue, RecordBatch.NO_TIMESTAMP, |
|
|
|
maxTimestampInMessages = RecordBatch.NO_TIMESTAMP, |
|
|
|
maxOffsetInMessages = 100L, messagesSize = 1024, time.milliseconds()) |
|
|
|
maxOffsetInMessages = 100L, |
|
|
|
assertFalse(reopened.shouldRoll(rollParams)) |
|
|
|
now = time.milliseconds())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// But we should still roll the segment if we cannot fit the next offset |
|
|
|
// But we should still roll the segment if we cannot fit the next offset |
|
|
|
assertTrue(reopened.shouldRoll(messagesSize = 1024, |
|
|
|
rollParams = RollParams(maxSegmentMs, maxSegmentBytes = Int.MaxValue, RecordBatch.NO_TIMESTAMP, |
|
|
|
maxTimestampInMessages = RecordBatch.NO_TIMESTAMP, |
|
|
|
maxOffsetInMessages = Int.MaxValue.toLong + 200L, messagesSize = 1024, time.milliseconds()) |
|
|
|
maxOffsetInMessages = Int.MaxValue.toLong + 200, |
|
|
|
assertTrue(reopened.shouldRoll(rollParams)) |
|
|
|
now = time.milliseconds())) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|