mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-23 21:02:48 +00:00
Wait for the deamon to become idle before rebuilding in UpgradesInBomNativeIT
This commit is contained in:
@@ -23,9 +23,8 @@ import org.jboss.fuse.mvnd.assertj.MatchInOrderAmongOthers;
|
|||||||
import org.jboss.fuse.mvnd.client.Client;
|
import org.jboss.fuse.mvnd.client.Client;
|
||||||
import org.jboss.fuse.mvnd.client.ClientOutput;
|
import org.jboss.fuse.mvnd.client.ClientOutput;
|
||||||
import org.jboss.fuse.mvnd.common.DaemonInfo;
|
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.MvndTest;
|
||||||
|
import org.jboss.fuse.mvnd.junit.TestRegistry;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -37,7 +36,7 @@ public class StopStatusTest {
|
|||||||
Client client;
|
Client client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DaemonRegistry registry;
|
TestRegistry registry;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void stopStatus() throws IOException, InterruptedException {
|
void stopStatus() throws IOException, InterruptedException {
|
||||||
@@ -62,16 +61,7 @@ public class StopStatusTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
/* Wait, till the instance becomes idle */
|
/* Wait, till the instance becomes idle */
|
||||||
final int timeoutMs = 5000;
|
registry.awaitIdle(d.getUid());
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
client.execute(Mockito.mock(ClientOutput.class), "clean").assertSuccess();
|
client.execute(Mockito.mock(ClientOutput.class), "clean").assertSuccess();
|
||||||
/* There should still be exactly one item in the registry after the second build */
|
/* There should still be exactly one item in the registry after the second build */
|
||||||
|
@@ -22,6 +22,7 @@ import javax.inject.Inject;
|
|||||||
import org.assertj.core.api.Assertions;
|
import org.assertj.core.api.Assertions;
|
||||||
import org.jboss.fuse.mvnd.client.Client;
|
import org.jboss.fuse.mvnd.client.Client;
|
||||||
import org.jboss.fuse.mvnd.client.ClientOutput;
|
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.ClientFactory;
|
||||||
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
|
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
|
||||||
import org.jboss.fuse.mvnd.junit.TestLayout;
|
import org.jboss.fuse.mvnd.junit.TestLayout;
|
||||||
@@ -62,6 +63,10 @@ public class UpgradesInBomNativeIT {
|
|||||||
}
|
}
|
||||||
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
|
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 */
|
/* Upgrade the dependency */
|
||||||
final Path parentPomPath = parentDir.resolve("pom.xml");
|
final Path parentPomPath = parentDir.resolve("pom.xml");
|
||||||
TestUtils.replace(parentPomPath, "<hello.version>0.0.1</hello.version>",
|
TestUtils.replace(parentPomPath, "<hello.version>0.0.1</hello.version>",
|
||||||
|
@@ -15,66 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.jboss.fuse.mvnd.it;
|
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.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")
|
@MvndTest(projectDir = "src/test/projects/upgrades-in-bom")
|
||||||
public class UpgradesInBomTest {
|
public class UpgradesInBomTest extends UpgradesInBomNativeIT {
|
||||||
|
|
||||||
@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, "<hello.version>0.0.1</hello.version>",
|
|
||||||
"<hello.version>0.0.2-SNAPSHOT</hello.version>");
|
|
||||||
/* 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);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -18,8 +18,10 @@ package org.jboss.fuse.mvnd.junit;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
import org.jboss.fuse.mvnd.common.DaemonInfo;
|
import org.jboss.fuse.mvnd.common.DaemonInfo;
|
||||||
import org.jboss.fuse.mvnd.common.DaemonRegistry;
|
import org.jboss.fuse.mvnd.common.DaemonRegistry;
|
||||||
|
import org.jboss.fuse.mvnd.common.DaemonState;
|
||||||
import org.jboss.fuse.mvnd.jpm.ProcessImpl;
|
import org.jboss.fuse.mvnd.jpm.ProcessImpl;
|
||||||
|
|
||||||
public class TestRegistry extends DaemonRegistry {
|
public class TestRegistry extends DaemonRegistry {
|
||||||
@@ -28,6 +30,9 @@ public class TestRegistry extends DaemonRegistry {
|
|||||||
super(registryFile);
|
super(registryFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kill all daemons in the registry.
|
||||||
|
*/
|
||||||
public void killAll() {
|
public void killAll() {
|
||||||
List<DaemonInfo> daemons;
|
List<DaemonInfo> daemons;
|
||||||
final int timeout = 5000;
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user