[jboss-cvs] JBoss Messaging SVN: r5969 - in trunk/tests: src/org/jboss/messaging/tests/integration/security and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Mar 3 09:21:06 EST 2009
Author: jmesnil
Date: 2009-03-03 09:21:06 -0500 (Tue, 03 Mar 2009)
New Revision: 5969
Removed:
trunk/tests/src/org/jboss/messaging/tests/integration/security/SecurityManagerClientTestBase.java
Modified:
trunk/tests/joram-tests/src/org/jboss/test/jms/JBossMessagingAdmin.java
trunk/tests/joram-tests/src/org/jboss/test/jms/SpawnedJMSServer.java
trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/security/SimpleClient.java
trunk/tests/src/org/jboss/messaging/tests/util/SpawnedVMSupport.java
Log:
fixed test infrastructure
* when spawning a VM to have a separate client or server, use the process IO to ensure everything is working properly and avoid race condition
* display the stack trace of the spawned VM if it not working as expected
Modified: trunk/tests/joram-tests/src/org/jboss/test/jms/JBossMessagingAdmin.java
===================================================================
--- trunk/tests/joram-tests/src/org/jboss/test/jms/JBossMessagingAdmin.java 2009-03-03 12:49:01 UTC (rev 5968)
+++ trunk/tests/joram-tests/src/org/jboss/test/jms/JBossMessagingAdmin.java 2009-03-03 14:21:06 UTC (rev 5969)
@@ -42,7 +42,10 @@
import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE;
import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
import java.util.Hashtable;
import javax.management.ObjectName;
@@ -263,20 +266,31 @@
String line = null;
while ((line = br.readLine()) != null)
{
- System.out.println(line);
- if ("OK".equals(line.trim()))
+ line.replace('|', '\n');
+ if (line.startsWith("Listening for transport"))
{
+ continue;
+ }
+ else if ("OK".equals(line.trim()))
+ {
return;
} else
{
- throw new IllegalStateException("Unable to start the spawned server");
+ throw new IllegalStateException("Unable to start the spawned server :" + line);
}
}
}
public void stopServer() throws Exception
{
- serverProcess.destroy();
+ OutputStreamWriter osw = new OutputStreamWriter(serverProcess.getOutputStream());
+ osw.write("STOP\n");
+ osw.flush();
+ int exitValue = serverProcess.waitFor();
+ if (exitValue != 0)
+ {
+ serverProcess.destroy();
+ }
}
// Constants -----------------------------------------------------
Modified: trunk/tests/joram-tests/src/org/jboss/test/jms/SpawnedJMSServer.java
===================================================================
--- trunk/tests/joram-tests/src/org/jboss/test/jms/SpawnedJMSServer.java 2009-03-03 12:49:01 UTC (rev 5968)
+++ trunk/tests/joram-tests/src/org/jboss/test/jms/SpawnedJMSServer.java 2009-03-03 14:21:06 UTC (rev 5969)
@@ -22,6 +22,8 @@
package org.jboss.test.jms;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
import java.util.Hashtable;
import javax.naming.InitialContext;
@@ -83,31 +85,38 @@
env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
serverManager.setContext(new InitialContext(env));
- Runtime.getRuntime().addShutdownHook(new Thread()
+ System.out.println("OK");
+
+ InputStreamReader isr = new InputStreamReader(System.in);
+ BufferedReader br = new BufferedReader(isr);
+ String line = null;
+ while ((line = br.readLine()) != null)
{
- @Override
- public void run()
+ if ("STOP".equals(line.trim()))
{
- try
- {
- server.stop();
- jndiServer.stop();
- namingInfo.stop();
- System.out.println("Server stopped");
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
+ server.stop();
+ jndiServer.stop();
+ namingInfo.stop();
+ System.out.println("Server stopped");
+ System.exit(0);
+ }
+ else
+ {
+ // stop anyway but with a error status
+ System.exit(1);
}
- });
-
- System.out.println("OK");
-
- while (true)
+ }
+ }
+ catch (Throwable t)
+ {
+ String allStack = t.getMessage() + "|";
+ StackTraceElement[] stackTrace = t.getStackTrace();
+ for (StackTraceElement stackTraceElement : stackTrace)
{
- Thread.sleep(100);
+ allStack += stackTraceElement.toString() + "|";
}
+ System.out.println(allStack);
+ System.exit(1);
}
finally
{
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java 2009-03-03 12:49:01 UTC (rev 5968)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java 2009-03-03 14:21:06 UTC (rev 5969)
@@ -22,47 +22,119 @@
package org.jboss.messaging.tests.integration.security;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.core.server.MessagingService;
import org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory;
import org.jboss.messaging.integration.transports.netty.NettyConnectorFactory;
+import org.jboss.messaging.tests.util.SpawnedVMSupport;
+import org.jboss.messaging.tests.util.UnitTestCase;
/**
* A NettySecurityClientTest
*
* @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
*/
-public class NettySecurityClientTest extends SecurityManagerClientTestBase
+public class NettySecurityClientTest extends UnitTestCase
{
// Constants -----------------------------------------------------
+ private static final Logger log = Logger.getLogger(NettySecurityClientTest.class);
+
// Attributes ----------------------------------------------------
+ private MessagingService messagingService;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
- // SecurityManagerClientTestBase overrides -----------------------
- @Override
- protected String getAcceptorFactoryClassName()
+ public void testProducerConsumerClientWithoutSecurityManager() throws Exception
{
- return NettyAcceptorFactory.class.getName();
+ doTestProducerConsumerClient(false);
}
- @Override
- protected String getConnectorFactoryClassName()
+ public void testProducerConsumerClientWithSecurityManager() throws Exception
{
- return NettyConnectorFactory.class.getName();
+ doTestProducerConsumerClient(true);
}
+
+ // SecurityManagerClientTestBase overrides -----------------------
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ ConfigurationImpl config = new ConfigurationImpl();
+ config.setSecurityEnabled(false);
+ config.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
+ messagingService = Messaging.newNullStorageMessagingService(config);
+ messagingService.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ messagingService.stop();
+
+ super.tearDown();
+ }
+
// Private -------------------------------------------------------
+ private void doTestProducerConsumerClient(boolean withSecurityManager) throws Exception
+ {
+ String[] vmargs = new String[0];
+ if (withSecurityManager)
+ {
+ URL securityPolicyURL = Thread.currentThread().getContextClassLoader().getResource("restricted-security-client.policy");
+ vmargs = new String[] { "-Djava.security.manager", "-Djava.security.policy=" + securityPolicyURL.getPath() };
+ }
+
+ // spawn a JVM that creates a client withor without a security manager which sends and receives a test message
+ Process p = SpawnedVMSupport.spawnVM(SimpleClient.class.getName(),
+ vmargs,
+ false,
+ new String[] { NettyConnectorFactory.class.getName() });
+
+ InputStreamReader isr = new InputStreamReader(p.getInputStream());
+ BufferedReader br = new BufferedReader(isr);
+ String line = null;
+ while ((line = br.readLine()) != null)
+ {
+ line = line.replace('|', '\n');
+ if ("OK".equals(line.trim()))
+ {
+ break;
+ } else
+ {
+ fail("Exception when starting the client: " + line);
+ }
+ }
+
+ // the client VM should exit by itself. If it doesn't, that means we have a problem
+ // and the test will timeout
+ log.debug("waiting for the client VM to exit ...");
+ p.waitFor();
+
+ assertEquals("client VM did not exit cleanly", 0, p.exitValue());
+ }
+
// Inner classes -------------------------------------------------
}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/security/SecurityManagerClientTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/security/SecurityManagerClientTestBase.java 2009-03-03 12:49:01 UTC (rev 5968)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/security/SecurityManagerClientTestBase.java 2009-03-03 14:21:06 UTC (rev 5969)
@@ -1,118 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt 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.messaging.tests.integration.security;
-
-import java.net.URL;
-
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.Messaging;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.tests.util.SpawnedVMSupport;
-import org.jboss.messaging.tests.util.UnitTestCase;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- */
-public abstract class SecurityManagerClientTestBase extends UnitTestCase
-{
- // Constants ------------------------------------------------------------------------------------
-
- private static final Logger log = Logger.getLogger(SecurityManagerClientTestBase.class);
-
- // Static ---------------------------------------------------------------------------------------
-
- // Attributes -----------------------------------------------------------------------------------
-
- private MessagingService messagingService;
-
- // Constructors ---------------------------------------------------------------------------------
-
- // Public ---------------------------------------------------------------------------------------
-
- public void testProducerConsumerClientWithoutSecurityManager() throws Exception
- {
- doTestProducerConsumerClient(false);
- }
-
- public void testProducerConsumerClientWithSecurityManager() throws Exception
- {
- doTestProducerConsumerClient(true);
- }
-
- // Package protected ----------------------------------------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ConfigurationImpl config = new ConfigurationImpl();
- config.setSecurityEnabled(false);
- config.getAcceptorConfigurations().add(new TransportConfiguration(getAcceptorFactoryClassName()));
- messagingService = Messaging.newNullStorageMessagingService(config);
- messagingService.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- messagingService.stop();
-
- super.tearDown();
- }
-
- // Protected ------------------------------------------------------------------------------------
-
- protected abstract String getAcceptorFactoryClassName();
-
- protected abstract String getConnectorFactoryClassName();
-
- // Private --------------------------------------------------------------------------------------
-
- private void doTestProducerConsumerClient(boolean withSecurityManager) throws Exception
- {
- String[] vmargs = new String[0];
- if (withSecurityManager)
- {
- URL securityPolicyURL = Thread.currentThread().getContextClassLoader().getResource("restricted-security-client.policy");
- vmargs = new String[] { "-Djava.security.manager", "-Djava.security.policy=" + securityPolicyURL.getPath() };
- }
-
- // spawn a JVM that creates a client withor without a security manager which sends and receives a test message
- Process p = SpawnedVMSupport.spawnVM(SimpleClient.class.getName(),
- vmargs,
- new String[] { getConnectorFactoryClassName() });
-
- // the client VM should exit by itself. If it doesn't, that means we have a problem
- // and the test will timeout
- log.debug("waiting for the client VM to exit ...");
- p.waitFor();
-
- assertEquals("client VM did not exit cleanly", 0, p.exitValue());
- }
-
- // Inner classes --------------------------------------------------------------------------------
-
-}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/security/SimpleClient.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/security/SimpleClient.java 2009-03-03 12:49:01 UTC (rev 5968)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/security/SimpleClient.java 2009-03-03 14:21:06 UTC (rev 5969)
@@ -96,11 +96,17 @@
session.deleteQueue(queueName);
session.close();
- System.out.println("DONE: client exited without any issue");
+ System.out.println("OK");
}
catch (Throwable t)
{
- log.error(t.getMessage(), t);
+ String allStack = t.getMessage() + "|";
+ StackTraceElement[] stackTrace = t.getStackTrace();
+ for (StackTraceElement stackTraceElement : stackTrace)
+ {
+ allStack += stackTraceElement.toString() + "|";
+ }
+ System.out.println(allStack);
System.exit(1);
}
}
Modified: trunk/tests/src/org/jboss/messaging/tests/util/SpawnedVMSupport.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/SpawnedVMSupport.java 2009-03-03 12:49:01 UTC (rev 5968)
+++ trunk/tests/src/org/jboss/messaging/tests/util/SpawnedVMSupport.java 2009-03-03 14:21:06 UTC (rev 5969)
@@ -104,6 +104,7 @@
sb.append("-Djava.library.path=").append(System.getProperty("java.library.path", "./native/bin")).append(" ");
+ //sb.append("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 ");
sb.append(className).append(' ');
for (int i = 0; i < args.length; i++)
More information about the jboss-cvs-commits
mailing list