aboutsummaryrefslogtreecommitdiffstats
path: root/routing-generator
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-11-01 20:45:00 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2022-11-01 20:49:49 +0100
commit32d6028cbe373d3c34eeda95ae1c73128f03845f (patch)
tree91315108889db0bca045750824ff1d1f77d8fd76 /routing-generator
parent74a79d5979f6484a304f755047f00be45808b3fa (diff)
There is no guarantee for when RoutingGenerator.routingTable() will reflect last value.
No option but wait until it is so.
Diffstat (limited to 'routing-generator')
-rw-r--r--routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingGeneratorTest.java24
1 files changed, 13 insertions, 11 deletions
diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingGeneratorTest.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingGeneratorTest.java
index 7c526eae4ed..543a3b0a4e8 100644
--- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingGeneratorTest.java
+++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingGeneratorTest.java
@@ -8,7 +8,7 @@ import com.yahoo.test.ManualClock;
import com.yahoo.vespa.config.ConfigKey;
import org.junit.Test;
-import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -23,7 +23,7 @@ public class RoutingGeneratorTest {
RouterMock router = new RouterMock();
RoutingGenerator generator = new RoutingGenerator(new ConfigSetMock(), router, new ManualClock());
try {
- router.awaitLoad();
+ router.awaitLoad(generator);
assertNotNull("Router loads table", router.currentTable);
assertEquals("Routing generator and router has same table",
generator.routingTable().get(),
@@ -34,22 +34,24 @@ public class RoutingGeneratorTest {
}
private static class RouterMock implements Router {
-
- private final CountDownLatch latch = new CountDownLatch(1);
-
private volatile RoutingTable currentTable = null;
@Override
public void load(RoutingTable table) {
currentTable = table;
- latch.countDown();
}
- public void awaitLoad() {
- try {
- latch.await();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
+ public void awaitLoad(RoutingGenerator generator) {
+ AtomicBoolean completed = new AtomicBoolean(false);
+ while (!completed.get()) {
+ generator.routingTable().ifPresent(table -> completed.set(table == currentTable));
+ if (!completed.get()) {
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
}