[jboss-cvs] JBoss Messaging SVN: r6201 - in trunk/tests/src/org/jboss/messaging/tests: util and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 27 12:51:59 EDT 2009
Author: jmesnil
Date: 2009-03-27 12:51:58 -0400 (Fri, 27 Mar 2009)
New Revision: 6201
Added:
trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java
Modified:
trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageDurabilityTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/client/TemporaryQueueTest.java
trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
Log:
close ClientSession tests
+ refactored tests to have common code checking for thrown {Messaging|XA}Exceptions
Added: trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java 2009-03-27 16:51:58 UTC (rev 6201)
@@ -0,0 +1,288 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, 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.client;
+
+import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
+import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
+import static org.jboss.messaging.tests.util.RandomUtil.randomXid;
+
+import java.io.File;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.utils.SimpleString;
+
+/**
+ * A SessionCloseTest
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ *
+ */
+public class ClientSessionCloseTest extends UnitTestCase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private MessagingServiceImpl service;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testCanNotUseAClosedSession() throws Exception
+ {
+
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ final ClientSession session = sf.createSession(false, true, true);
+
+ session.close();
+
+ assertTrue(session.isClosed());
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.createProducer();
+ }
+ });
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.createConsumer(randomSimpleString());
+ }
+ });
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.createFileConsumer(new File("."), randomSimpleString());
+ }
+ });
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.createQueue(randomSimpleString(), randomSimpleString(), randomBoolean());
+ }
+ });
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.createTemporaryQueue(randomSimpleString(), randomSimpleString());
+ }
+ });
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.start();
+ }
+ });
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.stop();
+ }
+ });
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.commit();
+ }
+ });
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.rollback();
+ }
+ });
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.queueQuery(randomSimpleString());
+ }
+ });
+
+ expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+ {
+ public void run() throws MessagingException
+ {
+ session.bindingQuery(randomSimpleString());
+ }
+ });
+
+ }
+
+ public void testCanNotUseXAWithClosedSession() throws Exception
+ {
+
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ final ClientSession session = sf.createSession(true, false, false);
+
+ session.close();
+
+ assertTrue(session.isXA());
+ assertTrue(session.isClosed());
+
+ expectXAException(XAException.XAER_RMERR, new MessagingAction()
+ {
+ public void run() throws XAException
+ {
+ session.commit(randomXid(), randomBoolean());
+ }
+ });
+
+ expectXAException(XAException.XAER_RMERR, new MessagingAction()
+ {
+ public void run() throws XAException
+ {
+ session.end(randomXid(), XAResource.TMSUCCESS);
+ }
+ });
+
+ expectXAException(XAException.XAER_RMERR, new MessagingAction()
+ {
+ public void run() throws XAException
+ {
+ session.forget(randomXid());
+ }
+ });
+
+ expectXAException(XAException.XAER_RMERR, new MessagingAction()
+ {
+ public void run() throws XAException
+ {
+ session.prepare(randomXid());
+ }
+ });
+
+ expectXAException(XAException.XAER_RMERR, new MessagingAction()
+ {
+ public void run() throws XAException
+ {
+ session.recover(XAResource.TMSTARTRSCAN);
+ }
+ });
+
+ expectXAException(XAException.XAER_RMERR, new MessagingAction()
+ {
+ public void run() throws XAException
+ {
+ session.rollback(randomXid());
+ }
+ });
+
+ expectXAException(XAException.XAER_RMERR, new MessagingAction()
+ {
+ public void run() throws XAException
+ {
+ session.start(randomXid(), XAResource.TMNOFLAGS);
+ }
+ });
+
+ }
+
+ public void testCloseHierarchy() throws Exception
+ {
+ SimpleString address = randomSimpleString();
+ SimpleString queue = randomSimpleString();
+
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ ClientSession session = sf.createSession(false, true, true);
+
+ session.createQueue(address, queue, false);
+
+ ClientProducer producer = session.createProducer(address);
+ ClientConsumer consumer = session.createConsumer(queue);
+
+ session.close();
+
+ assertTrue(session.isClosed());
+ assertTrue(producer.isClosed());
+ assertTrue(consumer.isClosed());
+
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ Configuration config = new ConfigurationImpl();
+ config.setSecurityEnabled(false);
+ service = Messaging.newNullStorageMessagingService(config);
+ service.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ service.stop();
+
+ super.tearDown();
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageDurabilityTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageDurabilityTest.java 2009-03-27 16:34:49 UTC (rev 6200)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageDurabilityTest.java 2009-03-27 16:51:58 UTC (rev 6201)
@@ -141,7 +141,7 @@
boolean durable = true;
SimpleString address = randomSimpleString();
- SimpleString queue = randomSimpleString();
+ final SimpleString queue = randomSimpleString();
session.createQueue(address, queue, !durable);
@@ -151,14 +151,14 @@
restart();
session.start();
- try
+
+ expectMessagingException(MessagingException.QUEUE_DOES_NOT_EXIST, new MessagingAction()
{
- session.createConsumer(queue);
- }
- catch (MessagingException e)
- {
- assertEquals(MessagingException.QUEUE_DOES_NOT_EXIST, e.getCode());
- }
+ public void run() throws MessagingException
+ {
+ session.createConsumer(queue);
+ }
+ });
}
/**
@@ -169,7 +169,7 @@
boolean durable = true;
SimpleString address = randomSimpleString();
- SimpleString queue = randomSimpleString();
+ final SimpleString queue = randomSimpleString();
session.createTemporaryQueue(address, queue);
@@ -179,14 +179,13 @@
restart();
session.start();
- try
+ expectMessagingException(MessagingException.QUEUE_DOES_NOT_EXIST, new MessagingAction()
{
- session.createConsumer(queue);
- }
- catch (MessagingException e)
- {
- assertEquals(MessagingException.QUEUE_DOES_NOT_EXIST, e.getCode());
- }
+ public void run() throws MessagingException
+ {
+ session.createConsumer(queue);
+ }
+ });
}
// Package protected ---------------------------------------------
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/TemporaryQueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/TemporaryQueueTest.java 2009-03-27 16:34:49 UTC (rev 6200)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/TemporaryQueueTest.java 2009-03-27 16:51:58 UTC (rev 6201)
@@ -171,7 +171,7 @@
public void testDeleteTemporaryQueueWhenClientCrash() throws Exception
{
- SimpleString queue = randomSimpleString();
+ final SimpleString queue = randomSimpleString();
SimpleString address = randomSimpleString();
session.createTemporaryQueue(address, queue);
@@ -194,15 +194,14 @@
sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
session = sf.createSession(false, true, true);
session.start();
- try
+
+ expectMessagingException("temp queue must not exist after the server detected the client crash", MessagingException.QUEUE_DOES_NOT_EXIST, new MessagingAction()
{
- session.createConsumer(queue);
- fail("temp queue must not exist after the server detected the client crash");
- }
- catch (MessagingException e)
- {
- assertEquals(MessagingException.QUEUE_DOES_NOT_EXIST, e.getCode());
- }
+ public void run() throws MessagingException
+ {
+ session.createConsumer(queue);
+ }
+ });
session.close();
}
Modified: trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java 2009-03-27 16:34:49 UTC (rev 6200)
+++ trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java 2009-03-27 16:51:58 UTC (rev 6201)
@@ -26,6 +26,7 @@
import org.jboss.messaging.core.buffers.ChannelBuffers;
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
import org.jboss.messaging.core.server.MessageReference;
@@ -37,6 +38,7 @@
import org.jboss.messaging.utils.SimpleString;
import org.jboss.messaging.utils.UUIDGenerator;
+import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -322,6 +324,39 @@
return testDir + "/temp";
}
+ protected static void expectMessagingException(String message, int errorCode, MessagingAction action)
+ {
+ try
+ {
+ action.run();
+ fail(message);
+ }
+ catch (Exception e)
+ {
+ assertTrue(e instanceof MessagingException);
+ assertEquals(errorCode, ((MessagingException)e).getCode());
+ }
+ }
+
+ protected static void expectMessagingException(int errorCode, MessagingAction action)
+ {
+ expectMessagingException("must throw a MessagingException with the expected errorCode: " + errorCode, errorCode, action);
+ }
+
+ protected static void expectXAException(int errorCode, MessagingAction action)
+ {
+ try
+ {
+ action.run();
+ fail("must throw a XAException with the expected errorCode: " + errorCode);
+ }
+ catch (Exception e)
+ {
+ assertTrue(e instanceof XAException);
+ assertEquals(errorCode, ((XAException)e).errorCode);
+ }
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@@ -576,4 +611,9 @@
// Inner classes -------------------------------------------------
+ protected static interface MessagingAction
+ {
+ void run() throws Exception;
+ }
+
}
More information about the jboss-cvs-commits
mailing list