Skip to content

Commit 2f3b57b

Browse files
committed
Updated tests
1 parent 32d3367 commit 2f3b57b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

core/common/test/unsafe/UnsafeBufferOperationsIterationTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ class UnsafeBufferOperationsIterationTest {
6262
fun acquireDataDuringIteration() {
6363
val buffer = Buffer().also { it.writeString("hello buffer") }
6464

65+
val expectedSize = buffer.size
66+
6567
UnsafeBufferOperations.iterate(buffer) { ctx, head ->
6668
assertNotNull(head)
6769

6870
ctx.withData(head) { data, startIndex, endIndex ->
6971
assertEquals("hello buffer", data.decodeToString(startIndex, endIndex))
7072
}
7173
}
74+
75+
assertEquals(expectedSize, buffer.size)
7276
}
7377

7478
@Test

core/common/test/unsafe/UnsafeBufferOperationsReadTest.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,21 @@ class UnsafeBufferOperationsReadTest {
105105

106106
@Test
107107
fun readFromTheSegmentEndUsingCtx() {
108-
val buffer = Buffer().apply { write(ByteArray(9000) { 0xff.toByte() }) }
109-
buffer.skip(8190)
108+
val segmentSize = UnsafeBufferOperations.maxSafeWriteCapacity
109+
val extraBytesCount = 128
110+
val bytesToSkip = segmentSize - 2
111+
112+
val buffer = Buffer().apply { write(ByteArray(segmentSize + extraBytesCount) { 0xff.toByte() }) }
113+
buffer.skip(bytesToSkip.toLong())
110114
val head = buffer.head!!
111-
assertEquals(8190, head.pos)
115+
assertEquals(bytesToSkip, head.pos)
112116

113117
UnsafeBufferOperations.readFromHead(buffer) { _, seg ->
114118
assertEquals(2, seg.size)
115119
2
116120
}
117121

118-
assertEquals(9000 - 8192, buffer.size.toInt())
122+
assertEquals(extraBytesCount, buffer.size.toInt())
119123
}
120124

121125
@Test

0 commit comments

Comments
 (0)