Author: ritchiem
Date: Tue Nov  7 08:46:25 2006
New Revision: 472159

URL: http://svn.apache.org/viewvc?view=rev&rev=472159
Log:
Corrected VMBroker Creation and clean up per test

Modified:
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/ack/RecoverTest.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/BytesMessageTest.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/SessionStartTest.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/TextMessageTest.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/TestAMQConnection.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/TestAMQSession.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/Combined.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/Service.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Bind.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/JNDIReferenceableTest.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Lookup.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Unbind.java
    
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java
 Tue Nov  7 08:46:25 2006
@@ -23,6 +23,7 @@
 import org.apache.qpid.client.AMQConnection;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
 import org.apache.qpid.client.transport.TransportConnection;
 import org.apache.qpid.server.registry.ApplicationRegistry;
 import org.apache.qpid.server.store.TestableMemoryMessageStore;
@@ -38,6 +39,7 @@
 {
     private static final Logger _logger = 
Logger.getLogger(DisconnectAndRedeliverTest.class);
 
+
     static
     {
         String workdir = System.getProperty("QPID_WORK");
@@ -54,7 +56,21 @@
     @Before
     public void resetAppliactionRegistry() throws Exception
     {
-        ApplicationRegistry.initialise(new TestApplicationRegistry());
+        createVMBroker();
+        ApplicationRegistry.initialise(new TestApplicationRegistry(), 1);
+    }
+
+
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
     }
 
     @After
@@ -83,6 +99,8 @@
         ((AMQSession) consumerSession).declareExchangeSynch("amq.direct", 
"direct");
 
         Connection con2 = new AMQConnection("vm://:1", "guest", "guest", 
"producer1", "/test");
+                 
+
         Session producerSession = con2.createSession(false, 
Session.CLIENT_ACKNOWLEDGE);
         MessageProducer producer = producerSession.createProducer(queue);
 

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/ack/RecoverTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/ack/RecoverTest.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/ack/RecoverTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/ack/RecoverTest.java
 Tue Nov  7 08:46:25 2006
@@ -49,6 +49,19 @@
         DOMConfigurator.configure("broker/etc/log4j.xml");
     }
 
