diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/StopStatusTest.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/StopStatusTest.java index 325a730f..d6332079 100644 --- a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/StopStatusTest.java +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/StopStatusTest.java @@ -23,9 +23,8 @@ import org.jboss.fuse.mvnd.assertj.MatchInOrderAmongOthers; import org.jboss.fuse.mvnd.client.Client; import org.jboss.fuse.mvnd.client.ClientOutput; import org.jboss.fuse.mvnd.common.DaemonInfo; -import org.jboss.fuse.mvnd.common.DaemonRegistry; -import org.jboss.fuse.mvnd.common.DaemonState; import org.jboss.fuse.mvnd.junit.MvndTest; +import org.jboss.fuse.mvnd.junit.TestRegistry; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -37,7 +36,7 @@ public class StopStatusTest { Client client; @Inject - DaemonRegistry registry; + TestRegistry registry; @Test void stopStatus() throws IOException, InterruptedException { @@ -62,16 +61,7 @@ public class StopStatusTest { } /* Wait, till the instance becomes idle */ - final int timeoutMs = 5000; - final long deadline = System.currentTimeMillis() + timeoutMs; - while (!registry.getAll().stream() - .filter(di -> di.getUid().equals(d.getUid()) && di.getState() == DaemonState.Idle) - .findFirst() - .isPresent()) { - Assertions.assertThat(deadline) - .withFailMessage("Daemon %s should have become idle within %d", d.getUid(), timeoutMs) - .isGreaterThan(System.currentTimeMillis()); - } + registry.awaitIdle(d.getUid()); client.execute(Mockito.mock(ClientOutput.class), "clean").assertSuccess(); /* There should still be exactly one item in the registry after the second build */ diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/UpgradesInBomNativeIT.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/UpgradesInBomNativeIT.java index 18a174b0..73ebb0e0 100644 --- a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/UpgradesInBomNativeIT.java +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/UpgradesInBomNativeIT.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import org.assertj.core.api.Assertions; import org.jboss.fuse.mvnd.client.Client; import org.jboss.fuse.mvnd.client.ClientOutput; +import org.jboss.fuse.mvnd.common.DaemonInfo; import org.jboss.fuse.mvnd.junit.ClientFactory; import org.jboss.fuse.mvnd.junit.MvndNativeTest; import org.jboss.fuse.mvnd.junit.TestLayout; @@ -62,6 +63,10 @@ public class UpgradesInBomNativeIT { } Assertions.assertThat(registry.getAll().size()).isEqualTo(1); + final DaemonInfo d = registry.getAll().get(0); + /* Wait, till the instance becomes idle */ + registry.awaitIdle(d.getUid()); + /* Upgrade the dependency */ final Path parentPomPath = parentDir.resolve("pom.xml"); TestUtils.replace(parentPomPath, "0.0.1", diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/UpgradesInBomTest.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/UpgradesInBomTest.java index 7bd3ba7d..10c14643 100644 --- a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/UpgradesInBomTest.java +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/UpgradesInBomTest.java @@ -15,66 +15,8 @@ */ package org.jboss.fuse.mvnd.it; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Arrays; -import javax.inject.Inject; -import org.assertj.core.api.Assertions; -import org.jboss.fuse.mvnd.client.Client; -import org.jboss.fuse.mvnd.client.ClientOutput; -import org.jboss.fuse.mvnd.junit.ClientFactory; import org.jboss.fuse.mvnd.junit.MvndTest; -import org.jboss.fuse.mvnd.junit.TestLayout; -import org.jboss.fuse.mvnd.junit.TestRegistry; -import org.jboss.fuse.mvnd.junit.TestUtils; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; @MvndTest(projectDir = "src/test/projects/upgrades-in-bom") -public class UpgradesInBomTest { - - @Inject - TestLayout layout; - - @Inject - TestRegistry registry; - - @Inject - ClientFactory clientFactory; - - @Test - void upgrade() throws IOException, InterruptedException { - /* Install the dependencies */ - for (String artifactDir : Arrays.asList("project/hello-0.0.1", "project/hello-0.0.2-SNAPSHOT")) { - final Client cl = clientFactory.newClient(layout.cd(layout.getTestDir().resolve(artifactDir))); - final ClientOutput output = Mockito.mock(ClientOutput.class); - cl.execute(output, "clean", "install", "-e").assertSuccess(); - registry.killAll(); - } - Assertions.assertThat(registry.getAll().size()).isEqualTo(0); - - /* Build the initial state of the test project */ - final Path parentDir = layout.getTestDir().resolve("project/parent"); - final Client cl = clientFactory.newClient(layout.cd(parentDir)); - { - final ClientOutput output = Mockito.mock(ClientOutput.class); - cl.execute(output, "clean", "install", "-e").assertSuccess(); - } - Assertions.assertThat(registry.getAll().size()).isEqualTo(1); - - /* Upgrade the dependency */ - final Path parentPomPath = parentDir.resolve("pom.xml"); - TestUtils.replace(parentPomPath, "0.0.1", - "0.0.2-SNAPSHOT"); - /* Adapt the caller */ - final Path useHelloPath = parentDir - .resolve("module/src/main/java/org/jboss/fuse/mvnd/test/upgrades/bom/module/UseHello.java"); - TestUtils.replace(useHelloPath, "new Hello().sayHello()", "new Hello().sayWisdom()"); - { - final ClientOutput output = Mockito.mock(ClientOutput.class); - cl.execute(output, "clean", "install", "-e").assertSuccess(); - } - Assertions.assertThat(registry.getAll().size()).isEqualTo(1); - - } +public class UpgradesInBomTest extends UpgradesInBomNativeIT { } diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestRegistry.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestRegistry.java index 3f7ef297..42a987a5 100644 --- a/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestRegistry.java +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestRegistry.java @@ -18,8 +18,10 @@ package org.jboss.fuse.mvnd.junit; import java.io.IOException; import java.nio.file.Path; import java.util.List; +import org.assertj.core.api.Assertions; import org.jboss.fuse.mvnd.common.DaemonInfo; import org.jboss.fuse.mvnd.common.DaemonRegistry; +import org.jboss.fuse.mvnd.common.DaemonState; import org.jboss.fuse.mvnd.jpm.ProcessImpl; public class TestRegistry extends DaemonRegistry { @@ -28,6 +30,9 @@ public class TestRegistry extends DaemonRegistry { super(registryFile); } + /** + * Kill all daemons in the registry. + */ public void killAll() { List daemons; final int timeout = 5000; @@ -50,4 +55,25 @@ public class TestRegistry extends DaemonRegistry { } } + /** + * Poll the state of the daemon with the given {@code uid} until it becomes idle. + * + * @param uid the uid of the daemon to poll + * @throws IllegalStateException if the daemon is not available in the registry + * @throws AssertionError if the timeout is exceeded + */ + public void awaitIdle(String uid) { + final int timeoutMs = 5000; + final long deadline = System.currentTimeMillis() + timeoutMs; + while (getAll().stream() + .filter(di -> di.getUid().equals(uid)) + .findFirst() + .orElseThrow(() -> new IllegalStateException("Daemon " + uid + " is not available in the registry")) + .getState() != DaemonState.Idle) { + Assertions.assertThat(deadline) + .withFailMessage("Daemon %s should have become idle within %d", uid, timeoutMs) + .isGreaterThan(System.currentTimeMillis()); + } + } + }