Permalink
Browse files

[AS7-6779] add controller client compatibility test

  • Loading branch information...
1 parent a5a28be commit 45da542be6ea66a3066e2cf35dff65180267c42e @emuckenhuber emuckenhuber committed with bstansberry Mar 26, 2013
@@ -190,7 +190,7 @@ public ChildFirstClassLoaderBuilder addMavenResourceURL(String artifactGav) thro
return this;
}
- public ChildFirstClassLoaderBuilder addRecursiveMavenResourceURL(String artifactGav)
+ public ChildFirstClassLoaderBuilder addRecursiveMavenResourceURL(String artifactGav, String... excludes)
throws DependencyCollectionException, DependencyResolutionException, IOException, ClassNotFoundException {
final String name = "maven-recursive-" + escape(artifactGav);
final File file = new File(cache, name);
@@ -207,7 +207,7 @@ public ChildFirstClassLoaderBuilder addRecursiveMavenResourceURL(String artifact
}
} else {
System.out.println("No cached recursive maven urls for " + artifactGav + " found. " + file.getAbsolutePath() + " does not exist.");
- final List<URL> urls = MavenUtil.createMavenGavRecursiveURLs(artifactGav);
+ final List<URL> urls = MavenUtil.createMavenGavRecursiveURLs(artifactGav, excludes);
classloaderURLs.addAll(urls);
final ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
try {
@@ -21,18 +21,6 @@
*/
package org.jboss.as.model.test;
-import java.io.File;
-import java.io.PrintStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
import org.apache.maven.repository.internal.MavenServiceLocator;
import org.apache.maven.wagon.Wagon;
@@ -49,6 +37,7 @@
import org.sonatype.aether.connector.wagon.WagonProvider;
import org.sonatype.aether.connector.wagon.WagonRepositoryConnectorFactory;
import org.sonatype.aether.graph.Dependency;
+import org.sonatype.aether.graph.DependencyFilter;
import org.sonatype.aether.graph.DependencyNode;
import org.sonatype.aether.repository.LocalRepository;
import org.sonatype.aether.repository.RemoteRepository;
@@ -62,11 +51,25 @@
import org.sonatype.aether.transfer.TransferEvent;
import org.sonatype.aether.transfer.TransferResource;
import org.sonatype.aether.util.artifact.DefaultArtifact;
+import org.sonatype.aether.util.filter.ExclusionsDependencyFilter;
import org.sonatype.aether.util.graph.PreorderNodeListGenerator;
import org.sonatype.aether.util.version.GenericVersionScheme;
import org.sonatype.aether.version.InvalidVersionSpecificationException;
import org.sonatype.aether.version.VersionScheme;
+import java.io.File;
+import java.io.PrintStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
/**
*
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
@@ -117,7 +120,7 @@ static URL createMavenGavURL(String artifactGav) throws MalformedURLException {
return file.toURI().toURL();
}
- static List<URL> createMavenGavRecursiveURLs(String artifactGav) throws MalformedURLException, DependencyCollectionException, DependencyResolutionException {
+ static List<URL> createMavenGavRecursiveURLs(String artifactGav, String... excludes) throws MalformedURLException, DependencyCollectionException, DependencyResolutionException {
Artifact artifact = new DefaultArtifact(artifactGav);
if (artifact.getVersion() == null) {
throw new IllegalArgumentException("Null version");
@@ -159,7 +162,8 @@ static URL createMavenGavURL(String artifactGav) throws MalformedURLException {
collectRequest.setRoot(new Dependency(artifact, "compile" ));
collectRequest.addRepository( central );
DependencyNode node = REPOSITORY_SYSTEM.collectDependencies( session, collectRequest ).getRoot();
- DependencyRequest dependencyRequest = new DependencyRequest( node, null );
+ DependencyFilter filter = new ExclusionsDependencyFilter(Arrays.asList(excludes));
+ DependencyRequest dependencyRequest = new DependencyRequest( node, filter );
REPOSITORY_SYSTEM.resolveDependencies( session, dependencyRequest );
@@ -281,6 +281,8 @@
<systemPropertyVariables>
<jboss.server.config.file.name>standalone.xml</jboss.server.config.file.name>
<jboss.inst>${basedir}/target/jbossas</jboss.inst>
+ <org.jboss.model.test.cache.root>${org.jboss.model.test.cache.root}</org.jboss.model.test.cache.root>
+ <org.jboss.model.test.classpath.cache>${org.jboss.model.test.classpath.cache}</org.jboss.model.test.classpath.cache>
</systemPropertyVariables>
<additionalClasspathElements>
@@ -0,0 +1,179 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.as.test.integration.management.api;
+
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.as.controller.client.ModelControllerClientConfiguration;
+import org.jboss.as.controller.client.Operation;
+import org.jboss.as.controller.client.OperationBuilder;
+import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
+import org.jboss.as.model.test.ChildFirstClassLoaderBuilder;
+import org.jboss.as.process.protocol.StreamUtils;
+import org.jboss.dmr.ModelNode;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.security.SecureRandom;
+import java.util.Random;
+
+/**
+ * Test supported remoting libraries combinations.
+ *
+ * @author Emanuel Muckenhuber
+ */
+@RunWith(Arquillian.class)
+@RunAsClient
+public class ClientCompatibilityUnitTestCase {
+
+ private static final String[] excludes = new String[] { "org.jboss.threads:jboss-threads", "org.jboss:jboss-dmr", "org.jboss.logging:jboss-logging" };
+
+ private static final Archive deployment;
+ static {
+ final WebArchive archive = ShrinkWrap.create(WebArchive.class);
+ // Create basic archive which exceeds the remoting window size
+ for(int i = 0; i < 10; i ++) {
+ final byte[] data = new byte[8096];
+ new Random(new SecureRandom().nextLong()).nextBytes(data);
+ archive.add(new ByteArrayAsset(data), "data" + i);
+ }
+ deployment = archive;
+ }
+
+ @Test
+ public void test700Final() throws Exception {
+ test("7.0.0.Final");
+ }
+
+ @Test
+ public void test701Final() throws Exception {
+ test("7.0.1.Final");
+ }
+
+ @Test
+ public void test710Final() throws Exception {
+ test("7.1.0.Final");
+ }
+
+ @Test
+ public void test711Final() throws Exception {
+ test("7.1.1.Final");
+ }
+
+ @Test
+ public void test720Final() throws Exception {
+ test("7.2.0.Final");
+ }
+
+ @Test
+ public void testCurrent() throws Exception {
+ test(ModelControllerClient.Factory.create("localhost", 9999));
+ }
+
+ protected void test(final String version) throws Exception {
+ test(createClient(version, "localhost", 9999));
+ }
+
+ protected void test(final ModelControllerClient client) throws Exception {
+ try {
+ final ModelNode operation = new ModelNode();
+ operation.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.READ_RESOURCE_OPERATION);
+ operation.get(ModelDescriptionConstants.OP_ADDR).setEmptyList();
+ // include a lot of garbage
+ operation.get(ModelDescriptionConstants.RECURSIVE).set(true);
+ operation.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(true);
+ operation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).set(true);
+ final ModelNode result = client.execute(operation);
+ Assert.assertEquals(ModelDescriptionConstants.SUCCESS, result.get(ModelDescriptionConstants.OUTCOME).asString());
+
+ final ModelNode deploy = new ModelNode();
+ deploy.get(ModelDescriptionConstants.OP).set("add");
+ deploy.get(ModelDescriptionConstants.OP_ADDR).add("deployment", "compat-test.war");
+ deploy.get("content").get(0).get("input-stream-index").set(0);
+ deploy.get("auto-start").set(true);
+
+ final Operation o = OperationBuilder.create(deploy)
+ .addInputStream(deployment.as(ZipExporter.class).exportAsInputStream()).build();
+
+ try {
+ final ModelNode deployResult = client.execute(o);
+ Assert.assertEquals(deployResult.toString(), ModelDescriptionConstants.SUCCESS, deployResult.get(ModelDescriptionConstants.OUTCOME).asString());
+
+ } finally {
+ final ModelNode undeploy = new ModelNode();
+ undeploy.get(ModelDescriptionConstants.OP).set("remove");
+ undeploy.get(ModelDescriptionConstants.OP_ADDR).add("deployment", "compat-test.war");
+
+ try {
+ client.execute(undeploy);
+ } catch (IOException ignore) {
+ ignore.printStackTrace();
+ }
+
+ }
+ } finally {
+ StreamUtils.safeClose(client);
+ }
+ }
+
+ protected static ModelControllerClient createClient(final String version, final String host, final int port) throws Exception {
+ final ChildFirstClassLoaderBuilder classLoaderBuilder = new ChildFirstClassLoaderBuilder();
+ classLoaderBuilder.addRecursiveMavenResourceURL("org.jboss.as:jboss-as-controller-client:" + version, excludes);
+ classLoaderBuilder.addParentFirstClassPattern("org.jboss.as.controller.client.ModelControllerClientConfiguration");
+ classLoaderBuilder.addParentFirstClassPattern("org.jboss.as.controller.client.ModelControllerClient");
+ classLoaderBuilder.addParentFirstClassPattern("org.jboss.as.controller.client.OperationMessageHandler");
+ classLoaderBuilder.addParentFirstClassPattern("org.jboss.as.controller.client.Operation");
+
+ final ClassLoader classLoader = classLoaderBuilder.build();
+ final Class<?> clazz = classLoader.loadClass("org.jboss.as.controller.client.impl.ClientConfigurationImpl");
+ // create(final String hostName, final int port
+ final Method method = clazz.getMethod("create", String.class, int.class);
+ final Object configuration = method.invoke(null, host, port);
+
+ final Class<?> clazz2 = classLoader.loadClass("org.jboss.as.controller.client.impl.RemotingModelControllerClient");
+ Constructor constructor = clazz2.getConstructor(ModelControllerClientConfiguration.class);
+ final Object client = constructor.newInstance(configuration);
+ final InvocationHandler invocationHandler = new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ return method.invoke(client, args);
+ }
+ };
+ final Class<?>[] interfaces = new Class<?>[] {ModelControllerClient.class};
+ return (ModelControllerClient) Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
+ }
+
+}
@@ -265,6 +265,10 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-model-test</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-core-model-test-framework</artifactId>
<scope>test</scope>
@@ -99,6 +99,8 @@
<systemPropertyVariables>
<jboss.server.config.file.name>standalone.xml</jboss.server.config.file.name>
<jboss.inst>${basedir}/target/jbossas</jboss.inst>
+ <org.jboss.model.test.cache.root>${org.jboss.model.test.cache.root}</org.jboss.model.test.cache.root>
+ <org.jboss.model.test.classpath.cache>${org.jboss.model.test.classpath.cache}</org.jboss.model.test.classpath.cache>
</systemPropertyVariables>
</configuration>
</execution>

0 comments on commit 45da542

Please sign in to comment.