You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by js...@apache.org on 2022/04/11 20:38:12 UTC
[kafka] branch trunk updated: MINOR: Re-use counter in mocking of LogSegment.size (#12021)
This is an automated email from the ASF dual-hosted git repository.
jsancio pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new 317fff9bb0 MINOR: Re-use counter in mocking of LogSegment.size (#12021)
317fff9bb0 is described below
commit 317fff9bb05fd7c7932f481fd200e56bff761459
Author: José Armando García Sancio <js...@users.noreply.github.com>
AuthorDate: Mon Apr 11 13:37:47 2022 -0700
MINOR: Re-use counter in mocking of LogSegment.size (#12021)
When migrating from Easymock to Mockito, the mockito implemetnation
didn't have the same semantic as the Easymock implementation.
Without this fix the mocking of LogSegment.size() always returns 0 because
a new AtomicInteger was getting created for each invocation of
LogSegment.size()
Reviewers: Mickael Maison <mi...@users.noreply.github.com>
---
.../test/scala/unit/kafka/server/LogOffsetTest.scala | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/core/src/test/scala/unit/kafka/server/LogOffsetTest.scala b/core/src/test/scala/unit/kafka/server/LogOffsetTest.scala
index e143539fd4..51f75b2ded 100755
--- a/core/src/test/scala/unit/kafka/server/LogOffsetTest.scala
+++ b/core/src/test/scala/unit/kafka/server/LogOffsetTest.scala
@@ -27,6 +27,8 @@ import org.apache.kafka.common.{IsolationLevel, TopicPartition}
import org.junit.jupiter.api.Assertions._
import org.junit.jupiter.api.Test
import org.mockito.Mockito.{mock, when}
+import org.mockito.invocation.InvocationOnMock
+import org.mockito.stubbing.Answer
import java.io.File
import java.util.concurrent.atomic.AtomicInteger
@@ -258,10 +260,9 @@ class LogOffsetTest extends BaseRequestTest {
def testFetchOffsetsBeforeWithChangingSegmentSize(): Unit = {
val log: UnifiedLog = mock(classOf[UnifiedLog])
val logSegment: LogSegment = mock(classOf[LogSegment])
- when(logSegment.size).thenAnswer(_ => {
- val value = new AtomicInteger(0)
- def answer: Int = value.getAndIncrement()
- answer
+ when(logSegment.size).thenAnswer(new Answer[Int] {
+ private[this] val value = new AtomicInteger(0)
+ override def answer(invocation: InvocationOnMock): Int = value.getAndIncrement()
})
val logSegments = Seq(logSegment)
when(log.logSegments).thenReturn(logSegments)
@@ -274,13 +275,12 @@ class LogOffsetTest extends BaseRequestTest {
def testFetchOffsetsBeforeWithChangingSegments(): Unit = {
val log: UnifiedLog = mock(classOf[UnifiedLog])
val logSegment: LogSegment = mock(classOf[LogSegment])
- when(log.logSegments).thenAnswer { _ =>
- def answer = new Iterable[LogSegment] {
+ when(log.logSegments).thenReturn(
+ new Iterable[LogSegment] {
override def size = 2
- def iterator = Seq(logSegment).iterator
+ override def iterator = Seq(logSegment).iterator
}
- answer
- }
+ )
log.legacyFetchOffsetsBefore(System.currentTimeMillis, 100)
}