mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-28 08:47:29 +00:00
Client: have just one event queue and one consuming thread #133
This commit is contained in:
@@ -63,11 +63,6 @@
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-model</artifactId>
|
||||
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.jboss.fuse.mvnd.assertj;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.assertj.core.api.Condition;
|
||||
|
||||
/**
|
||||
* An AssertJ {@link Condition} to assert that each item of a collection of expected items is equal to some item in
|
||||
* a list of strings exactly once in the order given by the expected items collection. The input list may contain other
|
||||
* non-matching items.
|
||||
*
|
||||
* @param <T> the type of the tested {@link List}.
|
||||
*/
|
||||
public class EqualsInOrderAmongOthers<T extends List<? extends String>> extends Condition<T> {
|
||||
|
||||
public EqualsInOrderAmongOthers(String... expectedItems) {
|
||||
this(Stream.of(expectedItems).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public EqualsInOrderAmongOthers(final Collection<String> expectedItems) {
|
||||
super(
|
||||
messages -> messages.stream()
|
||||
/* map each message to the matching pattern or null of none matches */
|
||||
.map(m -> expectedItems.stream()
|
||||
.filter(expected -> expected.equals(m))
|
||||
.findFirst()
|
||||
.orElse(null))
|
||||
.filter(pat -> pat != null) /* remove null patterns */
|
||||
.collect(Collectors.toList())
|
||||
/* if the mapped patterns equal the input patterns then each pattern matched exactly once */
|
||||
.equals(expectedItems),
|
||||
"Match in order: " + expectedItems.stream().collect(Collectors.joining(", ")),
|
||||
expectedItems);
|
||||
}
|
||||
|
||||
}
|
@@ -22,6 +22,8 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* An AssertJ {@link Condition} to assert that each item of a collection of regular expressions matches some item in
|
||||
@@ -32,22 +34,36 @@ import org.assertj.core.api.Condition;
|
||||
*/
|
||||
public class MatchInOrderAmongOthers<T extends List<? extends String>> extends Condition<T> {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MatchInOrderAmongOthers.class);
|
||||
|
||||
public MatchInOrderAmongOthers(String... expectedItems) {
|
||||
this(Stream.of(expectedItems).map(Pattern::compile).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public MatchInOrderAmongOthers(final Collection<Pattern> patterns) {
|
||||
super(
|
||||
messages -> messages.stream()
|
||||
/* map each message to the matching pattern or null of none matches */
|
||||
.map(m -> patterns.stream()
|
||||
.filter(pat -> pat.matcher(m).find())
|
||||
.findFirst()
|
||||
.orElse(null))
|
||||
.filter(Objects::nonNull) /* remove null patterns */
|
||||
.collect(Collectors.toList())
|
||||
/* if the mapped patterns equal the input patterns then each pattern matched exactly once */
|
||||
.equals(patterns),
|
||||
messages -> {
|
||||
final List<Pattern> matchingPatterns = messages.stream()
|
||||
/* map each message to the matching pattern or null of none matches */
|
||||
.map(m -> patterns.stream()
|
||||
.filter(pat -> pat.matcher(m).find())
|
||||
.findFirst()
|
||||
.orElse(null))
|
||||
.filter(Objects::nonNull) /* remove null patterns */
|
||||
.collect(Collectors.toList());
|
||||
final boolean result = matchingPatterns.equals(patterns);
|
||||
if (!result) {
|
||||
LOG.warn("Actually matched:\n"
|
||||
+ matchingPatterns.stream().map(p -> " " + p.pattern()).collect(Collectors.joining("\n")));
|
||||
LOG.warn("Did not match:\n"
|
||||
+ patterns.stream()
|
||||
.filter(p -> !matchingPatterns.contains(p))
|
||||
.map(p -> " " + p.pattern())
|
||||
.collect(Collectors.joining("\n")));
|
||||
}
|
||||
/* if the mapped patterns equal the input patterns then each pattern matched exactly once */
|
||||
return result;
|
||||
},
|
||||
"Match in order: " + patterns.stream().map(Pattern::pattern).collect(Collectors.joining(", ")),
|
||||
patterns);
|
||||
}
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.jboss.fuse.mvnd.assertj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.common.Message;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
|
||||
public class TestClientOutput implements ClientOutput {
|
||||
private final List<Message> messages = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Message message) {
|
||||
messages.add(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(List<Message> messages) {
|
||||
for (Message message : messages) {
|
||||
accept(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTerminal() {
|
||||
accept(Message.log("Test terminal"));
|
||||
}
|
||||
|
||||
public List<Message> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public void assertContainsMatchingSubsequence(String... patterns) {
|
||||
Assertions.assertThat(messagesToString()).is(new MatchInOrderAmongOthers<>(patterns));
|
||||
}
|
||||
|
||||
public List<String> messagesToString() {
|
||||
return messages.stream().map(m -> m.toString()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
@@ -21,14 +21,13 @@ import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
import javax.inject.Inject;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.client.DaemonParameters;
|
||||
import org.jboss.fuse.mvnd.common.DaemonException;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import org.jboss.fuse.mvnd.junit.MvndTest;
|
||||
import org.jboss.fuse.mvnd.junit.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@@ -58,7 +57,7 @@ public class DaemonCrashTest {
|
||||
};
|
||||
Stream.of(installedJars).forEach(jar -> Assertions.assertThat(jar).doesNotExist());
|
||||
|
||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
assertThrows(DaemonException.StaleAddressException.class,
|
||||
() -> client.execute(output, "clean", "install", "-e", "-Dmvnd.log.level=DEBUG").assertFailure());
|
||||
}
|
||||
|
@@ -18,14 +18,13 @@ package org.jboss.fuse.mvnd.it;
|
||||
import java.io.IOException;
|
||||
import javax.inject.Inject;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.client.DaemonParameters;
|
||||
import org.jboss.fuse.mvnd.common.DaemonInfo;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
|
||||
import org.jboss.fuse.mvnd.junit.TestRegistry;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -46,7 +45,7 @@ public class ExtensionsNativeIT {
|
||||
registry.killAll();
|
||||
Assertions.assertThat(registry.getAll().size()).isEqualTo(0);
|
||||
|
||||
final ClientOutput o = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput o = new TestClientOutput();
|
||||
client.execute(o, "-v").assertSuccess();
|
||||
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
|
||||
DaemonInfo daemon = registry.getAll().iterator().next();
|
||||
|
@@ -17,13 +17,14 @@ package org.jboss.fuse.mvnd.it;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.inject.Inject;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.client.DaemonParameters;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import org.jboss.fuse.mvnd.common.Message;
|
||||
import org.jboss.fuse.mvnd.common.Message.Prompt;
|
||||
import org.jboss.fuse.mvnd.junit.MvndTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@MvndTest(projectDir = "src/test/projects/single-module")
|
||||
public class InteractiveTest {
|
||||
@@ -39,9 +40,15 @@ public class InteractiveTest {
|
||||
final String version = MvndTestUtil.version(parameters.multiModuleProjectDirectory().resolve("pom.xml"));
|
||||
Assertions.assertEquals("0.0.1-SNAPSHOT", version);
|
||||
|
||||
final ClientOutput o = Mockito.mock(ClientOutput.class);
|
||||
Mockito.when(o.prompt("single-module", "Enter the new version to set 0.0.1-SNAPSHOT: ", false))
|
||||
.thenReturn("0.1.0-SNAPSHOT");
|
||||
final TestClientOutput o = new TestClientOutput() {
|
||||
@Override
|
||||
public void accept(Message m) {
|
||||
if (m instanceof Prompt) {
|
||||
((Prompt) m).getCallback().accept("0.1.0-SNAPSHOT");
|
||||
}
|
||||
super.accept(m);
|
||||
}
|
||||
};
|
||||
client.execute(o, "versions:set").assertSuccess();
|
||||
|
||||
final String newVersion = MvndTestUtil.version(parameters.multiModuleProjectDirectory().resolve("pom.xml"));
|
||||
|
@@ -23,12 +23,11 @@ import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.inject.Inject;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.client.DaemonParameters;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@MvndNativeTest(projectDir = "src/test/projects/invoker")
|
||||
public class InvokerNativeIT {
|
||||
@@ -55,7 +54,7 @@ public class InvokerNativeIT {
|
||||
throw new RuntimeException("Could not delete " + helloPath);
|
||||
}
|
||||
|
||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
client.execute(output, "clean", "verify", "-e", "-Dmvnd.log.level=DEBUG").assertSuccess();
|
||||
|
||||
Assertions.assertThat(helloPath).exists();
|
||||
|
@@ -22,13 +22,12 @@ import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
import javax.inject.Inject;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.client.DaemonParameters;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
|
||||
import org.jboss.fuse.mvnd.junit.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@MvndNativeTest(projectDir = "src/test/projects/module-and-plugin")
|
||||
public class ModuleAndPluginNativeIT {
|
||||
@@ -61,7 +60,7 @@ public class ModuleAndPluginNativeIT {
|
||||
|
||||
/* Build #1: with "Hello" output to target/hello.txt */
|
||||
{
|
||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
client.execute(output, "clean", "install", "-e", "-Dmvnd.log.level=DEBUG", "-Dhello.property=Hello1")
|
||||
.assertSuccess();
|
||||
|
||||
@@ -78,7 +77,7 @@ public class ModuleAndPluginNativeIT {
|
||||
.resolve("plugin/src/main/java/org/jboss/fuse/mvnd/test/module/plugin/mojo/HelloMojo.java");
|
||||
TestUtils.replace(mojoPath, "\"Hello\".getBytes", "\"Hi\".getBytes");
|
||||
|
||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
client.execute(output,
|
||||
"clean",
|
||||
"install", "-e", "-Dmvnd.log.level=DEBUG", "-Dhello.property=Hello2").assertSuccess();
|
||||
|
@@ -18,21 +18,22 @@ package org.jboss.fuse.mvnd.it;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import javax.inject.Inject;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.assertj.EqualsInOrderAmongOthers;
|
||||
import org.jboss.fuse.mvnd.assertj.MatchInOrderAmongOthers;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.client.DaemonParameters;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import org.jboss.fuse.mvnd.common.Message;
|
||||
import org.jboss.fuse.mvnd.common.Message.BuildEvent;
|
||||
import org.jboss.fuse.mvnd.common.Message.BuildMessage;
|
||||
import org.jboss.fuse.mvnd.junit.MvndTest;
|
||||
import org.jboss.fuse.mvnd.junit.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
||||
@MvndTest(projectDir = "src/test/projects/multi-module")
|
||||
public class MultiModuleTest {
|
||||
@@ -69,44 +70,52 @@ public class MultiModuleTest {
|
||||
};
|
||||
Stream.of(installedJars).forEach(jar -> Assertions.assertThat(jar).doesNotExist());
|
||||
|
||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
client.execute(output, "clean", "install", "-e").assertSuccess();
|
||||
|
||||
final ArgumentCaptor<String> logMessage = ArgumentCaptor.forClass(String.class);
|
||||
Mockito.verify(output, Mockito.atLeast(1)).accept(any(), logMessage.capture());
|
||||
Assertions.assertThat(logMessage.getAllValues())
|
||||
.satisfiesAnyOf( /* Two orderings are possible */
|
||||
messages -> Assertions.assertThat(messages)
|
||||
.is(new MatchInOrderAmongOthers<>(
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module$",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-api",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-hello",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-hi")),
|
||||
messages -> Assertions.assertThat(messages)
|
||||
.is(new MatchInOrderAmongOthers<>(
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module$",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-api",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-hi",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-hello"))
|
||||
{
|
||||
final List<String> filteredMessages = output.getMessages().stream()
|
||||
.filter(m -> m.getType() == Message.BUILD_MESSAGE)
|
||||
.map(m -> ((BuildMessage) m).getMessage())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
);
|
||||
Assertions.assertThat(filteredMessages)
|
||||
.satisfiesAnyOf( /* Two orderings are possible */
|
||||
messages -> Assertions.assertThat(messages)
|
||||
.is(new MatchInOrderAmongOthers<>(
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module$",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-api",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-hello",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-hi")),
|
||||
messages -> Assertions.assertThat(messages)
|
||||
.is(new MatchInOrderAmongOthers<>(
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module$",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-api",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-hi",
|
||||
"SUCCESS build of project org.jboss.fuse.mvnd.test.multi-module:multi-module-hello")));
|
||||
}
|
||||
|
||||
final ArgumentCaptor<String> projectFinished = ArgumentCaptor.forClass(String.class);
|
||||
Mockito.verify(output, Mockito.atLeast(1)).projectFinished(projectFinished.capture());
|
||||
Assertions.assertThat(projectFinished.getAllValues())
|
||||
.satisfiesAnyOf( /* Two orderings are possible */
|
||||
messages -> Assertions.assertThat(messages)
|
||||
.is(new EqualsInOrderAmongOthers<>(
|
||||
"multi-module",
|
||||
"multi-module-api",
|
||||
"multi-module-hello",
|
||||
"multi-module-hi")),
|
||||
messages -> Assertions.assertThat(messages)
|
||||
.is(new EqualsInOrderAmongOthers<>(
|
||||
"multi-module",
|
||||
"multi-module-api",
|
||||
"multi-module-hi",
|
||||
"multi-module-hello")));
|
||||
{
|
||||
final List<String> filteredMessages = output.getMessages().stream()
|
||||
.filter(m -> m.getType() == Message.PROJECT_STARTED)
|
||||
.map(m -> ((BuildEvent) m).getProjectId())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Assertions.assertThat(filteredMessages)
|
||||
.satisfiesAnyOf( /* Two orderings are possible */
|
||||
messages -> Assertions.assertThat(messages)
|
||||
.isEqualTo(Arrays.asList(
|
||||
"multi-module",
|
||||
"multi-module-api",
|
||||
"multi-module-hello",
|
||||
"multi-module-hi")),
|
||||
messages -> Assertions.assertThat(messages)
|
||||
.isEqualTo(Arrays.asList(
|
||||
"multi-module",
|
||||
"multi-module-api",
|
||||
"multi-module-hi",
|
||||
"multi-module-hello")));
|
||||
}
|
||||
|
||||
/* Make sure HelloTest and HiTest have created the files they were supposed to create */
|
||||
Stream.of(helloFilePaths).forEach(path -> Assertions.assertThat(path).exists());
|
||||
|
@@ -18,19 +18,19 @@ package org.jboss.fuse.mvnd.it;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.assertj.MatchInOrderAmongOthers;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.client.DaemonParameters;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import org.jboss.fuse.mvnd.common.Message;
|
||||
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
|
||||
import org.jboss.fuse.mvnd.junit.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
||||
@MvndNativeTest(projectDir = "src/test/projects/single-module")
|
||||
public class SingleModuleNativeIT {
|
||||
@@ -54,18 +54,23 @@ public class SingleModuleNativeIT {
|
||||
"org/jboss/fuse/mvnd/test/single-module/single-module/0.0.1-SNAPSHOT/single-module-0.0.1-SNAPSHOT.jar");
|
||||
Assertions.assertThat(installedJar).doesNotExist();
|
||||
|
||||
final ClientOutput o = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput o = new TestClientOutput();
|
||||
client.execute(o, "clean", "install", "-e").assertSuccess();
|
||||
final Properties props = MvndTestUtil.properties(parameters.multiModuleProjectDirectory().resolve("pom.xml"));
|
||||
|
||||
final InOrder inOrder = Mockito.inOrder(o);
|
||||
inOrder.verify(o).accept(any(), Mockito.contains("Building single-module"));
|
||||
inOrder.verify(o).accept(any(), Mockito.contains(MvndTestUtil.plugin(props, "maven-clean-plugin") + ":clean"));
|
||||
inOrder.verify(o).accept(any(), Mockito.contains(MvndTestUtil.plugin(props, "maven-compiler-plugin") + ":compile"));
|
||||
inOrder.verify(o).accept(any(), Mockito.contains(MvndTestUtil.plugin(props, "maven-compiler-plugin") + ":testCompile"));
|
||||
inOrder.verify(o).accept(any(), Mockito.contains(MvndTestUtil.plugin(props, "maven-surefire-plugin") + ":test"));
|
||||
inOrder.verify(o).accept(any(), Mockito.contains(MvndTestUtil.plugin(props, "maven-install-plugin") + ":install"));
|
||||
inOrder.verify(o).accept(any(), Mockito.contains("BUILD SUCCESS"));
|
||||
final List<String> messages = o.getMessages().stream()
|
||||
.filter(m -> m.getType() != Message.MOJO_STARTED)
|
||||
.map(m -> m.toString())
|
||||
.collect(Collectors.toList());
|
||||
Assertions.assertThat(messages)
|
||||
.is(new MatchInOrderAmongOthers<>(
|
||||
"Building single-module",
|
||||
MvndTestUtil.plugin(props, "maven-clean-plugin") + ":clean",
|
||||
MvndTestUtil.plugin(props, "maven-compiler-plugin") + ":compile",
|
||||
MvndTestUtil.plugin(props, "maven-compiler-plugin") + ":testCompile",
|
||||
MvndTestUtil.plugin(props, "maven-surefire-plugin") + ":test",
|
||||
MvndTestUtil.plugin(props, "maven-install-plugin") + ":install",
|
||||
"BUILD SUCCESS"));
|
||||
|
||||
assertJVM(o, props);
|
||||
|
||||
@@ -76,7 +81,7 @@ public class SingleModuleNativeIT {
|
||||
|
||||
}
|
||||
|
||||
protected void assertJVM(ClientOutput o, Properties props) {
|
||||
/* implemented in the subclass*/
|
||||
protected void assertJVM(TestClientOutput o, Properties props) {
|
||||
/* implemented in the subclass */
|
||||
}
|
||||
}
|
||||
|
@@ -15,50 +15,41 @@
|
||||
*/
|
||||
package org.jboss.fuse.mvnd.it;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import java.util.stream.Collectors;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.assertj.MatchInOrderAmongOthers;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.common.Message;
|
||||
import org.jboss.fuse.mvnd.junit.MvndTest;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@MvndTest(projectDir = "src/test/projects/single-module")
|
||||
public class SingleModuleTest extends SingleModuleNativeIT {
|
||||
|
||||
protected void assertJVM(ClientOutput output, Properties props) {
|
||||
final InOrder inOrder = Mockito.inOrder(output);
|
||||
inOrder.verify(output).projectStateChanged(
|
||||
"single-module",
|
||||
":single-module");
|
||||
inOrder.verify(output).projectStateChanged(
|
||||
"single-module",
|
||||
":single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-clean-plugin")
|
||||
+ ":clean {execution: default-clean}");
|
||||
inOrder.verify(output).projectStateChanged(
|
||||
"single-module",
|
||||
":single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-resources-plugin")
|
||||
+ ":resources {execution: default-resources}");
|
||||
inOrder.verify(output).projectStateChanged(
|
||||
"single-module",
|
||||
":single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-compiler-plugin")
|
||||
+ ":compile {execution: default-compile}");
|
||||
inOrder.verify(output).projectStateChanged(
|
||||
"single-module",
|
||||
":single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-resources-plugin")
|
||||
+ ":testResources {execution: default-testResources}");
|
||||
inOrder.verify(output).projectStateChanged(
|
||||
"single-module",
|
||||
":single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-compiler-plugin")
|
||||
+ ":testCompile {execution: default-testCompile}");
|
||||
inOrder.verify(output).projectStateChanged(
|
||||
"single-module",
|
||||
":single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-surefire-plugin")
|
||||
+ ":test {execution: default-test}");
|
||||
inOrder.verify(output).projectStateChanged(
|
||||
"single-module",
|
||||
":single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-install-plugin")
|
||||
+ ":install {execution: default-install}");
|
||||
protected void assertJVM(TestClientOutput o, Properties props) {
|
||||
final List<String> filteredMessages = o.getMessages().stream()
|
||||
.filter(m -> m.getType() == Message.MOJO_STARTED)
|
||||
.map(m -> m.toString())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Assertions.assertThat(filteredMessages)
|
||||
.is(new MatchInOrderAmongOthers<>(
|
||||
"\\Q:single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-clean-plugin")
|
||||
+ ":clean {execution: default-clean}\\E",
|
||||
"\\Q:single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-resources-plugin")
|
||||
+ ":resources {execution: default-resources}\\E",
|
||||
"\\Q:single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-compiler-plugin")
|
||||
+ ":compile {execution: default-compile}\\E",
|
||||
"\\Q:single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-resources-plugin")
|
||||
+ ":testResources {execution: default-testResources}\\E",
|
||||
"\\Q:single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-compiler-plugin")
|
||||
+ ":testCompile {execution: default-testCompile}\\E",
|
||||
"\\Q:single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-surefire-plugin")
|
||||
+ ":test {execution: default-test}\\E",
|
||||
"\\Q:single-module:org.apache.maven.plugins:" + MvndTestUtil.plugin(props, "maven-install-plugin")
|
||||
+ ":install {execution: default-install}\\E"));
|
||||
|
||||
inOrder.verify(output).projectFinished("single-module");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,17 +19,12 @@ import java.io.IOException;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.assertj.MatchInOrderAmongOthers;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.common.DaemonInfo;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
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;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
||||
@MvndTest(projectDir = "src/test/projects/single-module")
|
||||
public class StopStatusTest {
|
||||
@@ -46,41 +41,36 @@ public class StopStatusTest {
|
||||
/* The registry should be empty before we run anything */
|
||||
Assertions.assertThat(registry.getAll()).isEmpty();
|
||||
|
||||
client.execute(Mockito.mock(ClientOutput.class), "clean").assertSuccess();
|
||||
client.execute(new TestClientOutput(), "clean").assertSuccess();
|
||||
/* There should be exactly one item in the registry after the first build */
|
||||
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
|
||||
|
||||
final DaemonInfo d = registry.getAll().get(0);
|
||||
{
|
||||
/* The output of --status must be consistent with the registry */
|
||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
client.execute(output, "--status").assertSuccess();
|
||||
final ArgumentCaptor<String> logMessage = ArgumentCaptor.forClass(String.class);
|
||||
Mockito.verify(output, Mockito.atLeast(1)).accept(any(), logMessage.capture());
|
||||
Assertions.assertThat(logMessage.getAllValues())
|
||||
.is(new MatchInOrderAmongOthers<>(
|
||||
d.getUid() + " +" + d.getPid() + " +" + d.getAddress()));
|
||||
|
||||
output.assertContainsMatchingSubsequence(d.getUid() + " +" + d.getPid() + " +" + d.getAddress());
|
||||
}
|
||||
/* Wait, till the instance becomes idle */
|
||||
registry.awaitIdle(d.getUid());
|
||||
|
||||
client.execute(Mockito.mock(ClientOutput.class), "clean").assertSuccess();
|
||||
client.execute(new TestClientOutput(), "clean").assertSuccess();
|
||||
/* There should still be exactly one item in the registry after the second build */
|
||||
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
|
||||
|
||||
client.execute(Mockito.mock(ClientOutput.class), "--stop").assertSuccess();
|
||||
client.execute(new TestClientOutput(), "--stop").assertSuccess();
|
||||
/* No items in the registry after we have killed all daemons */
|
||||
Assertions.assertThat(registry.getAll()).isEmpty();
|
||||
|
||||
{
|
||||
/* After --stop, the output of --status may not contain the UID we have seen before */
|
||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
client.execute(output, "--status").assertSuccess();
|
||||
final ArgumentCaptor<String> logMessage = ArgumentCaptor.forClass(String.class);
|
||||
Mockito.verify(output, Mockito.atLeast(1)).accept(any(), logMessage.capture());
|
||||
|
||||
Assertions.assertThat(
|
||||
logMessage.getAllValues().stream()
|
||||
output.messagesToString().stream()
|
||||
.filter(m -> m.contains(d.getUid()))
|
||||
.collect(Collectors.toList()))
|
||||
.isEmpty();
|
||||
|
@@ -20,16 +20,15 @@ import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import javax.inject.Inject;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.common.DaemonInfo;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import org.jboss.fuse.mvnd.junit.ClientFactory;
|
||||
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
|
||||
import org.jboss.fuse.mvnd.junit.TestParameters;
|
||||
import org.jboss.fuse.mvnd.junit.TestRegistry;
|
||||
import org.jboss.fuse.mvnd.junit.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@MvndNativeTest(projectDir = "src/test/projects/upgrades-in-bom")
|
||||
public class UpgradesInBomNativeIT {
|
||||
@@ -48,7 +47,7 @@ public class UpgradesInBomNativeIT {
|
||||
/* Install the dependencies */
|
||||
for (String artifactDir : Arrays.asList("project/hello-0.0.1", "project/hello-0.0.2-SNAPSHOT")) {
|
||||
final Client cl = clientFactory.newClient(parameters.cd(parameters.getTestDir().resolve(artifactDir)));
|
||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
cl.execute(output, "clean", "install", "-e").assertSuccess();
|
||||
registry.killAll();
|
||||
}
|
||||
@@ -58,7 +57,7 @@ public class UpgradesInBomNativeIT {
|
||||
final Path parentDir = parameters.getTestDir().resolve("project/parent");
|
||||
final Client cl = clientFactory.newClient(parameters.cd(parentDir));
|
||||
{
|
||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
cl.execute(output, "clean", "install", "-e").assertSuccess();
|
||||
}
|
||||
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
|
||||
@@ -76,7 +75,7 @@ public class UpgradesInBomNativeIT {
|
||||
.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);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
cl.execute(output, "clean", "install", "-e").assertSuccess();
|
||||
}
|
||||
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
|
||||
|
@@ -17,18 +17,12 @@ package org.jboss.fuse.mvnd.it;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.inject.Inject;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jboss.fuse.mvnd.assertj.MatchInOrderAmongOthers;
|
||||
import org.jboss.fuse.mvnd.assertj.TestClientOutput;
|
||||
import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.client.DaemonParameters;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
|
||||
import org.jboss.fuse.mvnd.junit.MvndTestExtension;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
||||
@MvndNativeTest(projectDir = MvndTestExtension.TEMP_EXTERNAL)
|
||||
public class VersionNativeIT {
|
||||
@@ -41,20 +35,16 @@ public class VersionNativeIT {
|
||||
|
||||
@Test
|
||||
void version() throws IOException, InterruptedException {
|
||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||
final TestClientOutput output = new TestClientOutput();
|
||||
|
||||
client.execute(output, "-v").assertSuccess();
|
||||
|
||||
final ArgumentCaptor<String> logMessage = ArgumentCaptor.forClass(String.class);
|
||||
Mockito.verify(output, Mockito.atLeast(1)).accept(any(), logMessage.capture());
|
||||
|
||||
Assertions.assertThat(logMessage.getAllValues())
|
||||
.is(new MatchInOrderAmongOthers<>(
|
||||
"\\QMaven Daemon "
|
||||
+ System.getProperty("project.version")
|
||||
+ "-" + System.getProperty("os.detected.name")
|
||||
+ "-" + System.getProperty("os.detected.arch")
|
||||
+ "\\E",
|
||||
"\\QMaven home: " + parameters.mvndHome() + "\\E"));
|
||||
output.assertContainsMatchingSubsequence(
|
||||
"\\QMaven Daemon "
|
||||
+ System.getProperty("project.version")
|
||||
+ "-" + System.getProperty("os.detected.name")
|
||||
+ "-" + System.getProperty("os.detected.arch")
|
||||
+ "\\E",
|
||||
"\\QMaven home: " + parameters.mvndHome() + "\\E");
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ import org.jboss.fuse.mvnd.client.Client;
|
||||
import org.jboss.fuse.mvnd.client.DaemonParameters;
|
||||
import org.jboss.fuse.mvnd.client.ExecutionResult;
|
||||
import org.jboss.fuse.mvnd.common.Environment;
|
||||
import org.jboss.fuse.mvnd.common.Message;
|
||||
import org.jboss.fuse.mvnd.common.OsUtils.CommandProcess;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
|
||||
@@ -82,7 +83,7 @@ public class NativeTestClient implements Client {
|
||||
env.put("JAVA_HOME", System.getProperty("java.home"));
|
||||
}
|
||||
final String cmdString = String.join(" ", cmd);
|
||||
output.accept(null, "Executing " + cmdString);
|
||||
output.accept(Message.log("Executing " + cmdString));
|
||||
|
||||
final List<String> log = new ArrayList<>();
|
||||
final Consumer<String> loggingConsumer = s -> {
|
||||
@@ -91,7 +92,7 @@ public class NativeTestClient implements Client {
|
||||
}
|
||||
};
|
||||
try (CommandProcess process = new CommandProcess(builder.start(),
|
||||
loggingConsumer.andThen(s -> output.accept(null, s)))) {
|
||||
loggingConsumer.andThen(s -> output.accept(Message.log(s))))) {
|
||||
final int exitCode = process.waitFor(timeoutMs);
|
||||
return new Result(args, exitCode, log);
|
||||
} catch (IOException e) {
|
||||
|
32
integration-tests/src/test/resources/simplelogger.properties
Normal file
32
integration-tests/src/test/resources/simplelogger.properties
Normal file
@@ -0,0 +1,32 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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.
|
||||
|
||||
org.slf4j.simpleLogger.defaultLogLevel=info
|
||||
org.slf4j.simpleLogger.showDateTime=false
|
||||
org.slf4j.simpleLogger.showThreadName=false
|
||||
org.slf4j.simpleLogger.showLogName=false
|
||||
org.slf4j.simpleLogger.logFile=System.out
|
||||
org.slf4j.simpleLogger.cacheOutputStream=true
|
||||
org.slf4j.simpleLogger.levelInBrackets=true
|
||||
org.slf4j.simpleLogger.log.Sisu=info
|
||||
org.slf4j.simpleLogger.warnLevelString=WARNING
|
||||
|
||||
# MNG-6181: mvn -X also prints all debug logging from HttpClient
|
||||
# Be aware that the shaded packages are used
|
||||
# org.apache.http -> org.apache.maven.wagon.providers.http.httpclient
|
||||
org.slf4j.simpleLogger.log.org.apache.maven.wagon.providers.http.httpclient=off
|
||||
org.slf4j.simpleLogger.log.org.apache.maven.wagon.providers.http.httpclient.wire=off
|
Reference in New Issue
Block a user