Author: jmesnil
Date: 2009-12-07 06:09:31 -0500 (Mon, 07 Dec 2009)
New Revision: 8603
Removed:
trunk/tests/src/org/hornetq/tests/integration/ssl/CoreClientOverSSL.java
Modified:
trunk/tests/src/org/hornetq/tests/integration/ssl/CoreClientOverSSLTest.java
Log:
HORNETQ-234: test failure on CoreClientOverSSLTest.testPlainConnectionToSSLEndpoint
* refactored test code, it is not need to use external JVM process to test SSL
* uncommented testPlainConnectionToSSLEndpoint. it now fails with a CONNECTION_TIMEDOUT
Deleted: trunk/tests/src/org/hornetq/tests/integration/ssl/CoreClientOverSSL.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/ssl/CoreClientOverSSL.java 2009-12-07
10:59:41 UTC (rev 8602)
+++ trunk/tests/src/org/hornetq/tests/integration/ssl/CoreClientOverSSL.java 2009-12-07
11:09:31 UTC (rev 8603)
@@ -1,98 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat licenses this file to you 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.hornetq.tests.integration.ssl;
-
-import java.util.Arrays;
-
-import org.hornetq.core.client.ClientMessage;
-import org.hornetq.core.client.ClientProducer;
-import org.hornetq.core.client.ClientSession;
-import org.hornetq.core.client.ClientSessionFactory;
-import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
-import org.hornetq.core.config.TransportConfiguration;
-import org.hornetq.core.logging.Logger;
-import org.hornetq.integration.transports.netty.TransportConstants;
-import org.hornetq.jms.client.HornetQTextMessage;
-
-/**
- * This client will open a connection, send a message to a queue over SSL and
- * exit.
- *
- * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- */
-public class CoreClientOverSSL
-{
- // Constants -----------------------------------------------------
-
- private static final Logger log = Logger.getLogger(CoreClientOverSSL.class);
-
- // Static --------------------------------------------------------
-
- public static void main(String[] args)
- {
- try
- {
- System.out.println("Starting******");
-
- log.debug("args = " + Arrays.asList(args));
-
- if (args.length != 3)
- {
- log.fatal("unexpected number of args (should be 3)");
- System.exit(1);
- }
-
- boolean sslEnabled = Boolean.parseBoolean(args[0]);
- String keyStorePath = args[1];
- String keyStorePassword = args[2];
-
- TransportConfiguration tc = new
TransportConfiguration("org.hornetq.integration.transports.netty.NettyConnectorFactory");
- tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, sslEnabled);
- tc.getParams().put(TransportConstants.KEYSTORE_PATH_PROP_NAME, keyStorePath);
- tc.getParams().put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME,
keyStorePassword);
- ClientSessionFactory sf = new ClientSessionFactoryImpl(tc);
- ClientSession session = sf.createSession(false, true, true);
- ClientProducer producer = session.createProducer(CoreClientOverSSLTest.QUEUE);
-
- ClientMessage message = session.createClientMessage(HornetQTextMessage.TYPE,
false, 0,
- System.currentTimeMillis(), (byte) 1);
-
message.getBodyBuffer().writeString(CoreClientOverSSLTest.MESSAGE_TEXT_FROM_CLIENT);
- producer.send(message);
-
- session.close();
- }
- catch (Throwable t)
- {
- log.error(t.getMessage(), t);
- System.exit(1);
- }
- }
-
- // Attributes ----------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
Modified: trunk/tests/src/org/hornetq/tests/integration/ssl/CoreClientOverSSLTest.java
===================================================================
---
trunk/tests/src/org/hornetq/tests/integration/ssl/CoreClientOverSSLTest.java 2009-12-07
10:59:41 UTC (rev 8602)
+++
trunk/tests/src/org/hornetq/tests/integration/ssl/CoreClientOverSSLTest.java 2009-12-07
11:09:31 UTC (rev 8603)
@@ -17,11 +17,14 @@
import java.util.Map;
import org.hornetq.core.client.ClientConsumer;
+import org.hornetq.core.client.ClientMessage;
+import org.hornetq.core.client.ClientProducer;
import org.hornetq.core.client.ClientSession;
import org.hornetq.core.client.ClientSessionFactory;
import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
import org.hornetq.core.config.TransportConfiguration;
import org.hornetq.core.config.impl.ConfigurationImpl;
+import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.Message;
import org.hornetq.core.server.HornetQ;
@@ -29,7 +32,8 @@
import org.hornetq.integration.transports.netty.NettyAcceptorFactory;
import org.hornetq.integration.transports.netty.NettyConnectorFactory;
import org.hornetq.integration.transports.netty.TransportConstants;
-import org.hornetq.tests.util.SpawnedVMSupport;
+import org.hornetq.jms.client.HornetQTextMessage;
+import org.hornetq.tests.util.RandomUtil;
import org.hornetq.tests.util.UnitTestCase;
import org.hornetq.utils.SimpleString;
@@ -57,47 +61,71 @@
private HornetQServer server;
- private ClientSession session;
-
- private ClientConsumer consumer;
-
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
public void testSSL() throws Exception
{
- final Process p = SpawnedVMSupport.spawnVM(CoreClientOverSSL.class.getName(),
Boolean.TRUE.toString(), TransportConstants.DEFAULT_KEYSTORE_PATH,
TransportConstants.DEFAULT_KEYSTORE_PASSWORD);
+ String text = RandomUtil.randomString();
+
+ TransportConfiguration tc = new
TransportConfiguration(NettyConnectorFactory.class.getName());
+ tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
+ tc.getParams().put(TransportConstants.KEYSTORE_PATH_PROP_NAME,
TransportConstants.DEFAULT_KEYSTORE_PATH);
+ tc.getParams().put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME,
TransportConstants.DEFAULT_KEYSTORE_PASSWORD);
- Message m = consumer.receive(10000);
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(tc);
+ ClientSession session = sf.createSession(false, true, true);
+ session.createQueue(QUEUE, QUEUE, false);
+ ClientProducer producer = session.createProducer(QUEUE);
+
+ ClientMessage message = createTextMessage(text, session);
+ producer.send(message);
+
+ ClientConsumer consumer = session.createConsumer(QUEUE);
+ session.start();
+
+ Message m = consumer.receive(1000);
assertNotNull(m);
- assertEquals(MESSAGE_TEXT_FROM_CLIENT, m.getBodyBuffer().readString());
-
- log.debug("waiting for the client VM to exit ...");
- SpawnedVMSupport.assertProcessExits(true, 0, p);
+ assertEquals(text, m.getBodyBuffer().readString());
}
public void testSSLWithIncorrectKeyStorePassword() throws Exception
{
- Process p = SpawnedVMSupport.spawnVM(CoreClientOverSSL.class.getName(),
Boolean.TRUE.toString(), TransportConstants.DEFAULT_KEYSTORE_PATH, "invalid
pasword");
+ TransportConfiguration tc = new
TransportConfiguration(NettyConnectorFactory.class.getName());
+ tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
+ tc.getParams().put(TransportConstants.KEYSTORE_PATH_PROP_NAME,
TransportConstants.DEFAULT_KEYSTORE_PATH);
+ tc.getParams().put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "invalid
password");
- Message m = consumer.receive(5000);
- assertNull(m);
-
- log.debug("waiting for the client VM to exit ...");
- SpawnedVMSupport.assertProcessExits(false, 0, p);
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(tc);
+ try
+ {
+ sf.createSession(false, true, true);
+ fail();
+ }
+ catch (HornetQException e)
+ {
+ assertEquals(HornetQException.NOT_CONNECTED, e.getCode());
+ }
}
// see
https://jira.jboss.org/jira/browse/HORNETQ-234
- public void _testPlainConnectionToSSLEndpoint() throws Exception
+ public void testPlainConnectionToSSLEndpoint() throws Exception
{
- Process p = SpawnedVMSupport.spawnVM(CoreClientOverSSL.class.getName(),
Boolean.FALSE.toString(), TransportConstants.DEFAULT_KEYSTORE_PATH,
TransportConstants.DEFAULT_KEYSTORE_PASSWORD);
-
- Message m = consumer.receive(5000);
- assertNull(m);
-
- log.debug("waiting for the client VM to exit ...");
- SpawnedVMSupport.assertProcessExits(false, 0, p);
+ TransportConfiguration tc = new
TransportConfiguration(NettyConnectorFactory.class.getName());
+ tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, false);
+
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(tc);
+ sf.setCallTimeout(2000);
+ try
+ {
+ sf.createSession(false, true, true);
+ fail();
+ }
+ catch (HornetQException e)
+ {
+ assertEquals(HornetQException.CONNECTION_TIMEDOUT, e.getCode());
+ }
}
// Package protected ---------------------------------------------
@@ -112,20 +140,11 @@
config.getAcceptorConfigurations().add(new
TransportConfiguration(NettyAcceptorFactory.class.getName(), params));
server = HornetQ.newHornetQServer(config, false);
server.start();
- TransportConfiguration tc = new
TransportConfiguration(NettyConnectorFactory.class.getName(), params);
- ClientSessionFactory sf = new ClientSessionFactoryImpl(tc);
- session = sf.createSession(false, true, true);
- session.createQueue(QUEUE, QUEUE, false);
- consumer = session.createConsumer(QUEUE);
- session.start();
}
@Override
protected void tearDown() throws Exception
{
- consumer.close();
- session.close();
-
server.stop();
super.tearDown();