Wait for the deamon to become idle before rebuilding in UpgradesInBomNativeIT

This commit is contained in:
Peter Palaga
2020-09-29 13:52:44 +02:00
parent 231b99e036
commit 9886c5aa8f
4 changed files with 35 additions and 72 deletions

View File

@@ -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 */

View File

@@ -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, "<hello.version>0.0.1</hello.version>",

View File

@@ -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, "<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);
}
public class UpgradesInBomTest extends UpgradesInBomNativeIT {
}

View File

@@ -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<DaemonInfo> 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());
}
}
}