diff --git a/systemtest/src/main/java/io/strimzi/systemtest/utils/kafkaUtils/KafkaTopicUtils.java b/systemtest/src/main/java/io/strimzi/systemtest/utils/kafkaUtils/KafkaTopicUtils.java index 3c29bf684b3..e767a1063f1 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/utils/kafkaUtils/KafkaTopicUtils.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/utils/kafkaUtils/KafkaTopicUtils.java @@ -23,6 +23,8 @@ import java.util.Map; import java.util.Objects; import java.util.Random; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -278,11 +280,7 @@ public static void verifyUnchangedTopicAbsence(String namespaceName, String quer while (System.currentTimeMillis() < endTime) { assertThat(KafkaCmdClient.listTopicsUsingPodCli(namespaceName, queryingPodName, KafkaResources.plainBootstrapAddress(clusterName)), not(hasItems(absentTopicName))); - try { - Thread.sleep(TestConstants.POLL_INTERVAL_FOR_RESOURCE_READINESS); - } catch (InterruptedException e) { - e.printStackTrace(); - } + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(TestConstants.POLL_INTERVAL_FOR_RESOURCE_READINESS)); } } diff --git a/systemtest/src/test/java/io/strimzi/systemtest/metrics/MetricsST.java b/systemtest/src/test/java/io/strimzi/systemtest/metrics/MetricsST.java index 0743ea28be2..ccef60e5fcf 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/metrics/MetricsST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/metrics/MetricsST.java @@ -73,6 +73,8 @@ import java.util.Collections; import java.util.Map; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -763,7 +765,7 @@ void setupEnvironment() throws Exception { // wait some time for metrics to be stable - at least reconciliation interval + 10s LOGGER.info("Sleeping for {} to give operators and operands some time to stable the metrics values before collecting", TestConstants.SAFETY_RECONCILIATION_INTERVAL); - Thread.sleep(TestConstants.SAFETY_RECONCILIATION_INTERVAL); + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(TestConstants.SAFETY_RECONCILIATION_INTERVAL)); kafkaCollector = new MetricsCollector.Builder() .withScraperPodName(scraperPodName) diff --git a/systemtest/src/test/java/io/strimzi/systemtest/operators/topic/TopicST.java b/systemtest/src/test/java/io/strimzi/systemtest/operators/topic/TopicST.java index fcca30818f2..c157608c679 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/operators/topic/TopicST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/operators/topic/TopicST.java @@ -46,6 +46,8 @@ import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; import static io.strimzi.systemtest.TestConstants.REGRESSION; import static io.strimzi.systemtest.enums.ConditionStatus.False; @@ -124,7 +126,7 @@ void testCreateDeleteCreate() throws InterruptedException { assertThat(adminClient.listTopics(), containsString(testStorage.getTopicName())); for (int i = 0; i < 10; i++) { - Thread.sleep(2_000); + LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(2)); LOGGER.info("Iteration {}: Deleting {}", i, testStorage.getTopicName()); cmdKubeClient(Environment.TEST_SUITE_NAMESPACE).deleteByName(KafkaTopic.RESOURCE_KIND, testStorage.getTopicName()); @@ -132,8 +134,7 @@ void testCreateDeleteCreate() throws InterruptedException { assertThat(adminClient.listTopics(), not(containsString(testStorage.getTopicName()))); - Thread.sleep(2_000); - long t0 = System.currentTimeMillis(); + LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(2)); LOGGER.info("Iteration {}: Recreating {}", i, testStorage.getTopicName()); resourceManager.createResourceWithWait(KafkaTopicTemplates.topic(Environment.TEST_SUITE_NAMESPACE, testStorage.getTopicName(), sharedTestStorage.getClusterName()) @@ -297,7 +298,7 @@ void testCreateTopicAfterUnsupportedOperation() { * - kafkatopic-not-ready */ @IsolatedTest - void testKafkaTopicDifferentStatesInUTOMode() throws InterruptedException { + void testKafkaTopicDifferentStatesInUTOMode() { final TestStorage testStorage = new TestStorage(ResourceManager.getTestContext()); int initialReplicas = 1; int initialPartitions = 5; @@ -369,7 +370,8 @@ void testKafkaTopicDifferentStatesInUTOMode() throws InterruptedException { // Wait some time to check if error is still present in KafkaTopic status LOGGER.info("Waiting {} ms for next reconciliation", topicOperatorReconciliationIntervalMs); - Thread.sleep(topicOperatorReconciliationIntervalMs); + + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(topicOperatorReconciliationIntervalMs)); assertKafkaTopicStatus(testStorage.getTopicName(), Environment.TEST_SUITE_NAMESPACE, Ready, False, reason, reasonMessage, expectedObservedGeneration); LOGGER.info("Changing KafkaTopic's spec to correct state"); @@ -384,7 +386,7 @@ void testKafkaTopicDifferentStatesInUTOMode() throws InterruptedException { } @ParallelTest - void testKafkaTopicChangingMinInSyncReplicas() throws InterruptedException { + void testKafkaTopicChangingMinInSyncReplicas() { final TestStorage testStorage = new TestStorage(ResourceManager.getTestContext()); resourceManager.createResourceWithWait(KafkaTopicTemplates.topic(Environment.TEST_SUITE_NAMESPACE, testStorage.getTopicName(), sharedTestStorage.getClusterName(), 5).build()); @@ -406,7 +408,7 @@ void testKafkaTopicChangingMinInSyncReplicas() throws InterruptedException { // Wait some time to check if error is still present in KafkaTopic status LOGGER.info("Waiting {} ms for next reconciliation", topicOperatorReconciliationIntervalMs); - Thread.sleep(topicOperatorReconciliationIntervalMs); + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(topicOperatorReconciliationIntervalMs)); assertKafkaTopicStatus(testStorage.getTopicName(), Environment.TEST_SUITE_NAMESPACE, resourceStatus, conditionStatus, reason, reasonMessage, 2); } diff --git a/test/src/main/java/io/strimzi/test/TestUtils.java b/test/src/main/java/io/strimzi/test/TestUtils.java index 0695c5258df..6a2cfccd111 100644 --- a/test/src/main/java/io/strimzi/test/TestUtils.java +++ b/test/src/main/java/io/strimzi/test/TestUtils.java @@ -55,6 +55,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.concurrent.locks.LockSupport; import java.util.function.BooleanSupplier; import java.util.function.Function; @@ -187,11 +188,7 @@ public static long waitFor(String description, long pollIntervalMs, long timeout if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} not ready, will try again in {} ms ({}ms till timeout)", description, sleepTime, timeLeft); } - try { - Thread.sleep(sleepTime); - } catch (InterruptedException e) { - return deadline - System.currentTimeMillis(); - } + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(sleepTime)); } }