Skip to content

Commit

Permalink
Merge pull request #74 from ppalaga/200929-await-idle
Browse files Browse the repository at this point in the history
Wait for the deamon to become idle before rebuilding in UpgradesInBom…
  • Loading branch information
ppalaga authored Sep 29, 2020
2 parents 231b99e + 8e714c0 commit 00aa81b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 91 deletions.
22 changes: 3 additions & 19 deletions RELEASING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 37 additions & 0 deletions build/release.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
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;
Expand All @@ -37,7 +36,7 @@ public class StopStatusTest {
Client client;

@Inject
DaemonRegistry registry;
TestRegistry registry;

@Test
void stopStatus() throws IOException, InterruptedException {
Expand All @@ -62,16 +61,7 @@ void stopStatus() throws IOException, InterruptedException {

}
/* 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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -62,6 +63,10 @@ void upgrade() throws IOException, InterruptedException {
}
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>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
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 {
Expand All @@ -28,6 +30,9 @@ public TestRegistry(Path registryFile) {
super(registryFile);
}

/**
* Kill all daemons in the registry.
*/
public void killAll() {
List<DaemonInfo> daemons;
final int timeout = 5000;
Expand All @@ -50,4 +55,25 @@ public void killAll() {
}
}

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

}

0 comments on commit 00aa81b

Please sign in to comment.