Skip to content

Commit

Permalink
(chores) core/camel-core: replace Thread.sleep with Awaitility in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
orpiske committed Nov 24, 2021
1 parent d2e1d30 commit d58c731
Showing 1 changed file with 9 additions and 18 deletions.
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.camel.support;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -58,13 +59,8 @@ public void testDefaultTimeoutMapPurge() throws Exception {
map.put("A", 123, 50);
assertEquals(1, map.size());

Thread.sleep(250);
if (map.size() > 0) {
LOG.warn("Waiting extra due slow CI box");
Thread.sleep(1000);
}

assertEquals(0, map.size());
await().atMost(Duration.ofSeconds(2))
.untilAsserted(() -> assertEquals(0, map.size()));

map.stop();
}
Expand Down Expand Up @@ -120,14 +116,9 @@ public void testExecutor() throws Exception {
map.put("A", 123, 100);
assertEquals(1, map.size());

Thread.sleep(250);

if (map.size() > 0) {
LOG.warn("Waiting extra due slow CI box");
Thread.sleep(1000);
}
// should have been timed out now
assertEquals(0, map.size());
await().atMost(Duration.ofSeconds(2))
.untilAsserted(() -> assertEquals(0, map.size()));

assertSame(e, map.getExecutor());

Expand Down Expand Up @@ -157,9 +148,9 @@ public void testExpiredInCorrectOrder() throws Exception {
// is not expired
map.put("F", 6, 800);

Thread.sleep(250);
await().atMost(Duration.ofSeconds(1))
.untilAsserted(() -> assertEquals("D", keys.get(0)));

assertEquals("D", keys.get(0));
assertEquals(4, values.get(0).intValue());
assertEquals("B", keys.get(1));
assertEquals(2, values.get(1).intValue());
Expand Down Expand Up @@ -188,8 +179,8 @@ public void testDefaultTimeoutMapStopStart() throws Exception {
map.put("A", 1, 50);

// should not timeout as the scheduler doesn't run
Thread.sleep(250);
assertEquals(1, map.size());
await().atMost(Duration.ofSeconds(1))
.untilAsserted(() -> assertEquals(1, map.size()));

// start
map.start();
Expand Down

0 comments on commit d58c731

Please sign in to comment.