Merge pull request #74 from ppalaga/200929-await-idle

Wait for the deamon to become idle before rebuilding in UpgradesInBom…
This commit is contained in:
Peter Palaga
2020-09-29 14:13:02 +02:00
committed by GitHub
6 changed files with 75 additions and 91 deletions

View File

@@ -2,26 +2,10 @@
[source,shell]
----
export VERSION=... # e.g. 1.2.3
export NEXT_VERSION=... # e.g. 1.2.4-SNAPSHOT
git checkout master
git fetch upstream
git reset --hard upstream/master
mvn versions:set -DnewVersion=$VERSION
git add -A
git commit -m "Release $VERSION"
git tag $VERSION
git push upstream $VERSION
# Pushing a tag will trigger the CI to build the release and publish the artifacts on https://github.com/mvndaemon/mvnd/releases
mvn versions:set -DnewVersion=$NEXT_VERSION
git add -A
git commit -m "Next is $NEXT_VERSION"
git push upstream master
./build/release.sh <released-version> <next-SNAPSHOT>
----
* Re-run the https://github.com/mvndaemon/mvnd/actions?query=workflow%3A%22Mvnd+Changelog%22[Changelog update] manually.
* Find the anchor of the released tag in the https://github.com/mvndaemon/mvnd/blob/master/CHANGELOG.md[Changelog] by
clicking the chain link on the left.
* When it terminates, find the anchor of the released tag in the
https://github.com/mvndaemon/mvnd/blob/master/CHANGELOG.md[Changelog] by clicking the chain link on the left.
* Wait for the release job to finish, paste the link to changelog to the release.

37
build/release.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
#
# Copyright 2019 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -e
set -x
export VERSION=$1
export NEXT_VERSION=$2
git checkout master
git fetch upstream
git reset --hard upstream/master
mvn versions:set -DnewVersion=$VERSION
git add -A
git commit -m "Release $VERSION"
git tag $VERSION
git push upstream $VERSION
# Pushing a tag will trigger the CI to build the release and publish the artifacts on https://github.com/mvndaemon/mvnd/releases
mvn versions:set -DnewVersion=$NEXT_VERSION
git add -A
git commit -m "Next is $NEXT_VERSION"
git push upstream master

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