Skip to content

Commit 3e95e1b

Browse files
committed
Defend agains 1+ deployments
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
1 parent 6e7368e commit 3e95e1b

File tree

3 files changed

+74
-60
lines changed

3 files changed

+74
-60
lines changed

microprofile/tests/arquillian/src/main/java/io/helidon/microprofile/arquillian/HelidonContainerConfiguration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
* <li>useBeanXmlTemplate: (Optional) defaults to true: will create the default templates/beans.xml when beans.xml is missing</li>
4242
* <li>includeWarContextPath: (Optional) defaults to false: will include the war name as a root context.
4343
* For example, if a example.war is deployed, the root context is going to be /example.</li>
44+
* <li>multipleDeployments: (Optional) defaults to true: workaround for tests that unintentionally
45+
* executes 1+ times @org.jboss.arquillian.container.test.api.Deployment</li>
4446
* </ul>
4547
*/
4648
public class HelidonContainerConfiguration implements ContainerConfiguration {
@@ -52,6 +54,7 @@ public class HelidonContainerConfiguration implements ContainerConfiguration {
5254
private boolean useParentClassloader = true;
5355
private boolean inWebContainer = false;
5456
private boolean useBeanXmlTemplate = true;
57+
private boolean multipleDeployments = true;
5558
/*
5659
* Restful requires it, but core profile don't (because rest used to be deployed in a
5760
* web container together with other apps and in core profile there is only one app)
@@ -140,6 +143,14 @@ public void setIncludeWarContextPath(boolean includeWarContextPath) {
140143
this.includeWarContextPath = includeWarContextPath;
141144
}
142145

146+
public boolean isMultipleDeployments() {
147+
return multipleDeployments;
148+
}
149+
150+
public void setMultipleDeployments(boolean multipleDeployments) {
151+
this.multipleDeployments = multipleDeployments;
152+
}
153+
143154
@Override
144155
public void validate() throws ConfigurationException {
145156
if ((port <= 0) || (port > Short.MAX_VALUE)) {

microprofile/tests/arquillian/src/main/java/io/helidon/microprofile/arquillian/HelidonDeployableContainer.java

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -189,79 +189,81 @@ public ProtocolDescription getDefaultProtocol() {
189189

190190
@Override
191191
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
192-
// Because helidon doesn't have a dynamic war deployment model, we need to actually start the server here.
193-
RunContext context = new RunContext();
194-
contexts.put(archive.getId(), context);
192+
if (containerConfig.isMultipleDeployments() || (!containerConfig.isMultipleDeployments() && contexts.isEmpty())) {
193+
// Because helidon doesn't have a dynamic war deployment model, we need to actually start the server here.
194+
RunContext context = new RunContext();
195+
contexts.put(archive.getId(), context);
195196

196-
// Is it a JavaArchive?
197-
boolean isJavaArchive = archive instanceof JavaArchive;
197+
// Is it a JavaArchive?
198+
boolean isJavaArchive = archive instanceof JavaArchive;
198199

199-
try {
200-
// Create the temporary deployment directory.
201-
if (containerConfig.getUseRelativePath()) {
202-
context.deployDir = Paths.get("target/helidon-arquillian-test");
203-
} else {
204-
context.deployDir = Files.createTempDirectory("helidon-arquillian-test");
205-
}
206-
LOGGER.log(Level.INFO, "Running Arquillian tests in directory: " + context.deployDir.toAbsolutePath());
200+
try {
201+
// Create the temporary deployment directory.
202+
if (containerConfig.getUseRelativePath()) {
203+
context.deployDir = Paths.get("target/helidon-arquillian-test");
204+
} else {
205+
context.deployDir = Files.createTempDirectory("helidon-arquillian-test");
206+
}
207+
LOGGER.log(Level.INFO, "Running Arquillian tests in directory: " + context.deployDir.toAbsolutePath());
207208

208-
copyArchiveToDeployDir(archive, context.deployDir);
209+
copyArchiveToDeployDir(archive, context.deployDir);
209210

210-
for (Archive<?> additionalArchive : additionalArchives) {
211-
copyArchiveToDeployDir(additionalArchive, context.deployDir);
212-
}
211+
for (Archive<?> additionalArchive : additionalArchives) {
212+
copyArchiveToDeployDir(additionalArchive, context.deployDir);
213+
}
213214

214-
List<Path> classPath = new ArrayList<>();
215+
List<Path> classPath = new ArrayList<>();
215216

216-
Path rootDir = context.deployDir.resolve("");
217-
if (isJavaArchive) {
218-
ensureBeansXml(rootDir, null);
219-
classPath.add(rootDir);
220-
} else {
221-
// Prepare the launcher files
222-
Path webInfDir = context.deployDir.resolve("WEB-INF");
223-
Path classesDir = webInfDir.resolve("classes");
224-
Path libDir = webInfDir.resolve("lib");
225-
ensureBeansXml(classesDir, webInfDir);
226-
addServerClasspath(classPath, classesDir, libDir, rootDir);
227-
if (containerConfig.isInWebContainer()) {
228-
if (containerConfig.isIncludeWarContextPath()) {
229-
context.rootContext = archive.getName().split("\\.")[0];
230-
}
231-
if (!loadApplicationFromWebXml(context, webInfDir)) {
232-
// Search Application in classes
233-
loadApplicationFromClasses(context, archive);
217+
Path rootDir = context.deployDir.resolve("");
218+
if (isJavaArchive) {
219+
ensureBeansXml(rootDir, null);
220+
classPath.add(rootDir);
221+
} else {
222+
// Prepare the launcher files
223+
Path webInfDir = context.deployDir.resolve("WEB-INF");
224+
Path classesDir = webInfDir.resolve("classes");
225+
Path libDir = webInfDir.resolve("lib");
226+
ensureBeansXml(classesDir, webInfDir);
227+
addServerClasspath(classPath, classesDir, libDir, rootDir);
228+
if (containerConfig.isInWebContainer()) {
229+
if (containerConfig.isIncludeWarContextPath()) {
230+
context.rootContext = archive.getName().split("\\.")[0];
231+
}
232+
if (!loadApplicationFromWebXml(context, webInfDir)) {
233+
// Search Application in classes
234+
loadApplicationFromClasses(context, archive);
235+
}
234236
}
235237
}
236-
}
237238

238-
startServer(context, classPath.toArray(new Path[0]));
239-
} catch (IOException | SAXException | ParserConfigurationException e) {
240-
LOGGER.log(Level.INFO, "Failed to start container", e);
241-
throw new DeploymentException("Failed to copy the archive assets into the deployment directory", e);
242-
} catch (InvocationTargetException e) {
239+
startServer(context, classPath.toArray(new Path[0]));
240+
} catch (IOException | SAXException | ParserConfigurationException e) {
241+
LOGGER.log(Level.INFO, "Failed to start container", e);
242+
throw new DeploymentException("Failed to copy the archive assets into the deployment directory", e);
243+
} catch (InvocationTargetException e) {
243244

244-
try {
245-
context.runnerClass
246-
.getDeclaredMethod("abortedCleanup")
247-
.invoke(context.runner);
248-
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
249-
ex.printStackTrace();
250-
}
245+
try {
246+
context.runnerClass
247+
.getDeclaredMethod("abortedCleanup")
248+
.invoke(context.runner);
249+
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
250+
ex.printStackTrace();
251+
}
251252

252-
throw lookForSupressedDeploymentException(e.getTargetException())
253-
.map(d ->
253+
throw lookForSupressedDeploymentException(e.getTargetException())
254+
.map(d ->
254255
new org.jboss.arquillian.container.spi.client.container.DeploymentException("Deployment failure!", d))
255-
.orElseThrow(() -> new DefinitionException(e));
256-
} catch (ReflectiveOperationException e) {
257-
LOGGER.log(Level.INFO, "Failed to start container", e);
258-
throw new DefinitionException(e); // validation exceptions
259-
}
256+
.orElseThrow(() -> new DefinitionException(e));
257+
} catch (ReflectiveOperationException e) {
258+
LOGGER.log(Level.INFO, "Failed to start container", e);
259+
throw new DefinitionException(e); // validation exceptions
260+
}
260261

261-
// Server has started, so we're done.
262-
// ProtocolMetaData pm = new ProtocolMetaData();
263-
// pm.addContext(new HTTPContext("Helidon", "localhost", containerConfig.getPort()));
264-
// return pm;
262+
// Server has started, so we're done.
263+
// ProtocolMetaData pm = new ProtocolMetaData();
264+
// pm.addContext(new HTTPContext("Helidon", "localhost", containerConfig.getPort()));
265+
// return pm;
266+
}
265267
return new ProtocolMetaData();
266268
}
267269

microprofile/tests/tck/tck-restful/tck-restful-test/src/test/resources/arquillian.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<property name="useRelativePath">false</property>
3232
<property name="inWebContainer">true</property>
3333
<property name="includeWarContextPath">true</property>
34+
<property name="multipleDeployments">false</property>
3435
</configuration>
3536
</container>
3637
</arquillian>

0 commit comments

Comments
 (0)