showuon commented on a change in pull request #9888:
URL: https://github.com/apache/kafka/pull/9888#discussion_r559301599



##########
File path: 
streams/src/test/java/org/apache/kafka/streams/integration/AdjustStreamThreadCountTest.java
##########
@@ -90,24 +91,61 @@ public void setup() {
         );
     }
 
+    private void startStreamsAndWaitForRunning(final KafkaStreams 
kafkaStreams) throws InterruptedException {
+        kafkaStreams.start();
+        waitForRunning();
+    }
+
     @After
     public void teardown() throws IOException {
+        stateTransitionHistory.clear();
         purgeLocalStreamsState(properties);
     }
 
+    private void addStreamStateChangeListener(final KafkaStreams kafkaStreams) 
{
+        // we store each new state in state transition so that we won't miss 
any state change

Review comment:
       Sure

##########
File path: 
streams/src/test/java/org/apache/kafka/streams/integration/AdjustStreamThreadCountTest.java
##########
@@ -90,24 +91,61 @@ public void setup() {
         );
     }
 
+    private void startStreamsAndWaitForRunning(final KafkaStreams 
kafkaStreams) throws InterruptedException {
+        kafkaStreams.start();
+        waitForRunning();
+    }
+
     @After
     public void teardown() throws IOException {
+        stateTransitionHistory.clear();
         purgeLocalStreamsState(properties);
     }
 
+    private void addStreamStateChangeListener(final KafkaStreams kafkaStreams) 
{
+        // we store each new state in state transition so that we won't miss 
any state change
+        kafkaStreams.setStateListener(
+            (newState, oldState) -> stateTransitionHistory.add(newState)
+        );
+    }
+
+    private void waitForRunning() throws InterruptedException {
+        waitForCondition(
+            () -> !stateTransitionHistory.isEmpty() &&
+                stateTransitionHistory.get(stateTransitionHistory.size() - 
1).equals(KafkaStreams.State.RUNNING),
+            DEFAULT_DURATION.toMillis(),
+            () -> String.format("Client did not transit to state %s in %d 
seconds",
+                KafkaStreams.State.RUNNING, DEFAULT_DURATION.toMillis() / 1000)
+        );
+    }
+
+    // verify if state change from "before" state into "after" state
+    private boolean hasStateTransition(final KafkaStreams.State before, final 
KafkaStreams.State after) {
+        final int historySize = stateTransitionHistory.size();
+        // should have at least 2 states in history

Review comment:
       Sure




----------------------------------------------------------------
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.

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


Reply via email to