[rhmessaging-commits] rhmessaging commits: r2101 - in store/branches/java/M2.x/java/bdbstore: src/test/java/org/apache/qpid/server/store/berkeleydb and 3 other directories.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Mon Jun 2 10:29:56 EDT 2008


Author: ritchiem
Date: 2008-06-02 10:29:56 -0400 (Mon, 02 Jun 2008)
New Revision: 2101

Added:
   store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/server/QueueDeleteWhilstRoutingTest.java
   store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/testutil/
   store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/testutil/BDBVMTestCase.java
Modified:
   store/branches/java/M2.x/java/bdbstore/pom.xml
   store/branches/java/M2.x/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreTest.java
   store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/server/StoreContextRaceConditionTest.java
Log:
QPID-1101, QPID-1103 :Added BDBVMTestCase to allow the clean up of BDB files on disk for InVM brokers based using persistentn configuration. Updated StoreContextRaceConditionTest.java to utilise these methods.
QueueDeleteWhilstRoutingTest added to check against one cause of MetaData exceptions. 
BDBStoreTest.java also edited to extends BDBVMTestCase.java to utilise deleteDirectory method.

Known issues: VMTestCase still creates an inVMBroker in the setUp method. This is to easy development on Qpid M2x but results in additional work directory being created on disk. 

Modified: store/branches/java/M2.x/java/bdbstore/pom.xml
===================================================================
--- store/branches/java/M2.x/java/bdbstore/pom.xml	2008-05-30 20:41:48 UTC (rev 2100)
+++ store/branches/java/M2.x/java/bdbstore/pom.xml	2008-06-02 14:29:56 UTC (rev 2101)
@@ -52,10 +52,6 @@
         </dependency>
         <dependency>
             <groupId>org.apache.qpid</groupId>
-            <artifactId>qpid-common</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.qpid</groupId>
             <artifactId>qpid-perftests</artifactId>
         </dependency>
         <dependency>
@@ -88,12 +84,24 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <configuration>
+		    <forkMode>always</forkMode>
                     <systemProperties>
                         <property>
                             <name>QPID_HOME</name>
-                            <value>${basedir}/${topDirectoryLocation}/broker</value>
+                            <value>${basedir}\${topDirectoryLocation}\broker</value>
                         </property>
+                        <property>
+                            <name>BDB_WORK</name>
+                            <value>${basedir}\${topDirectoryLocation}\bdbstore\target\qpidWork</value>
+                        </property>
+                        <property>
+                            <name>amqj.logging.level</name>
+                            <value>${amqj.logging.level}</value>
+                        </property>
                     </systemProperties>
+                    <excludes>
+                            <exclude>**/BDBVMTestCase.class</exclude>
+                    </excludes>
                 </configuration>
             </plugin>
 

Modified: store/branches/java/M2.x/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreTest.java
===================================================================
--- store/branches/java/M2.x/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreTest.java	2008-05-30 20:41:48 UTC (rev 2100)
+++ store/branches/java/M2.x/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreTest.java	2008-06-02 14:29:56 UTC (rev 2101)
@@ -19,36 +19,40 @@
 
 import com.sleepycat.je.DatabaseException;
 import junit.framework.Assert;
-import junit.framework.TestCase;
 import junit.framework.TestSuite;
+import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.log4j.Logger;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.*;
-import org.apache.qpid.framing.abstraction.MessagePublishInfo;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.BasicContentHeaderProperties;
+import org.apache.qpid.framing.ContentHeaderBody;
+import org.apache.qpid.framing.MethodRegistry;
+import org.apache.qpid.framing.ProtocolVersion;
 import org.apache.qpid.framing.abstraction.ContentChunk;
+import org.apache.qpid.framing.abstraction.MessagePublishInfo;
 import org.apache.qpid.server.RequiredDeliveryException;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.store.StoreContext;
 import org.apache.qpid.server.queue.AMQQueue;
 import org.apache.qpid.server.queue.MessageMetaData;
-import org.apache.qpid.server.queue.QueueRegistry;
 import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.store.StoreContext;
 import org.apache.qpid.server.txn.NonTransactionalContext;
 import org.apache.qpid.server.txn.TransactionalContext;
 import org.apache.qpid.server.util.NullApplicationRegistry;
-import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.etp.qpid.testutil.BDBVMTestCase;
 
 import java.io.File;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.HashSet;
 
