You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "akatona84 (via GitHub)" <gi...@apache.org> on 2024/03/27 15:36:29 UTC
Re: [PR] KAFKA-15915: Flaky ProducerIdManagerTest error injection fix [kafka]
akatona84 commented on code in PR #15605:
URL: https://github.com/apache/kafka/pull/15605#discussion_r1541357369
##########
core/src/test/scala/unit/kafka/coordinator/transaction/ProducerIdManagerTest.scala:
##########
@@ -38,19 +38,57 @@ import org.mockito.Mockito.{mock, when}
import java.util.concurrent.{CountDownLatch, Executors, TimeUnit}
import java.util.concurrent.atomic.AtomicBoolean
import scala.collection.mutable
-import scala.util.{Failure, Success}
+import scala.util.{Failure, Success, Try}
class ProducerIdManagerTest {
var brokerToController: NodeToControllerChannelManager = mock(classOf[NodeToControllerChannelManager])
val zkClient: KafkaZkClient = mock(classOf[KafkaZkClient])
+ case class ErrorCount(error: Errors, var repeat: Int)
+
+ object ErrorCount {
+ val INDEFINITE: Int = -1
+
+ def indefinitely(error: Errors): ErrorCount = {
+ ErrorCount(error, INDEFINITE)
+ }
+ }
+
+ class ErrorQueue(initialErrorCounts: ErrorCount*) {
+ private val queue: mutable.Queue[ErrorCount] = mutable.Queue.empty ++ initialErrorCounts
+
+ def takeError(): Errors = queue.synchronized {
+ while (queue.head.repeat == 0) {
+ queue.dequeue()
+ }
+ if (queue.head.repeat > 0) {
+ queue.head.repeat -= 1
+ }
+ queue.head.error
+ }
+
+ def peekError(): Errors = queue.synchronized {
+ queue.head.error
+ }
+
+ def clearProcessedError(): Unit = {
+ TestUtils.waitUntilTrue(() =>
+ queue.synchronized {
+ queue.head.repeat == 0
+ }, "error wasn't processed")
+ queue.synchronized {
+ queue.dequeue()
Review Comment:
no, but doesn't matter any more. I was able to get rid of the maybeRequestNextBlock override completely and the whole "mocking" became much more easier.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org