-
Notifications
You must be signed in to change notification settings - Fork 15.1k
MINOR: Cleanup TestUtils.scala #22091
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
base: trunk
Are you sure you want to change the base?
Changes from 2 commits
9a7a276
36d3fb4
64cd0cb
7060354
5e89ce1
30a484d
6a0dfd2
c2ccb7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1229,7 +1229,7 @@ class LogCleanerTest extends Logging { | |
|
|
||
| // the last (active) segment has just one message | ||
|
|
||
| def distinctValuesBySegment = log.logSegments.asScala.map(s => s.log.records.asScala.map(record => TestUtils.readString(record.value)).toSet.size).toSeq | ||
| def distinctValuesBySegment = log.logSegments.asScala.map(s => s.log.records.asScala.map(record => LogTestUtils.readString(record.value)).toSet.size).toSeq | ||
|
|
||
| val distinctValuesBySegmentBeforeClean = distinctValuesBySegment | ||
| assertTrue(distinctValuesBySegment.reverse.tail.forall(_ > N), | ||
|
|
@@ -1927,7 +1927,7 @@ class LogCleanerTest extends Logging { | |
|
|
||
| for (segment <- log.logSegments.asScala; batch <- segment.log.batches.asScala; record <- batch.asScala) { | ||
| assertTrue(record.hasMagic(batch.magic)) | ||
| val value = TestUtils.readString(record.value).toLong | ||
| val value = LogTestUtils.readString(record.value).toLong | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. val value = StandardCharsets.UTF_8.decode(record.value()).toString.toLong |
||
| assertEquals(record.offset, value) | ||
| } | ||
| } | ||
|
|
@@ -1947,7 +1947,7 @@ class LogCleanerTest extends Logging { | |
|
|
||
| for (logEntry <- records.records.asScala) { | ||
| val offset = logEntry.offset | ||
| val value = TestUtils.readString(logEntry.value).toLong | ||
| val value = LogTestUtils.readString(logEntry.value).toLong | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. val value = StandardCharsets.UTF_8.decode(logEntry.value()).toString.toLong |
||
| assertEquals(offset, value) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ package kafka.log | |
|
|
||
| import java.io.File | ||
| import java.util.Properties | ||
| import kafka.utils.TestUtils | ||
| import org.apache.kafka.common.Uuid | ||
| import org.apache.kafka.common.compress.Compression | ||
| import org.apache.kafka.common.record.internal.{ControlRecordType, EndTransactionMarker, FileRecords, MemoryRecords, RecordBatch, SimpleRecord} | ||
|
|
@@ -38,9 +37,11 @@ import org.apache.kafka.server.storage.log.FetchIsolation | |
| import org.apache.kafka.server.util.Scheduler | ||
| import org.apache.kafka.storage.internals.log.LogConfig.{DEFAULT_REMOTE_LOG_COPY_DISABLE_CONFIG, DEFAULT_REMOTE_LOG_DELETE_ON_DISABLE_CONFIG} | ||
| import org.apache.kafka.common.message.AbortedTxn | ||
| import org.apache.kafka.storage.internals.log.{AppendOrigin, FetchDataInfo, LazyIndex, LogAppendInfo, LogConfig, LogDirFailureChannel, LogFileUtils, LogOffsetsListener, LogSegment, ProducerStateManager, ProducerStateManagerConfig, TransactionIndex, VerificationGuard, UnifiedLog} | ||
| import org.apache.kafka.storage.internals.log.{AppendOrigin, FetchDataInfo, LazyIndex, LogAppendInfo, LogConfig, LogDirFailureChannel, LogFileUtils, LogOffsetsListener, LogSegment, ProducerStateManager, ProducerStateManagerConfig, TransactionIndex, UnifiedLog, VerificationGuard} | ||
| import org.apache.kafka.storage.log.metrics.BrokerTopicStats | ||
|
|
||
| import java.nio.ByteBuffer | ||
| import java.nio.charset.Charset | ||
| import scala.jdk.CollectionConverters._ | ||
| import scala.jdk.OptionConverters.RichOption | ||
|
|
||
|
|
@@ -202,7 +203,7 @@ object LogTestUtils { | |
| for (logSegment <- log.logSegments.asScala; | ||
| batch <- logSegment.log.batches.asScala if !batch.isControlBatch; | ||
| record <- batch.asScala if record.hasValue && record.hasKey) | ||
| yield TestUtils.readString(record.key).toLong | ||
| yield readString(record.key).toLong | ||
| } | ||
|
|
||
| def recoverAndCheck(logDir: File, config: LogConfig, expectedKeys: Iterable[Long], brokerTopicStats: BrokerTopicStats, time: Time, scheduler: Scheduler): UnifiedLog = { | ||
|
|
@@ -308,4 +309,16 @@ object LogTestUtils { | |
| sequence += numRecords | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Translate the given buffer into a string | ||
| * | ||
| * @param buffer The buffer to translate | ||
| * @param encoding The encoding to use in translating bytes to characters | ||
| */ | ||
| def readString(buffer: ByteBuffer, encoding: String = Charset.defaultCharset.toString): String = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks a bit verbose. Please see my other comments for suggestions on how to remove it. |
||
| val bytes = new Array[Byte](buffer.remaining) | ||
| buffer.get(bytes) | ||
| new String(bytes, encoding) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.