From 29d5f17027b9afb3764d2ecece601c076c550359 Mon Sep 17 00:00:00 2001 From: Sergii Kabashniuk <skabashnyuk@users.noreply.github.com> Date: Wed, 30 Oct 2019 17:07:03 +0100 Subject: [PATCH] Fixed MeteredExecutorServiceWrapperTest that is failing some Linux system (#15034) * Fixed MeteredExecutorServiceWrapperTest that are failing some Linux system Signed-off-by: Sergii Kabashniuk <skabashniuk@redhat.com> --- .../MeteredExecutorServiceWrapperTest.java | 45 +++++++------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/core/commons/che-core-commons-observability/src/test/java/org/eclipse/che/commons/observability/MeteredExecutorServiceWrapperTest.java b/core/commons/che-core-commons-observability/src/test/java/org/eclipse/che/commons/observability/MeteredExecutorServiceWrapperTest.java index 57bdaf2421..80fda51f9e 100644 --- a/core/commons/che-core-commons-observability/src/test/java/org/eclipse/che/commons/observability/MeteredExecutorServiceWrapperTest.java +++ b/core/commons/che-core-commons-observability/src/test/java/org/eclipse/che/commons/observability/MeteredExecutorServiceWrapperTest.java @@ -86,11 +86,7 @@ public class MeteredExecutorServiceWrapperTest { "userTagValue"); CountDownLatch runnableTaskStart = new CountDownLatch(1); // when - Future<?> future = - executor.submit( - () -> { - runnableTaskStart.countDown(); - }); + Future<?> future = executor.submit(runnableTaskStart::countDown); // then runnableTaskStart.await(10, TimeUnit.SECONDS); future.get(1, TimeUnit.MINUTES); @@ -132,14 +128,17 @@ public class MeteredExecutorServiceWrapperTest { .gauge() .value(), 1.0); - assertEquals( - registry - .get("executor.completed") - .tag("name", MeteredExecutorServiceWrapperTest.class.getName()) - .tags(userTags) - .functionCounter() - .count(), - 1.0); + assertWithRetry( + () -> + registry + .get("executor.completed") + .tag("name", MeteredExecutorServiceWrapperTest.class.getName()) + .tags(userTags) + .functionCounter() + .count(), + 1.0, + 10, + 50); assertEquals( registry .get("executor.queued") @@ -163,7 +162,7 @@ public class MeteredExecutorServiceWrapperTest { .tags(userTags) .gauge() .value(), - new Double(Integer.MAX_VALUE)); + (double) Integer.MAX_VALUE); assertEquals( registry .get("executor") @@ -194,13 +193,7 @@ public class MeteredExecutorServiceWrapperTest { CountDownLatch runnableTaskStart = new CountDownLatch(1); // when ((ScheduledExecutorService) executor) - .scheduleAtFixedRate( - () -> { - runnableTaskStart.countDown(); - }, - 0, - 100, - TimeUnit.SECONDS); + .scheduleAtFixedRate(runnableTaskStart::countDown, 0, 100, TimeUnit.SECONDS); // then runnableTaskStart.await(10, TimeUnit.SECONDS); @@ -277,7 +270,7 @@ public class MeteredExecutorServiceWrapperTest { .tags(userTags) .gauge() .value(), - new Double(Integer.MAX_VALUE)); + (double) Integer.MAX_VALUE); assertEquals( registry .get("executor") @@ -323,11 +316,7 @@ public class MeteredExecutorServiceWrapperTest { "userTagValue"); CountDownLatch runnableTaskStart = new CountDownLatch(1); // when - executor.schedule( - () -> { - runnableTaskStart.countDown(); - }, - new CronExpression(" * * * ? * * *")); + executor.schedule(runnableTaskStart::countDown, new CronExpression(" * * * ? * * *")); // then runnableTaskStart.await(10, TimeUnit.SECONDS); assertEquals( @@ -444,7 +433,7 @@ public class MeteredExecutorServiceWrapperTest { 1.0); } - public <V> void assertWithRetry(Supplier<V> predicate, V expected, int times, int pause_millis) + <V> void assertWithRetry(Supplier<V> predicate, V expected, int times, int pause_millis) throws InterruptedException { for (int i = 0; i <= times; i++) { V actual = predicate.get(); -- GitLab