+    @Before
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
     @After
     public void stopVmBroker()
     {

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/BytesMessageTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/BytesMessageTest.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/BytesMessageTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/BytesMessageTest.java
 Tue Nov  7 08:46:25 2006
@@ -22,9 +22,14 @@
 import org.apache.qpid.client.AMQDestination;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.transport.TransportConnection;
 import org.apache.qpid.client.message.JMSBytesMessage;
 import org.apache.mina.common.ByteBuffer;
 import org.junit.Test;
+import org.junit.Before;
+import org.junit.Assert;
+import org.junit.After;
 
 import javax.jms.*;
 import java.util.ArrayList;
@@ -41,9 +46,29 @@
     private int _count = 100;
     public String _connectionString = "vm://:1";
 
-    void init() throws Exception
+    @Before
+    public void init() throws Exception
     {
         init(new AMQConnection(_connectionString, "guest", "guest", 
randomize("Client"), "/test_path"));
+        createVMBroker();
+    }
+
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    @After
+    public void stopVmBroker()
+    {
+        TransportConnection.killVMBroker(1);
     }
 
     void init(AMQConnection connection) throws Exception
@@ -65,7 +90,6 @@
     @Test
     public void test() throws Exception
     {
-        init();
 
         try
         {
@@ -96,7 +120,7 @@
 
     void waitFor(int count) throws InterruptedException
     {
-        synchronized (received)
+        synchronized(received)
         {
             while (received.size() < count)
             {
@@ -164,7 +188,7 @@
 
     public void onMessage(Message message)
     {
-        synchronized (received)
+        synchronized(received)
         {
             received.add((JMSBytesMessage) message);
             received.notify();

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java
 Tue Nov  7 08:46:25 2006
@@ -22,6 +22,8 @@
 import org.apache.qpid.client.AMQDestination;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.transport.TransportConnection;
 import org.apache.qpid.client.message.JMSBytesMessage;
 import org.apache.qpid.framing.AMQFrameDecodingException;
 import org.apache.qpid.framing.FieldTable;
@@ -29,6 +31,8 @@
 import org.apache.mina.common.ByteBuffer;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.Assert;
+import org.junit.After;
 
 import javax.jms.*;
 import java.io.IOException;
@@ -49,8 +53,28 @@
     public void init() throws Exception
     {
         init(new AMQConnection(_connectionString, "guest", "guest", 
randomize("Client"), "/test_path"));
+        createVMBroker();
     }
 
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    @After
+    public void stopVmBroker()
+    {
+        TransportConnection.killVMBroker(1);
+    }
+
+
     private void init(AMQConnection connection) throws Exception
     {
         init(connection, new AMQQueue(randomize("FieldTableMessageTest"), 
true));
@@ -109,7 +133,7 @@
     {
         synchronized(received)
         {
-            while(received.size() < count)
+            while (received.size() < count)
             {
                 received.wait();
             }

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java
 Tue Nov  7 08:46:25 2006
@@ -22,9 +22,13 @@
 import org.apache.qpid.client.AMQDestination;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.transport.TransportConnection;
 import org.apache.qpid.client.message.JMSObjectMessage;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.Assert;
+import org.junit.After;
 
 import javax.jms.JMSException;
 import javax.jms.Message;
@@ -50,6 +54,25 @@
     {
         String broker = _connectionString;
         init(new AMQConnection(broker, "guest", "guest", randomize("Client"), 
"/test_path"));
+        createVMBroker();
+    }
+
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    @After
+    public void stopVmBroker()
+    {
+        TransportConnection.killVMBroker(1);
     }
 
     private void init(AMQConnection connection) throws Exception
@@ -95,7 +118,7 @@
     {
         synchronized(received)
         {
-            while(received.size() < count)
+            while (received.size() < count)
             {
                 received.wait();
             }
@@ -116,25 +139,26 @@
     private static void assertEqual(Iterator expected, Iterator actual)
     {
         List<String> errors = new ArrayList<String>();
-        while(expected.hasNext() && actual.hasNext())
+        while (expected.hasNext() && actual.hasNext())
         {
-            try{
+            try
+            {
                 assertEqual(expected.next(), actual.next());
             }
-            catch(Exception e)
+            catch (Exception e)
             {
                 errors.add(e.getMessage());
             }
         }
-        while(expected.hasNext())
+        while (expected.hasNext())
         {
             errors.add("Expected " + expected.next() + " but no more actual 
values.");
         }
-        while(actual.hasNext())
+        while (actual.hasNext())
         {
             errors.add("Found " + actual.next() + " but no more expected 
values.");
         }
-        if(!errors.isEmpty())
+        if (!errors.isEmpty())
         {
             throw new RuntimeException(errors.toString());
         }
@@ -142,7 +166,7 @@
 
     private static void assertEqual(Object expected, Object actual)
     {
-        if(!expected.equals(actual))
+        if (!expected.equals(actual))
         {
             throw new RuntimeException("Expected '" + expected + "' found '" + 
actual + "'");
         }
@@ -183,7 +207,7 @@
 
         public String toString()
         {
-            return "Payload[" + data +"]";
+            return "Payload[" + data + "]";
         }
     }
 

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/SessionStartTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/SessionStartTest.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/SessionStartTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/SessionStartTest.java
 Tue Nov  7 08:46:25 2006
@@ -40,12 +40,31 @@
     private AMQDestination _destination;
     private AMQSession _session;
     private int count;
-    public String _connectionString = "vm://:1";  
+    public String _connectionString = "vm://:1";
 
     @Before
     public void init() throws Exception
     {
         init(new AMQConnection(_connectionString, "guest", "guest", 
randomize("Client"), "/test_path"));
+        createVMBroker();
+    }
+
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    @After
+    public void stopVmBroker()
+    {
+        TransportConnection.killVMBroker(1);
     }
 
     private void init(AMQConnection connection) throws Exception

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/TextMessageTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/TextMessageTest.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/TextMessageTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/basic/TextMessageTest.java
 Tue Nov  7 08:46:25 2006
@@ -22,9 +22,13 @@
 import org.apache.qpid.client.AMQDestination;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.transport.TransportConnection;
 import org.apache.qpid.client.message.JMSTextMessage;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.Assert;
+import org.junit.After;
 
 import javax.jms.*;
 import java.util.ArrayList;
@@ -45,6 +49,25 @@
     public void init() throws Exception
     {
         init(new AMQConnection(_connectionString, "guest", "guest", 
randomize("Client"), "/test_path"));
+        createVMBroker();
+    }
+
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    @After
+    public void stopVmBroker()
+    {
+        TransportConnection.killVMBroker(1);
     }
 
     private void init(AMQConnection connection) throws Exception
@@ -91,7 +114,7 @@
     {
         synchronized(received)
         {
-            while(received.size() < count)
+            while (received.size() < count)
             {
                 received.wait();
             }
@@ -112,25 +135,26 @@
     private static void assertEqual(Iterator expected, Iterator actual)
     {
         List<String> errors = new ArrayList<String>();
-        while(expected.hasNext() && actual.hasNext())
+        while (expected.hasNext() && actual.hasNext())
         {
-            try{
+            try
+            {
                 assertEqual(expected.next(), actual.next());
             }
-            catch(Exception e)
+            catch (Exception e)
             {
                 errors.add(e.getMessage());
             }
         }
-        while(expected.hasNext())
+        while (expected.hasNext())
         {
             errors.add("Expected " + expected.next() + " but no more actual 
values.");
         }
-        while(actual.hasNext())
+        while (actual.hasNext())
         {
             errors.add("Found " + actual.next() + " but no more expected 
values.");
         }
-        if(!errors.isEmpty())
+        if (!errors.isEmpty())
         {
             throw new RuntimeException(errors.toString());
         }
@@ -138,7 +162,7 @@
 
     private static void assertEqual(Object expected, Object actual)
     {
-        if(!expected.equals(actual))
+        if (!expected.equals(actual))
         {
             throw new RuntimeException("Expected '" + expected + "' found '" + 
actual + "'");
         }
@@ -163,7 +187,10 @@
         TextMessageTest test = new TextMessageTest();
         test._connectionString = argv.length == 0 ? "vm://:1" : argv[0];
         test.init();
-        if (argv.length > 1) test._count = Integer.parseInt(argv[1]);
+        if (argv.length > 1)
+        {
+            test._count = Integer.parseInt(argv[1]);
+        }
         test.test();
     }
 

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/TestAMQConnection.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/TestAMQConnection.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/TestAMQConnection.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/TestAMQConnection.java
 Tue Nov  7 08:46:25 2006
@@ -26,7 +26,8 @@
 
 import javax.jms.*;
 
-public class TestAMQConnection {
+public class TestAMQConnection
+{
 
     private static AMQConnection _connection;
     private static AMQTopic _topic;
@@ -34,18 +35,47 @@
     private static QueueSession _queueSession;
     private static TopicSession _topicSession;
 
-    @BeforeClass
-    public static void setUp() throws AMQException, URLSyntaxException, 
JMSException {
+
+    @Before
+    public void setUp() throws AMQException, URLSyntaxException, JMSException
+    {
+        createVMBroker();
         //initialise the variables we need for testing
         _connection = new AMQConnection("vm://:1", "guest", "guest", "fred", 
"/test");
         _topic = new AMQTopic("mytopic");
         _queue = new AMQQueue("myqueue");
     }
 
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    @After
+    public void stopVmBroker()
+    {
+        try
+        {
+            _connection.close();
+        }
+        catch (JMSException e)
+        {
+            //ignore 
+        }
+        TransportConnection.killVMBroker(1);
+    }
+
     /**
-    * Simple tests to check we can create TopicSession and QueueSession ok
-    * And that they throw exceptions where appropriate as per JMS spec
-    */
+     * Simple tests to check we can create TopicSession and QueueSession ok
+     * And that they throw exceptions where appropriate as per JMS spec
+     */
 
     @Test
     public void testCreateQueueSession() throws JMSException
@@ -59,38 +89,45 @@
         _topicSession = _connection.createTopicSession(false, 
AMQSession.NO_ACKNOWLEDGE);
     }
 
-    @Test(expected=javax.jms.IllegalStateException.class)
-    public void testTopicSessionCreateBrowser() throws JMSException {
+    @Test(expected = javax.jms.IllegalStateException.class)
+    public void testTopicSessionCreateBrowser() throws JMSException
+    {
         _topicSession.createBrowser(_queue);
     }
 
-    @Test(expected=javax.jms.IllegalStateException.class)
-    public void testTopicSessionCreateQueue() throws JMSException {
+    @Test(expected = javax.jms.IllegalStateException.class)
+    public void testTopicSessionCreateQueue() throws JMSException
+    {
         _topicSession.createQueue("abc");
     }
 
-    @Test(expected=javax.jms.IllegalStateException.class)
-    public void testTopicSessionCreateTemporaryQueue() throws JMSException {
+    @Test(expected = javax.jms.IllegalStateException.class)
+    public void testTopicSessionCreateTemporaryQueue() throws JMSException
+    {
         _topicSession.createTemporaryQueue();
     }
 
-    @Test(expected=javax.jms.IllegalStateException.class)
-    public void testQueueSessionCreateTemporaryTopic() throws JMSException {
+    @Test(expected = javax.jms.IllegalStateException.class)
+    public void testQueueSessionCreateTemporaryTopic() throws JMSException
+    {
         _queueSession.createTemporaryTopic();
     }
 
-    @Test(expected=javax.jms.IllegalStateException.class)
-    public void testQueueSessionCreateTopic() throws JMSException {
+    @Test(expected = javax.jms.IllegalStateException.class)
+    public void testQueueSessionCreateTopic() throws JMSException
+    {
         _queueSession.createTopic("abc");
     }
 
-    @Test(expected=javax.jms.IllegalStateException.class)
-    public void testQueueSessionDurableSubscriber() throws JMSException {
-        _queueSession.createDurableSubscriber(_topic,"abc");
+    @Test(expected = javax.jms.IllegalStateException.class)
+    public void testQueueSessionDurableSubscriber() throws JMSException
+    {
+        _queueSession.createDurableSubscriber(_topic, "abc");
     }
 
-    @Test(expected=javax.jms.IllegalStateException.class)
-    public void testQueueSessionUnsubscribe() throws JMSException {
+    @Test(expected = javax.jms.IllegalStateException.class)
+    public void testQueueSessionUnsubscribe() throws JMSException
+    {
         _queueSession.unsubscribe("abc");
     }
 

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/TestAMQSession.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/TestAMQSession.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/TestAMQSession.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/TestAMQSession.java
 Tue Nov  7 08:46:25 2006
@@ -38,15 +38,44 @@
     private static AMQSession _session;
     private static AMQTopic _topic;
     private static AMQQueue _queue;
+    private static AMQConnection _connection;
 
-    @BeforeClass
-    public static void setUp() throws AMQException, URLSyntaxException, 
JMSException
+    @Before
+    public  void setUp() throws AMQException, URLSyntaxException, JMSException
     {
+        createVMBroker();
         //initialise the variables we need for testing
-        AMQConnection connection = new AMQConnection("vm://:1", "guest", 
"guest", "fred", "/test");
+        _connection = new AMQConnection("vm://:1", "guest", "guest", "fred", 
"/test");
         _topic = new AMQTopic("mytopic");
         _queue = new AMQQueue("myqueue");
-        _session = (AMQSession) connection.createSession(false, 
AMQSession.NO_ACKNOWLEDGE);
+        _session = (AMQSession) _connection.createSession(false, 
AMQSession.NO_ACKNOWLEDGE);
+    }
+
+
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    @After
+    public void stopVmBroker()
+    {
+        try
+        {
+            _connection.close();
+        }
+        catch (JMSException e)
+        {
+            //just close
+        }
+        TransportConnection.killVMBroker(1);
     }
 
     @Test

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java
 Tue Nov  7 08:46:25 2006
@@ -20,11 +20,14 @@
 import junit.framework.JUnit4TestAdapter;
 import org.apache.qpid.client.AMQConnection;
 import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.transport.TransportConnection;
 import org.apache.log4j.Logger;
 import org.junit.After;
 import static org.junit.Assert.assertEquals;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.Assert;
 
 import javax.jms.*;
 import java.util.ArrayList;
@@ -33,16 +36,16 @@
 /**
  * Due to bizarre exception handling all sessions are closed if you get
  * a channel close request and no exception listener is registered.
- *
+ * <p/>
  * JIRA issue IBTBLZ-10.
- *
+ * <p/>
  * Simulate by:
- *
+ * <p/>
  * 0. Create two sessions with no exception listener.
  * 1. Publish message to queue/topic that does not exist (wrong routing key).
  * 2. This will cause a channel close.
  * 3. Since client does not have an exception listener, currently all sessions 
are
- *    closed.
+ * closed.
  */
 public class ChannelCloseOkTest
 {
@@ -57,18 +60,40 @@
     private final static Logger _log = 
Logger.getLogger(ChannelCloseOkTest.class);
     public String _connectionString = "vm://:1";
 
+
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    public void stopVmBroker()
+    {
+        TransportConnection.killVMBroker(1);
+    }
+
     @Before
     public void init() throws Exception
     {
+        createVMBroker();
+
         _connection = new AMQConnection(_connectionString, "guest", "guest", 
randomize("Client"), "/test_path");
+
         _destination1 = new AMQQueue("q1", true);
         _destination2 = new AMQQueue("q2", true);
         _session1 = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        _session1.createConsumer(_destination1).setMessageListener(new 
MessageListener() {
+        _session1.createConsumer(_destination1).setMessageListener(new 
MessageListener()
+        {
             public void onMessage(Message message)
             {
                 _log.debug("consumer 1 got message [" + 
getTextMessage(message) + "]");
-                synchronized (_received1)
+                synchronized(_received1)
                 {
                     _received1.add(message);
                     _received1.notify();
@@ -76,11 +101,12 @@
             }
         });
         _session2 = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        _session2.createConsumer(_destination2).setMessageListener(new 
MessageListener() {
+        _session2.createConsumer(_destination2).setMessageListener(new 
MessageListener()
+        {
             public void onMessage(Message message)
             {
-                _log.debug("consumer 2 got message [" +  
getTextMessage(message) + "]");
-                synchronized (_received2)
+                _log.debug("consumer 2 got message [" + 
getTextMessage(message) + "]");
+                synchronized(_received2)
                 {
                     _received2.add(message);
                     _received2.notify();
@@ -93,7 +119,7 @@
 
     private String getTextMessage(Message message)
     {
-        TextMessage tm = (TextMessage)message;
+        TextMessage tm = (TextMessage) message;
         try
         {
             return tm.getText();
@@ -112,6 +138,8 @@
             System.out.println(">>>>>>>>>>>>>>.. closing");
             _connection.close();
         }
+
+        stopVmBroker();
     }
 
     @Test
@@ -123,7 +151,8 @@
     @Test
     public void testWithExceptionListener() throws Exception
     {
-        _connection.setExceptionListener(new ExceptionListener() {
+        _connection.setExceptionListener(new ExceptionListener()
+        {
             public void onException(JMSException jmsException)
             {
                 _log.error("onException - ", jmsException);
@@ -177,7 +206,7 @@
 
     private void waitFor(List<Message> received, int count) throws 
InterruptedException
     {
-        synchronized (received)
+        synchronized(received)
         {
             while (received.size() < count)
             {

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/Combined.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/Combined.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/Combined.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/Combined.java
 Tue Nov  7 08:46:25 2006
@@ -31,18 +31,36 @@
  */
 public class Combined
 {
+
+    @Before
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    @After
+    public void stopVmBroker()
+    {
+        ServiceCreator.closeAll();
+        TransportConnection.killVMBroker(1);
+    }
+
     @Test
     public void forwardAll() throws Exception
     {
         int services = 2;
         ServiceCreator.start("vm://:1", services);
 
-        //give them time to get registered etc.
-        System.out.println("Services started, waiting for them to 
initialise...");
-        Thread.sleep(5 * 1000);
         System.out.println("Starting client...");
 
-        new Client("vm://:1", services).waitUntilComplete();
+        new Client("vm://:1", services).shutdownWhenComplete();
 
         System.out.println("Completed successfully!");
     }

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/Service.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/Service.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/Service.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/Service.java
 Tue Nov  7 08:46:25 2006
@@ -24,6 +24,7 @@
 import javax.jms.Destination;
 import javax.jms.Message;
 import javax.jms.MessageListener;
+import javax.jms.JMSException;
 
 /**
  * Declare a queue and bind it to amq.direct with a 'well known' routing key,
@@ -56,10 +57,15 @@
             Destination replyTo = request.getJMSReplyTo();
             _session.createProducer(replyTo).send(response);
         }
-        catch(Exception e)
+        catch (Exception e)
         {
             e.printStackTrace(System.out);
         }
+    }
+
+    public void close() throws JMSException
+    {
+        _connection.close();
     }
 
     static AMQConnection connect(String broker) throws Exception

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java
 Tue Nov  7 08:46:25 2006
@@ -17,9 +17,15 @@
  */
 package org.apache.qpid.forwardall;
 
+import javax.jms.JMSException;
+
 public class ServiceCreator implements Runnable
 {
+    private static Thread[] threads;
+    private static ServiceCreator[] _services;
+
     private final String broker;
+    private Service service;
 
     ServiceCreator(String broker)
     {
@@ -30,7 +36,7 @@
     {
         try
         {
-            new Service(broker);
+            service = new Service(broker);
         }
         catch (Exception e)
         {
@@ -38,15 +44,37 @@
         }
     }
 
+    public void closeSC() throws JMSException
+    {
+        service.close();
+    }
+
+    static void closeAll()
+    {
+        for (int i = 0; i < _services.length; i++)
+        {
+            try
+            {
+                _services[i].closeSC();
+            }
+            catch (JMSException e)
+            {
+                //ignore
+            }
+        }
+    }
+
     static void start(String broker, int services) throws InterruptedException
     {
-        Thread[] threads = new Thread[services];
+        threads = new Thread[services];
+        _services = new ServiceCreator[services];
         ServiceCreator runner = new ServiceCreator(broker);
         //start services
         System.out.println("Starting " + services + " services...");
         for (int i = 0; i < services; i++)
         {
             threads[i] = new Thread(runner);
+            _services[i] = runner;
             threads[i].start();
         }
 
@@ -60,7 +88,8 @@
     {
         final String connectionString;
         final int services;
-        if (argv.length == 0) {
+        if (argv.length == 0)
+        {
             connectionString = "localhost:5672";
             services = 100;
         }

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Bind.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Bind.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Bind.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Bind.java
 Tue Nov  7 08:46:25 2006
@@ -91,7 +91,7 @@
             }
         }
 
-
+        Connection connection = null;
         try
         {
             // Create the initial context
@@ -100,7 +100,7 @@
             // Create the connection factory to be bound
             ConnectionFactory connectionFactory = null;
             // Create the Connection to be bound
-            Connection connection = null;
+
 
             try
             {
@@ -164,6 +164,20 @@
             if (e instanceof NoInitialContextException)
             {
                 throw(NoInitialContextException) e;
+            }
+        }
+        finally
+        {
+            try
+            {
+                if (connection != null)
+                {
+                    connection.close();
+                }
+            }
+            catch (JMSException e)
+            {
+                //ignore just want it closed
             }
         }
     }

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/JNDIReferenceableTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/JNDIReferenceableTest.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/JNDIReferenceableTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/JNDIReferenceableTest.java
 Tue Nov  7 08:46:25 2006
@@ -19,6 +19,10 @@
 
 import org.junit.Test;
 import org.junit.Assert;
+import org.junit.After;
+import org.junit.Before;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
 import junit.framework.JUnit4TestAdapter;
 
 import javax.naming.NameAlreadyBoundException;
@@ -37,6 +41,24 @@
  */
 public class JNDIReferenceableTest
 {
+    @Before
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    @After
+    public void stopVmBroker()
+    {
+        TransportConnection.killVMBroker(1);
+    }
 
     @Test
     public void referenceable()
@@ -70,19 +92,19 @@
         catch (NoInitialContextException e)
         {
             Assert.fail("You don't have the File System SPI on you class 
path.\n" +
-                    "This can be downloaded from sun here:\n" +
-                    "http://java.sun.com/products/jndi/downloads/index.html\n"; 
+
-                    "Click : Download JNDI 1.2.1 & More button\n" +
-                    "Download: File System Service Provider, 1.2 Beta 3\n" +
-                    "and add the two jars in the lib dir to your class path.");
+                        "This can be downloaded from sun here:\n" +
+                        
"http://java.sun.com/products/jndi/downloads/index.html\n"; +
+                        "Click : Download JNDI 1.2.1 & More button\n" +
+                        "Download: File System Service Provider, 1.2 Beta 3\n" 
+
+                        "and add the two jars in the lib dir to your class 
path.");
         }
 
         Assert.assertTrue(b.bound());
-
+        
         Lookup l = new Lookup();
 
         
Assert.assertTrue(l.connectionFactoryValue().equals(b.connectionFactoryValue()));
-        
+
         Assert.assertTrue(l.connectionValue().equals(b.connectionValue()));
 
         Assert.assertTrue(l.topicValue().equals(b.topicValue()));

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Lookup.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Lookup.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Lookup.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Lookup.java
 Tue Nov  7 08:46:25 2006
@@ -24,6 +24,7 @@
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.jms.JMSException;
 import java.io.File;
 import java.util.Hashtable;
 
@@ -46,6 +47,7 @@
     AMQTopic _topic = null;
     AMQConnection _connection = null;
     AMQConnectionFactory _connectionFactory = null;
+    private String _connectionURL;
 
     public Lookup()
     {
@@ -83,6 +85,8 @@
 
             _connection = (AMQConnection) ctx.lookup("Connection");
 
+            _connectionURL = _connection.toURL();
+
             _connectionFactory = (AMQConnectionFactory) 
ctx.lookup("ConnectionFactory");
             //System.out.println(topic);
 
@@ -93,6 +97,20 @@
         {
             System.out.println("Operation failed: " + e);
         }
+        finally
+        {
+            try
+            {
+                if (_connection != null)
+                {
+                    _connection.close();
+                }
+            }
+            catch (JMSException e)
+            {
+                //ignore just need to close
+            }
+        }
     }
 
     public String connectionFactoryValue()
@@ -102,7 +120,7 @@
 
     public String connectionValue()
     {
-        return _connection.toURL();
+        return _connectionURL;
     }
 
     public String topicValue()

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Unbind.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Unbind.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Unbind.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Unbind.java
 Tue Nov  7 08:46:25 2006
@@ -21,6 +21,8 @@
 import javax.naming.InitialContext;
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
+import javax.jms.Connection;
+import javax.jms.JMSException;
 import java.io.File;
 import java.util.Hashtable;
 
@@ -48,7 +50,6 @@
 
     public Unbind(boolean output)
     {
-
         // Set up the environment for creating the initial context
         Hashtable env = new Hashtable(11);
         env.put(Context.INITIAL_CONTEXT_FACTORY,
@@ -99,6 +100,14 @@
                 try
                 {
                     obj = ctx.lookup("Connection");
+                    try
+                    {
+                        ((Connection) obj).close();
+                    }
+                    catch (JMSException e)
+                    {
+                        //ignore just need to close
+                    }
                 }
                 catch (NameNotFoundException ne2)
                 {
@@ -125,7 +134,9 @@
             //System.out.println("unbind failed; object still there: " + obj);
 
             // Close the context when we're done
+
             ctx.close();
+
         }
         catch (NamingException e)
         {

Modified: 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java?view=diff&rev=472159&r1=472158&r2=472159
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java
 Tue Nov  7 08:46:25 2006
@@ -54,9 +54,28 @@
     private MessageConsumer testConsumer2;
 
 
+    public void createVMBroker()
+    {
+        try
+        {
+            TransportConnection.createVMBroker(1);
+        }
+        catch (AMQVMBrokerCreationException e)
+        {
+            Assert.fail("Unable to create broker: " + e);
+        }
+    }
+
+    @After
+    public void stopVmBroker()
+    {
+        TransportConnection.killVMBroker(1);
+    }
+
     @Before
     public void setup() throws Exception
     {
+        createVMBroker();
         queue1 = new AMQQueue("Q1", false);
         queue2 = new AMQQueue("Q2", false);
 
@@ -71,20 +90,6 @@
         prepProducer1 = prepSession.createProducer(queue1);
         prepCon.start();
 
-        // Sleep to ensure all queues have been created in the Broker.
-        try
-        {
-            System.out.println("Allowing Server to create queues");
-            Thread.sleep(2000);
-        }
-        catch (InterruptedException e)
-        {
-            //do nothing
-        }
-        finally
-        {
-            System.out.println("Setup Complete");
-        }
 
         //add some messages
         prepProducer1.send(prepSession.createTextMessage("A"));
@@ -96,21 +101,6 @@
         testConsumer1 = testSession.createConsumer(queue1);
         testConsumer2 = testSession.createConsumer(queue2);
         testCon.start();
-
-         // Sleep to ensure all queues have been created in the Broker.
-        try
-        {
-            System.out.println("Allowing Server to create queues");
-            Thread.sleep(2000);
-        }
-        catch (InterruptedException e)
-        {
-            //do nothing
-        }
-        finally
-        {
-            System.out.println("Setup Complete");
-        }
     }
 
     @After


Reply via email to