public static <R> StateQueryResult<R> iqv2WaitForPartitions(
        final KafkaStreams kafkaStreams,
        final StateQueryRequest<R> request,
        final Set<Integer> partitions) {

        final long start = System.currentTimeMillis();
        final long deadline = start + DEFAULT_TIMEOUT;

        do {
            if (Thread.currentThread().isInterrupted()) {
                fail("Test was interrupted.");
            }
            final StateQueryResult<R> result = kafkaStreams.query(request);
            if (result.getPartitionResults().keySet().containsAll(partitions)) {
                return result;
            } else {
                sleep(100L);
            }
        } while (System.currentTimeMillis() < deadline);

        throw new TimeoutException("The query never returned the desired partitions");
    }
Repeatedly runs the query until the response is valid and then return the response.
<p>
Validity in this case means that the response contains all the desired partitions or that
it's a global response.
<p>
Once position bounding is generally supported, we should migrate tests to wait on the
expected response position.
streams/src/test/java/org/apache/kafka/streams/integration/utils/IntegrationTestUtils.java