Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed MeteredExecutorServiceWrapperTest that is failing some Linux system #15034

Merged
merged 2 commits into from
Oct 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ public void shouldRecordExecutorServiceMetrics()
"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);
Expand Down Expand Up @@ -132,14 +128,17 @@ public void shouldRecordExecutorServiceMetrics()
.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")
Expand All @@ -163,7 +162,7 @@ public void shouldRecordExecutorServiceMetrics()
.tags(userTags)
.gauge()
.value(),
new Double(Integer.MAX_VALUE));
(double) Integer.MAX_VALUE);
assertEquals(
registry
.get("executor")
Expand Down Expand Up @@ -194,13 +193,7 @@ public void shouldRecordScheduledExecutorServiceMetrics() throws InterruptedExce
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);
Expand Down Expand Up @@ -277,7 +270,7 @@ public void shouldRecordScheduledExecutorServiceMetrics() throws InterruptedExce
.tags(userTags)
.gauge()
.value(),
new Double(Integer.MAX_VALUE));
(double) Integer.MAX_VALUE);
assertEquals(
registry
.get("executor")
Expand Down Expand Up @@ -323,11 +316,7 @@ public void shouldRecordCronExecutorServiceMetrics() throws InterruptedException
"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(
Expand Down Expand Up @@ -444,7 +433,7 @@ public void shouldRecordCronExecutorServiceMetrics() throws InterruptedException
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();
Expand Down