-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
KAFKA-14961: harden DefaultBackgroundThreadTest.testStartupAndTearDown test #13664
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -28,6 +28,7 @@ | |||
import org.apache.kafka.common.utils.LogContext; | ||||
import org.apache.kafka.common.utils.MockTime; | ||||
import org.apache.kafka.common.utils.Time; | ||||
import org.apache.kafka.test.TestUtils; | ||||
import org.junit.jupiter.api.BeforeEach; | ||||
import org.junit.jupiter.api.Test; | ||||
import org.mockito.Mockito; | ||||
|
@@ -42,8 +43,8 @@ | |||
import static org.apache.kafka.clients.consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG; | ||||
import static org.apache.kafka.clients.consumer.ConsumerConfig.RETRY_BACKOFF_MS_CONFIG; | ||||
import static org.apache.kafka.clients.consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG; | ||||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||||
import static org.mockito.ArgumentMatchers.anyLong; | ||||
import static org.mockito.Mockito.mock; | ||||
import static org.mockito.Mockito.times; | ||||
|
@@ -89,11 +90,14 @@ public void setup() { | |||
} | ||||
|
||||
@Test | ||||
public void testStartupAndTearDown() { | ||||
public void testStartupAndTearDown() throws InterruptedException { | ||||
when(coordinatorManager.poll(anyLong())).thenReturn(mockPollCoordinatorResult()); | ||||
when(commitManager.poll(anyLong())).thenReturn(mockPollCommitResult()); | ||||
DefaultBackgroundThread backgroundThread = mockBackgroundThread(); | ||||
backgroundThread.start(); | ||||
assertTrue(backgroundThread.isRunning()); | ||||
TestUtils.waitForCondition(backgroundThread::isRunning, "Failed awaiting for the background thread to be running"); | ||||
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 will wait up to 15s, the default timeout. It should be good enough! |
||||
backgroundThread.close(); | ||||
assertFalse(backgroundThread.isRunning()); | ||||
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. Is it possible that 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. Thanks for the review @kirktrue It is guaranteed that is running will be false when kafka/clients/src/main/java/org/apache/kafka/clients/consumer/internals/DefaultBackgroundThread.java Line 230 in 6c3e82f
|
||||
} | ||||
|
||||
@Test | ||||
|
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.
These stubs call where missing thus causing the NPE as indicated in the JIRA