-public class BDBStoreTest extends TestCase
+public class BDBStoreTest extends BDBVMTestCase
 {
     private static final Logger _log = Logger.getLogger(BDBStoreTest.class);
 
     private BDBMessageStore _store;
+    private String STORE_LOCATION = System.getProperty("BDB_WORK") + "/bdbTestEnv";
 
     private StoreContext _storeContext = new StoreContext();
     private VirtualHost _virtualHost;
@@ -65,16 +69,10 @@
     {
         ApplicationRegistry.initialise(new NullApplicationRegistry());
 
-        File bdbDir = new File("bdbTestEnv");
-        if (bdbDir.exists())
-        {
-            File[] entries = bdbDir.listFiles();
-            for (File f : entries)
-            {
-                f.delete();
-            }
-            bdbDir.delete();
-        }
+        File bdbDir = new File(STORE_LOCATION);
+
+        deleteDirectory(bdbDir);
+
         bdbDir.mkdirs();
         _store = new BDBMessageStore();
 
@@ -386,7 +384,7 @@
 
         PropertiesConfiguration env = new PropertiesConfiguration();
 
-        env.addProperty("store.environment-path", "bdbTestEnv");
+        env.addProperty("store.environment-path", STORE_LOCATION);
         env.addProperty("store.class", "org.apache.qpid.server.store.berkeleydb.BDBMessageStore");
 
         _virtualHost = new VirtualHost("test", env);

Added: store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/server/QueueDeleteWhilstRoutingTest.java
===================================================================
--- store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/server/QueueDeleteWhilstRoutingTest.java	                        (rev 0)
+++ store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/server/QueueDeleteWhilstRoutingTest.java	2008-06-02 14:29:56 UTC (rev 2101)
@@ -0,0 +1,206 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.etp.qpid.server;
+
+import org.apache.log4j.Logger;
+import org.etp.qpid.testutil.BDBVMTestCase;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.NamingException;
+import java.io.File;
+
+public class QueueDeleteWhilstRoutingTest extends BDBVMTestCase
+{
+    private static final Logger _logger = Logger.getLogger(QueueDeleteWhilstRoutingTest.class);
+
+    protected Queue _queue;
+    MessageConsumer _consumer1, _consumer2;
+    Session _clientSession1;
+    Connection _producerConnection, _clientConnection1;
+
+    int brokerID = 2;
+
+    /**
+     * Issue analysis:
+     * When an Exclusive NonDurable queue is created a queueDelete task is added to the sessionCloseTaskList
+     * When the last consumer on an autodelete queue closes queueDelete is called.
+     *
+     * Hence the queue is delted twice. Which would hurt the ref counting of all messages in the consumers
+     * unacked map
+     *
+     * Test Plan:
+     *
+     * Create two subscribers same topic
+     *
+     * Send two messages
+     *
+     * consume one from each consumer to validate that all is good
+     *
+     * Shutdown persistent broker
+     *
+     * restart.
+     *
+     * Expecting failure in broker startup.
+     */
+    public void test() throws NamingException, JMSException
+    {
+        _logger.debug("Performing receives");
+
+        Message msg1 = _consumer1.receive(1000);
+
+        assertNotNull(msg1);
+
+        //Check message recevied ok
+        assertEquals("Message 1 not received on consumer 1", "Message: 1", ((TextMessage) msg1).getText());
+
+        _consumer1.close();
+
+        _clientConnection1.close();
+
+        _producerConnection.close();
+
+        try
+        {
+            _logger.debug("Shutdown broker in 1 second");
+            Thread.sleep(4000);
+        }
+        catch (InterruptedException e)
+        {
+            fail(e.getMessage());
+        }
+
+        //Stop the broker
+        stopVMBroker(brokerID);
+
+        try
+        {
+            _logger.debug("Restart broker in 2 second");
+            Thread.sleep(4000);
+        }
+        catch (InterruptedException e)
+        {
+            fail(e.getMessage());
+        }
+
+        //Start the broker
+        try
+        {
+            startVMBroker(brokerID, _persistentConfigFile);
+        }
+        catch (Exception e)
+        {
+            fail(e.getMessage());
+        }
+
+        //Test Connection
+        _clientConnection1 = ((ConnectionFactory) _context.lookup("connection2")).createConnection();
+
+        _clientConnection1.close();
+    }
+
+    public void setUp() throws Exception
+    {
+        _connections.put("connection2", "amqp://guest:guest@" + this.getClass().getName() + "/test?brokerlist='vm://:" + brokerID + "'");
+
+        super.setUp();
+
+        startVMBroker(brokerID, _persistentConfigFile);
+
+        // Initialise ACLs.
+
+        //Create Consumers
+        //Create consumer on the temp queue
+        Queue requestQueue = (Queue) _context.lookup("queue");
+
+        _clientConnection1 = ((ConnectionFactory) _context.lookup("connection2")).createConnection();
+        _clientSession1 = _clientConnection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        _queue = _clientSession1.createTemporaryQueue();
+
+        _consumer1 = _clientSession1.createConsumer(_queue);
+
+        //Start the connection
+        _clientConnection1.start();
+
+        //Create Producer
+        _producerConnection = ((ConnectionFactory) _context.lookup("connection2")).createConnection();
+        final Session producerSession = _producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        //Create a listener for the messages
+        producerSession.createConsumer(requestQueue).setMessageListener(new MessageListener()
+        {
+            public void onMessage(final Message message)
+            {
+                try
+                {
+                    Destination responseQueue = message.getJMSReplyTo();
+
+                    //Send a response to the message
+                    producerSession.createProducer(responseQueue)
+                            .send(producerSession.createTextMessage(((TextMessage) message).getText()));
+                }
+                catch (JMSException e)
+                {
+                    fail(e.getMessage());
+                }
+            }
+        });
+        //Start the connection
+        _producerConnection.start();
+
+        //Send two messages
+
+        MessageProducer _clientProducer = _clientSession1.createProducer(requestQueue);
+        Message msg = _clientSession1.createTextMessage("Message: 1");
+        msg.setJMSReplyTo(_queue);
+        _clientProducer.send(msg);
+
+        msg = _clientSession1.createTextMessage("Message: 2");
+        msg.setJMSReplyTo(_queue);
+        _clientProducer.send(msg);
+    }
+
+    public void tearDown() throws Exception
+    {
+        //Stop the broker
+        try
+        {
+            stopVMBroker(brokerID);
+        }
+        catch (Exception e)
+        {
+            fail(e.getMessage());
+        }
+
+        super.tearDown();
+    }
+
+}


Property changes on: store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/server/QueueDeleteWhilstRoutingTest.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/server/StoreContextRaceConditionTest.java
===================================================================
--- store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/server/StoreContextRaceConditionTest.java	2008-05-30 20:41:48 UTC (rev 2100)
+++ store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/server/StoreContextRaceConditionTest.java	2008-06-02 14:29:56 UTC (rev 2101)
@@ -24,11 +24,10 @@
 import org.apache.commons.configuration.Configuration;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
-import org.apache.log4j.BasicConfigurator;
 import org.apache.qpid.server.registry.ApplicationRegistry;
 import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry;
 import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-import org.apache.qpid.test.VMTestCase;
+import org.etp.qpid.testutil.BDBVMTestCase;
 
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
@@ -41,7 +40,7 @@
 import javax.naming.NamingException;
 import java.io.File;
 
-public class StoreContextRaceConditionTest extends VMTestCase
+public class StoreContextRaceConditionTest extends BDBVMTestCase
 {
     private static final Logger _logger = Logger.getLogger(StoreContextRaceConditionTest.class);
     private long _TimeToLive = 0L;
@@ -55,26 +54,13 @@
     {
         //Disable the logging
         _loggingOriginal = System.getProperty(LOGGING_KEY);
-        System.setProperty(LOGGING_KEY, "WARN");
+        System.setProperty(LOGGING_KEY, Level.WARN.toString());
 
-        // Initialise ACLs.
-        final String qpidHome = System.getProperty("QPID_HOME");
+        //Set the Work Directory
+        setupWorkDirectory();
 
-        final File defaultaclConfigFile = new File(qpidHome, "etc/persistent_config.xml");
+        Configuration configuration = ConfigurationFileApplicationRegistry.config(_persistentConfigFile);
 
-        if (!defaultaclConfigFile.exists())
-        {
-            System.err.println("Configuration file not found:" + defaultaclConfigFile);
-            fail("Configuration file not found:" + defaultaclConfigFile);
-        }
-
-        if (System.getProperty("QPID_HOME") == null)
-        {
-            fail("QPID_HOME not set");
-        }
-
-        Configuration configuration = ConfigurationFileApplicationRegistry.config(defaultaclConfigFile);
-
         //Reset the housekeeping threads to run every second.
         configuration.setProperty("virtualhosts.virtualhost.test.housekeeping.expiredMessageCheckPeriod", 10 * SECOND);
         configuration.setProperty("management.enabled", "false");
@@ -96,9 +82,11 @@
         _queue = (Queue) _context.lookup("queue");
     }
 
-    public void tearDown()
+    public void tearDown() throws Exception
     {
         System.setProperty(LOGGING_KEY, _loggingOriginal);
+
+        super.tearDown();
     }
 
     protected static final String MESSAGE_ID_PROPERTY = "MessageIDProperty";
@@ -172,8 +160,8 @@
 
                 try
                 {
-                    int run = 1;
-                    while (true)
+                    int run = 0;
+                    while (run < 1)
                     {
                         try
                         {
@@ -215,8 +203,6 @@
                             sendMessages(50);
                             _logger.info("***** SENT TTL msgs");
 
-                            System.err.println("********************************* Running test again (" + run +
-                                               ")in attempt to cause race condition.");
                             run++;
                         }
                         catch (JMSException e)

Added: store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/testutil/BDBVMTestCase.java
===================================================================
--- store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/testutil/BDBVMTestCase.java	                        (rev 0)
+++ store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/testutil/BDBVMTestCase.java	2008-06-02 14:29:56 UTC (rev 2101)
@@ -0,0 +1,107 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.etp.qpid.testutil;
+
+import org.apache.qpid.test.VMTestCase;
+
+import java.io.File;
+
+public class BDBVMTestCase extends VMTestCase
+{
+    public static final String BDB_WORK = "BDB_WORK";
+    public static final String QPID_WORK = "QPID_WORK";
+
+    protected String testWork = null;
+
+    protected String BDB_WORK_PRE_TEST;
+    protected String QPID_WORK_PRE_TEST;
+
+    protected final String QpidHome = System.getProperty("QPID_HOME");
+    protected final File _persistentConfigFile = new File(QpidHome, "etc/persistent_config.xml");
+
+    public void setUp() throws Exception
+    {
+        setupWorkDirectory();
+        super.setUp();
+    }
+
+    public void tearDown() throws Exception
+    {
+        super.tearDown();
+
+        if (testWork != null)
+        {
+            // Clean up the BDB store
+            deleteDirectory(new File(testWork));
+            testWork = null;
+        }
+
+        //Reset BDB_WORK
+        System.setProperty(BDB_WORK, BDB_WORK_PRE_TEST == null ? "" : BDB_WORK_PRE_TEST);
+
+        //Reset QPID_WORK
+        System.setProperty(QPID_WORK, QPID_WORK_PRE_TEST == null ? "" : QPID_WORK_PRE_TEST);
+    }
+
+    public void setupWorkDirectory()
+    {
+        if (System.getProperty(BDB_WORK) == null)
+        {
+            fail("BDB_WORK required for BDB tests");
+        }
+
+        BDB_WORK_PRE_TEST = System.getProperty(BDB_WORK);
+        QPID_WORK_PRE_TEST = System.getProperty(QPID_WORK);
+
+        //IF BDB_WORK is set but not QPID_WORK then set QPID_WORK to BDB_WORK
+        if (QPID_WORK_PRE_TEST == null && BDB_WORK_PRE_TEST != null)
+        {
+            System.setProperty(QPID_WORK, BDB_WORK_PRE_TEST);
+        }
+    }
+
+    public void startVMBroker(int vmID, File configFile)
+    {
+        testWork = BDB_WORK_PRE_TEST + "-" + vmID;
+        System.setProperty(BDB_WORK, testWork);
+        System.setProperty(QPID_WORK, testWork);
+
+        super.startVMBroker(vmID, configFile);
+    }
+
+    public boolean deleteDirectory(File dir)
+    {
+        if (dir.isDirectory())
+        {
+            String[] children = dir.list();
+            for (int i = 0; i < children.length; i++)
+            {
+                if (!deleteDirectory(new File(dir, children[i])))
+                {
+                    return false;
+                }
+            }
+        }
+
+        return (dir.delete());
+    }
+
+}


Property changes on: store/branches/java/M2.x/java/bdbstore/src/test/java/org/etp/qpid/testutil/BDBVMTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native




More information about the rhmessaging-commits mailing list