lianetm commented on code in PR #16200:
URL: https://github.com/apache/kafka/pull/16200#discussion_r1636933032


##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/HeartbeatRequestManagerTest.java:
##########
@@ -86,91 +79,169 @@
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-
 public class HeartbeatRequestManagerTest {
     private static final String DEFAULT_GROUP_ID = "groupId";
-    private static final String CONSUMER_COORDINATOR_METRICS = 
"consumer-coordinator-metrics";
+    private static final String DEFAULT_REMOTE_ASSIGNOR = "uniform";
+    private static final String DEFAULT_GROUP_INSTANCE_ID = 
"group-instance-id";
+    private static final int DEFAULT_HEARTBEAT_INTERVAL_MS = 1000;
+    private static final int DEFAULT_MAX_POLL_INTERVAL_MS = 10000;
+    private static final long DEFAULT_RETRY_BACKOFF_MS = 80;
+    private static final long DEFAULT_RETRY_BACKOFF_MAX_MS = 1000;
+    private static final double DEFAULT_HEARTBEAT_JITTER_MS = 0.0;
 
-    private ConsumerTestBuilder testBuilder;
     private Time time;
     private Timer pollTimer;
     private CoordinatorRequestManager coordinatorRequestManager;
     private SubscriptionState subscriptions;
     private Metadata metadata;
     private HeartbeatRequestManager heartbeatRequestManager;
+    private HeartbeatRequestManager heartbeatRequestManager1;
     private MembershipManager membershipManager;
+    private MembershipManager membershipManager1;
     private HeartbeatRequestManager.HeartbeatRequestState 
heartbeatRequestState;
+    private HeartbeatRequestManager.HeartbeatRequestState 
heartbeatRequestState1;
     private HeartbeatRequestManager.HeartbeatState heartbeatState;
     private final String memberId = "member-id";
     private final int memberEpoch = 1;
     private BackgroundEventHandler backgroundEventHandler;
-    private Metrics metrics;
+    private RequestManagers requestManagers;
+    private LogContext logContext;
+    private ConsumerConfig config;
 
     @BeforeEach
     public void setUp() {
-        setUp(ConsumerTestBuilder.createDefaultGroupInformation());
-    }
-
-    private void setUp(Optional<ConsumerTestBuilder.GroupInformation> 
groupInfo) {
-        testBuilder = new ConsumerTestBuilder(groupInfo, true, false);
-        time = testBuilder.time;
-        coordinatorRequestManager = 
testBuilder.coordinatorRequestManager.orElseThrow(IllegalStateException::new);
-        heartbeatRequestManager = 
testBuilder.heartbeatRequestManager.orElseThrow(IllegalStateException::new);
-        heartbeatRequestState = 
testBuilder.heartbeatRequestState.orElseThrow(IllegalStateException::new);
-        heartbeatState = 
testBuilder.heartbeatState.orElseThrow(IllegalStateException::new);
-        backgroundEventHandler = testBuilder.backgroundEventHandler;
-        subscriptions = testBuilder.subscriptions;
-        membershipManager = 
testBuilder.membershipManager.orElseThrow(IllegalStateException::new);
-        metadata = testBuilder.metadata;
-        metrics = new Metrics(time);
+        this.time = new MockTime();
+        Metrics metrics = new Metrics();
+        this.logContext = new LogContext();
+        this.pollTimer = mock(Timer.class);
+        this.coordinatorRequestManager = mock(CoordinatorRequestManager.class);
+        this.heartbeatRequestState = mock(HeartbeatRequestState.class);
+        this.heartbeatState = mock(HeartbeatState.class);

Review Comment:
   turning this into a mock requires a little bit more work I would expect. 
Several tests assert on this request state (because it's mainly the internal 
component that dictates the timing of the heartbeats). Also I notice we end up 
having this mock and another request state that holds an actual instance 
(heartbeatRequestState1). So I wonder if this HeartbeatRequestState only is 
maybe a sensible usage for a spy in this test?
   



-- 
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-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to