Author: ropalka
Date: 2012-03-13 09:24:23 -0400 (Tue, 13 Mar 2012)
New Revision: 15930
Added:
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/AppclientHelper.java
Modified:
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/CleanupOperation.java
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestSetup.java
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/serviceref/ServiceRefClientTestCase.java
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/webserviceref/WebServiceRefClientTestCase.java
Log:
[JBWS-3435] finalizing appclient integration
Added: shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/AppclientHelper.java
===================================================================
--- shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/AppclientHelper.java
(rev 0)
+++
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/AppclientHelper.java 2012-03-13
13:24:23 UTC (rev 15930)
@@ -0,0 +1,213 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, 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.wsf.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.jboss.ws.common.concurrent.CopyJob;
+import org.jboss.ws.common.io.TeeOutputStream;
+
+/**
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ */
+final class AppclientHelper
+{
+
+ private static final String JBOSS_HOME = System.getProperty("jboss.home");
+ private static final String FS = System.getProperty("file.separator"); //
'/' on unix, '\' on windows
+ private static final String PS = System.getProperty("path.separator"); //
':' on unix, ';' on windows
+ private static final String EXT = ":".equals(PS) ? ".sh" :
".bat";
+ private static final String appclientScript = JBOSS_HOME + FS + "bin" + FS +
"appclient" + EXT;
+ private static Map<String, AppclientProcess> appclients = new HashMap<String,
AppclientProcess>();
+ private static ExecutorService es = Executors.newCachedThreadPool();
+ private static String appclientOutputDir;
+
+ private static class AppclientProcess {
+ public Process process;
+ public CopyJob outTask;
+ public CopyJob errTask;
+ public OutputStream output;
+ public OutputStream log;
+ }
+
+ private AppclientHelper()
+ {
+ // forbidden instantiation
+ }
+
+ static Process deployAppclient(final String archive, final OutputStream appclientOS,
final String... appclientArgs) throws Exception
+ {
+ final AppclientProcess ap = newAppclientProcess(archive, appclientOS,
appclientArgs);
+ final String appclientEarName = getAppclientEarName(archive);
+ final String appclientFullName = getAppclientFullName(archive);
+ final String patternToMatch = "Deployed \"" + appclientEarName +
"\"";
+ final String errorMessage = "Cannot deploy " + appclientFullName + "
to appclient";
+ awaitOutput(ap.output, patternToMatch, errorMessage);
+ appclients.put(archive, ap);
+ return ap.process;
+ }
+
+ static void undeployAppclient(final String archive, boolean awaitShutdown) throws
Exception
+ {
+ final AppclientProcess ap = appclients.remove(archive);
+ try
+ {
+ if (awaitShutdown)
+ {
+ shutdownAppclient(archive, ap.output);
+ }
+ }
+ finally
+ {
+ ap.outTask.kill();
+ ap.errTask.kill();
+ ap.process.destroy();
+ ap.log.close();
+ }
+ }
+
+ private static AppclientProcess newAppclientProcess(final String archive, final
OutputStream appclientOS, final String... appclientArgs) throws IOException
+ {
+ final String killFileName = getKillFileName(archive);
+ final String appclientFullName = getAppclientFullName(archive);
+ final String appclientShortName = getAppclientShortName(archive);
+ final AppclientProcess ap = new AppclientProcess();
+ ap.output = new ByteArrayOutputStream();
+ final List<String> args = new LinkedList<String>();
+ args.add(appclientScript);
+ args.add("--appclient-config=appclient-ws.xml");
+ args.add(appclientFullName);
+ if (appclientOS == null)
+ {
+ args.add(killFileName);
+ }
+ else
+ {
+ // propagate appclient args
+ for (final String appclientArg : appclientArgs)
+ {
+ args.add(appclientArg);
+ }
+ }
+ ap.process = new ProcessBuilder().command(args).start();
+ ap.log = new FileOutputStream(new File(getAppclientOutputDir(), appclientShortName
+ ".log-" + System.currentTimeMillis()));
+ // appclient out
+ ap.outTask = new CopyJob(ap.process.getInputStream(),
+ appclientOS == null ? new TeeOutputStream(ap.output, ap.log) : new
TeeOutputStream(ap.output, ap.log, appclientOS));
+ // appclient err
+ ap.errTask = new CopyJob(ap.process.getErrorStream(), ap.log);
+ // unfortunately the following threads are needed because of Windows behavior
+ es.submit(ap.outTask);
+ es.submit(ap.errTask);
+ return ap;
+ }
+
+ private static void shutdownAppclient(final String archive, final OutputStream os)
throws IOException, InterruptedException
+ {
+ final File killFile = new File(getKillFileName(archive));
+ killFile.createNewFile();
+ final String appclientFullName = getAppclientFullName(archive);
+ final String patternToMatch = "stopped in";
+ final String errorMessage = "Cannot undeploy " + appclientFullName +
" from appclient";
+ try
+ {
+ awaitOutput(os, patternToMatch, errorMessage);
+ }
+ finally
+ {
+ if (!killFile.delete())
+ {
+ killFile.deleteOnExit();
+ }
+ }
+ }
+
+ private static void awaitOutput(final OutputStream os, final String patternToMatch,
final String errorMessage) throws InterruptedException {
+ int countOfAttempts = 0;
+ final int maxCountOfAttempts = 120; // max wait time: 2 minutes
+ while (!os.toString().contains(patternToMatch))
+ {
+ Thread.sleep(1000);
+ if (countOfAttempts++ == maxCountOfAttempts)
+ {
+ throw new RuntimeException(errorMessage);
+ }
+ }
+ }
+
+ private static String getKillFileName(final String archive)
+ {
+ final int sharpIndex = archive.indexOf('#');
+ return JBOSS_HOME + FS + "bin" + FS + archive.substring(sharpIndex + 1) +
".kill";
+ }
+
+ private static String getAppclientOutputDir()
+ {
+ if (appclientOutputDir == null)
+ {
+ appclientOutputDir = System.getProperty("appclient.output.dir");
+ if (appclientOutputDir == null)
+ {
+ throw new IllegalStateException("System property appclient.output.dir
not configured");
+ }
+ final File appclientOutputDirectory = new File(appclientOutputDir);
+ if (!appclientOutputDirectory.exists())
+ {
+ if (!appclientOutputDirectory.mkdirs())
+ {
+ throw new IllegalStateException("Unable to create directory " +
appclientOutputDir);
+ }
+ }
+ }
+ return appclientOutputDir;
+ }
+
+ private static String getAppclientFullName(final String archive)
+ {
+ final int sharpIndex = archive.indexOf('#');
+ final String earName = archive.substring(0, sharpIndex);
+ return JBossWSTestHelper.getArchiveFile(earName).getParent() + FS + archive;
+ }
+
+ private static String getAppclientShortName(final String archive)
+ {
+ final int sharpIndex = archive.indexOf('#');
+ return archive.substring(sharpIndex + 1);
+ }
+
+ private static String getAppclientEarName(final String archive)
+ {
+ final int sharpIndex = archive.indexOf('#');
+ return archive.substring(0, sharpIndex);
+ }
+}
Modified: shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/CleanupOperation.java
===================================================================
---
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/CleanupOperation.java 2012-03-13
11:47:59 UTC (rev 15929)
+++
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/CleanupOperation.java 2012-03-13
13:24:23 UTC (rev 15930)
@@ -21,8 +21,7 @@
*/
package org.jboss.wsf.test;
-public abstract class CleanupOperation {
-
- public abstract void cleanUp();
-
+public interface CleanupOperation
+{
+ void cleanUp();
}
Modified: shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java
===================================================================
---
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java 2012-03-13
11:47:59 UTC (rev 15929)
+++
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java 2012-03-13
13:24:23 UTC (rev 15930)
@@ -21,9 +21,7 @@
*/
package org.jboss.wsf.test;
-import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Inet6Address;
@@ -31,12 +29,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnectorFactory;
@@ -48,8 +41,6 @@
import javax.xml.ws.soap.SOAPBinding;
import org.jboss.logging.Logger;
-import org.jboss.ws.common.concurrent.CopyJob;
-import org.jboss.ws.common.io.TeeOutputStream;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.deployer.Deployer;
@@ -65,10 +56,6 @@
{
private static final Logger LOGGER = Logger.getLogger(JBossWSTestHelper.class);
- private static final String JBOSS_HOME = System.getProperty("jboss.home");
- private static final String FS = System.getProperty("file.separator"); //
'/' on unix, '\' on windows
- private static final String PS = System.getProperty("path.separator"); //
':' on unix, ';' on windows
- private static final String EXT = ":".equals(PS) ? ".sh" :
".bat";
private static final String SYSPROP_JBOSSWS_INTEGRATION_TARGET =
"jbossws.integration.target";
private static final String SYSPROP_JBOSS_BIND_ADDRESS =
"jboss.bind.address";
private static final String SYSPROP_TEST_ARCHIVE_DIRECTORY =
"test.archive.directory";
@@ -85,18 +72,7 @@
private static String implVersion;
private static String testArchiveDir;
private static String testResourcesDir;
- private static String appclientOutputDir;
- private static Map<String, AppclientProcess> appclients = new HashMap<String,
JBossWSTestHelper.AppclientProcess>();
- private static ExecutorService es = Executors.newCachedThreadPool();
-
- private static class AppclientProcess {
- public Process process;
- public CopyJob outTask;
- public CopyJob errTask;
- public OutputStream output;
- public OutputStream log;
- }
-
+
private static synchronized Deployer getDeployer()
{
//lazy loading of deployer
@@ -137,55 +113,7 @@
{
if (DEPLOY_PROCESS_ENABLED)
{
- final int sharpIndex = archive.indexOf('#');
- final String appclientScript = JBOSS_HOME + FS + "bin" + FS +
"appclient" + EXT;
- final String earName = archive.substring(0, sharpIndex);
- final String appclientName = archive.substring(sharpIndex + 1);
- final String appclientFullName = getArchiveFile(earName).getParent() + FS +
archive;
- final String touchFile = JBOSS_HOME + FS + "bin" + FS + appclientName
+ ".kill";
- final String appclientOutputDirName =
System.getProperty("appclient.output.dir");
- if (appclientOutputDirName == null)
- {
- throw new IllegalStateException("System property appclient.output.dir
not configured");
- }
- final File appclientOutputDir = new File(appclientOutputDirName);
- if (!appclientOutputDir.exists())
- {
- appclientOutputDir.mkdirs();
- }
- AppclientProcess ap = new AppclientProcess();
- ap.output = new ByteArrayOutputStream();
- if (appclientOS == null)
- {
- ap.process = new ProcessBuilder().command(appclientScript,
"--appclient-config=appclient-ws.xml", appclientFullName, touchFile).start();
- }
- else
- {
- final List<String> args = new LinkedList<String>();
- args.add(appclientScript);
- args.add("--appclient-config=appclient-ws.xml");
- args.add(appclientFullName);
- // propagate appclient args
- for (final String appclientArg : appclientArgs)
- {
- args.add(appclientArg);
- }
- ap.process = new ProcessBuilder().command(args).start();
- }
- ap.log = new FileOutputStream(new File(getAppclientOutputDir(), appclientName +
".log-" + System.currentTimeMillis()));
- // appclient out
- ap.outTask = new CopyJob(ap.process.getInputStream(),
- appclientOS == null ? new TeeOutputStream(ap.output, ap.log) : new
TeeOutputStream(ap.output, ap.log, appclientOS));
- // appclient err
- ap.errTask = new CopyJob(ap.process.getErrorStream(), ap.log);
- // unfortunately the following threads are needed because of Windows behavior
- es.submit(ap.outTask);
- es.submit(ap.errTask);
- final String patternToMatch = "Deployed \"" + earName +
"\"";
- final String errorMessage = "Cannot deploy " + appclientFullName +
" to appclient";
- awaitOutput(ap.output, patternToMatch, errorMessage);
- appclients.put(archive, ap);
- return ap.process;
+ return AppclientHelper.deployAppclient(archive, appclientOS, appclientArgs);
}
return null;
}
@@ -193,68 +121,14 @@
/** Undeploy the given archive from the appclient
* Archive name is always in form archive.ear#appclient.jar
*/
- public static void undeployAppclient(final String archive) throws Exception
+ public static void undeployAppclient(final String archive, boolean awaitShutdown)
throws Exception
{
if (DEPLOY_PROCESS_ENABLED)
{
- AppclientProcess ap = appclients.get(archive);
- final int sharpIndex = archive.indexOf('#');
- final String earName = archive.substring(0, sharpIndex);
- final String appclientFullName = getArchiveFile(earName).getParent() + FS +
archive;
- final File touchFile = new File(JBOSS_HOME + FS + "bin" + FS +
archive.substring(sharpIndex + 1) + ".kill");
- touchFile.createNewFile();
- final String patternToMatch = "stopped in";
- final String errorMessage = "Cannot undeploy " + appclientFullName +
" from appclient";
- try
- {
- awaitOutput(ap.output, patternToMatch, errorMessage);
- }
- finally
- {
- touchFile.delete();
- ap.outTask.kill();
- ap.errTask.kill();
- ap.log.close();
- ap.process.destroy();
- appclients.remove(archive);
- }
+ AppclientHelper.undeployAppclient(archive, awaitShutdown);
}
}
- private static String getAppclientOutputDir()
- {
- if (appclientOutputDir == null)
- {
- appclientOutputDir = System.getProperty("appclient.output.dir");
- if (appclientOutputDir == null)
- {
- throw new IllegalStateException("System property appclient.output.dir
not configured");
- }
- final File appclientOutputDirectory = new File(appclientOutputDir);
- if (!appclientOutputDirectory.exists())
- {
- if (!appclientOutputDirectory.mkdirs())
- {
- throw new IllegalStateException("Unable to create directory " +
appclientOutputDir);
- }
- }
- }
- return appclientOutputDir;
- }
-
- private static void awaitOutput(final OutputStream os, final String patternToMatch,
final String errorMessage) throws InterruptedException {
- int countOfAttempts = 0;
- final int maxCountOfAttempts = 120; // max wait time: 2 minutes
- while (!os.toString().contains(patternToMatch))
- {
- Thread.sleep(1000);
- if (countOfAttempts++ == maxCountOfAttempts)
- {
- throw new RuntimeException(errorMessage);
- }
- }
- }
-
public static boolean isTargetJBoss7()
{
String target = getIntegrationTarget();
Modified: shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestSetup.java
===================================================================
---
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestSetup.java 2012-03-13
11:47:59 UTC (rev 15929)
+++
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestSetup.java 2012-03-13
13:24:23 UTC (rev 15930)
@@ -281,7 +281,7 @@
String archive = archives[archives.length - i - 1];
if (archive.endsWith("-appclient.jar"))
{
- JBossWSTestHelper.undeployAppclient(archive);
+ JBossWSTestHelper.undeployAppclient(archive, true);
}
else
{
Modified:
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/serviceref/ServiceRefClientTestCase.java
===================================================================
---
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/serviceref/ServiceRefClientTestCase.java 2012-03-13
11:47:59 UTC (rev 15929)
+++
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/serviceref/ServiceRefClientTestCase.java 2012-03-13
13:24:23 UTC (rev 15930)
@@ -76,18 +76,25 @@
public void testApplicationClient() throws Exception
{
- final OutputStream appclientOS = new ByteArrayOutputStream();
-
JBossWSTestHelper.deployAppclient("jaxws-samples-serviceref-appclient.ear#jaxws-samples-serviceref-appclient.jar",
appclientOS, "Hello World!");
- // wait till appclient stops
- String appclientLog = appclientOS.toString();
- while (!appclientLog.contains("stopped in")) {
- Thread.sleep(100);
- appclientLog = appclientOS.toString();
+ try
+ {
+ final OutputStream appclientOS = new ByteArrayOutputStream();
+
JBossWSTestHelper.deployAppclient("jaxws-samples-serviceref-appclient.ear#jaxws-samples-serviceref-appclient.jar",
appclientOS, "Hello World!");
+ // wait till appclient stops
+ String appclientLog = appclientOS.toString();
+ while (!appclientLog.contains("stopped in")) {
+ Thread.sleep(100);
+ appclientLog = appclientOS.toString();
+ }
+ // assert appclient logs
+ assertTrue(appclientLog.contains("TEST START"));
+ assertTrue(appclientLog.contains("TEST END"));
+ assertFalse(appclientLog.contains("not overridden through
service-ref"));
+ assertFalse(appclientLog.contains("Invalid echo return"));
}
- // assert appclient logs
- assertTrue(appclientLog.contains("TEST START"));
- assertTrue(appclientLog.contains("TEST END"));
- assertFalse(appclientLog.contains("not overridden through
service-ref"));
- assertFalse(appclientLog.contains("Invalid echo return"));
+ finally
+ {
+
JBossWSTestHelper.undeployAppclient("jaxws-samples-serviceref-appclient.ear#jaxws-samples-serviceref-appclient.jar",
false);
+ }
}
}
Modified:
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/webserviceref/WebServiceRefClientTestCase.java
===================================================================
---
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/webserviceref/WebServiceRefClientTestCase.java 2012-03-13
11:47:59 UTC (rev 15929)
+++
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/webserviceref/WebServiceRefClientTestCase.java 2012-03-13
13:24:23 UTC (rev 15930)
@@ -76,18 +76,25 @@
public void testApplicationClient() throws Throwable
{
- final String appclientArg = "Hello World!";
- final OutputStream appclientOS = new ByteArrayOutputStream();
- final Process appclientProcess =
JBossWSTestHelper.deployAppclient("jaxws-samples-webserviceref-appclient.ear#jaxws-samples-webserviceref-appclient.jar",
appclientOS, appclientArg);
- // wait till appclient stops
- String appclientLog = appclientOS.toString();
- while (!appclientLog.contains("stopped in")) {
- Thread.sleep(100);
- appclientLog = appclientOS.toString();
+ try
+ {
+ final String appclientArg = "Hello World!";
+ final OutputStream appclientOS = new ByteArrayOutputStream();
+ final Process appclientProcess =
JBossWSTestHelper.deployAppclient("jaxws-samples-webserviceref-appclient.ear#jaxws-samples-webserviceref-appclient.jar",
appclientOS, appclientArg);
+ // wait till appclient stops
+ String appclientLog = appclientOS.toString();
+ while (!appclientLog.contains("stopped in")) {
+ Thread.sleep(100);
+ appclientLog = appclientOS.toString();
+ }
+ // assert appclient logs
+ assertTrue(!appclientLog.contains("Invalid echo return"));
+ assertTrue(appclientLog.contains("TEST START"));
+ assertTrue(appclientLog.contains("TEST END"));
}
- // assert appclient logs
- assertTrue(!appclientLog.contains("Invalid echo return"));
- assertTrue(appclientLog.contains("TEST START"));
- assertTrue(appclientLog.contains("TEST END"));
+ finally
+ {
+
JBossWSTestHelper.undeployAppclient("jaxws-samples-webserviceref-appclient.ear#jaxws-samples-webserviceref-appclient.jar",
false);
+ }
}
}