Skip to content

Commit

Permalink
Merge pull request #448 from jamezp/WFARQ-165
Browse files Browse the repository at this point in the history
Upgrade WildFly Plugin Tools and add new utilities and behavior
  • Loading branch information
jamezp authored Apr 19, 2024
2 parents 4cdcf6b + 5d6d5df commit 3e82f8e
Show file tree
Hide file tree
Showing 32 changed files with 2,654 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Future;

Expand All @@ -39,7 +40,6 @@
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.wildfly.common.Assert;
import org.wildfly.plugin.tools.Deployment;
import org.wildfly.plugin.tools.DeploymentManager;
import org.wildfly.plugin.tools.DeploymentResult;
Expand All @@ -56,7 +56,7 @@
* @author <a href="mailto:[email protected]">James R. Perkins</a>
* @since 17-Nov-2010
*/
@SuppressWarnings({ "WeakerAccess", "TypeMayBeWeakened", "DeprecatedIsStillUsed", "deprecation", "unused" })
@SuppressWarnings({ "WeakerAccess", "TypeMayBeWeakened", "DeprecatedIsStillUsed", "unused" })
public class ArchiveDeployer {

private static final Logger log = Logger.getLogger(ArchiveDeployer.class);
Expand All @@ -77,8 +77,7 @@ public class ArchiveDeployer {
*/
@Deprecated
public ArchiveDeployer(DomainDeploymentManager deploymentManager) {
Assert.checkNotNullParam("deploymentManager", deploymentManager);
this.deploymentManagerDeprecated = deploymentManager;
this.deploymentManagerDeprecated = Objects.requireNonNull(deploymentManager, "The deploymentManager cannot be null");
this.deploymentManager = null;
}

Expand All @@ -88,7 +87,7 @@ public ArchiveDeployer(DomainDeploymentManager deploymentManager) {
* @param client the client used to communicate with the server
*/
public ArchiveDeployer(final ManagementClient client) {
Assert.checkNotNullParam("client", client);
Objects.requireNonNull(client, "The client cannot be null");
deploymentManagerDeprecated = null;
this.deploymentManager = DeploymentManager.Factory.create(client.getControllerClient());
}
Expand Down
8 changes: 4 additions & 4 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<groupId>org.jboss.remotingjmx</groupId>
<artifactId>remoting-jmx</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-testing-tools</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-controller-client</artifactId>
Expand All @@ -81,10 +85,6 @@
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-impl-base</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,48 @@

package org.jboss.as.arquillian.api;

import java.io.IOException;
import java.util.function.Function;

import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.Operation;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.dmr.ModelNode;
import org.wildfly.plugin.tools.OperationExecutionException;

/**
*
* A task which is run before deployment that allows the client to customize the server config.
*
* @author Stuart Douglas
*/
@SuppressWarnings("unused")
public interface ServerSetupTask {

/**
* Execute any necessary setup work that needs to happen before the first deployment
* to the given container.
* <p>
* <strong>Note on exception handling:</strong> If an implementation of this method
* throws {@code org.junit.AssumptionViolatedException}, the implementation can assume
* the following:
* throws any exception, the implementation can assume the following:
* <ol>
* <li>Any subsequent {@code ServerSetupTask}s {@link ServerSetup associated with test class}
* <strong>will not</strong> be executed.</li>
* <li>The deployment event that triggered the call to this method will be skipped.</li>
* <li>The {@link #tearDown(ManagementClient, String) tearDown} method of the instance
* that threw the exception <strong>will not</strong> be invoked. Therefore, implementations
* that throw {@code AssumptionViolatedException} should do so before altering any
* that throw {@code AssumptionViolatedException}, or any other exception, should do so before altering any
* system state.</li>
* <li>The {@link #tearDown(ManagementClient, String) tearDown} method for any
* previously executed {@code ServerSetupTask}s {@link ServerSetup associated with test class}
* <strong>will</strong> be invoked.</li>
* </ol>
* <p>
* If any other exception is thrown, the {@link #tearDown(ManagementClient, String)} will be executed, including
* this implementations {@code tearDown()}, re-throwing the original exception. The original exception will have
* any other exceptions thrown in the {@code tearDown()} methods add as
* {@linkplain Throwable#addSuppressed(Throwable) suppressed} messages.
* </p>
*
* @param managementClient management client to use to interact with the container
* @param containerId id of the container to which the deployment will be deployed
Expand All @@ -61,4 +74,78 @@ public interface ServerSetupTask {
* @throws Exception if a failure occurs
*/
void tearDown(ManagementClient managementClient, String containerId) throws Exception;

/**
* Executes an operation failing with a {@code RuntimeException} if the operation was not successful.
*
* @param client the client used to communicate with the server
* @param op the operation to execute
*
* @return the result from the operation
*
* @throws OperationExecutionException if the operation failed
* @throws IOException if an error occurs communicating with the server
*/
default ModelNode executeOperation(final ManagementClient client, final ModelNode op) throws IOException {
return executeOperation(client, op, (result) -> String.format("Failed to execute operation '%s': %s", op
.asString(),
Operations.getFailureDescription(result).asString()));
}

/**
* Executes an operation failing with a {@code RuntimeException} if the operation was not successful.
*
* @param client the client used to communicate with the server
* @param op the operation to execute
* @param errorMessage a function which accepts the result as the argument and returns an error message for an
* unsuccessful operation
*
* @return the result from the operation
*
* @throws OperationExecutionException if the operation failed
* @throws IOException if an error occurs communicating with the server
*/
default ModelNode executeOperation(final ManagementClient client, final ModelNode op,
final Function<ModelNode, String> errorMessage) throws IOException {
return executeOperation(client, Operation.Factory.create(op), errorMessage);
}

/**
* Executes an operation failing with a {@code RuntimeException} if the operation was not successful.
*
* @param client the client used to communicate with the server
* @param op the operation to execute
*
* @return the result from the operation
*
* @throws OperationExecutionException if the operation failed
* @throws IOException if an error occurs communicating with the server
*/
default ModelNode executeOperation(final ManagementClient client, final Operation op) throws IOException {
return executeOperation(client, op, (result) -> String.format("Failed to execute operation '%s': %s", op.getOperation()
.asString(),
Operations.getFailureDescription(result).asString()));
}

/**
* Executes an operation failing with a {@code RuntimeException} if the operation was not successful.
*
* @param client the client used to communicate with the server
* @param op the operation to execute
* @param errorMessage a function which accepts the result as the argument and returns an error message for an
* unsuccessful operation
*
* @return the result from the operation
*
* @throws OperationExecutionException if the operation failed
* @throws IOException if an error occurs communicating with the server
*/
default ModelNode executeOperation(final ManagementClient client, final Operation op,
final Function<ModelNode, String> errorMessage) throws IOException {
final ModelNode result = client.getControllerClient().execute(op);
if (!Operations.isSuccessfulOutcome(result)) {
throw new OperationExecutionException(op, result);
}
return Operations.readResult(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.as.arquillian.container;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.dmr.ModelNode;
import org.wildfly.plugin.tools.ContainerDescription;
import org.wildfly.plugin.tools.DeploymentManager;
import org.wildfly.plugin.tools.server.ServerManager;

/**
* A delegating implementation of a {@link ServerManager} which does not allow {@link #shutdown()} attempts. If either
* shutdown method is invoked, an {@link UnsupportedOperationException} will be thrown.
*
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
class ArquillianServerManager implements ServerManager {

private final ServerManager delegate;

ArquillianServerManager(ServerManager delegate) {
this.delegate = delegate;
}

@Override
public ModelControllerClient client() {
return delegate.client();
}

@Override
public String serverState() {
return delegate.serverState();
}

@Override
public String launchType() {
return delegate.launchType();
}

@Override
public String takeSnapshot() throws IOException {
return delegate.takeSnapshot();
}

@Override
public ContainerDescription containerDescription() throws IOException {
return delegate.containerDescription();
}

@Override
public DeploymentManager deploymentManager() {
return delegate.deploymentManager();
}

@Override
public boolean isRunning() {
return delegate.isRunning();
}

@Override
public boolean waitFor(final long startupTimeout) throws InterruptedException {
return delegate.waitFor(startupTimeout);
}

@Override
public boolean waitFor(final long startupTimeout, final TimeUnit unit) throws InterruptedException {
return delegate.waitFor(startupTimeout, unit);
}

/**
* Throws an {@link UnsupportedOperationException} as the server is managed by Arquillian
*
* @throws UnsupportedOperationException as the server is managed by Arquillian
*/
@Override
public void shutdown() throws UnsupportedOperationException {
throw new UnsupportedOperationException("Cannot shutdown a server managed by Arquillian");
}

/**
* Throws an {@link UnsupportedOperationException} as the server is managed by Arquillian
*
* @throws UnsupportedOperationException s the server is managed by Arquillian
*/
@Override
public void shutdown(final long timeout) throws UnsupportedOperationException {
throw new UnsupportedOperationException("Cannot shutdown a server managed by Arquillian");
}

@Override
public void executeReload() throws IOException {
delegate.executeReload();
}

@Override
public void executeReload(final ModelNode reloadOp) throws IOException {
delegate.executeReload(reloadOp);
}

@Override
public void reloadIfRequired() throws IOException {
delegate.reloadIfRequired();
}

@Override
public void reloadIfRequired(final long timeout, final TimeUnit unit) throws IOException {
delegate.reloadIfRequired(timeout, unit);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.as.arquillian.container;

import org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.setup.ConfigureLoggingSetupTask;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.wildfly.plugin.tools.OperationExecutionException;

/**
* Creates a library to add to deployments for common container based dependencies for in-container tests.
*
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
public class CommonContainerArchiveAppender implements AuxiliaryArchiveAppender {

@Override
public Archive<?> createAuxiliaryArchive() {
return ShrinkWrap.create(JavaArchive.class, "wildfly-common-testencricher.jar")
// These two types are added to avoid exceptions with class loading for in-container tests. These
// shouldn't really be used for in-container tests.
.addClasses(ServerSetupTask.class, ServerSetup.class)
.addClasses(ManagementClient.class)
// Add the setup task implementations
.addPackage(ConfigureLoggingSetupTask.class.getPackage())
// Adds wildfly-plugin-tools, this exception itself is explicitly needed
.addPackages(true, OperationExecutionException.class.getPackage())
.setManifest(new StringAsset("Manifest-Version: 1.0\n"
+ "Dependencies: org.jboss.as.controller-client,org.jboss.dmr\n"));
}
}
Loading

0 comments on commit 3e82f8e

Please sign in to comment.