[jboss-cvs] JBoss Messaging SVN: r3800 - in trunk: docs/examples/embedded/src/org/jboss/example/embedded and 84 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 26 11:57:26 EST 2008


Author: timfox
Date: 2008-02-26 11:57:25 -0500 (Tue, 26 Feb 2008)
New Revision: 3800

Added:
   trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/
   trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullPersistenceManager.java
   trunk/src/main/org/jboss/messaging/core/settings/impl/QueueSettings.java
   trunk/src/main/org/jboss/messaging/core/version/
   trunk/src/main/org/jboss/messaging/core/version/impl/
   trunk/src/main/org/jboss/messaging/util/VersionImpl.java
   trunk/tests/src/org/jboss/messaging/core/config/
   trunk/tests/src/org/jboss/messaging/core/config/impl/
   trunk/tests/src/org/jboss/messaging/core/config/impl/test/
   trunk/tests/src/org/jboss/messaging/core/config/impl/test/unit/
   trunk/tests/src/org/jboss/messaging/core/config/impl/test/unit/ConfigurationTest.java
   trunk/tests/src/org/jboss/messaging/core/deployer/
   trunk/tests/src/org/jboss/messaging/core/deployer/impl/
   trunk/tests/src/org/jboss/messaging/core/deployer/impl/test/
   trunk/tests/src/org/jboss/messaging/core/deployer/impl/test/unit/
   trunk/tests/src/org/jboss/messaging/core/deployers/
   trunk/tests/src/org/jboss/messaging/core/deployers/impl/
   trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/
   trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/
   trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/DeployerTest.java
   trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/QueueSettingsDeployerTest.java
   trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/SecurityDeployerTest.java
   trunk/tests/src/org/jboss/messaging/core/filter/
   trunk/tests/src/org/jboss/messaging/core/filter/impl/
   trunk/tests/src/org/jboss/messaging/core/filter/impl/test/
   trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/
   trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterParserTest.java
   trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterTest.java
   trunk/tests/src/org/jboss/messaging/core/list/
   trunk/tests/src/org/jboss/messaging/core/list/impl/
   trunk/tests/src/org/jboss/messaging/core/list/impl/test/
   trunk/tests/src/org/jboss/messaging/core/list/impl/test/unit/
   trunk/tests/src/org/jboss/messaging/core/list/impl/test/unit/PriorityLinkedListTest.java
   trunk/tests/src/org/jboss/messaging/core/persistence/
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/test/
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/test/unit/
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/test/unit/BDBSpeedTest.java
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/test/unit/RealBDBJEEnvironmentTest.java
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/FakeBDBJEEnvironmentTest.java
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/fakes/
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/fakes/FakeBDBJEEnvironment.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/test/
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/test/unit/
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/test/unit/SSLSupportTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java
   trunk/tests/src/org/jboss/messaging/core/server/
   trunk/tests/src/org/jboss/messaging/core/server/impl/
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/concurrent/
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/concurrent/QueueTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/timing/
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/timing/QueueTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessageTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessagingXidTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/PostOfficeTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/QueueTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/RoundRobinDistributionPolicyTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/TransactionTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeConsumer.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeFilter.java
   trunk/tests/src/org/jboss/messaging/core/settings/
   trunk/tests/src/org/jboss/messaging/core/settings/impl/
   trunk/tests/src/org/jboss/messaging/core/settings/impl/test/
   trunk/tests/src/org/jboss/messaging/core/settings/impl/test/unit/
   trunk/tests/src/org/jboss/messaging/core/settings/impl/test/unit/QueueSettingsTest.java
   trunk/tests/src/org/jboss/messaging/core/settings/impl/test/unit/RepositoryTest.java
Removed:
   trunk/src/etc/VERSION-PRE-SUBSTITUTE
   trunk/src/main/org/jboss/messaging/core/server/NullPersistenceManager.java
   trunk/src/main/org/jboss/messaging/core/server/impl/QueueSettings.java
   trunk/src/main/org/jboss/messaging/util/Version.java
   trunk/tests/src/org/jboss/jms/server/deployer/test/unit/DeployerTest.java
   trunk/tests/src/org/jboss/jms/server/security/test/unit/SecurityDeployerTest.java
   trunk/tests/src/org/jboss/jms/server/test/unit/ConfigurationTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/BDBSpeedTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/RealBDBJEEnvironmentTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java
   trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/FakeBDBJEEnvironmentTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/fakes/FakeBDBJEEnvironment.java
   trunk/tests/src/org/jboss/messaging/core/impl/filter/test/unit/FilterParserTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/filter/test/unit/FilterTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/test/concurrent/QueueTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/test/timing/QueueTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/test/unit/MessageTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/test/unit/PriorityLinkedListTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/test/unit/QueueTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/test/unit/RoundRobinDistributionPolicyTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java
   trunk/tests/src/org/jboss/messaging/core/impl/test/unit/fakes/FakeConsumer.java
   trunk/tests/src/org/jboss/messaging/core/impl/test/unit/fakes/FakeFilter.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/test/unit/SSLSupportTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/ssl/
   trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/
   trunk/tests/src/org/jboss/messaging/core/test/unit/QueueSettingsTest.java
   trunk/tests/src/org/jboss/messaging/core/tx/test/unit/MessagingXidTest.java
   trunk/tests/src/org/jboss/messaging/deployers/queue/tests/unit/QueueSettingsDeployerTest.java
   trunk/tests/src/org/jboss/messaging/util/test/unit/RepositoryTest.java
   trunk/tests/src/org/jboss/test/messaging/DropTablesTest.java
Modified:
   trunk/build-messaging.xml
   trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java
   trunk/src/etc/default.mf
   trunk/src/etc/embedded.mf
   trunk/src/main/org/jboss/messaging/core/client/ClientConnectionFactory.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientConnectionFactoryImpl.java
   trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java
   trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/CreateConnectionRequest.java
   trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
   trunk/src/main/org/jboss/messaging/core/server/Queue.java
   trunk/src/main/org/jboss/messaging/core/server/QueueFactory.java
   trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/QueueFactoryImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossConnection.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionMetaData.java
   trunk/tests/build.xml
   trunk/tests/src/org/jboss/test/messaging/jms/ManifestTest.java
   trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java
Log:
Package restructuing part III


Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/build-messaging.xml	2008-02-26 16:57:25 UTC (rev 3800)
@@ -44,22 +44,18 @@
    <!--
         Module name(s) & version.
    -->
+   
+   <property name="module.name" value="messaging"/>
 
    <property name="messaging.version.major" value="2"/>
    <property name="messaging.version.minor" value="0"/>
-   <property name="messaging.version.revision" value="0"/>
-   <property name="messaging.version.incrementing" value="0"/>
-   <property name="messaging.version.tag" value="alpha1"/>
+   <property name="messaging.version.micro" value="0"/>
+   <property name="messaging.version.suffix" value="alpha1"/>
+   <property name="messaging.version.incrementing" value="100"/>
    <property name="messaging.version.name" value="Stilton"/>
-   <property name="messaging.version.cvstag" value="JBossMessaging_1_4_0_SP1"/>
-   <property name="module.name" value="messaging"/>
-   <property name="module.Name" value="JBoss Messaging"/>
-   <property name="module.version" value="${messaging.version.major}.${messaging.version.minor}.${messaging.version.revision}.${messaging.version.tag}"/>
+   <property name="messaging.version.svnurl" value="https://svn.jboss.org/repos/messaging/trunk"/>
+   <property name="messaging.version.string" value="${messaging.version.major}.${messaging.version.minor}.${messaging.version.micro}.${messaging.version.suffix} (${messaging.version.name}, ${messaging.version.incrementing})"/>
 
-   <property name="jms.version.major" value="1"/>
-   <property name="jms.version.minor" value="1"/>
-   <property name="jms.version" value="1.1"/>
-
    <!--
         Jar manifest version information.
     -->
@@ -68,16 +64,6 @@
      <format property="build.number" pattern="yyyyMMddHHmm"/>
    </tstamp>
 
-   <property name="messaging.specification.title" value="${module.Name}"/>
-   <property name="messaging.specification.version" value="${module.version}"/>
-   <property name="messaging.specification.vendor" value="JBoss Inc. (http://www.jboss.org/)"/>
-
-   <property name="messaging.implementation.title" value="${module.Name}"/>
-   <property name="messaging.implementation.url" value="http://www.jboss.org/"/>
-   <property name="messaging.implementation.version" value="${messaging.version.major}.${messaging.version.minor}.${messaging.version.revision}.${messaging.version.tag} (build: CVSTag=${messaging.version.cvstag} date=${build.number})"/>
-   <property name="messaging.implementation.vendor" value="${messaging.specification.vendor}"/>
-   <property name="messaging.implementation.vendor.id" value="${messaging.implementation.url}"/>
-
    <property environment="ENV"/>
 
    <!--
@@ -259,25 +245,13 @@
       <mkdir dir="${build.etc}"/>
       <copy todir="${build.etc}" filtering="yes">
          <fileset dir="${source.etc}">
-            <include name="**"/>
+            <include name="*.mf"/>
          </fileset>
          <filterset>
-            <filter token="JMS_VERSION" value="${jms.version}"/>
-            <filter token="JMS_VERSION_MAJOR" value="${jms.version.major}"/>
-            <filter token="JMS_VERSION_MINOR" value="${jms.version.minor}"/>
-            <filter token="MODULE_VERSION" value="${module.version}"/>
-            <filter token="MESSAGING_VERSION_MAJOR" value="${messaging.version.major}"/>
-            <filter token="MESSAGING_VERSION_MINOR" value="${messaging.version.minor}"/>
-            <filter token="MESSAGING_VERSION_INCREMENTING" value="${messaging.version.incrementing}"/>
-            <filter token="MODULE_NAME" value="${module.Name}"/>
-            <filter token="MODULE_VENDOR" value="${messaging.specification.vendor}"/>
-            <filter token="MODULE_URL" value="${messaging.implementation.url}"/>
-            <filter token="MODULE_IMPLEMENTATION_VERSION" value="${messaging.implementation.version}"/>
-            <filter token="JAVA_VM_VERSION" value="${java.vm.version}"/>
-            <filter token="JAVA_VM_VENDOR" value="${java.vm.vendor}"/>
+            <filter token="JBM_VERSION" value="${messaging.version.string}"/>
+	    <filter token="JBM_SVN_URL" value="${messaging.version.svnurl}"/>
          </filterset>
       </copy>
-      <move file="${build.etc}/VERSION-PRE-SUBSTITUTE" toFile="${build.etc}/VERSION"/>
    </target>
 
    <!-- ======================================================================================== -->
@@ -311,8 +285,6 @@
             todir="${jboss.home}/server/${jboss.config}/conf"/>
        <copy file="${source.etc}/server/default/deploy/queues.xml"
             todir="${jboss.home}/server/${jboss.config}/conf"/>
-       <!--<copy file="${build.lib}/jboss-${module.name}.sar"
-            todir="${jboss.home}/server/${jboss.config}/deploy"/>-->
        <copy
             todir="${jboss.home}/server/${jboss.config}/deploy/messaging.sar">
           <fileset dir="${build.sar}"/>
@@ -356,7 +328,6 @@
 
       <mkdir dir="${build.jar}/META-INF"/>
       <mkdir dir="${build.jar}/xmdesc"/>
-      <copy file="${build.etc}/VERSION" toFile="${build.jar}/VERSION"/>
    </target>
 
    <target name="sar-structure" depends="jar-structure">

Modified: trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java
===================================================================
--- trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -23,18 +23,17 @@
 
 import static org.jboss.messaging.core.remoting.TransportType.TCP;
 
-import javax.jms.Session;
-
-import org.jboss.messaging.core.DestinationType;
-import org.jboss.messaging.core.client.*;
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+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.impl.ClientConnectionFactoryImpl;
 import org.jboss.messaging.core.remoting.impl.RemotingConfiguration;
 import org.jboss.messaging.core.server.Message;
 import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.impl.MessageImpl;
 import org.jboss.messaging.core.server.impl.MessagingServerImpl;
-import org.jboss.messaging.core.server.impl.QueueImpl;
 import org.jboss.messaging.jms.client.JBossTextMessage;
 
 /**

Deleted: trunk/src/etc/VERSION-PRE-SUBSTITUTE
===================================================================
--- trunk/src/etc/VERSION-PRE-SUBSTITUTE	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/etc/VERSION-PRE-SUBSTITUTE	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,11 +0,0 @@
-#
-# This is an automatically generated file. DO NOT EDIT!
-#
-jboss.messaging.jmsVersion=@JMS_VERSION@
-jboss.messaging.jmsMajorVersion=@JMS_VERSION_MAJOR@
-jboss.messaging.jmsMinorVersion=@JMS_VERSION_MINOR@
-jboss.messaging.jmsProviderName=@MODULE_NAME@
-jboss.messaging.providerVersion=@MODULE_VERSION@
-jboss.messaging.providerMajorVersion=@MESSAGING_VERSION_MAJOR@
-jboss.messaging.providerMinorVersion=@MESSAGING_VERSION_MINOR@
-jboss.messaging.providerIncrementingVersion=@MESSAGING_VERSION_INCREMENTING@

Modified: trunk/src/etc/default.mf
===================================================================
--- trunk/src/etc/default.mf	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/etc/default.mf	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,10 +1,3 @@
 Manifest-Version: 1.0
-Created-By: @JAVA_VM_VERSION@ (@JAVA_VM_VENDOR@)
-Specification-Title: @MODULE_NAME@
-Specification-Version: @MODULE_VERSION@
-Specification-Vendor: @MODULE_VENDOR@
-Implementation-Title: @MODULE_NAME@
-Implementation-URL: @MODULE_URL@
-Implementation-Version: @MODULE_IMPLEMENTATION_VERSION@
-Implementation-Vendor: @MODULE_VENDOR@
-Implementation-Vendor-Id: @MODULE_URL@
+JBossMessaging-Version: @JBM_VERSION@
+JBossMessaging-SVN-URL: @JBM_SVN_URL@

Modified: trunk/src/etc/embedded.mf
===================================================================
--- trunk/src/etc/embedded.mf	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/etc/embedded.mf	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,12 +1,5 @@
 Manifest-Version: 1.0
-Created-By: @JAVA_VM_VERSION@ (@JAVA_VM_VENDOR@)
-Specification-Title: @MODULE_NAME@
-Specification-Version: @MODULE_VERSION@
-Specification-Vendor: @MODULE_VENDOR@
-Implementation-Title: @MODULE_NAME@
-Implementation-URL: @MODULE_URL@
-Implementation-Version: @MODULE_IMPLEMENTATION_VERSION@
-Implementation-Vendor: @MODULE_VENDOR@
-Implementation-Vendor-Id: @MODULE_URL@
+JBossMessaging-Version: @JBM_VERSION@
+JBossMessaging-SVN-URL: @JBM_SVN_URL@
 Main-Class: org.jboss.jms.server.microcontainer.JBMBootstrapServer
 Class-Path: jboss-kernel.jar jboss-javaee.jar jboss-common.jar jboss-xml-binding.jar jboss-common-core.jar jboss-container.jar jboss-dependency.jar concurrent.jar jnp-client.jar jnpserver.jar xercesImpl.jar jgroups.jar jboss-remoting.jar commons-logging.jar hsqldb.jar jbossjta.jar jbossjta-integration.jar jbossts-common.jar jbosssx-client.jar jboss-system.jar jboss-jmx.jar jboss-aop-jdk50.jar trove.jar javassist.jar log4j.jar jboss-common-logging-spi.jar jboss-xml-binding.jar jboss-transaction-spi.jar jboss-security-spi.jar jboss-jaspi-api.jar jnpserver.jar mina-core.jar slf4j-api-1.4.3.jar slf4j-log4j12.jar
\ No newline at end of file

Modified: trunk/src/main/org/jboss/messaging/core/client/ClientConnectionFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ClientConnectionFactory.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/client/ClientConnectionFactory.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -22,7 +22,7 @@
 package org.jboss.messaging.core.client;
 
 import org.jboss.messaging.core.server.MessagingException;
-import org.jboss.messaging.util.Version;
+import org.jboss.messaging.core.version.Version;
 
 /**
  * 

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientConnectionFactoryImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientConnectionFactoryImpl.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientConnectionFactoryImpl.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -30,8 +30,9 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionRequest;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionResponse;
 import org.jboss.messaging.core.server.MessagingException;
-import org.jboss.messaging.util.Version;
+import org.jboss.messaging.core.version.Version;
 
+
 /**
  * Core connection factory.
  * 
@@ -99,9 +100,7 @@
    
    public ClientConnection createConnection(String username, String password) throws MessagingException
    {
-      Version version = getVersionToUse(serverVersion);
-      
-      byte v = version.getProviderIncrementingVersion();
+      int v = serverVersion.getIncrementingVersion();
                        
       RemotingConnection remotingConnection = null;
       try
@@ -172,25 +171,5 @@
 
    // Private --------------------------------------------------------------------------------------
    
-   private Version getVersionToUse(Version connectionVersion)
-   {
-      Version clientVersion = Version.instance();
-
-      Version versionToUse;
-
-      if (connectionVersion != null && connectionVersion.getProviderIncrementingVersion() <=
-          clientVersion.getProviderIncrementingVersion())
-      {
-         versionToUse = connectionVersion;
-      }
-      else
-      {
-         versionToUse = clientVersion;
-      }
-
-      return versionToUse;
-   }
-   
    // Inner Classes --------------------------------------------------------------------------------
-
 }

Modified: trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -23,8 +23,8 @@
 
 import org.jboss.messaging.core.deployers.Deployer;
 import org.jboss.messaging.core.server.PostOffice;
-import org.jboss.messaging.core.server.impl.QueueSettings;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
@@ -33,31 +33,32 @@
  * @author <a href="ataylor at redhat.com">Andy Taylor</a>
  */
 public class QueueSettingsDeployer extends Deployer
-{
-   /**
-    * The repository to add to
-    */
-   HierarchicalRepository<QueueSettings> queueSettingsRepository;
-
-   PostOffice postOffice;
+{   
    private static final String CLUSTERED_NODE_NAME = "clustered";
+   
    private static final String DLQ_NODE_NAME = "dlq";
-   private static final String EXPIREY_QUEUE_NODE_NAME = "expiry-queue";
+   
+   private static final String EXPIRY_QUEUE_NODE_NAME = "expiry-queue";
+   
    private static final String REDELIVERY_DELAY_NODE_NAME = "redelivery-delay";
+   
    private static final String MAX_SIZE_NODE_NAME = "max-size";
+   
    private static final String DISTRIBUTION_POLICY_CLASS_NODE_NAME = "distribution-policy-class";
+   
    private static final String MESSAGE_COUNTER_HISTORY_DAY_LIMIT_NODE_NAME = "message-counter-history-day-limit";
 
-   public void setQueueSettingsRepository(HierarchicalRepository<QueueSettings> queueSettingsRepository)
-   {
-      this.queueSettingsRepository = queueSettingsRepository;
-   }
+   private final HierarchicalRepository<QueueSettings> queueSettingsRepository;
 
-   public void setPostOffice(PostOffice postOffice)
+   private final PostOffice postOffice;
+   
+   public QueueSettingsDeployer(final PostOffice postOffice, final HierarchicalRepository<QueueSettings> queueSettingsRepository)
    {
-      this.postOffice = postOffice;
+   	this.postOffice = postOffice;
+   	
+   	this.queueSettingsRepository = queueSettingsRepository;
    }
-
+   
    /**
     * the names of the elements to deploy
     * @return the names of the elements todeploy
@@ -75,53 +76,58 @@
    public void deploy(Node node) throws Exception
    {
       String match = node.getAttributes().getNamedItem(getKeyAttribute()).getNodeValue();
+      
       NodeList children = node.getChildNodes();
+      
       QueueSettings queueSettings = new QueueSettings();
+      
       for (int i = 0; i < children.getLength(); i++)
       {
          Node child = children.item(i);
-         if(CLUSTERED_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
+         
+         if (CLUSTERED_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
          {
             queueSettings.setClustered(Boolean.valueOf(child.getTextContent()));
          }
-         if(DLQ_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
+         else if (DLQ_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
          {
             String queueName = child.getTextContent();
-            if(postOffice.getBinding(queueName) == null)
+            
+            if (postOffice.getBinding(queueName) == null)
             {
-
                postOffice.addBinding(queueName, queueName, null, true, false);
             }
+            
             queueSettings.setDLQ(postOffice.getBinding(queueName).getQueue());
          }
-         if(EXPIREY_QUEUE_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
+         else if (EXPIRY_QUEUE_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
          {
             String queueName = child.getTextContent();
-            if(postOffice.getBinding(queueName) == null)
+            
+            if (postOffice.getBinding(queueName) == null)
             {
                postOffice.addBinding(queueName, queueName, null, true, false);
             }
+            
             queueSettings.setExpiryQueue(postOffice.getBinding(queueName).getQueue());
          }
-         if(REDELIVERY_DELAY_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
+         else if (REDELIVERY_DELAY_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
          {
             queueSettings.setRedeliveryDelay(Long.valueOf(child.getTextContent()));
          }
-         if(MAX_SIZE_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
+         else if (MAX_SIZE_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
          {
             queueSettings.setMaxSize(Integer.valueOf(child.getTextContent()));   
          }
-         if(DISTRIBUTION_POLICY_CLASS_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
+         else if (DISTRIBUTION_POLICY_CLASS_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
          {
             queueSettings.setDistributionPolicyClass(child.getTextContent());
          }
-         if(MESSAGE_COUNTER_HISTORY_DAY_LIMIT_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
+         else if (MESSAGE_COUNTER_HISTORY_DAY_LIMIT_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
          {
             queueSettings.setMessageCounterHistoryDayLimit(Integer.valueOf(child.getTextContent()));
          }
       }
-
-
       
       queueSettingsRepository.addMatch(match, queueSettings);
    }
@@ -144,6 +150,7 @@
    public void undeploy(Node node) throws Exception
    {
       String match = node.getAttributes().getNamedItem(getKeyAttribute()).getNodeValue();
+      
       queueSettingsRepository.removeMatch(match);
    }
 

Modified: trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -78,7 +78,7 @@
         operator = (Operator)parser.parse(filterString, identifiers);
      }
      catch (Throwable e)
-     {
+     {   	  
         throw new MessagingException(MessagingException.INVALID_FILTER_EXPRESSION, "Invalid filter: " + filterString);
      }
   }

Copied: trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullPersistenceManager.java (from rev 3799, trunk/src/main/org/jboss/messaging/core/server/NullPersistenceManager.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullPersistenceManager.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullPersistenceManager.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,125 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005, JBoss Inc., and individual contributors as indicated
+   * 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.core.persistence.impl.nullpm;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.server.Binding;
+import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.PersistenceManager;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.QueueFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class NullPersistenceManager implements PersistenceManager
+{
+   public long generateMessageID()
+   {
+      return 0;
+   }
+
+   public void addMessage(Message message) throws Exception
+   {
+
+   }
+
+   public void deleteReference(MessageReference reference) throws Exception
+   {
+
+   }
+
+   public void commitTransaction(List<Message> messagesToAdd, List<MessageReference> referencesToRemove) throws Exception
+   {
+
+   }
+
+   public void prepareTransaction(Xid xid, List<Message> messagesToAdd, List<MessageReference> referencesToRemove) throws Exception
+   {
+
+   }
+
+   public void commitPreparedTransaction(Xid xid) throws Exception
+   {
+
+   }
+
+   public void unprepareTransaction(Xid xid, List<Message> messagesToAdd, List<MessageReference> referencesToRemove) throws Exception
+   {
+
+   }
+
+   public void updateDeliveryCount(Queue queue, MessageReference ref) throws Exception
+   {
+
+   }
+
+   public void deleteAllReferences(Queue queue) throws Exception
+   {
+
+   }
+
+   public List<Xid> getInDoubtXids() throws Exception
+   {
+      return new ArrayList<Xid>();
+   }
+
+   public boolean isInRecoveryMode() throws Exception
+   {
+      return false;
+   }
+
+   public void setInRecoveryMode(boolean recoveryMode)
+   {
+
+   }
+
+   public List<Binding> loadBindings(QueueFactory queueFactory) throws Exception
+   {
+      return new ArrayList<Binding>();
+   }
+
+   public void addBinding(Binding binding) throws Exception
+   {
+
+   }
+
+   public void deleteBinding(Binding binding) throws Exception
+   {
+
+   }
+
+   public void start() throws Exception
+   {
+
+   }
+
+   public void stop() throws Exception
+   {
+      
+   }
+}

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionMessageCodec.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionMessageCodec.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -38,14 +38,14 @@
          RemotingBuffer out)
          throws Exception
    {
-      byte version = request.getVersion();
+      int version = request.getVersion();
       String remotingSessionID = request.getRemotingSessionID();
       String clientVMID = request.getClientVMID();
       String username = request.getUsername();
       String password = request.getPassword();
       int prefetchSize = request.getPrefetchSize();
 
-      int bodyLength = 1 // version
+      int bodyLength = INT_LENGTH // version
             + sizeof(remotingSessionID)
             + sizeof(clientVMID)
             + sizeof(username) 
@@ -53,7 +53,7 @@
             + INT_LENGTH;
 
       out.putInt(bodyLength);
-      out.put(version);
+      out.putInt(version);
       out.putNullableString(remotingSessionID);
       out.putNullableString(clientVMID);
       out.putNullableString(username);
@@ -70,7 +70,7 @@
       {
          return null;
       }
-      byte version = in.get();
+      int version = in.getInt();
       String remotingSessionID = in.getNullableString();
       String clientVMID = in.getNullableString();
       String username = in.getNullableString();

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/CreateConnectionRequest.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/CreateConnectionRequest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/CreateConnectionRequest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -22,7 +22,7 @@
 
    // Attributes ----------------------------------------------------
 
-   private final byte version;
+   private final int version;
    private final String remotingSessionID;
    private final String clientVMID;
    private final String username;
@@ -33,7 +33,7 @@
 
    // Constructors --------------------------------------------------
 
-   public CreateConnectionRequest(final byte version,
+   public CreateConnectionRequest(final int version,
          final String remotingSessionID, final String clientVMID, final String username, final String password,
          final int prefetchSize)
    {
@@ -52,7 +52,7 @@
 
    // Public --------------------------------------------------------
 
-   public byte getVersion()
+   public int getVersion()
    {
       return version;
    }

Modified: trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -27,9 +27,9 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionResponse;
 import org.jboss.messaging.core.security.Role;
 import org.jboss.messaging.core.security.SecurityStore;
-import org.jboss.messaging.core.server.impl.QueueSettings;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
-import org.jboss.messaging.util.Version;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.core.version.Version;
 
 /**
  * This interface defines the internal interface of the Messaging Server exposed

Deleted: trunk/src/main/org/jboss/messaging/core/server/NullPersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/NullPersistenceManager.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/server/NullPersistenceManager.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,117 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005, JBoss Inc., and individual contributors as indicated
-   * 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.core.server;
-
-import javax.transaction.xa.Xid;
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class NullPersistenceManager implements PersistenceManager
-{
-   public long generateMessageID()
-   {
-      return 0;
-   }
-
-   public void addMessage(Message message) throws Exception
-   {
-
-   }
-
-   public void deleteReference(MessageReference reference) throws Exception
-   {
-
-   }
-
-   public void commitTransaction(List<Message> messagesToAdd, List<MessageReference> referencesToRemove) throws Exception
-   {
-
-   }
-
-   public void prepareTransaction(Xid xid, List<Message> messagesToAdd, List<MessageReference> referencesToRemove) throws Exception
-   {
-
-   }
-
-   public void commitPreparedTransaction(Xid xid) throws Exception
-   {
-
-   }
-
-   public void unprepareTransaction(Xid xid, List<Message> messagesToAdd, List<MessageReference> referencesToRemove) throws Exception
-   {
-
-   }
-
-   public void updateDeliveryCount(Queue queue, MessageReference ref) throws Exception
-   {
-
-   }
-
-   public void deleteAllReferences(Queue queue) throws Exception
-   {
-
-   }
-
-   public List<Xid> getInDoubtXids() throws Exception
-   {
-      return new ArrayList<Xid>();
-   }
-
-   public boolean isInRecoveryMode() throws Exception
-   {
-      return false;
-   }
-
-   public void setInRecoveryMode(boolean recoveryMode)
-   {
-
-   }
-
-   public List<Binding> loadBindings(QueueFactory queueFactory) throws Exception
-   {
-      return new ArrayList<Binding>();
-   }
-
-   public void addBinding(Binding binding) throws Exception
-   {
-
-   }
-
-   public void deleteBinding(Binding binding) throws Exception
-   {
-
-   }
-
-   public void start() throws Exception
-   {
-
-   }
-
-   public void stop() throws Exception
-   {
-      
-   }
-}

Modified: trunk/src/main/org/jboss/messaging/core/server/Queue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/Queue.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/server/Queue.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -22,8 +22,8 @@
 package org.jboss.messaging.core.server;
 
 import org.jboss.messaging.core.filter.impl.FilterImpl;
-import org.jboss.messaging.core.server.impl.QueueSettings;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
 
 import java.util.LinkedList;
 import java.util.List;
@@ -101,9 +101,6 @@
    String getName();
    
    int getMessagesAdded();
-   
-   //--------
 
    HierarchicalRepository<QueueSettings> getQueueSettings();
-
 }

Modified: trunk/src/main/org/jboss/messaging/core/server/QueueFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/QueueFactory.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/server/QueueFactory.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -21,8 +21,6 @@
   */
 package org.jboss.messaging.core.server;
 
-import org.jboss.messaging.core.server.impl.QueueSettings;
-import org.jboss.messaging.core.settings.HierarchicalRepository;
 
 
 /**
@@ -37,8 +35,6 @@
  */
 public interface QueueFactory
 {
-   Queue createQueue(long id, String name, Filter filter,
+   Queue createQueue(long persistenceID, String name, Filter filter,
                      boolean durable, boolean temporary);
-   
-   void setQueueSettingsRepository(HierarchicalRepository<QueueSettings> queueSettingsRepository);
 }

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -134,12 +134,17 @@
          persistenceManager.updateDeliveryCount(queue, this);
       }
             
+      log.info("Queue settings is " + queue.getQueueSettings());
+   	
+      
       queue.decrementDeliveringCount();
 
       int maxDeliveries = queue.getQueueSettings().getMatch(queue.getName()).getMaxDeliveryAttempts();
       
       if (maxDeliveries > 0 && deliveryCount >= maxDeliveries)
       {
+      	
+      	
          Queue DLQ = queue.getQueueSettings().getMatch(queue.getName()).getDLQ();
          
          if (DLQ != null)

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -34,6 +34,7 @@
 import org.jboss.messaging.core.memory.MemoryManager;
 import org.jboss.messaging.core.memory.impl.SimpleMemoryManager;
 import org.jboss.messaging.core.messagecounter.MessageCounterManager;
+import org.jboss.messaging.core.persistence.impl.nullpm.NullPersistenceManager;
 import org.jboss.messaging.core.remoting.Interceptor;
 import org.jboss.messaging.core.remoting.RemotingService;
 import org.jboss.messaging.core.remoting.impl.RemotingConfiguration;
@@ -49,7 +50,6 @@
 import org.jboss.messaging.core.server.Filter;
 import org.jboss.messaging.core.server.MessageReference;
 import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.core.server.NullPersistenceManager;
 import org.jboss.messaging.core.server.PersistenceManager;
 import org.jboss.messaging.core.server.PostOffice;
 import org.jboss.messaging.core.server.Queue;
@@ -58,7 +58,9 @@
 import org.jboss.messaging.core.server.ServerConnection;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
 import org.jboss.messaging.core.settings.impl.HierarchicalObjectRepository;
-import org.jboss.messaging.util.Version;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.core.version.Version;
+import org.jboss.messaging.util.VersionImpl;
 import org.jboss.security.AuthenticationManager;
 
 /**
@@ -109,7 +111,7 @@
    private Configuration configuration = new Configuration();
    private HierarchicalRepository<HashSet<Role>> securityRepository = new HierarchicalObjectRepository<HashSet<Role>>();
    private HierarchicalRepository<QueueSettings> queueSettingsRepository = new HierarchicalObjectRepository<QueueSettings>();
-   private QueueFactory queueFactory = new QueueFactoryImpl();
+   private QueueFactory queueFactory;
    private ResourceManager resourceManager = new ResourceManagerImpl(0);
    private ScheduledExecutorService scheduledExecutor;
 
@@ -119,9 +121,9 @@
     */
    public MessagingServerImpl()
    {
-      // Some wired components need to be started here
+      //We need to hard code the version information into a source file
 
-      version = Version.instance();
+      version = new VersionImpl("Stilton", 2, 0, 0, 100, "alpha1");
 
       started = false;
    }
@@ -163,12 +165,9 @@
       securityStore.setAuthenticationManager(authenticationManager);
       securityDeployer = new SecurityDeployer();
       securityDeployer.setSecurityRepository(securityRepository);
-      queueSettingsDeployer = new QueueSettingsDeployer();
       queueSettingsRepository.setDefault(new QueueSettings());
-      queueSettingsDeployer.setQueueSettingsRepository(queueSettingsRepository);
       scheduledExecutor = new ScheduledThreadPoolExecutor(configuration.getScheduledThreadPoolMaxSize());
-      queueFactory = new QueueFactoryImpl(scheduledExecutor);
-      queueFactory.setQueueSettingsRepository(queueSettingsRepository);
+      queueFactory = new QueueFactoryImpl(queueSettingsRepository, scheduledExecutor);
       connectionManager = new ConnectionManagerImpl();
       memoryManager = new SimpleMemoryManager();
       messageCounterManager = new MessageCounterManager(configuration.getMessageCounterSamplePeriod());
@@ -182,7 +181,7 @@
       });
       postOffice = new PostOfficeImpl(configuration.getMessagingServerID(),
               persistenceManager, queueFactory, configuration.isStrictTck());
-      queueSettingsDeployer.setPostOffice(postOffice);
+      queueSettingsDeployer = new QueueSettingsDeployer(postOffice, queueSettingsRepository);
 
       if (createTransport)
       {

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/QueueFactoryImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/QueueFactoryImpl.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/QueueFactoryImpl.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -27,7 +27,7 @@
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.QueueFactory;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
-import org.jboss.messaging.core.settings.impl.HierarchicalObjectRepository;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
 
 /**
  *
@@ -39,38 +39,28 @@
  */
 public class QueueFactoryImpl implements QueueFactory
 {
-   private HierarchicalRepository<QueueSettings> queueSettingsRepository;
+   private final HierarchicalRepository<QueueSettings> queueSettingsRepository;
 
-   private ScheduledExecutorService scheduledExecutor;
+   private final ScheduledExecutorService scheduledExecutor;
 
-   public QueueFactoryImpl(ScheduledExecutorService scheduledExecutor)
+   public QueueFactoryImpl(final HierarchicalRepository<QueueSettings> queueSettingsRepository,
+   		                  final ScheduledExecutorService scheduledExecutor)
    {
-      this();
-
+      this.queueSettingsRepository = queueSettingsRepository;
+      
       this.scheduledExecutor = scheduledExecutor;
    }
-
-   public QueueFactoryImpl()
+   
+   public Queue createQueue(final long persistenceID, final String name, final Filter filter,
+                            final boolean durable, final boolean temporary)
    {
-      queueSettingsRepository = new HierarchicalObjectRepository<QueueSettings>();
-
-      queueSettingsRepository.setDefault(new QueueSettings());
-   }
-
-   public Queue createQueue(long id, String name, Filter filter,
-                            boolean durable, boolean temporary)
-   {
       QueueSettings queueSettings = queueSettingsRepository.getMatch(name);
+            
+      Queue queue = new QueueImpl(persistenceID, name, filter, queueSettings.isClustered(), durable, temporary,
+      		queueSettings.getMaxSize(), scheduledExecutor, queueSettingsRepository);
 
-      Queue queue =  new QueueImpl(id, name, filter, queueSettings.isClustered(), durable, temporary, queueSettings.getMaxSize(), queueSettingsRepository);
-
       queue.setDistributionPolicy(queueSettings.getDistributionPolicy());
 
       return queue;
    }
-
-   public void setQueueSettingsRepository(HierarchicalRepository<QueueSettings> queueSettingsRepository)
-   {
-      this.queueSettingsRepository = queueSettingsRepository;
-   }
 }

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -32,7 +32,6 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.jboss.messaging.core.*;
 import org.jboss.messaging.core.list.PriorityLinkedList;
 import org.jboss.messaging.core.list.impl.PriorityLinkedListImpl;
 import org.jboss.messaging.core.logging.Logger;
@@ -43,7 +42,7 @@
 import org.jboss.messaging.core.server.MessageReference;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
-import org.jboss.messaging.core.settings.impl.HierarchicalObjectRepository;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
 
 /**
  *
@@ -61,65 +60,48 @@
 
    private static final boolean trace = log.isTraceEnabled();
 
-   protected volatile long id = -1;
+   private volatile long persistenceID = -1;
 
-   protected String name;
+   private final String name;
+   
+   private volatile Filter filter;
 
-   protected volatile int maxSize = -1;
+   private final boolean clustered;
 
-   protected boolean clustered;
+   private final boolean durable;
 
-   protected boolean temporary;
+   private final boolean temporary;
 
-   protected boolean durable;
+   private volatile int maxSize;
+         
+   private final ScheduledExecutorService scheduledExecutor;
 
-   protected Filter filter;
+   private final HierarchicalRepository<QueueSettings> queueSettings;
 
-   protected PriorityLinkedList<MessageReference> messageReferences;
+   private final PriorityLinkedList<MessageReference> messageReferences = new PriorityLinkedListImpl<MessageReference>(NUM_PRIORITIES);
 
-   protected List<Consumer> consumers;
+   private final List<Consumer> consumers  = new ArrayList<Consumer>();
 
-   protected Set<ScheduledDeliveryRunnable> scheduledRunnables;
+   private final Set<ScheduledDeliveryRunnable> scheduledRunnables = new HashSet<ScheduledDeliveryRunnable>();
 
-   protected DistributionPolicy distributionPolicy;
+   private volatile DistributionPolicy distributionPolicy = new RoundRobinDistributionPolicy();
 
-   protected boolean direct;
+   private boolean direct;
 
-   protected boolean promptDelivery;
+   private boolean promptDelivery;
 
    private int pos;
 
    private AtomicInteger messagesAdded = new AtomicInteger(0);
 
    private AtomicInteger deliveringCount = new AtomicInteger(0);
-
-   private ScheduledExecutorService scheduledExecutor;
-
-   // ---------
-
-   HierarchicalRepository<QueueSettings> queueSettings;
-
-   public QueueImpl(long id, String name, Filter filter, boolean clustered,
-                    boolean durable, boolean temporary, int maxSize, ScheduledExecutorService scheduledExecutor)
+   
+   public QueueImpl(final long persistenceID, final String name, final Filter filter, final boolean clustered,
+                    final boolean durable, final boolean temporary, final int maxSize, final ScheduledExecutorService scheduledExecutor,
+                    final HierarchicalRepository<QueueSettings> queueSettings)
    {
-   	this(id, name, filter, clustered, durable, temporary, maxSize);
+   	this.persistenceID = persistenceID;
 
-   	this.scheduledExecutor = scheduledExecutor;
-   }
-
-   public QueueImpl(long id, String name, Filter filter, boolean clustered,
-                    boolean durable, boolean temporary, int maxSize, HierarchicalRepository<QueueSettings> queueSettingsRepository)
-   {
-      this(id, name, filter, clustered, durable, temporary, maxSize);
-
-      queueSettings = queueSettingsRepository;
-   }
-
-   public QueueImpl(long id, String name, Filter filter, boolean clustered,
-                    boolean durable, boolean temporary, int maxSize)
-   {
-      this.id = id;
-
       this.name = name;
 
       this.filter = filter;
@@ -131,23 +113,14 @@
       this.temporary = temporary;
 
       this.maxSize = maxSize;
+      
+      this.scheduledExecutor = scheduledExecutor;
+   	
+   	this.queueSettings = queueSettings;
 
-      //TODO - use a wait free concurrent queue
-      messageReferences = new PriorityLinkedListImpl<MessageReference>(NUM_PRIORITIES);
-
-      consumers = new ArrayList<Consumer>();
-
-      scheduledRunnables = new HashSet<ScheduledDeliveryRunnable>();
-
-      distributionPolicy = new RoundRobinDistributionPolicy();
-
-      direct = true;
-
-      queueSettings = new HierarchicalObjectRepository<QueueSettings>();
-      queueSettings.setDefault(new QueueSettings());
+      direct = true;        	
    }
-
-
+   
    // Queue implementation -------------------------------------------------------------------
 
    public boolean isClustered()
@@ -355,12 +328,12 @@
 
    public long getPersistenceID()
    {
-      return id;
+      return persistenceID;
    }
 
    public void setPersistenceID(long id)
    {
-      this.id = id;
+      this.persistenceID = id;
    }
 
    public synchronized Filter getFilter()
@@ -375,7 +348,6 @@
 
    public synchronized int getMessageCount()
    {
-     // log.info("mr: " + messageReferences.size() + " sc: " + getScheduledCount() + " dc: " + getDeliveringCount());
       return messageReferences.size() + getScheduledCount() + getDeliveringCount();
    }
 
@@ -424,6 +396,13 @@
    {
       return messagesAdded.get();
    }
+   
+   public HierarchicalRepository<QueueSettings> getQueueSettings()
+   {
+      return queueSettings;
+   }
+   
+   // Public -----------------------------------------------------------------------------
 
    public boolean equals(Object other)
    {
@@ -685,11 +664,4 @@
          }
       }
    }
-
-   // -------------------------------
-
-   public HierarchicalRepository<QueueSettings> getQueueSettings()
-   {
-      return queueSettings;
-   }
 }

Deleted: trunk/src/main/org/jboss/messaging/core/server/impl/QueueSettings.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/QueueSettings.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/QueueSettings.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,228 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005, JBoss Inc., and individual contributors as indicated
-   * 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.core.server.impl;
-
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.server.DistributionPolicy;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.settings.Mergeable;
-
-/**
- * The Queue Settings that will be used to configure a queue
- * 
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class QueueSettings implements Mergeable<QueueSettings>
-{
-   private static Logger log = Logger.getLogger(QueueSettings.class);
-   /**
-    * defaults used if null, this allows merging
-    */
-   public static final DistributionPolicy DEFAULT_DISTRIBUTION_POLICY = new RoundRobinDistributionPolicy();
-   public static final Boolean DEFAULT_CLUSTERED = false;
-   public static final Integer DEFAULT_MAX_SIZE = -1;
-   public static final Integer DEFAULT_MAX_DELIVERY_ATTEMPTS = 10;
-   public static final Integer DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT = 0;
-   public static final Long DEFAULT_REDELIVER_DELAY = (long) 500;
-
-   private Boolean clustered = false;
-   private Integer maxSize = null;
-   private String distributionPolicyClass = null;
-   private Integer maxDeliveryAttempts = null;
-   private Integer messageCounterHistoryDayLimit = null;
-   private Long redeliveryDelay = null;
-   private Queue DLQ = null;
-   private Queue ExpiryQueue = null;
-
-
-   public Boolean isClustered()
-   {
-      return clustered != null?clustered:DEFAULT_CLUSTERED;
-   }
-
-   public void setClustered(Boolean clustered)
-   {
-      this.clustered = clustered;
-   }
-
-   public Integer getMaxSize()
-   {
-      return maxSize != null?maxSize:DEFAULT_MAX_SIZE;
-   }
-
-   public void setMaxSize(Integer maxSize)
-   {
-      this.maxSize = maxSize;
-   }
-
-   public Integer getMaxDeliveryAttempts()
-   {
-      return maxDeliveryAttempts != null?maxDeliveryAttempts:DEFAULT_MAX_DELIVERY_ATTEMPTS;
-   }
-
-   public void setMaxDeliveryAttempts(Integer maxDeliveryAttempts)
-   {
-      this.maxDeliveryAttempts = maxDeliveryAttempts;
-   }
-
-   public Integer getMessageCounterHistoryDayLimit()
-   {
-      return messageCounterHistoryDayLimit!=null?messageCounterHistoryDayLimit:DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT;
-   }
-
-   public void setMessageCounterHistoryDayLimit(Integer messageCounterHistoryDayLimit)
-   {
-      this.messageCounterHistoryDayLimit = messageCounterHistoryDayLimit;
-   }
-
-   public Long getRedeliveryDelay()
-   {
-      return redeliveryDelay!=null?redeliveryDelay:DEFAULT_REDELIVER_DELAY;
-   }
-
-   public void setRedeliveryDelay(Long redeliveryDelay)
-   {
-      this.redeliveryDelay = redeliveryDelay;
-   }
-
-   public String getDistributionPolicyClass()
-   {
-      return distributionPolicyClass;
-   }
-
-   public void setDistributionPolicyClass(String distributionPolicyClass)
-   {
-      this.distributionPolicyClass = distributionPolicyClass;
-   }
-
-
-   public Queue getDLQ()
-   {
-      return DLQ;
-   }
-
-   public void setDLQ(Queue DLQ)
-   {
-      this.DLQ = DLQ;
-   }
-
-   public Queue getExpiryQueue()
-   {
-      return ExpiryQueue;
-   }
-
-   public void setExpiryQueue(Queue expiryQueue)
-   {
-      ExpiryQueue = expiryQueue;
-   }
-
-   public DistributionPolicy getDistributionPolicy()
-   {
-      if(distributionPolicyClass != null)
-      {
-         try
-         {
-            return (DistributionPolicy) getClass().getClassLoader().loadClass(distributionPolicyClass).newInstance();
-         }
-         catch (Exception e)
-         {
-            log.warn("unable to create Distribution Policy using default", e);
-         }
-      }
-      return DEFAULT_DISTRIBUTION_POLICY;
-   }
-
-
-   public boolean equals(Object o)
-   {
-      if (this == o) return true;
-      if (o == null || getClass() != o.getClass()) return false;
-
-      QueueSettings that = (QueueSettings) o;
-
-      if (clustered != that.clustered) return false;
-      if (maxDeliveryAttempts != that.maxDeliveryAttempts) return false;
-      if (maxSize != that.maxSize) return false;
-      if (messageCounterHistoryDayLimit != that.messageCounterHistoryDayLimit) return false;
-      if (redeliveryDelay != that.redeliveryDelay) return false;
-      if (DLQ != null ? !DLQ.equals(that.DLQ) : that.DLQ != null) return false;
-      if (ExpiryQueue != null ? !ExpiryQueue.equals(that.ExpiryQueue) : that.ExpiryQueue != null) return false;
-      if (distributionPolicyClass != null ? !distributionPolicyClass.equals(that.distributionPolicyClass) : that.distributionPolicyClass != null)
-         return false;
-
-      return true;
-   }
-
-   public int hashCode()
-   {
-      int result;
-      result = (clustered ? 1 : 0);
-      result = 31 * result + maxSize;
-      result = 31 * result + (distributionPolicyClass != null ? distributionPolicyClass.hashCode() : 0);
-      result = 31 * result + maxDeliveryAttempts;
-      result = 31 * result + messageCounterHistoryDayLimit;
-      result = 31 * result + (int) (redeliveryDelay ^ (redeliveryDelay >>> 32));
-      result = 31 * result + (DLQ != null ? DLQ.hashCode() : 0);
-      result = 31 * result + (ExpiryQueue != null ? ExpiryQueue.hashCode() : 0);
-      return result;
-   }
-
-   /**
-    * merge 2 objects in to 1
-    * @param merged
-    */
-   public void merge(QueueSettings merged)
-   {
-      if(!DEFAULT_CLUSTERED.equals(merged.clustered))
-      {
-         clustered = merged.clustered;
-      }
-      if(!DEFAULT_MAX_DELIVERY_ATTEMPTS.equals(merged.maxDeliveryAttempts) && merged.maxDeliveryAttempts != null)
-      {
-         maxDeliveryAttempts = merged.maxDeliveryAttempts;
-      }
-      if(!DEFAULT_MAX_SIZE.equals(merged.maxSize) && merged.maxSize != null)
-      {
-         maxSize = merged.maxSize;
-      }
-      if(!DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT.equals(merged.messageCounterHistoryDayLimit) && merged.messageCounterHistoryDayLimit != null)
-      {
-         messageCounterHistoryDayLimit = merged.messageCounterHistoryDayLimit;
-      }
-      if(!DEFAULT_REDELIVER_DELAY.equals(merged.redeliveryDelay) && merged.redeliveryDelay != null && merged.redeliveryDelay != null)
-      {
-         redeliveryDelay = merged.redeliveryDelay;
-      }
-      if(merged.distributionPolicyClass != null)
-      {
-         distributionPolicyClass = merged.distributionPolicyClass;
-      }
-      if(merged.DLQ != null)
-      {
-         DLQ = merged.DLQ;
-      }
-      if(merged.ExpiryQueue != null)
-      {
-         ExpiryQueue = merged.ExpiryQueue;
-      }
-   }
-}

Copied: trunk/src/main/org/jboss/messaging/core/settings/impl/QueueSettings.java (from rev 3799, trunk/src/main/org/jboss/messaging/core/server/impl/QueueSettings.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/settings/impl/QueueSettings.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/settings/impl/QueueSettings.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,229 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005, JBoss Inc., and individual contributors as indicated
+   * 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.core.settings.impl;
+
+import org.jboss.logging.Logger;
+import org.jboss.messaging.core.server.DistributionPolicy;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy;
+import org.jboss.messaging.core.settings.Mergeable;
+
+/**
+ * The Queue Settings that will be used to configure a queue
+ * 
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class QueueSettings implements Mergeable<QueueSettings>
+{
+   private static Logger log = Logger.getLogger(QueueSettings.class);
+   /**
+    * defaults used if null, this allows merging
+    */
+   public static final DistributionPolicy DEFAULT_DISTRIBUTION_POLICY = new RoundRobinDistributionPolicy();
+   public static final Boolean DEFAULT_CLUSTERED = false;
+   public static final Integer DEFAULT_MAX_SIZE = -1;
+   public static final Integer DEFAULT_MAX_DELIVERY_ATTEMPTS = 10;
+   public static final Integer DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT = 0;
+   public static final Long DEFAULT_REDELIVER_DELAY = (long) 500;
+
+   private Boolean clustered = false;
+   private Integer maxSize = null;
+   private String distributionPolicyClass = null;
+   private Integer maxDeliveryAttempts = null;
+   private Integer messageCounterHistoryDayLimit = null;
+   private Long redeliveryDelay = null;
+   private Queue DLQ = null;
+   private Queue ExpiryQueue = null;
+
+
+   public Boolean isClustered()
+   {
+      return clustered != null?clustered:DEFAULT_CLUSTERED;
+   }
+
+   public void setClustered(Boolean clustered)
+   {
+      this.clustered = clustered;
+   }
+
+   public Integer getMaxSize()
+   {
+      return maxSize != null?maxSize:DEFAULT_MAX_SIZE;
+   }
+
+   public void setMaxSize(Integer maxSize)
+   {
+      this.maxSize = maxSize;
+   }
+
+   public Integer getMaxDeliveryAttempts()
+   {
+      return maxDeliveryAttempts != null?maxDeliveryAttempts:DEFAULT_MAX_DELIVERY_ATTEMPTS;
+   }
+
+   public void setMaxDeliveryAttempts(Integer maxDeliveryAttempts)
+   {
+      this.maxDeliveryAttempts = maxDeliveryAttempts;
+   }
+
+   public Integer getMessageCounterHistoryDayLimit()
+   {
+      return messageCounterHistoryDayLimit!=null?messageCounterHistoryDayLimit:DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT;
+   }
+
+   public void setMessageCounterHistoryDayLimit(Integer messageCounterHistoryDayLimit)
+   {
+      this.messageCounterHistoryDayLimit = messageCounterHistoryDayLimit;
+   }
+
+   public Long getRedeliveryDelay()
+   {
+      return redeliveryDelay!=null?redeliveryDelay:DEFAULT_REDELIVER_DELAY;
+   }
+
+   public void setRedeliveryDelay(Long redeliveryDelay)
+   {
+      this.redeliveryDelay = redeliveryDelay;
+   }
+
+   public String getDistributionPolicyClass()
+   {
+      return distributionPolicyClass;
+   }
+
+   public void setDistributionPolicyClass(String distributionPolicyClass)
+   {
+      this.distributionPolicyClass = distributionPolicyClass;
+   }
+
+
+   public Queue getDLQ()
+   {
+      return DLQ;
+   }
+
+   public void setDLQ(Queue DLQ)
+   {
+      this.DLQ = DLQ;
+   }
+
+   public Queue getExpiryQueue()
+   {
+      return ExpiryQueue;
+   }
+
+   public void setExpiryQueue(Queue expiryQueue)
+   {
+      ExpiryQueue = expiryQueue;
+   }
+
+   public DistributionPolicy getDistributionPolicy()
+   {
+      if(distributionPolicyClass != null)
+      {
+         try
+         {
+            return (DistributionPolicy) getClass().getClassLoader().loadClass(distributionPolicyClass).newInstance();
+         }
+         catch (Exception e)
+         {
+            log.warn("unable to create Distribution Policy using default", e);
+         }
+      }
+      return DEFAULT_DISTRIBUTION_POLICY;
+   }
+
+
+   public boolean equals(Object o)
+   {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      QueueSettings that = (QueueSettings) o;
+
+      if (clustered != that.clustered) return false;
+      if (maxDeliveryAttempts != that.maxDeliveryAttempts) return false;
+      if (maxSize != that.maxSize) return false;
+      if (messageCounterHistoryDayLimit != that.messageCounterHistoryDayLimit) return false;
+      if (redeliveryDelay != that.redeliveryDelay) return false;
+      if (DLQ != null ? !DLQ.equals(that.DLQ) : that.DLQ != null) return false;
+      if (ExpiryQueue != null ? !ExpiryQueue.equals(that.ExpiryQueue) : that.ExpiryQueue != null) return false;
+      if (distributionPolicyClass != null ? !distributionPolicyClass.equals(that.distributionPolicyClass) : that.distributionPolicyClass != null)
+         return false;
+
+      return true;
+   }
+
+   public int hashCode()
+   {
+      int result;
+      result = (clustered ? 1 : 0);
+      result = 31 * result + maxSize;
+      result = 31 * result + (distributionPolicyClass != null ? distributionPolicyClass.hashCode() : 0);
+      result = 31 * result + maxDeliveryAttempts;
+      result = 31 * result + messageCounterHistoryDayLimit;
+      result = 31 * result + (int) (redeliveryDelay ^ (redeliveryDelay >>> 32));
+      result = 31 * result + (DLQ != null ? DLQ.hashCode() : 0);
+      result = 31 * result + (ExpiryQueue != null ? ExpiryQueue.hashCode() : 0);
+      return result;
+   }
+
+   /**
+    * merge 2 objects in to 1
+    * @param merged
+    */
+   public void merge(QueueSettings merged)
+   {
+      if(!DEFAULT_CLUSTERED.equals(merged.clustered))
+      {
+         clustered = merged.clustered;
+      }
+      if(!DEFAULT_MAX_DELIVERY_ATTEMPTS.equals(merged.maxDeliveryAttempts) && merged.maxDeliveryAttempts != null)
+      {
+         maxDeliveryAttempts = merged.maxDeliveryAttempts;
+      }
+      if(!DEFAULT_MAX_SIZE.equals(merged.maxSize) && merged.maxSize != null)
+      {
+         maxSize = merged.maxSize;
+      }
+      if(!DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT.equals(merged.messageCounterHistoryDayLimit) && merged.messageCounterHistoryDayLimit != null)
+      {
+         messageCounterHistoryDayLimit = merged.messageCounterHistoryDayLimit;
+      }
+      if(!DEFAULT_REDELIVER_DELAY.equals(merged.redeliveryDelay) && merged.redeliveryDelay != null && merged.redeliveryDelay != null)
+      {
+         redeliveryDelay = merged.redeliveryDelay;
+      }
+      if(merged.distributionPolicyClass != null)
+      {
+         distributionPolicyClass = merged.distributionPolicyClass;
+      }
+      if(merged.DLQ != null)
+      {
+         DLQ = merged.DLQ;
+      }
+      if(merged.ExpiryQueue != null)
+      {
+         ExpiryQueue = merged.ExpiryQueue;
+      }
+   }
+}

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossConnection.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossConnection.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossConnection.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -49,7 +49,7 @@
 import org.jboss.messaging.core.client.impl.ClientConnectionInternal;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.server.MessagingException;
-import org.jboss.messaging.util.Version;
+import org.jboss.messaging.core.version.Version;
 
 /**
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionMetaData.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionMetaData.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionMetaData.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -27,7 +27,7 @@
 import javax.jms.ConnectionMetaData;
 import javax.jms.JMSException;
 
-import org.jboss.messaging.util.Version;
+import org.jboss.messaging.core.version.Version;
 
 /**
  * Connection metadata
@@ -61,37 +61,37 @@
 
    public String getJMSVersion() throws JMSException
    {
-      return serverVersion.getJMSVersion();
+      return "1.1";
    }
 
    public int getJMSMajorVersion() throws JMSException
    {
-      return serverVersion.getJMSMajorVersion();
+      return 1;
    }
 
    public int getJMSMinorVersion() throws JMSException
    {
-      return serverVersion.getJMSMinorVersion();
+      return 1;
    }
 
    public String getJMSProviderName() throws JMSException
    {
-      return serverVersion.getJMSProviderName();
+      return "JBoss Messaging";
    }
 
    public String getProviderVersion() throws JMSException
    {
-      return serverVersion.getProviderVersion();
+      return serverVersion.getFullVersion();
    }
 
    public int getProviderMajorVersion() throws JMSException
    {
-      return serverVersion.getProviderMajorVersion();
+      return serverVersion.getMajorVersion();
    }
 
    public int getProviderMinorVersion() throws JMSException
    {
-      return serverVersion.getProviderMinorVersion();
+      return serverVersion.getMinorVersion();
    }
 
    public Enumeration getJMSXPropertyNames() throws JMSException

Deleted: trunk/src/main/org/jboss/messaging/util/Version.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/Version.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/src/main/org/jboss/messaging/util/Version.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,279 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.util;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.util.Properties;
-
-import org.jboss.messaging.core.logging.Logger;
-
-/**
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class Version implements Streamable, Serializable
-{
-   // Constants -----------------------------------------------------
-
-   private static final long serialVersionUID = 3605477218138273630L;
-
-   private static final Logger log = Logger.getLogger(Version.class);
-
-   // Static --------------------------------------------------------
-   
-   // Attributes ----------------------------------------------------
-
-   private String jmsVersion = "UNKNOWN";
-   private int jmsMajorVersion = 0;
-   private int jmsMinorVersion = 0;
-   private String jmsProviderName = "UNKNOWN";
-   private String providerVersion = "UNKNOWN";
-   private int providerMajorVersion = 0;
-   private int providerMinorVersion = 0;
-   private byte providerIncrementingVersion;
-   
-   private static Version singleton;
-
-   // Constructors --------------------------------------------------
-
-   /**
-    * @param versionFile - the name of the version file. It must be available as resource to the
-    *        current class loader.
-    */
-
-   private Version(String versionFile)
-   {
-      load(versionFile);
-   }
-
-   // Public -------------------------------------------------------
-   
-   public Version()
-   {      
-   }
-   
-   public static synchronized Version instance()
-   {
-      if (singleton == null)
-      {
-         singleton = new Version("VERSION");
-      }
-      return singleton;
-   }
-
-   public String getJMSVersion()
-   {
-      return jmsVersion;
-   }
-
-   public int getJMSMajorVersion()
-   {
-      return jmsMajorVersion;
-   }
-
-   public int getJMSMinorVersion()
-   {
-      return jmsMinorVersion;
-   }
-
-   public String getJMSProviderName()
-   {
-      return jmsProviderName;
-   }
-
-   public String getProviderVersion()
-   {
-      return providerVersion;
-   }
-
-   public int getProviderMajorVersion()
-   {
-      return providerMajorVersion;
-   }
-
-   public int getProviderMinorVersion()
-   {
-      return providerMinorVersion;
-   }
-   
-   public byte getProviderIncrementingVersion()
-   {
-      return providerIncrementingVersion;
-   }
-
-   // Package protected ---------------------------------------------
-   
-   // Protected -----------------------------------------------------
-   
-   // Private -------------------------------------------------------
-
-   private void load(String versionFile)
-   {
-      InputStream is = null;
-
-      try
-      {
-         Properties versionInfo = new Properties();
-
-         //Note we use the context classloader so this works in a scoped deployment
-         
-         is = Thread.currentThread().getContextClassLoader().getResourceAsStream(versionFile);
-         
-         versionInfo.load(is);
-
-         String s;
-
-         s = versionInfo.getProperty("jboss.messaging.jmsVersion");
-         if (s != null)
-         {
-            jmsVersion = s;
-         }
-
-         s = versionInfo.getProperty("jboss.messaging.jmsMajorVersion");
-         if (s != null)
-         {
-            try
-            {
-               jmsMajorVersion = Integer.parseInt(s);
-            }
-            catch(Exception e)
-            {
-               log.debug("failed to parse jmsMajorVersion: " + s);
-            }
-         }
-
-         s = versionInfo.getProperty("jboss.messaging.jmsMinorVersion");
-         if (s != null)
-         {
-            try
-            {
-               jmsMinorVersion = Integer.parseInt(s);
-            }
-            catch(Exception e)
-            {
-               log.debug("failed to parse jmsMinorVersion: " + s);
-            }
-         }
-
-         s = versionInfo.getProperty("jboss.messaging.jmsProviderName");
-         if (s != null)
-         {
-            jmsProviderName = s;
-         }
-
-         s = versionInfo.getProperty("jboss.messaging.providerVersion");
-         if (s != null)
-         {
-            providerVersion = s;
-         }
-
-         s = versionInfo.getProperty("jboss.messaging.providerMajorVersion");
-         if (s != null)
-         {
-            try
-            {
-               providerMajorVersion = Integer.parseInt(s);
-            }
-            catch(Exception e)
-            {
-               log.debug("failed to parse providerMajorVersion: " + s);
-            }
-         }
-
-         s = versionInfo.getProperty("jboss.messaging.providerMinorVersion");
-         if (s != null)
-         {
-            try
-            {
-               providerMinorVersion = Integer.parseInt(s);
-            }
-            catch(Exception e)
-            {
-               log.debug("failed to parse providerMinorVersion: " + s);
-            }
-         }
-         
-         s = versionInfo.getProperty("jboss.messaging.providerIncrementingVersion");
-         if (s != null)
-         {
-            try
-            {
-               providerIncrementingVersion = Byte.parseByte(s);
-            }
-            catch(Exception e)
-            {
-               log.debug("failed to parse providerIncrementingVersion: " + s);
-            }
-         }
-      }
-      catch(Exception e)
-      {
-         log.warn("Unable to read version info: " + e.getMessage());
-         log.debug("Unable to read version info", e);
-      }
-      finally
-      {
-         if (is != null)
-         {
-            try
-            {
-               is.close();
-            }
-            catch(Exception e)
-            {
-               log.debug("failed to close the version info stream", e);
-            }
-         }
-      }
-   }
-   
-   public void read(DataInputStream in) throws Exception
-   {
-      jmsVersion = in.readUTF();
-      
-      jmsMajorVersion = in.readInt();
-      
-      jmsMinorVersion = in.readInt();
-      
-      jmsProviderName = in.readUTF();
-      
-      providerVersion = in.readUTF();
-      
-      providerMajorVersion = in.readInt();
-      
-      providerMinorVersion = in.readInt();
-      
-      providerIncrementingVersion = in.readByte();      
-   }
-
-   public void write(DataOutputStream out) throws Exception
-   {
-      out.writeUTF(jmsVersion);
-      
-      out.writeInt(jmsMajorVersion);
-      
-      out.writeInt(jmsMinorVersion);
-      
-      out.writeUTF(jmsProviderName);
-      
-      out.writeUTF(providerVersion);
-      
-      out.writeInt(providerMajorVersion);
-      
-      out.writeInt(providerMinorVersion);
-      
-      out.writeByte(providerIncrementingVersion);
-   }
-
-   // Inner classes -------------------------------------------------
-}

Copied: trunk/src/main/org/jboss/messaging/util/VersionImpl.java (from rev 3799, trunk/src/main/org/jboss/messaging/util/Version.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/util/VersionImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/util/VersionImpl.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,140 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.util;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.Serializable;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.version.Version;
+
+/**
+ * 
+ * A VersionImpl
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class VersionImpl implements Version, Streamable, Serializable
+{
+   // Constants -----------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(VersionImpl.class);
+
+   // Static --------------------------------------------------------
+   
+   // Attributes ----------------------------------------------------
+
+   private String versionName;
+   
+   private int majorVersion;
+   
+   private int minorVersion;
+   
+   private int microVersion;
+   
+   private int incrementingVersion;
+   
+   private String versionSuffix;
+   
+   // Constructors --------------------------------------------------
+
+   public VersionImpl(String versionName, int majorVersion, int minorVersion, int microVersion,
+   		             int incrementingVersion, String versionSuffix)
+   {
+   	this.versionName = versionName;
+   	
+   	this.majorVersion = majorVersion;
+   	
+   	this.minorVersion = minorVersion;
+   	
+   	this.microVersion = microVersion;
+   	
+   	this.incrementingVersion = incrementingVersion;
+   	
+   	this.versionSuffix = versionSuffix;
+   }
+   
+   // Version implementation ------------------------------------------
+   
+   public String getFullVersion()
+   {
+   	return majorVersion + "." + minorVersion + "." + microVersion + "." + versionSuffix +
+   	       " (" + versionName + ", " + incrementingVersion +")";
+   }
+   
+   public String getVersionName()
+   {
+   	return versionName;
+   }
+	
+	public int getMajorVersion()
+	{
+		return majorVersion;
+	}
+	
+	public int getMinorVersion()
+	{
+		return minorVersion;
+	}
+	
+	public int getMicroVersion()
+	{
+		return microVersion;
+	}
+	
+	public String getVersionSuffix()
+	{
+		return versionSuffix;
+	}
+	
+	public int getIncrementingVersion()
+	{
+		return incrementingVersion;
+	}
+   
+   // Public -------------------------------------------------------
+   
+   // Package protected ---------------------------------------------
+   	
+   // Protected -----------------------------------------------------
+   
+   // Private -------------------------------------------------------
+   
+   public void read(DataInputStream in) throws Exception
+   {
+      versionName = in.readUTF();
+      
+      majorVersion = in.readInt();
+      
+      minorVersion = in.readInt();
+      
+      microVersion = in.readInt();
+      
+      versionSuffix = in.readUTF();
+      
+      incrementingVersion = in.readInt();            
+   }
+
+   public void write(DataOutputStream out) throws Exception
+   {
+      out.writeUTF(versionName);
+      
+      out.writeInt(majorVersion);
+      
+      out.writeInt(minorVersion);
+      
+      out.writeInt(microVersion);
+      
+      out.writeUTF(versionSuffix);
+      
+      out.writeInt(incrementingVersion);
+   }
+
+   // Inner classes -------------------------------------------------
+}

Modified: trunk/tests/build.xml
===================================================================
--- trunk/tests/build.xml	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/build.xml	2008-02-26 16:57:25 UTC (rev 3800)
@@ -501,7 +501,7 @@
                     haltonerror="${junit.batchtest.haltonerror}">
             <formatter type="plain" usefile="${junit.formatter.usefile}"/>
             <fileset dir="${build.tests.classes}">
-	       <include name="**/messaging/core/**/${test-mask}.class"/>
+	       <include name="**/messaging/**/${test-mask}.class"/>
 	       <include name="**/jms/**/${test-mask}.class"/>	      	       	       
 	       
 	       <!-- We exclude the recovery tests for now, until we get recovery up and running again -->

Deleted: trunk/tests/src/org/jboss/jms/server/deployer/test/unit/DeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/jms/server/deployer/test/unit/DeployerTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/jms/server/deployer/test/unit/DeployerTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,243 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005, JBoss Inc., and individual contributors as indicated
-   * 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.jms.server.deployer.test.unit;
-
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.deployers.Deployer;
-import org.jboss.messaging.util.XMLUtil;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-
-/**
- * tests the abstract deployer class
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class DeployerTest  extends TestCase
-{
-   private String conf1 = "<deployment>\n" +
-           "   <test name=\"test1\">content1</test>\n" +
-           "   <test name=\"test2\">content2</test>\n" +
-           "   <test name=\"test3\">content3</test>\n" +
-           "   <test name=\"test4\">content4</test>\n" +
-           "</deployment>";
-
-   private String conf2 = "<deployment>\n" +
-           "   <test name=\"test1\">content1</test>\n" +
-           "   <test name=\"test2\">contenthaschanged2</test>\n" +
-           "   <test name=\"test3\">contenthaschanged3</test>\n" +
-           "   <test name=\"test4\">content4</test>\n" +
-           "</deployment>";
-
-   private String conf3 = "<deployment>\n" +
-           "   <test name=\"test1\">content1</test>\n" +
-           "   <test name=\"test2\">contenthaschanged2</test>\n" +
-           "</deployment>";
-
-   private String conf4 = "<deployment>\n" +
-           "   <test name=\"test1\">content1</test>\n" +
-           "   <test name=\"test2\">content2</test>\n" +
-           "   <test name=\"test3\">content3</test>\n" +
-           "   <test name=\"test4\">content4</test>\n" +
-           "   <test name=\"test5\">content5</test>\n" +
-           "   <test name=\"test6\">content6</test>\n" +
-           "</deployment>";
-
-   private URL url;
-
-
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-      url = new URL("http://thisdoesntmatter");
-   }
-
-   public void testDeploy() throws Exception
-   {
-      Element e = XMLUtil.stringToElement(conf1);
-      TestDeployer testDeployer = new TestDeployer();
-      testDeployer.setElement(e);
-      testDeployer.deploy(url);
-      assertEquals(testDeployer.getDeployments(), 4);
-      assertNotNull(testDeployer.getNodes().get("test1"));
-      assertNotNull(testDeployer.getNodes().get("test2"));
-      assertNotNull(testDeployer.getNodes().get("test3"));
-      assertNotNull(testDeployer.getNodes().get("test4"));
-      assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1");
-      assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "content2");
-      assertEquals(testDeployer.getNodes().get("test3").getTextContent(), "content3");
-      assertEquals(testDeployer.getNodes().get("test4").getTextContent(), "content4");
-   }
-
-   public void testRedeploy() throws Exception
-   {
-      Element e = XMLUtil.stringToElement(conf1);
-      TestDeployer testDeployer = new TestDeployer();
-      testDeployer.setElement(e);
-      testDeployer.deploy(url);
-      e = XMLUtil.stringToElement(conf2);
-      testDeployer.setElement(e);
-      testDeployer.redeploy(url);
-      assertEquals(testDeployer.getDeployments(), 4);
-      assertNotNull(testDeployer.getNodes().get("test1"));
-      assertNotNull(testDeployer.getNodes().get("test2"));
-      assertNotNull(testDeployer.getNodes().get("test3"));
-      assertNotNull(testDeployer.getNodes().get("test4"));
-      assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1");
-      assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "contenthaschanged2");
-      assertEquals(testDeployer.getNodes().get("test3").getTextContent(), "contenthaschanged3");
-      assertEquals(testDeployer.getNodes().get("test4").getTextContent(), "content4");
-   }
-
-   public void testRedeployRemovingNodes() throws Exception
-   {
-      Element e = XMLUtil.stringToElement(conf1);
-      TestDeployer testDeployer = new TestDeployer();
-      testDeployer.setElement(e);
-      testDeployer.deploy(url);
-      e = XMLUtil.stringToElement(conf3);
-      testDeployer.setElement(e);
-      testDeployer.redeploy(url);
-      assertEquals(testDeployer.getDeployments(), 2);
-      assertNotNull(testDeployer.getNodes().get("test1"));
-      assertNotNull(testDeployer.getNodes().get("test2"));
-      assertNull(testDeployer.getNodes().get("test3"));
-      assertNull(testDeployer.getNodes().get("test4"));
-      assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1");
-      assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "contenthaschanged2");
-   }
-
-   public void testRedeployAddingNodes() throws Exception
-   {
-      Element e = XMLUtil.stringToElement(conf1);
-      TestDeployer testDeployer = new TestDeployer();
-      testDeployer.setElement(e);
-      testDeployer.deploy(url);
-      e = XMLUtil.stringToElement(conf4);
-      testDeployer.setElement(e);
-      testDeployer.redeploy(url);
-      assertEquals(testDeployer.getDeployments(), 6);
-      assertNotNull(testDeployer.getNodes().get("test1"));
-      assertNotNull(testDeployer.getNodes().get("test2"));
-      assertNotNull(testDeployer.getNodes().get("test3"));
-      assertNotNull(testDeployer.getNodes().get("test4"));
-      assertNotNull(testDeployer.getNodes().get("test5"));
-      assertNotNull(testDeployer.getNodes().get("test6"));
-      assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1");
-      assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "content2");
-      assertEquals(testDeployer.getNodes().get("test3").getTextContent(), "content3");
-      assertEquals(testDeployer.getNodes().get("test4").getTextContent(), "content4");      
-      assertEquals(testDeployer.getNodes().get("test5").getTextContent(), "content5");
-      assertEquals(testDeployer.getNodes().get("test6").getTextContent(), "content6");
-   }
-
-   public void testUndeploy() throws Exception
-   {
-      Element e = XMLUtil.stringToElement(conf1);
-      TestDeployer testDeployer = new TestDeployer();
-      testDeployer.setElement(e);
-      testDeployer.deploy(url);
-      testDeployer.undeploy(url);
-      assertEquals(testDeployer.getDeployments(), 0);
-      assertNull(testDeployer.getNodes().get("test1"));
-      assertNull(testDeployer.getNodes().get("test2"));
-      assertNull(testDeployer.getNodes().get("test3"));
-      assertNull(testDeployer.getNodes().get("test4"));
-   }
-   class TestDeployer extends Deployer
-   {
-      private String elementname = "test";
-      Element element = null;
-      private int deployments = 0;
-      ArrayList<String> contents = new ArrayList<String>();
-      HashMap<String, Node> nodes = new HashMap<String, Node>();
-
-      public HashMap<String, Node> getNodes()
-      {
-         return nodes;
-      }
-
-      public ArrayList<String> getContents()
-      {
-         return contents;
-      }
-
-      public int getDeployments()
-      {
-         return deployments;
-      }
-
-      public String getElementname()
-      {
-         return elementname;
-      }
-
-      public void setElementname(String elementname)
-      {
-         this.elementname = elementname;
-      }
-
-      public Element getElement()
-      {
-         return element;
-      }
-
-      public void setElement(Element element)
-      {
-         this.element = element;
-      }
-
-      public String[] getElementTagName()
-      {
-         return new String[]{elementname};
-      }
-
-
-      public String getConfigFileName()
-      {
-         return "test";
-      }
-
-      public void deploy(Node node) throws Exception
-      {
-         deployments++;
-         contents.add(node.getTextContent());
-         nodes.put(node.getAttributes().getNamedItem(NAME_ATTR).getNodeValue(), node);
-      }
-
-      public void undeploy(Node node) throws Exception
-      {
-         deployments--;
-         nodes.remove(node.getAttributes().getNamedItem(NAME_ATTR).getNodeValue());
-      }
-
-      protected Element getRootElement(URL url)
-      {
-         return element;
-      }
-   }
-}

Deleted: trunk/tests/src/org/jboss/jms/server/security/test/unit/SecurityDeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/jms/server/security/test/unit/SecurityDeployerTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/jms/server/security/test/unit/SecurityDeployerTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,110 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005, JBoss Inc., and individual contributors as indicated
-   * 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.jms.server.security.test.unit;
-
-import junit.framework.TestCase;
-import org.easymock.EasyMock;
-import org.jboss.messaging.core.deployers.impl.SecurityDeployer;
-import org.jboss.messaging.core.security.Role;
-import org.jboss.messaging.core.settings.HierarchicalRepository;
-import org.jboss.messaging.util.XMLUtil;
-import org.w3c.dom.Element;
-
-import java.util.HashSet;
-
-/**
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class SecurityDeployerTest extends TestCase
-{
-   private SecurityDeployer deployer;
-   private String conf = 
-           "   <security match=\"topics.testTopic\">\n" +
-           "      <permission type=\"create\" roles=\"durpublisher\"/>\n" +
-           "      <permission type=\"read\" roles=\"guest,publisher,durpublisher\"/>\n" +
-           "      <permission type=\"write\" roles=\"guest,publisher,durpublisher\"/>\n" +
-           "   </security>";
-
-   private String conf2 =
-           "   <security match=\"queues.testQueue\">\n" +
-           "      <permission type=\"create\" roles=\"durpublisher\"/>\n" +
-           "      <permission type=\"read\" roles=\"guest,publisher,durpublisher\"/>\n" +
-           "      <permission type=\"write\" roles=\"guest,publisher,durpublisher\"/>\n" +
-           "   </security>";
-
-   private String noRoles =
-           "   <securityfoo match=\"queues.testQueue\">\n" +
-           "   </securityfoo>";
-
-   protected void setUp() throws Exception
-   {
-      deployer = new SecurityDeployer();
-   }
-
-   public void testSingle() throws Exception
-   {
-
-      HierarchicalRepository<HashSet<Role>> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
-      deployer.setSecurityRepository(repository);
-      Element e = XMLUtil.stringToElement(conf);
-      Role role = new Role("durpublisher", true, true, true);
-      Role role2 = new Role("guest", true, true, false);
-      Role role3 = new Role("publisher", true, true, false);
-      HashSet<Role> roles = new HashSet<Role>();
-      roles.add(role);
-      roles.add(role2);
-      roles.add(role3);
-      repository.addMatch("topics.testTopic", roles);
-      EasyMock.replay(repository);
-      deployer.deploy(e);
-      
-   }
-
-   public void testMultiple() throws Exception
-   {
-      HierarchicalRepository<HashSet<Role>> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
-      deployer.setSecurityRepository(repository);
-      Role role = new Role("durpublisher", true, true, true);
-      Role role2 = new Role("guest", true, true, false);
-      Role role3 = new Role("publisher", true, true, false);
-      HashSet<Role> roles = new HashSet<Role>();
-      roles.add(role);
-      roles.add(role2);
-      roles.add(role3);
-      repository.addMatch("topics.testTopic", roles);
-      repository.addMatch("queues.testQueue", roles);
-      EasyMock.replay(repository);
-      deployer.deploy(XMLUtil.stringToElement(conf));
-      deployer.deploy(XMLUtil.stringToElement(conf2));
-
-   }
-   public void testNoRolesAdded() throws Exception
-   {
-      HierarchicalRepository<HashSet<Role>> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
-      deployer.setSecurityRepository(repository);
-      HashSet<Role> roles = new HashSet<Role>();
-      repository.addMatch("queues.testQueue", roles);
-      EasyMock.replay(repository);
-      deployer.deploy(XMLUtil.stringToElement(noRoles));
-
-   }
-}

Deleted: trunk/tests/src/org/jboss/jms/server/test/unit/ConfigurationTest.java
===================================================================
--- trunk/tests/src/org/jboss/jms/server/test/unit/ConfigurationTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/jms/server/test/unit/ConfigurationTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,124 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005, JBoss Inc., and individual contributors as indicated
-   * 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.jms.server.test.unit;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.config.impl.FileConfiguration;
-import org.jboss.messaging.core.remoting.TransportType;
-import org.jboss.messaging.core.remoting.impl.RemotingConfiguration;
-
-/**
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class ConfigurationTest extends TestCase
-{
-   private FileConfiguration configuration;
-
-   protected void setUp() throws Exception
-   {
-      configuration = new FileConfiguration();
-      configuration.setConfigurationUrl("ConfigurationTest-config.xml");
-      configuration.start();
-   }
-
-   protected void tearDown() throws Exception
-   {
-      configuration = null;
-   }
-
-   public void testSetServerPeerId() throws Exception
-   {
-      assertEquals("failed to set ServerPeerId", 10, configuration.getMessagingServerID());
-   }
-  
-   public void testSetSecurityDomain() throws Exception
-   {
-      assertEquals("failed to set security domain", "java:/jaas/messagingtest", configuration.getSecurityDomain());
-   }
-  
-   public void testSetMessageCounterSamplePeriod() throws Exception
-   {
-      assertEquals("failed to set Message Counter sample period", 50000, configuration.getMessageCounterSamplePeriod());
-   }
-
-   public void testSetDefaultMessageCounterHistory() throws Exception
-   {
-      assertEquals("failed to set default message counter history", new Integer(21), configuration.getDefaultMessageCounterHistoryDayLimit());
-   }
-
-   public void testSetStrictTck() throws Exception
-   {
-      assertEquals("failed to set strict tck", Boolean.TRUE, configuration.isStrictTck());
-   }
-
-   public void testSetClustered() throws Exception
-   {
-      assertEquals("failed to set clustered", Boolean.TRUE, configuration.isClustered());
-   }
-
-   public void testSetRemoteBindAddress() throws Exception
-   {
-      RemotingConfiguration remotingConfig = configuration.getRemotingConfiguration();
-      assertEquals(TransportType.TCP, remotingConfig.getTransport());
-      assertEquals(10000, remotingConfig.getPort());
-      assertEquals(100, remotingConfig.getTimeout());
-   }
-   public void testSetInterceptorsList() throws Exception
-   {
-      assertEquals("Didn't get the correct number of elements on interceptors", 2, configuration.getDefaultInterceptors().size());
-      assertEquals("org.jboss.tst", configuration.getDefaultInterceptors().get(0));
-      assertEquals("org.jboss.tst2", configuration.getDefaultInterceptors().get(1));
-   }
-   
-
-   public void testPropertyChangeListener() throws Exception
-   {
-      MyListener listener = new MyListener();
-      configuration.addPropertyChangeListener(listener);
-      listener.setCalled(false);
-      configuration.setMessageCounterSamplePeriod(1000000);
-      assertTrue("property change listener not fired", listener.isCalled());
-   }
-   class MyListener implements PropertyChangeListener
-   {
-      boolean called = false;
-
-      public boolean isCalled()
-      {
-         return called;
-      }
-
-      public void setCalled(boolean called)
-      {
-         this.called = called;
-      }
-
-      public void propertyChange(PropertyChangeEvent evt)
-      {
-         called = true;
-      }
-   }
-}

Added: trunk/tests/src/org/jboss/messaging/core/config/impl/test/unit/ConfigurationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/config/impl/test/unit/ConfigurationTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/config/impl/test/unit/ConfigurationTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,126 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005, JBoss Inc., and individual contributors as indicated
+   * 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.core.config.impl.test.unit;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.config.impl.FileConfiguration;
+import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.core.remoting.impl.RemotingConfiguration;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class ConfigurationTest extends TestCase
+{
+   private FileConfiguration configuration;
+
+   protected void setUp() throws Exception
+   {
+      configuration = new FileConfiguration();
+      configuration.setConfigurationUrl("ConfigurationTest-config.xml");
+      configuration.start();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      configuration = null;
+   }
+
+   public void testSetServerPeerId() throws Exception
+   {
+      assertEquals("failed to set ServerPeerId", 10, configuration.getMessagingServerID());
+   }
+  
+   public void testSetSecurityDomain() throws Exception
+   {
+      assertEquals("failed to set security domain", "java:/jaas/messagingtest", configuration.getSecurityDomain());
+   }
+  
+   public void testSetMessageCounterSamplePeriod() throws Exception
+   {
+      assertEquals("failed to set Message Counter sample period", 50000, configuration.getMessageCounterSamplePeriod());
+   }
+
+   public void testSetDefaultMessageCounterHistory() throws Exception
+   {
+      assertEquals("failed to set default message counter history", new Integer(21), configuration.getDefaultMessageCounterHistoryDayLimit());
+   }
+
+   public void testSetStrictTck() throws Exception
+   {
+      assertEquals("failed to set strict tck", Boolean.TRUE, configuration.isStrictTck());
+   }
+
+   public void testSetClustered() throws Exception
+   {
+      assertEquals("failed to set clustered", Boolean.TRUE, configuration.isClustered());
+   }
+
+   public void testSetRemoteBindAddress() throws Exception
+   {
+      RemotingConfiguration remotingConfig = configuration.getRemotingConfiguration();
+      assertEquals(TransportType.TCP, remotingConfig.getTransport());
+      assertEquals(10000, remotingConfig.getPort());
+      assertEquals(100, remotingConfig.getTimeout());
+   }
+   
+   public void testSetInterceptorsList() throws Exception
+   {
+      assertEquals("Didn't get the correct number of elements on interceptors", 2, configuration.getDefaultInterceptors().size());
+      assertEquals("org.jboss.tst", configuration.getDefaultInterceptors().get(0));
+      assertEquals("org.jboss.tst2", configuration.getDefaultInterceptors().get(1));
+   }
+   
+   //config is supposed to be immutable??
+//   public void testPropertyChangeListener() throws Exception
+//   {
+//      MyListener listener = new MyListener();
+//      configuration.addPropertyChangeListener(listener);
+//      listener.setCalled(false);
+//      configuration.setMessageCounterSamplePeriod(1000000);
+//      assertTrue("property change listener not fired", listener.isCalled());
+//   }
+   
+   class MyListener implements PropertyChangeListener
+   {
+      boolean called = false;
+
+      public boolean isCalled()
+      {
+         return called;
+      }
+
+      public void setCalled(boolean called)
+      {
+         this.called = called;
+      }
+
+      public void propertyChange(PropertyChangeEvent evt)
+      {
+         called = true;
+      }
+   }
+}

Added: trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/DeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/DeployerTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/DeployerTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,243 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005, JBoss Inc., and individual contributors as indicated
+   * 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.core.deployers.impl.test.unit;
+
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.deployers.Deployer;
+import org.jboss.messaging.util.XMLUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+/**
+ * tests the abstract deployer class
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class DeployerTest  extends TestCase
+{
+   private String conf1 = "<deployment>\n" +
+           "   <test name=\"test1\">content1</test>\n" +
+           "   <test name=\"test2\">content2</test>\n" +
+           "   <test name=\"test3\">content3</test>\n" +
+           "   <test name=\"test4\">content4</test>\n" +
+           "</deployment>";
+
+   private String conf2 = "<deployment>\n" +
+           "   <test name=\"test1\">content1</test>\n" +
+           "   <test name=\"test2\">contenthaschanged2</test>\n" +
+           "   <test name=\"test3\">contenthaschanged3</test>\n" +
+           "   <test name=\"test4\">content4</test>\n" +
+           "</deployment>";
+
+   private String conf3 = "<deployment>\n" +
+           "   <test name=\"test1\">content1</test>\n" +
+           "   <test name=\"test2\">contenthaschanged2</test>\n" +
+           "</deployment>";
+
+   private String conf4 = "<deployment>\n" +
+           "   <test name=\"test1\">content1</test>\n" +
+           "   <test name=\"test2\">content2</test>\n" +
+           "   <test name=\"test3\">content3</test>\n" +
+           "   <test name=\"test4\">content4</test>\n" +
+           "   <test name=\"test5\">content5</test>\n" +
+           "   <test name=\"test6\">content6</test>\n" +
+           "</deployment>";
+
+   private URL url;
+
+
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      url = new URL("http://thisdoesntmatter");
+   }
+
+   public void testDeploy() throws Exception
+   {
+      Element e = XMLUtil.stringToElement(conf1);
+      TestDeployer testDeployer = new TestDeployer();
+      testDeployer.setElement(e);
+      testDeployer.deploy(url);
+      assertEquals(testDeployer.getDeployments(), 4);
+      assertNotNull(testDeployer.getNodes().get("test1"));
+      assertNotNull(testDeployer.getNodes().get("test2"));
+      assertNotNull(testDeployer.getNodes().get("test3"));
+      assertNotNull(testDeployer.getNodes().get("test4"));
+      assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1");
+      assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "content2");
+      assertEquals(testDeployer.getNodes().get("test3").getTextContent(), "content3");
+      assertEquals(testDeployer.getNodes().get("test4").getTextContent(), "content4");
+   }
+
+   public void testRedeploy() throws Exception
+   {
+      Element e = XMLUtil.stringToElement(conf1);
+      TestDeployer testDeployer = new TestDeployer();
+      testDeployer.setElement(e);
+      testDeployer.deploy(url);
+      e = XMLUtil.stringToElement(conf2);
+      testDeployer.setElement(e);
+      testDeployer.redeploy(url);
+      assertEquals(testDeployer.getDeployments(), 4);
+      assertNotNull(testDeployer.getNodes().get("test1"));
+      assertNotNull(testDeployer.getNodes().get("test2"));
+      assertNotNull(testDeployer.getNodes().get("test3"));
+      assertNotNull(testDeployer.getNodes().get("test4"));
+      assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1");
+      assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "contenthaschanged2");
+      assertEquals(testDeployer.getNodes().get("test3").getTextContent(), "contenthaschanged3");
+      assertEquals(testDeployer.getNodes().get("test4").getTextContent(), "content4");
+   }
+
+   public void testRedeployRemovingNodes() throws Exception
+   {
+      Element e = XMLUtil.stringToElement(conf1);
+      TestDeployer testDeployer = new TestDeployer();
+      testDeployer.setElement(e);
+      testDeployer.deploy(url);
+      e = XMLUtil.stringToElement(conf3);
+      testDeployer.setElement(e);
+      testDeployer.redeploy(url);
+      assertEquals(testDeployer.getDeployments(), 2);
+      assertNotNull(testDeployer.getNodes().get("test1"));
+      assertNotNull(testDeployer.getNodes().get("test2"));
+      assertNull(testDeployer.getNodes().get("test3"));
+      assertNull(testDeployer.getNodes().get("test4"));
+      assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1");
+      assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "contenthaschanged2");
+   }
+
+   public void testRedeployAddingNodes() throws Exception
+   {
+      Element e = XMLUtil.stringToElement(conf1);
+      TestDeployer testDeployer = new TestDeployer();
+      testDeployer.setElement(e);
+      testDeployer.deploy(url);
+      e = XMLUtil.stringToElement(conf4);
+      testDeployer.setElement(e);
+      testDeployer.redeploy(url);
+      assertEquals(testDeployer.getDeployments(), 6);
+      assertNotNull(testDeployer.getNodes().get("test1"));
+      assertNotNull(testDeployer.getNodes().get("test2"));
+      assertNotNull(testDeployer.getNodes().get("test3"));
+      assertNotNull(testDeployer.getNodes().get("test4"));
+      assertNotNull(testDeployer.getNodes().get("test5"));
+      assertNotNull(testDeployer.getNodes().get("test6"));
+      assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1");
+      assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "content2");
+      assertEquals(testDeployer.getNodes().get("test3").getTextContent(), "content3");
+      assertEquals(testDeployer.getNodes().get("test4").getTextContent(), "content4");      
+      assertEquals(testDeployer.getNodes().get("test5").getTextContent(), "content5");
+      assertEquals(testDeployer.getNodes().get("test6").getTextContent(), "content6");
+   }
+
+   public void testUndeploy() throws Exception
+   {
+      Element e = XMLUtil.stringToElement(conf1);
+      TestDeployer testDeployer = new TestDeployer();
+      testDeployer.setElement(e);
+      testDeployer.deploy(url);
+      testDeployer.undeploy(url);
+      assertEquals(testDeployer.getDeployments(), 0);
+      assertNull(testDeployer.getNodes().get("test1"));
+      assertNull(testDeployer.getNodes().get("test2"));
+      assertNull(testDeployer.getNodes().get("test3"));
+      assertNull(testDeployer.getNodes().get("test4"));
+   }
+   class TestDeployer extends Deployer
+   {
+      private String elementname = "test";
+      Element element = null;
+      private int deployments = 0;
+      ArrayList<String> contents = new ArrayList<String>();
+      HashMap<String, Node> nodes = new HashMap<String, Node>();
+
+      public HashMap<String, Node> getNodes()
+      {
+         return nodes;
+      }
+
+      public ArrayList<String> getContents()
+      {
+         return contents;
+      }
+
+      public int getDeployments()
+      {
+         return deployments;
+      }
+
+      public String getElementname()
+      {
+         return elementname;
+      }
+
+      public void setElementname(String elementname)
+      {
+         this.elementname = elementname;
+      }
+
+      public Element getElement()
+      {
+         return element;
+      }
+
+      public void setElement(Element element)
+      {
+         this.element = element;
+      }
+
+      public String[] getElementTagName()
+      {
+         return new String[]{elementname};
+      }
+
+
+      public String getConfigFileName()
+      {
+         return "test";
+      }
+
+      public void deploy(Node node) throws Exception
+      {
+         deployments++;
+         contents.add(node.getTextContent());
+         nodes.put(node.getAttributes().getNamedItem(NAME_ATTR).getNodeValue(), node);
+      }
+
+      public void undeploy(Node node) throws Exception
+      {
+         deployments--;
+         nodes.remove(node.getAttributes().getNamedItem(NAME_ATTR).getNodeValue());
+      }
+
+      protected Element getRootElement(URL url)
+      {
+         return element;
+      }
+   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/QueueSettingsDeployerTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/deployers/queue/tests/unit/QueueSettingsDeployerTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/QueueSettingsDeployerTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/QueueSettingsDeployerTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,80 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005, JBoss Inc., and individual contributors as indicated
+   * 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.core.deployers.impl.test.unit;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.deployers.impl.QueueSettingsDeployer;
+import org.jboss.messaging.core.server.PostOffice;
+import org.jboss.messaging.core.settings.HierarchicalRepository;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.util.XMLUtil;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class QueueSettingsDeployerTest extends TestCase
+{
+   private String conf = "<queue-settings match=\"queues.*\">\n" +
+           "      <clustered>false</clustered>\n" +
+           "      <dlq>DLQtest</dlq>\n" +
+           "      <expiry-queue>ExpiryQueueTest</expiry-queue>\n" +
+           "      <redelivery-delay>100</redelivery-delay>\n" +
+           "      <max-size>-100</max-size>\n" +
+           "      <distribution-policy-class>org.jboss.messaging.core.impl.RoundRobinDistributionPolicy</distribution-policy-class>\n" +
+           "      <message-counter-history-day-limit>1000</message-counter-history-day-limit>\n" +
+           "   </queue-settings>";
+
+   private QueueSettingsDeployer queueSettingsDeployer;
+   
+   private HierarchicalRepository<QueueSettings> repository;
+
+   protected void setUp() throws Exception
+   {
+   	PostOffice postOffice = EasyMock.createStrictMock(PostOffice.class);
+   	
+   	repository = EasyMock.createStrictMock(HierarchicalRepository.class);
+   	   	
+      queueSettingsDeployer = new QueueSettingsDeployer(postOffice, repository);
+   }
+
+   public void testDeploy() throws Exception
+   {
+      QueueSettings queueSettings = new QueueSettings();
+      queueSettings.setClustered(false);
+      queueSettings.setRedeliveryDelay((long)100);
+      queueSettings.setMaxSize(-100);
+      queueSettings.setDistributionPolicyClass("org.jboss.messaging.core.impl.RoundRobinDistributionPolicy");
+      queueSettings.setMessageCounterHistoryDayLimit(1000);
+      repository.addMatch("queues.*", queueSettings);
+      EasyMock.replay(repository);
+      queueSettingsDeployer.deploy(XMLUtil.stringToElement(conf));
+   }
+
+   public void testUndeploy()
+   {
+      repository.removeMatch(conf);
+      EasyMock.replay(repository);
+
+   }
+}

Added: trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/SecurityDeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/SecurityDeployerTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/SecurityDeployerTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,110 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005, JBoss Inc., and individual contributors as indicated
+   * 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.core.deployers.impl.test.unit;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.deployers.impl.SecurityDeployer;
+import org.jboss.messaging.core.security.Role;
+import org.jboss.messaging.core.settings.HierarchicalRepository;
+import org.jboss.messaging.util.XMLUtil;
+import org.w3c.dom.Element;
+
+import java.util.HashSet;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class SecurityDeployerTest extends TestCase
+{
+   private SecurityDeployer deployer;
+   private String conf = 
+           "   <security match=\"topics.testTopic\">\n" +
+           "      <permission type=\"create\" roles=\"durpublisher\"/>\n" +
+           "      <permission type=\"read\" roles=\"guest,publisher,durpublisher\"/>\n" +
+           "      <permission type=\"write\" roles=\"guest,publisher,durpublisher\"/>\n" +
+           "   </security>";
+
+   private String conf2 =
+           "   <security match=\"queues.testQueue\">\n" +
+           "      <permission type=\"create\" roles=\"durpublisher\"/>\n" +
+           "      <permission type=\"read\" roles=\"guest,publisher,durpublisher\"/>\n" +
+           "      <permission type=\"write\" roles=\"guest,publisher,durpublisher\"/>\n" +
+           "   </security>";
+
+   private String noRoles =
+           "   <securityfoo match=\"queues.testQueue\">\n" +
+           "   </securityfoo>";
+
+   protected void setUp() throws Exception
+   {
+      deployer = new SecurityDeployer();
+   }
+
+   public void testSingle() throws Exception
+   {
+
+      HierarchicalRepository<HashSet<Role>> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
+      deployer.setSecurityRepository(repository);
+      Element e = XMLUtil.stringToElement(conf);
+      Role role = new Role("durpublisher", true, true, true);
+      Role role2 = new Role("guest", true, true, false);
+      Role role3 = new Role("publisher", true, true, false);
+      HashSet<Role> roles = new HashSet<Role>();
+      roles.add(role);
+      roles.add(role2);
+      roles.add(role3);
+      repository.addMatch("topics.testTopic", roles);
+      EasyMock.replay(repository);
+      deployer.deploy(e);
+      
+   }
+
+   public void testMultiple() throws Exception
+   {
+      HierarchicalRepository<HashSet<Role>> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
+      deployer.setSecurityRepository(repository);
+      Role role = new Role("durpublisher", true, true, true);
+      Role role2 = new Role("guest", true, true, false);
+      Role role3 = new Role("publisher", true, true, false);
+      HashSet<Role> roles = new HashSet<Role>();
+      roles.add(role);
+      roles.add(role2);
+      roles.add(role3);
+      repository.addMatch("topics.testTopic", roles);
+      repository.addMatch("queues.testQueue", roles);
+      EasyMock.replay(repository);
+      deployer.deploy(XMLUtil.stringToElement(conf));
+      deployer.deploy(XMLUtil.stringToElement(conf2));
+
+   }
+   public void testNoRolesAdded() throws Exception
+   {
+      HierarchicalRepository<HashSet<Role>> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
+      deployer.setSecurityRepository(repository);
+      HashSet<Role> roles = new HashSet<Role>();
+      repository.addMatch("queues.testQueue", roles);
+      EasyMock.replay(repository);
+      deployer.deploy(XMLUtil.stringToElement(noRoles));
+
+   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterParserTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/filter/test/unit/FilterParserTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterParserTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterParserTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,332 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * 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.core.filter.impl.test.unit;
+
+import java.io.ByteArrayInputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.messaging.core.filter.impl.Identifier;
+import org.jboss.messaging.core.filter.impl.Operator;
+import org.jboss.messaging.core.filter.impl.FilterParser;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ Tests of the JavaCC LL(1) parser for the JBoss Messaging filters
+ 
+ @author Scott.Stark at jboss.org
+ @author d_jencks at users.sourceforge.net
+ @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ 
+ @version $Revision: 3465 $
+ 
+ * (david jencks)  Used constructor of SelectorParser taking a stream
+ * to avoid reInit npe in all tests.  Changed to JBossTestCase and logging.
+ */
+public class FilterParserTest extends UnitTestCase
+{
+   private static final Logger log = Logger.getLogger(FilterParserTest.class);
+   
+   private Map<String, Identifier> identifierMap;
+   
+   private FilterParser parser;
+    
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      identifierMap = new HashMap<String, Identifier>();
+      
+      parser = new FilterParser(new ByteArrayInputStream(new byte[0]));      
+   }
+ 
+   public void testSimpleUnary() throws Exception
+   {
+      // Neg Long
+      log.trace("parse(-12345 = -1 * 12345)");
+      Operator result = (Operator) parser.parse("-12345 = -1 * 12345", identifierMap);
+      log.trace("result -> "+result);
+      Boolean b = (Boolean) result.apply();
+      assertTrue("is true", b.booleanValue());
+
+      // Neg Double
+      log.trace("parse(-1 * 12345.67 = -12345.67)");
+      result = (Operator) parser.parse("-1 * 12345.67 = -12345.67", identifierMap);
+      log.trace("result -> "+result);
+      b = (Boolean) result.apply();
+      assertTrue("is true", b.booleanValue());
+
+      log.trace("parse(-(1 * 12345.67) = -12345.67)");
+      result = (Operator) parser.parse("-(1 * 12345.67) = -12345.67", identifierMap);
+      log.trace("result -> "+result);
+      b = (Boolean) result.apply();
+      assertTrue("is true", b.booleanValue());
+   }
+   
+   public void testPrecedenceNAssoc() throws Exception
+   {
+      log.trace("parse(4 + 2 * 3 / 2 = 7)");
+      Operator result = (Operator) parser.parse("4 + 2 * 3 / 2 = 7", identifierMap);
+      log.trace("result -> "+result);
+      Boolean b = (Boolean) result.apply();
+      assertTrue("is true", b.booleanValue());
+      
+      log.trace("parse(4 + ((2 * 3) / 2) = 7)");
+      result = (Operator) parser.parse("4 + ((2 * 3) / 2) = 7", identifierMap);
+      log.trace("result -> "+result);
+      b = (Boolean) result.apply();
+      assertTrue("is true", b.booleanValue());
+      
+      log.trace("parse(4 * -2 / -1 - 4 = 4)");
+      result = (Operator) parser.parse("4 * -2 / -1 - 4 = 4", identifierMap);
+      log.trace("result -> "+result);
+      b = (Boolean) result.apply();
+      assertTrue("is true", b.booleanValue());
+      
+      log.trace("parse(4 * ((-2 / -1) - 4) = -8)");
+      result = (Operator) parser.parse("4 * ((-2 / -1) - 4) = -8", identifierMap);
+      log.trace("result -> "+result);
+      b = (Boolean) result.apply();
+      assertTrue("is true", b.booleanValue());
+   }
+   
+   public void testIds() throws Exception
+   {
+      log.trace("parse(a + b * c / d = e)");
+      Operator result = (Operator) parser.parse("a + b * c / d = e", identifierMap);
+      // 4 + 2 * 3 / 2 = 7
+      Identifier a = identifierMap.get("a");
+      a.setValue(new Long(4));
+      Identifier b = identifierMap.get("b");
+      b.setValue(new Long(2));
+      Identifier c = identifierMap.get("c");
+      c.setValue(new Long(3));
+      Identifier d = identifierMap.get("d");
+      d.setValue(new Long(2));
+      Identifier e = identifierMap.get("e");
+      e.setValue(new Long(7));
+      log.trace("result -> "+result);
+      Boolean bool = (Boolean) result.apply();
+      assertTrue("is true", bool.booleanValue());
+      
+   }
+   
+   public void testTrueINOperator() throws Exception
+   {
+      log.trace("parse(Status IN ('new', 'cleared', 'acknowledged'))");
+      Operator result = (Operator) parser.parse("Status IN ('new', 'cleared', 'acknowledged')", identifierMap);
+      Identifier a = identifierMap.get("Status");
+      a.setValue("new");
+      log.trace("result -> "+result);
+      Boolean bool = (Boolean) result.apply();
+      assertTrue("is true", bool.booleanValue());
+   }
+   public void testFalseINOperator() throws Exception
+   {
+      log.trace("parse(Status IN ('new', 'cleared', 'acknowledged'))");
+      Operator result = (Operator) parser.parse("Status IN ('new', 'cleared', 'acknowledged')", identifierMap);
+      Identifier a = identifierMap.get("Status");
+      a.setValue("none");
+      log.trace("result -> "+result);
+      Boolean bool = (Boolean) result.apply();
+      assertTrue("is false", !bool.booleanValue());
+   }
+   
+   public void testTrueOROperator() throws Exception
+   {
+      log.trace("parse((Status = 'new') OR (Status = 'cleared') OR (Status = 'acknowledged'))");
+      Operator result = (Operator) parser.parse("(Status = 'new') OR (Status = 'cleared') OR (Status= 'acknowledged')", identifierMap);
+      Identifier a = identifierMap.get("Status");
+      a.setValue("new");
+      log.trace("result -> "+result);
+      Boolean bool = (Boolean) result.apply();
+      assertTrue("is true", bool.booleanValue());
+   }
+   public void testFalseOROperator() throws Exception
+   {
+      log.trace("parse((Status = 'new') OR (Status = 'cleared') OR (Status = 'acknowledged'))");
+      Operator result = (Operator) parser.parse("(Status = 'new') OR (Status = 'cleared') OR (Status = 'acknowledged')", identifierMap);
+      Identifier a = identifierMap.get("Status");
+      a.setValue("none");
+      log.trace("result -> "+result);
+      Boolean bool = (Boolean) result.apply();
+      assertTrue("is false", !bool.booleanValue());
+   }
+   
+   public void testInvalidSelector() throws Exception
+   {
+      log.trace("parse(definitely not a message selector!)");
+      try
+      {
+         Object result = parser.parse("definitely not a message selector!", identifierMap);
+         log.trace("result -> "+result);
+         fail("Should throw an Exception.\n");
+      }
+      catch (Exception e)
+      {
+         log.trace("testInvalidSelector failed as expected", e);
+      }
+   }
+ 
+   /**
+    * Test diffent syntax for approximate numeric literal (+6.2, -95.7, 7.)
+    */
+   public void testApproximateNumericLiteral1()
+   {
+      try
+      {
+         log.trace("parse(average = +6.2)");
+         Object result = parser.parse("average = +6.2", identifierMap);
+         log.trace("result -> "+result);
+      } catch (Exception e)
+      {
+         fail(""+e);
+      }
+   }
+   
+   public void testApproximateNumericLiteral2()
+   {
+      try
+      {
+         log.trace("parse(average = -95.7)");
+         Object result = parser.parse("average = -95.7", identifierMap);
+         log.trace("result -> "+result);
+      } catch (Exception e)
+      {
+         fail(""+e);
+      }
+   }
+   public void testApproximateNumericLiteral3()
+   {
+      try
+      {
+         log.trace("parse(average = 7.)");
+         Object result = parser.parse("average = 7.", identifierMap);
+         log.trace("result -> "+result);
+      } catch (Exception e)
+      {
+         fail(""+e);
+      }
+   }
+   
+   public void testGTExact()
+   {
+      try
+      {
+         log.trace("parse(weight > 2500)");
+         Operator result = (Operator)parser.parse("weight > 2500", identifierMap);
+         (identifierMap.get("weight")).setValue(new Integer(3000));
+         log.trace("result -> "+result);
+         Boolean bool = (Boolean) result.apply();
+         assertTrue("is true", bool.booleanValue());
+      } catch (Exception e)
+      {
+         log.trace("failed", e);
+         fail(""+e);
+      }
+   }
+
+   public void testGTFloat()
+   {
+      try
+      {
+         log.trace("parse(weight > 2500)");
+         Operator result = (Operator)parser.parse("weight > 2500", identifierMap);
+         (identifierMap.get("weight")).setValue(new Float(3000));
+         log.trace("result -> "+result);
+         Boolean bool = (Boolean) result.apply();
+         assertTrue("is true", bool.booleanValue());
+      } catch (Exception e)
+      {
+         log.trace("failed", e);
+         fail(""+e);
+      }
+   }
+
+   public void testLTDouble()
+   {
+      try
+      {
+         log.trace("parse(weight < 1.5)");
+         Operator result = (Operator)parser.parse("weight < 1.5", identifierMap);
+         (identifierMap.get("weight")).setValue(new Double(1.2));
+         log.trace("result -> "+result);
+         Boolean bool = (Boolean) result.apply();
+         assertTrue("is true", bool.booleanValue());
+      } catch (Exception e)
+      {
+         log.trace("failed", e);
+         fail(""+e);
+      }
+   }
+
+   public void testAndCombination()
+   {
+      try
+      {
+         log.trace("parse(JMSType = 'car' AND color = 'blue' AND weight > 2500)");
+         Operator result = (Operator)parser.parse("JMSType = 'car' AND color = 'blue' AND weight > 2500", identifierMap);
+         (identifierMap.get("JMSType")).setValue("car");
+         (identifierMap.get("color")).setValue("blue");
+         (identifierMap.get("weight")).setValue("3000");
+         
+         log.trace("result -> "+result);
+         Boolean bool = (Boolean) result.apply();
+         assertTrue("is false", !bool.booleanValue());
+      } catch (Exception e)
+      {
+         log.trace("failed", e);
+         fail(""+e);
+      }
+   }
+   
+   public void testINANDCombination()
+   {
+      try
+      {
+         log.trace("parse(Cateogry IN ('category1') AND Rating >= 2");
+         Operator result = (Operator)parser.parse("Cateogry IN ('category1') AND Rating >= 2", identifierMap);
+         (identifierMap.get("Cateogry")).setValue("category1");
+         (identifierMap.get("Rating")).setValue(new Integer(3));
+         log.trace("result -> "+result);
+         Boolean bool = (Boolean) result.apply();
+         assertTrue("is true", bool.booleanValue());
+      } catch (Exception e)
+      {
+         log.trace("failed", e);
+         fail(""+e);
+      }
+   }
+
+   /** This testcase does not use the JBossServer so override
+   the testServerFound to be a noop
+   */
+   public void testServerFound()
+   {
+   }
+
+   public static void main(java.lang.String[] args)
+   {
+      junit.textui.TestRunner.run(FilterParserTest.class);
+   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/filter/test/unit/FilterTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,615 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * 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.core.filter.impl.test.unit;
+
+import org.jboss.messaging.core.filter.impl.FilterImpl;
+import org.jboss.messaging.core.server.Filter;
+import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.server.MessagingException;
+import org.jboss.messaging.core.server.impl.MessageImpl;
+import org.jboss.test.messaging.JBMBaseTestCase;
+
+/**
+ * Tests the compliance with the JBoss Messaging Filter syntax.
+ *
+ * <p>Needs a lot of work...
+ *
+ * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version $Revision: 3514 $
+ */
+public class FilterTest  extends JBMBaseTestCase
+{
+   private Filter filter;
+   
+   private Message message;
+   
+   public FilterTest(String name)
+   {
+      super(name);
+   }
+   
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      message = new MessageImpl();
+   }
+   
+   public void testInvalidString() throws Exception
+   {
+      testInvalidFilter("invalid");
+      
+      testInvalidFilter("color = 'red");
+      
+      testInvalidFilter("3");
+      
+      testInvalidFilter(null);
+   }
+   
+   public void testJBMDurable() throws Exception
+   {
+      filter = new FilterImpl("JBMDurable='DURABLE'");
+      
+      Message message = new MessageImpl();
+      message.setDurable(true);
+      
+      assertTrue(filter.match(message));
+      
+      message.setDurable(false);
+      
+      assertFalse(filter.match(message));
+      
+      filter = new FilterImpl("JBMDurable='NON_DURABLE'");
+      
+      message = new MessageImpl();
+      message.setDurable(true);
+      
+      assertFalse(filter.match(message));
+      
+      message.setDurable(false);
+      
+      assertTrue(filter.match(message));
+      
+   }
+
+   public void testJBMPriority() throws Exception
+   {
+      filter = new FilterImpl("JBMPriority=3");
+      
+      Message message = new MessageImpl();
+      
+      for (int i = 0; i < 10; i++)
+      {         
+         message.setPriority((byte)i);
+         
+         if (i == 3)
+         {
+            assertTrue(filter.match(message));
+         }
+         else
+         {
+            assertFalse(filter.match(message));
+         }                     
+      }
+   }
+   
+   public void testJBMMessageID() throws Exception
+   {
+      filter = new FilterImpl("JBMMessageID=11223344");
+      
+      Message message = new MessageImpl();
+      
+      message.setMessageID(78676);
+      
+      assertFalse(filter.match(message));
+      
+      message.setMessageID(11223344);
+      
+      assertTrue(filter.match(message));
+   }
+   
+   public void testJBMTimestamp() throws Exception
+   {
+      filter = new FilterImpl("JBMTimestamp=12345678");
+      
+      Message message = new MessageImpl();
+      
+      message.setTimestamp(87654321);
+      
+      assertFalse(filter.match(message));
+      
+      message.setTimestamp(12345678);
+      
+      assertTrue(filter.match(message));
+   }
+         
+   public void testBooleanTrue() throws Exception
+   {
+      filter = new FilterImpl("MyBoolean=true");
+      
+      testBoolean("MyBoolean", true);
+   }
+   
+   public void testBooleanFalse() throws Exception
+   {
+      filter = new FilterImpl("MyBoolean=false");
+      testBoolean("MyBoolean", false);
+   }
+   
+   private void testBoolean(String name, boolean flag) throws Exception
+   {
+      message.putHeader(name, flag);
+      assertTrue(filter.match(message));
+      
+      message.putHeader(name, !flag);
+      assertTrue(!filter.match(message));
+   }
+   
+   public void testStringEquals() throws Exception
+   {
+      // First, simple test of string equality and inequality
+      filter = new FilterImpl("MyString='astring'");
+      
+      message.putHeader("MyString", "astring");
+      assertTrue(filter.match(message));
+      
+      message.putHeader("MyString", "NOTastring");
+      assertTrue(!filter.match(message));
+      
+      // test empty string
+      filter = new FilterImpl("MyString=''");
+      
+      message.putHeader("MyString", "");
+      assertTrue("test 1", filter.match(message));
+      
+      message.putHeader("MyString", "NOTastring");
+      assertTrue("test 2", !filter.match(message));
+      
+      // test literal apostrophes (which are escaped using two apostrophes
+      // in selectors)
+      filter = new FilterImpl("MyString='test JBoss''s filter'");
+      
+      // note: apostrophes are not escaped in string properties
+      message.putHeader("MyString", "test JBoss's filter");
+      // this test fails -- bug 530120
+      //assertTrue("test 3", filter.match(message));
+      
+      message.putHeader("MyString", "NOTastring");
+      assertTrue("test 4", !filter.match(message));
+      
+   }
+   
+   public void testStringLike() throws Exception
+   {
+      // test LIKE operator with no wildcards
+      filter = new FilterImpl("MyString LIKE 'astring'");
+      
+      // test where LIKE operand matches
+      message.putHeader("MyString", "astring");
+      assertTrue(filter.match(message));
+      
+      // test one character string
+      filter = new FilterImpl("MyString LIKE 'a'");
+      message.putHeader("MyString","a");
+      assertTrue(filter.match(message));
+      
+      // test empty string
+      filter = new FilterImpl("MyString LIKE ''");
+      message.putHeader("MyString", "");
+      assertTrue(filter.match(message));
+      
+      // tests where operand does not match
+      filter = new FilterImpl("MyString LIKE 'astring'");
+      
+      // test with extra characters at beginning
+      message.putHeader("MyString", "NOTastring");
+      assertTrue(!filter.match(message));
+      
+      // test with extra characters at end
+      message.putHeader("MyString", "astringNOT");
+      assertTrue(!filter.match(message));
+      
+      // test with extra characters in the middle
+      message.putHeader("MyString", "astNOTring");
+      assertTrue(!filter.match(message));
+      
+      // test where operand is entirely different
+      message.putHeader("MyString", "totally different");
+      assertTrue(!filter.match(message));
+      
+      // test case sensitivity
+      message.putHeader("MyString", "ASTRING");
+      assertTrue(!filter.match(message));
+      
+      // test empty string
+      message.putHeader("MyString", "");
+      assertTrue(!filter.match(message));
+      
+      
+      // test lower-case 'like' operator?
+   }
+   
+   public void testStringLikeUnderbarWildcard() throws Exception
+   {
+      // test LIKE operator with the _ wildcard, which
+      // matches any single character
+      
+      // first, some tests with the wildcard by itself
+      filter = new FilterImpl("MyString LIKE '_'");
+      
+      // test match against single character
+      message.putHeader("MyString", "a");
+      assertTrue(filter.match(message));
+      
+      // test match failure against multiple characters
+      message.putHeader("MyString", "aaaaa");
+      assertTrue(!filter.match(message));
+      
+      // test match failure against the empty string
+      message.putHeader("MyString", "");
+      assertTrue(!filter.match(message));
+      
+      
+      // next, tests with wildcard at the beginning of the string
+      filter = new FilterImpl("MyString LIKE '_bcdf'");
+      
+      // test match at beginning of string
+      message.putHeader("MyString", "abcdf");
+      assertTrue(filter.match(message));
+      
+      // match failure in first character after wildcard
+      message.putHeader("MyString", "aXcdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in middle character
+      message.putHeader("MyString", "abXdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in last character
+      message.putHeader("MyString", "abcdX");
+      assertTrue(!filter.match(message));
+      
+      // match failure with empty string
+      message.putHeader("MyString", "");
+      assertTrue(!filter.match(message));
+      
+      // match failure due to extra characters at beginning
+      message.putHeader("MyString", "XXXabcdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure due to extra characters at the end
+      message.putHeader("MyString", "abcdfXXX");
+      assertTrue(!filter.match(message));
+      
+      // test that the _ wildcard does not match the 'empty' character
+      message.putHeader("MyString", "bcdf");
+      assertTrue(!filter.match(message));
+      
+      // next, tests with wildcard at the end of the string
+      filter = new FilterImpl("MyString LIKE 'abcd_'");
+      
+      // test match at end of string
+      message.putHeader("MyString", "abcdf");
+      assertTrue(filter.match(message));
+      
+      // match failure in first character before wildcard
+      message.putHeader("MyString", "abcXf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in middle character
+      message.putHeader("MyString", "abXdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in first character
+      message.putHeader("MyString", "Xbcdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure with empty string
+      message.putHeader("MyString", "");
+      assertTrue(!filter.match(message));
+      
+      // match failure due to extra characters at beginning
+      message.putHeader("MyString", "XXXabcdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure due to extra characters at the end
+      message.putHeader("MyString", "abcdfXXX");
+      assertTrue(!filter.match(message));
+      
+      // test that the _ wildcard does not match the 'empty' character
+      message.putHeader("MyString", "abcd");
+      assertTrue(!filter.match(message));
+      
+      // test match in middle of string
+      
+      // next, tests with wildcard in the middle of the string
+      filter = new FilterImpl("MyString LIKE 'ab_df'");
+      
+      // test match in the middle of string
+      message.putHeader("MyString", "abcdf");
+      assertTrue(filter.match(message));
+      
+      // match failure in first character before wildcard
+      message.putHeader("MyString", "aXcdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in first character after wildcard
+      message.putHeader("MyString", "abcXf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in last character
+      message.putHeader("MyString", "abcdX");
+      assertTrue(!filter.match(message));
+      
+      // match failure with empty string
+      message.putHeader("MyString", "");
+      assertTrue(!filter.match(message));
+      
+      // match failure due to extra characters at beginning
+      message.putHeader("MyString", "XXXabcdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure due to extra characters at the end
+      message.putHeader("MyString", "abcdfXXX");
+      assertTrue(!filter.match(message));
+      
+      // test that the _ wildcard does not match the 'empty' character
+      message.putHeader("MyString", "abdf");
+      assertTrue(!filter.match(message));
+      
+      // test match failures
+   }
+   
+   public void testStringLikePercentWildcard() throws Exception
+   {
+      // test LIKE operator with the % wildcard, which
+      // matches any sequence of characters
+      // note many of the tests are similar to those for _
+      
+      
+      // first, some tests with the wildcard by itself
+      filter = new FilterImpl("MyString LIKE '%'");
+      
+      // test match against single character
+      message.putHeader("MyString", "a");
+      assertTrue(filter.match(message));
+      
+      // test match against multiple characters
+      message.putHeader("MyString", "aaaaa");
+      assertTrue(filter.match(message));
+      
+      message.putHeader("MyString", "abcdf");
+      assertTrue(filter.match(message));
+      
+      // test match against the empty string
+      message.putHeader("MyString", "");
+      assertTrue(filter.match(message));
+      
+      
+      // next, tests with wildcard at the beginning of the string
+      filter = new FilterImpl("MyString LIKE '%bcdf'");
+      
+      // test match with single character at beginning of string
+      message.putHeader("MyString", "Xbcdf");
+      assertTrue(filter.match(message));
+      
+      // match with multiple characters at beginning
+      message.putHeader("MyString", "XXbcdf");
+      assertTrue(filter.match(message));
+      
+      // match failure in middle character
+      message.putHeader("MyString", "abXdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in last character
+      message.putHeader("MyString", "abcdX");
+      assertTrue(!filter.match(message));
+      
+      // match failure with empty string
+      message.putHeader("MyString", "");
+      assertTrue(!filter.match(message));
+      
+      // match failure due to extra characters at the end
+      message.putHeader("MyString", "abcdfXXX");
+      assertTrue(!filter.match(message));
+      
+      // test that the % wildcard matches the empty string
+      message.putHeader("MyString", "bcdf");
+      assertTrue(filter.match(message));
+      
+      // next, tests with wildcard at the end of the string
+      filter = new FilterImpl("MyString LIKE 'abcd%'");
+      
+      // test match of single character at end of string
+      message.putHeader("MyString", "abcdf");
+      assertTrue(filter.match(message));
+      
+      // test match of multiple characters at end of string
+      message.putHeader("MyString", "abcdfgh");
+      assertTrue(filter.match(message));
+      
+      // match failure in first character before wildcard
+      message.putHeader("MyString", "abcXf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in middle character
+      message.putHeader("MyString", "abXdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in first character
+      message.putHeader("MyString", "Xbcdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure with empty string
+      message.putHeader("MyString", "");
+      assertTrue(!filter.match(message));
+      
+      // match failure due to extra characters at beginning
+      message.putHeader("MyString", "XXXabcdf");
+      assertTrue(!filter.match(message));
+      
+      // test that the % wildcard matches the empty string
+      message.putHeader("MyString", "abcd");
+      assertTrue(filter.match(message));
+      
+      // next, tests with wildcard in the middle of the string
+      filter = new FilterImpl("MyString LIKE 'ab%df'");
+      
+      // test match with single character in the middle of string
+      message.putHeader("MyString", "abXdf");
+      assertTrue(filter.match(message));
+      
+      // test match with multiple characters in the middle of string
+      message.putHeader("MyString", "abXXXdf");
+      assertTrue(filter.match(message));
+      
+      // match failure in first character before wildcard
+      message.putHeader("MyString", "aXcdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in first character after wildcard
+      message.putHeader("MyString", "abcXf");
+      assertTrue(!filter.match(message));
+      
+      // match failure in last character
+      message.putHeader("MyString", "abcdX");
+      assertTrue(!filter.match(message));
+      
+      // match failure with empty string
+      message.putHeader("MyString", "");
+      assertTrue(!filter.match(message));
+      
+      // match failure due to extra characters at beginning
+      message.putHeader("MyString", "XXXabcdf");
+      assertTrue(!filter.match(message));
+      
+      // match failure due to extra characters at the end
+      message.putHeader("MyString", "abcdfXXX");
+      assertTrue(!filter.match(message));
+      
+      // test that the % wildcard matches the empty string
+      message.putHeader("MyString", "abdf");
+      assertTrue(filter.match(message));
+      
+   }
+   
+   public void testStringLikePunctuation() throws Exception
+   {
+      // test proper handling of some punctuation characters.
+      // non-trivial since the underlying implementation might
+      // (and in fact currently does) use a general-purpose
+      // RE library, which has a different notion of which
+      // characters are wildcards
+      
+      // the particular tests here are motivated by the
+      // wildcards of the current underlying RE engine,
+      // GNU regexp.
+      
+      filter = new FilterImpl("MyString LIKE 'a^$b'");
+      message.putHeader("MyString", "a^$b");
+      assertTrue(filter.match(message));
+      
+      // this one has a double backslash since backslash
+      // is interpreted specially by Java
+      filter = new FilterImpl("MyString LIKE 'a\\dc'");
+      message.putHeader("MyString", "a\\dc");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE 'a.c'");
+      message.putHeader("MyString", "abc");
+      assertTrue(!filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '[abc]'");
+      message.putHeader("MyString", "[abc]");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '[^abc]'");
+      message.putHeader("MyString", "[^abc]");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '[a-c]'");
+      message.putHeader("MyString", "[a-c]");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '[:alpha]'");
+      message.putHeader("MyString", "[:alpha]");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '(abc)'");
+      message.putHeader("MyString", "(abc)");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE 'a|bc'");
+      message.putHeader("MyString", "a|bc");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '(abc)?'");
+      message.putHeader("MyString", "(abc)?");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '(abc)*'");
+      message.putHeader("MyString", "(abc)*");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '(abc)+'");
+      message.putHeader("MyString", "(abc)+");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '(abc){3}'");
+      message.putHeader("MyString", "(abc){3}");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '(abc){3,5}'");
+      message.putHeader("MyString", "(abc){3,5}");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '(abc){3,}'");
+      message.putHeader("MyString", "(abc){3,}");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '(?=abc)'");
+      message.putHeader("MyString", "(?=abc)");
+      assertTrue(filter.match(message));
+      
+      filter = new FilterImpl("MyString LIKE '(?!abc)'");
+      message.putHeader("MyString", "(?!abc)");
+      assertTrue(filter.match(message));
+   }
+   
+   // Private -----------------------------------------------------------------------------------
+   
+   private void testInvalidFilter(String filterString) throws Exception
+   {
+      try
+      {
+         filter = new FilterImpl(filterString);
+         
+         fail("Should throw exception");
+      }
+      catch (MessagingException e)
+      {
+         assertEquals(MessagingException.INVALID_FILTER_EXPRESSION, e.getCode());
+      }            
+   }
+   
+}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/BDBSpeedTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/BDBSpeedTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/BDBSpeedTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,647 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * 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.core.impl.bdbje.integration.test.unit;
-
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- * 
- * A BDBSpeedTest
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class BDBSpeedTest extends UnitTestCase
-{
-   
-   public void test1()
-   {      
-   }
-   
-//   public void testCommitMessage() throws Exception
-//   {
-//      String envPath = "/home/tim/test-env";
-//      
-//      File file = new File(envPath);
-//      
-//      deleteDirectory(file);
-//      
-//      file.mkdir();
-//      
-//      final int numMessages = 5000;
-//      
-//      final int numRefs = 10;
-//      
-//      BDBJEPersistenceManager2 bdb = new BDBJEPersistenceManager2(envPath);
-//      
-//      bdb.start();
-//      
-//      Queue queue = new QueueImpl(1);
-//      
-//      //List<Message> messages = new ArrayList<Message>();
-//      
-//      long start = System.currentTimeMillis();
-//      
-//      byte[] payload = new byte[1 * 1024];
-//      
-//      for (int i = 0; i < numMessages; i++)
-//      {
-//         Message message = new MessageImpl(i, 0, true, 0, System.currentTimeMillis(), (byte)4);
-//         
-//         for (int j = 0; j < numRefs; j++)
-//         {
-//            message.createReference(queue);
-//            
-//            message.setPayload(payload);
-//         }
-//         
-//         //messages.add(message);
-//         
-//         bdb.commitMessage(message);
-//      }
-//      
-//      long end = System.currentTimeMillis();
-//      
-//      double rate = 1000 * (double)numMessages / (end - start);
-//      
-//      System.out.println("Insert Rate: " + rate);
-//      
-//   }
-//   
-//   public void testCommitMessages() throws Exception
-//   {
-//      String envPath = "/home/tim/test-env";
-//      
-//      File file = new File(envPath);
-//      
-//      deleteDirectory(file);
-//      
-//      file.mkdir();
-//      
-//      final int numMessages = 5000;
-//      
-//      final int numRefs = 10;
-//      
-//      BDBJEPersistenceManager2 bdb = new BDBJEPersistenceManager2(envPath);
-//      
-//      bdb.start();
-//      
-//      Queue queue = new QueueImpl(1);
-//      
-//      List<Message> messages = new ArrayList<Message>();
-//      
-//      long start = System.currentTimeMillis();
-//      
-//      byte[] payload = new byte[1 * 1024];
-//                  
-//      for (int i = 0; i < numMessages; i++)
-//      {
-//         Message message = new MessageImpl(i, 0, true, 0, System.currentTimeMillis(), (byte)4);
-//         
-//         for (int j = 0; j < numRefs; j++)
-//         {
-//            message.createReference(queue);
-//            
-//            message.setPayload(payload);
-//         }
-//         
-//         messages.add(message);
-//         
-//         if (i % 100 == 0)
-//         {
-//            bdb.commitMessages(messages);
-//            
-//            messages.clear();
-//         }         
-//      }
-//      bdb.commitMessages(messages);
-//      
-//      long end = System.currentTimeMillis();
-//      
-//      double rate = 1000 * (double)numMessages / (end - start);
-//      
-//      System.out.println("Insert Rate: " + rate);
-//      
-//   }
-//   
-//   public void testDeleteReferences() throws Exception
-//   {
-//      String envPath = "/home/tim/test-env";
-//      
-//      File file = new File(envPath);
-//      
-//      deleteDirectory(file);
-//      
-//      file.mkdir();
-//      
-//      final int numMessages = 5000;
-//      
-//      final int numRefs = 10;
-//      
-//      BDBJEPersistenceManager2 bdb = new BDBJEPersistenceManager2(envPath);
-//      
-//      bdb.start();
-//      
-//      Queue queue = new QueueImpl(1);
-//      
-//      List<Message> messages = new ArrayList<Message>();
-//      
-//      byte[] payload = new byte[1 * 1024];
-//      
-//      List<MessageReference> refs = new ArrayList<MessageReference>();
-//                  
-//      for (int i = 0; i < numMessages; i++)
-//      {
-//         Message message = new MessageImpl(i, 0, true, 0, System.currentTimeMillis(), (byte)4);
-//         
-//         for (int j = 0; j < numRefs; j++)
-//         {
-//            MessageReference ref = message.createReference(queue);
-//            
-//            message.setPayload(payload);
-//            
-//            refs.add(ref);
-//         }
-//         
-//         messages.add(message);
-//         
-//         if (i % 100 == 0)
-//         {
-//            bdb.commitMessages(messages);
-//            
-//            messages.clear();
-//         }         
-//      }
-//      bdb.commitMessages(messages);
-//      
-//      long start = System.currentTimeMillis();
-//      
-//      //Now delete them
-//      
-//      bdb.deleteReferences(refs);      
-//      
-//      long end = System.currentTimeMillis();
-//      
-//      double rate = 1000 * (double)numMessages / (end - start);
-//      
-//      System.out.println("Delete Rate: " + rate);
-//      
-//   }
-//   
-//   public void testDeleteReference() throws Exception
-//   {
-//      String envPath = "/home/tim/test-env";
-//      
-//      File file = new File(envPath);
-//      
-//      deleteDirectory(file);
-//      
-//      file.mkdir();
-//      
-//      final int numMessages = 5000;
-//      
-//      final int numRefs = 1;
-//      
-//      BDBJEPersistenceManager bdb = new BDBJEPersistenceManager(envPath);
-//      
-//      bdb.start();
-//      
-//      Queue queue = new QueueImpl(1);
-//      
-//      List<Message> messages = new ArrayList<Message>();
-//      
-//      byte[] payload = new byte[1 * 1024];
-//      
-//      List<MessageReference> refs = new ArrayList<MessageReference>();
-//                  
-//      for (int i = 0; i < numMessages; i++)
-//      {
-//         Message message = new MessageImpl(i, 0, true, 0, System.currentTimeMillis(), (byte)4);
-//         
-//         for (int j = 0; j < numRefs; j++)
-//         {
-//            MessageReference ref = message.createReference(queue);
-//            
-//            message.setPayload(payload);
-//            
-//            refs.add(ref);
-//         }
-//         
-//         messages.add(message);
-//         
-//         if (i % 100 == 0)
-//         {
-//            bdb.commitMessages(messages);
-//            
-//            messages.clear();
-//         }         
-//      }
-//      bdb.commitMessages(messages);
-//      
-//      System.out.println("Added them");
-//      
-//      long start = System.currentTimeMillis();
-//      
-//      //Now delete them
-//      
-//      for (MessageReference ref: refs)
-//      {      
-//         bdb.deleteReference(ref);
-//      }
-//      
-//      long end = System.currentTimeMillis();
-//      
-//      double rate = 1000 * (double)numMessages / (end - start);
-//      
-//      System.out.println("Delete Rate: " + rate);
-//      
-//   }
-//   
-//   
-//   public void testPrepareMessages() throws Exception
-//   {
-//      String envPath = "/home/tim/test-env";
-//      
-//      File file = new File(envPath);
-//      
-//      deleteDirectory(file);
-//      
-//      file.mkdir();
-//      
-//      final int numMessages = 5000;
-//      
-//      final int numRefs = 10;
-//      
-//      BDBJEPersistenceManager2 bdb = new BDBJEPersistenceManager2(envPath);
-//      
-//      bdb.start();
-//      
-//      Queue queue = new QueueImpl(1);
-//      
-//      List<Message> messages = new ArrayList<Message>();
-//      
-//      long start = System.currentTimeMillis();
-//      
-//      byte[] payload = new byte[1 * 1024];
-//                  
-//      for (int i = 0; i < numMessages; i++)
-//      {
-//         Message message = new MessageImpl(i, 0, true, 0, System.currentTimeMillis(), (byte)4);
-//         
-//         for (int j = 0; j < numRefs; j++)
-//         {
-//            message.createReference(queue);
-//            
-//            message.setPayload(payload);
-//         }
-//         
-//         messages.add(message);
-//         
-//         if (i % 100 == 0)
-//         {
-//            Xid xid = this.generateXid();
-//            
-//            bdb.prepareMessages(xid, messages);
-//            
-//            bdb.commitPreparedMessages(xid);
-//            
-//            messages.clear();
-//         }         
-//      }
-//      
-//      Xid xid = this.generateXid();
-//      
-//      bdb.prepareMessages(xid, messages);
-//      
-//      bdb.commitPreparedMessages(xid);
-//      
-//      long end = System.currentTimeMillis();
-//      
-//      double rate = 1000 * (double)numMessages / (end - start);
-//      
-//      System.out.println("Insert Rate: " + rate);
-//      
-//   }
-   
-//   /*
-//    * Test with message and ref in separate databases
-//    */
-//   public void testMsgandRefsDifferentDBSNoXA() throws Exception
-//   {
-//      File file = new File("/home/tim/test-env");
-//      
-//      deleteDirectory(file);
-//      
-//      file.mkdir();
-//      
-//      EnvironmentConfig envConfig = new EnvironmentConfig();
-//        
-//      envConfig.setAllowCreate(true);
-//      
-//      envConfig.setTransactional(true);
-//      
-////      envConfig.setTxnNoSync(true);
-////      
-////      envConfig.setTxnWriteNoSync(true);
-//      
-//      Environment env1 = new Environment(file, envConfig);
-//
-//      DatabaseConfig dbConfig1 = new DatabaseConfig();
-//      
-//      dbConfig1.setTransactional(true);
-//      
-//      dbConfig1.setAllowCreate(true);
-//      
-//      Database msgDB = env1.openDatabase(null, "message", dbConfig1);
-//      
-//      DatabaseConfig dbConfig2 = new DatabaseConfig();
-//      
-//      dbConfig2.setTransactional(true);
-//      
-//      dbConfig2.setAllowCreate(true);
-//      
-//      Database refDB = env1.openDatabase(null, "ref", dbConfig2);
-//      
-//      
-//      DatabaseConfig dbConfig3 = new DatabaseConfig();
-//      
-//      dbConfig3.setTransactional(true);
-//      
-//      dbConfig3.setAllowCreate(true);
-//      
-//      Database txDB = env1.openDatabase(null, "tx", dbConfig3);
-//      
-//      
-//      
-//      final int numMessages = 5000;
-//      
-//      byte[] msgBytes = new byte[256];
-//      
-//      final int numRefs = 10;
-//      
-//      byte[] refBytes = new byte[numRefs * 20];
-//      
-//      byte[] txBytes = new byte[numRefs * 50];
-//      
-//      
-//      long start = System.currentTimeMillis();
-//      
-//      for (int i = 0; i < numMessages; i++)
-//      {
-//         byte[] keyBytes = new byte[8];
-//         
-//         ByteBuffer buffer = ByteBuffer.wrap(keyBytes);
-//         
-//         buffer.putLong(i);
-//         
-//         DatabaseEntry key = new DatabaseEntry(keyBytes);
-//         
-//         
-//         //Prepare refs
-//         
-//         DatabaseEntry refVal = new DatabaseEntry(refBytes);
-//         
-//         Transaction tx = env1.beginTransaction(null, null);
-//                  
-//         refDB.put(tx, key, refVal);
-//         
-//         // Message
-//         
-//         DatabaseEntry msgVal = new DatabaseEntry(msgBytes);
-//         
-//         msgDB.put(tx, key, msgVal);
-//         
-//         //Write a tx record
-//         
-//         DatabaseEntry txVal = new DatabaseEntry(txBytes);
-//         
-//         txDB.put(tx, key, txVal);
-//               
-//         //Commit the prepare
-//         
-//         tx.commit();    
-//         
-//         tx = env1.beginTransaction(null, null);
-//         
-//         //Now commit the refs
-//                  
-//         refVal = new DatabaseEntry(refBytes);
-//         
-//         refDB.put(tx, key, refVal);
-//         
-//         //And delete the tx record
-//         
-//         txDB.delete(tx, key);
-//                  
-//         tx.commit();         
-//      }
-//      
-//      long end = System.currentTimeMillis();
-//      
-//      double rate = 1000 * (double)numMessages / (end - start);
-//      
-//      System.out.println("Insert Rate: " + rate);
-//      
-//    
-//   }
-//   
-//   public void testMsgandRefsDifferentDBSXA() throws Exception
-//   {
-//      File file = new File("/home/tim/test-env");
-//      
-//      deleteDirectory(file);
-//      
-//      file.mkdir();
-//      
-//      EnvironmentConfig envConfig = new EnvironmentConfig();
-//        
-//      envConfig.setAllowCreate(true);
-//      
-//      envConfig.setTransactional(true);
-//      
-//      XAEnvironment env1 = new XAEnvironment(file, envConfig);
-//
-//      DatabaseConfig dbConfig1 = new DatabaseConfig();
-//      
-//      dbConfig1.setTransactional(true);
-//      
-//      dbConfig1.setAllowCreate(true);
-//      
-//      Database msgDB = env1.openDatabase(null, "message", dbConfig1);
-//      
-//      DatabaseConfig dbConfig2 = new DatabaseConfig();
-//      
-//      dbConfig2.setTransactional(true);
-//      
-//      dbConfig2.setAllowCreate(true);
-//      
-//      Database refDB = env1.openDatabase(null, "ref", dbConfig2);
-//      
-//      
-//      
-//      final int numMessages = 5000;
-//      
-//      byte[] msgBytes = new byte[256];
-//      
-//      final int numRefs = 10;
-//      
-//      byte[] refBytes = new byte[numRefs * 20];
-//      
-//      long start = System.currentTimeMillis();
-//      
-//      for (int i = 0; i < numMessages; i++)
-//      {
-//         Xid xid = generateXid();
-//         
-//         env1.start(xid, XAResource.TMNOFLAGS);
-//         
-//         byte[] keyBytes = new byte[8];
-//         
-//         ByteBuffer buffer = ByteBuffer.wrap(keyBytes);
-//         
-//         buffer.putLong(i);
-//         
-//         DatabaseEntry key = new DatabaseEntry(keyBytes);
-//         
-//         DatabaseEntry msgVal = new DatabaseEntry(msgBytes);
-//         
-//         Transaction tx = env1.beginTransaction(null, null);
-//         
-//         msgDB.put(null, key, msgVal);
-//         
-//         //Now the refs
-//                  
-//         DatabaseEntry refVal = new DatabaseEntry(refBytes);
-//         
-//         refDB.put(null, key, refVal);
-//         
-//         env1.end(xid, XAResource.TMSUCCESS);
-//         
-//         env1.prepare(xid);
-//         
-//         env1.commit(xid, false);
-//                  
-//        // tx.commit();         
-//      }
-//      
-//      long end = System.currentTimeMillis();
-//      
-//      double rate = 1000 * (double)numMessages / (end - start);
-//      
-//      System.out.println("Insert Rate: " + rate);
-//      
-//      start = System.currentTimeMillis();
-//   }
-//   
-//   private Xid generateXid()
-//   {      
-//      String id = java.util.UUID.randomUUID().toString();
-//      
-//      Xid xid = new XidImpl("blah".getBytes(), 123, id.getBytes());
-//      
-//      return xid;
-//   }
-//   
-//   
-//// This is very slow   
-////   public void testMsgandRefsSameDBSNoXA() throws Exception
-////   {
-////      File file = new File("/home/tim/test-env");
-////      
-////      deleteDirectory(file);
-////      
-////      file.mkdir();
-////      
-////      EnvironmentConfig envConfig = new EnvironmentConfig();
-////        
-////      envConfig.setAllowCreate(true);
-////      
-////      envConfig.setTransactional(true);
-////      
-////      Environment env1 = new Environment(file, envConfig);
-////
-////      DatabaseConfig dbConfig1 = new DatabaseConfig();
-////      
-////      dbConfig1.setTransactional(true);
-////      
-////      dbConfig1.setAllowCreate(true);
-////      
-////      Database msgDB = env1.openDatabase(null, "message", dbConfig1);      
-////     
-////      final int numMessages = 5000;
-////      
-////      byte[] msgBytes = new byte[10 * 1024];
-////      
-////      byte[] refBytes = new byte[24];
-////      
-////      long start = System.currentTimeMillis();
-////      
-////      for (int i = 0; i < numMessages; i++)
-////      {
-////         byte[] keyBytes = new byte[8];
-////         
-////         ByteBuffer buffer = ByteBuffer.wrap(keyBytes);
-////         
-////         buffer.putLong(i);
-////         
-////         DatabaseEntry key = new DatabaseEntry(keyBytes);
-////         
-////         DatabaseEntry msgVal = new DatabaseEntry(msgBytes);
-////         
-////         Transaction tx = env1.beginTransaction(null, null);
-////         
-////         msgDB.put(tx, key, msgVal);
-////         
-////         //Now the refs
-////         
-////         final int numRefs = 50;
-////         
-////         for (int j = 0; j < numRefs; j++)
-////         {
-////            keyBytes = new byte[8];
-////            
-////            buffer = ByteBuffer.wrap(keyBytes);
-////            
-////            buffer.putLong(j);
-////            
-////            key = new DatabaseEntry(keyBytes);
-////                                    
-////            DatabaseEntry value = new DatabaseEntry();
-////            
-////            value.setPartial(0, refBytes.length, true);
-////                        
-////            value.setData(refBytes);
-////            
-////            msgDB.put(tx, key, value);
-////         }
-////         
-////         tx.commit();
-////         
-////      }
-////      
-////      long end = System.currentTimeMillis();
-////      
-////      double rate = 1000 * (double)numMessages / (end - start);
-////      
-////      System.out.println("Rate: " + rate);
-////   }
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/RealBDBJEEnvironmentTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/RealBDBJEEnvironmentTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/RealBDBJEEnvironmentTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,94 +0,0 @@
-package org.jboss.messaging.core.impl.bdbje.integration.test.unit;
-
-import java.io.File;
-import java.io.FileOutputStream;
-
-import org.jboss.messaging.core.impl.bdbje.test.unit.BDBJEEnvironmentTestBase;
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
-import org.jboss.messaging.core.persistence.impl.bdbje.integration.RealBDBJEEnvironment;
-
-/**
- * 
- * A RealBDBJEEnvironmentTest
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class RealBDBJEEnvironmentTest extends BDBJEEnvironmentTestBase
-{
-   protected void setUp() throws Exception
-   {   
-      createDir(ENV_DIR);
-      
-      env = createEnvironment();
-      
-      env.setEnvironmentPath(ENV_DIR);
-      
-      env.setCreateEnvironment(true);
-      
-      env.start();
-      
-      database = env.getDatabase("test-db");            
-   }
-   
-   protected BDBJEEnvironment createEnvironment() throws Exception
-   {
-      BDBJEEnvironment env = new RealBDBJEEnvironment(true);
-      
-      env.setTransacted(true);
-      
-      return env;
-   }    
-   
-   protected void createDir(String path)
-   {  
-      File file = new File(path);
-      
-      deleteDirectory(file);
-      
-      file.mkdir();
-   }
-   
-   protected void copyEnvironment() throws Exception
-   {
-      File envDir = new File(ENV_DIR);
-      
-      File envCopyDir = new File(ENV_COPY_DIR);
-      
-      deleteDirectory(envCopyDir);
-      
-      copyRecursive(envDir, envCopyDir);
-      
-      deleteDirectory(envDir);
-      
-      //Need to sync
-      
-      FileOutputStream fos = new FileOutputStream(ENV_COPY_DIR + "/je.lck");
-      
-      fos.getFD().sync();
-   }
-   
-   protected void copyBackEnvironment() throws Exception
-   {
-      File envDir = new File(ENV_DIR);
-      
-      File envCopyDir = new File(ENV_COPY_DIR);
-      
-      deleteDirectory(envDir);
-      
-      copyRecursive(envCopyDir, envDir);
-      
-      deleteDirectory(envCopyDir);
-      
-      //Need to sync
-      
-      FileOutputStream fos = new FileOutputStream(ENV_DIR + "/je.lck");
-      
-      fos.getFD().sync();
-   }    
-   
-   protected boolean isFake()
-   {
-      return false;
-   }
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,1918 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * 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.core.impl.bdbje.test.unit;
-
-import java.io.File;
-import java.util.List;
-
-import javax.transaction.xa.Xid;
-
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEDatabase;
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJETransaction;
-import org.jboss.messaging.core.server.impl.XidImpl;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-import com.sleepycat.je.DatabaseException;
-
-/**
- * 
- * Base for tests for BDBJEEnvironment and BDBJEDatabase
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public abstract class BDBJEEnvironmentTestBase extends UnitTestCase
-{
-   protected BDBJEEnvironment env;
-   
-   protected BDBJEDatabase database;
-   
-   protected static final String HOME_DIR = System.getProperty("user.home");
-   
-   protected static final String ENV_DIR = HOME_DIR + "/test-bdb-environment";
-      
-   protected static final String ENV_COPY_DIR = HOME_DIR + "/test-bdb-environment-copy";
-   
-   protected static final String DB_NAME = "test-db";
-   
-   @Override
-   protected void setUp() throws Exception
-   {   
-      super.setUp();
-      
-      env = createEnvironment();
-      
-      env.setCreateEnvironment(true);
-      
-      env.setEnvironmentPath(ENV_DIR);
-      
-      env.start();
-      
-      database = env.getDatabase(DB_NAME);      
-   }
-   
-   protected abstract void createDir(String path);
-   
-   protected void tearDown() throws Exception
-   {
-      super.tearDown();
-      
-      if (env.isStarted())
-      {
-         env.stop();
-      }
-   }
-   
-   protected abstract BDBJEEnvironment createEnvironment() throws Exception;
-   
-   protected abstract void copyEnvironment() throws Exception;
-
-   protected abstract void copyBackEnvironment() throws Exception;
-   
-   protected abstract boolean isFake();
-   
-
-   // The tests ----------------------------------------------------------------
-      
-   public void testGetInDoubtXidsCompleteWithCommit() throws Exception
-   {
-      List<Xid> xids = env.getInDoubtXids();
-      
-      assertTrue(xids.isEmpty());
-      
-      Xid xid1 = generateXid();
-      
-      env.startWork(xid1);
-      
-      database.put(null, 1, new byte[10], 0, 10);
-      
-      env.endWork(xid1, false);
-      
-      env.prepare(xid1);
-      
-      xids = env.getInDoubtXids();
-      
-      assertEquals(xid1, xids.get(0));
-      
-      env.commit(xid1);
-      
-      xids = env.getInDoubtXids();
-      
-      assertTrue(xids.isEmpty());
-   }
-      
-   public void testGetInDoubtXidsCompleteWithRollback() throws Exception
-   {
-      List<Xid> xids = env.getInDoubtXids();
-      
-      assertTrue(xids.isEmpty());
-      
-      Xid xid1 = generateXid();
-      
-      env.startWork(xid1);
-      
-      database.put(null, 1, new byte[10], 0, 10);
-      
-      env.endWork(xid1, false);
-      
-      env.prepare(xid1);
-      
-      xids = env.getInDoubtXids();
-      
-      assertEquals(xid1, xids.get(0));
-      
-      env.rollback(xid1);
-      
-      xids = env.getInDoubtXids();
-      
-      assertTrue(xids.isEmpty());
-   }
-   
-   
-   public void testGetInDoubtXidsMultiple() throws Exception
-   {
-      List<Xid> xids = env.getInDoubtXids();
-      
-      assertTrue(xids.isEmpty());
-      
-      Xid xid1 = generateXid();      
-      env.startWork(xid1);      
-      database.put(null, 1, new byte[10], 0, 10);      
-      env.endWork(xid1, false); 
-      
-      env.prepare(xid1);      
-      xids = env.getInDoubtXids();      
-      assertEquals(xid1, xids.get(0));
-      
-      
-      Xid xid2 = generateXid();      
-      env.startWork(xid2);      
-      database.put(null, 2, new byte[10], 0, 10);      
-      env.endWork(xid2, false); 
-      
-      env.prepare(xid2);      
-      xids = env.getInDoubtXids();      
-      assertTrue(xids.contains(xid1));
-      assertTrue(xids.contains(xid2));
-      
-      Xid xid3 = generateXid();      
-      env.startWork(xid3);      
-      database.put(null, 3, new byte[10], 0, 10);      
-      env.endWork(xid3, false); 
-      
-      env.prepare(xid3);      
-      xids = env.getInDoubtXids();      
-      assertTrue(xids.contains(xid1));
-      assertTrue(xids.contains(xid2));
-      assertTrue(xids.contains(xid3));
-      
-      env.commit(xid1);
-      
-      env.commit(xid2);
-      
-      env.commit(xid3);
-     
-   }
-   
-   // Commented out until http://jira.jboss.org/jira/browse/JBMESSAGING-1192 is complete   
-//   public void testGetInDoubtXidsMultipleWithRestart() throws Exception
-//   {
-//      List<Xid> xids = env.getInDoubtXids();
-//      
-//      assertTrue(xids.isEmpty());
-//      
-//      Xid xid1 = generateXid();      
-//      env.startWork(xid1);      
-//      database.put(null, 1, new byte[10], 0, 10);      
-//      env.endWork(xid1, false); 
-//      
-//      env.prepare(xid1);      
-//      xids = env.getInDoubtXids();      
-//      assertEquals(xid1, xids.get(0));
-//      
-//      
-//      Xid xid2 = generateXid();      
-//      env.startWork(xid2);      
-//      database.put(null, 2, new byte[10], 0, 10);      
-//      env.endWork(xid2, false); 
-//      
-//      env.prepare(xid2);      
-//      xids = env.getInDoubtXids();      
-//      assertTrue(xids.contains(xid1));
-//      assertTrue(xids.contains(xid2));
-//      
-//      Xid xid3 = generateXid();      
-//      env.startWork(xid3);      
-//      database.put(null, 3, new byte[10], 0, 10);      
-//      env.endWork(xid3, false); 
-//      
-//      env.prepare(xid3);      
-//      xids = env.getInDoubtXids();      
-//      assertTrue(xids.contains(xid1));
-//      assertTrue(xids.contains(xid2));
-//      assertTrue(xids.contains(xid3));
-//      
-//      //Now to simulate a crash we copy the environment directory from under BDB, then close
-//      //BDB. Then start it again with the copied config.
-//      //We can't just stop the environment and restart it since on stopping cleanly BDB will abort any open
-//      //transactions
-//      
-//      copyEnvironment();
-//      
-//      database.close();
-//      
-//      env.stop();
-//      
-//      copyBackEnvironment();
-//      
-//      env.start();
-//                 
-//      database = env.getDatabase(DB_NAME);
-//      
-//      xids = env.getInDoubtXids();      
-//      assertTrue(xids.contains(xid1));
-//      assertTrue(xids.contains(xid2));
-//      assertTrue(xids.contains(xid3));
-//      
-//      env.commit(xid1);
-//      env.commit(xid2);
-//      env.commit(xid3);
-//      
-//      xids = env.getInDoubtXids();
-//      
-//      assertTrue(xids.isEmpty());     
-//   }
-      
-      
-   public void testPutAndRemoveNonTransactional() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      assertContainsPair(id, bytes, 1);
-      
-      database.remove(null, 1);
-      
-      assertStoreEmpty();
-   }
-   
-   public void testPutAndRemoveNonTransactionalWithRestart() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      long id = 1;
-      
-      int offset = 0;
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      assertContainsPair(id, bytes, 1);
-      
-      database.close();
-      
-      env.stop();
-      
-      env.start();
-      
-      database = env.getDatabase(DB_NAME);
-      
-      assertContainsPair(id, bytes, 1);
-   }
-   
-   public void testPutAndRemoveMultipleNonTransactional() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-      
-      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
-       
-      long id1 = 1;
-      
-      long id2 = 2;
-      
-      long id3 = 3;
-      
-      int offset = 0;
-      
-      database.put(null, id1, bytes1, offset, bytes1.length);
-      
-      database.put(null, id2, bytes2, offset, bytes2.length);
-      
-      database.put(null, id3, bytes3, offset, bytes3.length);
-      
-      assertContainsPair(id1, bytes1, 3);
-      
-      assertContainsPair(id2, bytes2, 3);
-      
-      assertContainsPair(id3, bytes3, 3);
-                       
-      database.remove(null, id2);
-      
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id3, bytes3, 2);
-            
-      database.remove(null, id3);
-      
-      assertContainsPair(id1, bytes1, 1);
-      
-      database.remove(null, id1);
-      
-      assertStoreEmpty();      
-   }
-            
-   public void testPutTransactionalCommit() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      BDBJETransaction tx = env.createTransaction();
-      
-      database.put(tx, id, bytes, offset, bytes.length);
-      
-      tx.commit();
-      
-      assertContainsPair(id, bytes, 1);
-      
-      database.remove(null, 1);
-      
-      assertStoreEmpty();            
-   }
-   
-   public void testPutTransactionalWithRestart() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      BDBJETransaction tx = env.createTransaction();
-      
-      database.put(tx, id, bytes, offset, bytes.length);
-      
-      //Now restart before committing
-      
-      database.close();
-      
-      //This will abort the transaction
-      env.stop();
-
-      env.start();
-      
-      database = env.getDatabase(DB_NAME);
-      
-      assertStoreEmpty();            
-   }
-   
-   public void testPutXACommit() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      env.commit(xid);
-      
-      assertContainsPair(id, bytes, 1);
-      
-      database.remove(null, 1);
-      
-      assertStoreEmpty();            
-   }
-   
-   public void testPutXAWithRestart() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      env.endWork(xid, false);
-      
-      // Now restart
-      
-      database.close();
-      
-      env.stop();
-      
-      env.start();
-      
-      database = env.getDatabase(DB_NAME);
-      
-      assertStoreEmpty();            
-   }
-   
-   
-   public void testPutXAWithRestartAfterPrepare() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      // Now restart
-      
-      database.close();
-      
-      env.stop();
-      
-      env.start();
-      
-      database = env.getDatabase(DB_NAME);
-      
-      assertStoreEmpty();            
-   }
-   
-   public void testRemoveTransactional() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      assertContainsPair(id, bytes, 1);
-                        
-      BDBJETransaction tx = env.createTransaction();
-      
-      database.remove(tx, id);
-      
-      tx.commit();
-      
-      assertStoreEmpty();        
-   }
-   
-   public void testRemoveTransactionalWithRestart() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      assertContainsPair(id, bytes, 1);
-                        
-      BDBJETransaction tx = env.createTransaction();
-      
-      database.remove(tx, id);
-      
-      // Now restart
-      
-      database.close();
-      
-      env.stop();
-      
-      env.start();
-      
-      database = env.getDatabase(DB_NAME);
-      
-      assertContainsPair(id, bytes, 1);       
-   }
-   
-   public void testRemoveXACommit() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-            
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      assertContainsPair(id, bytes, 1);
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-                             
-      database.remove(null, id);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      env.commit(xid);
-
-      assertStoreEmpty();        
-   }
-   
-   public void testRemoveXAWithRestart() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-            
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      assertContainsPair(id, bytes, 1);
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-                             
-      database.remove(null, id);
-      
-      env.endWork(xid, false);
-      
-      // Now restart
-      
-      database.close();
-      
-      env.stop();
-      
-      env.start();
-      
-      database = env.getDatabase(DB_NAME);
-
-      assertContainsPair(id, bytes, 1);     
-   }
-   
-   public void testRemoveXAWithRestartAfterPrepare() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-            
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      assertContainsPair(id, bytes, 1);
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-                             
-      database.remove(null, id);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      // Now restart
-      
-      database.close();
-      
-      env.stop();
-      
-      env.start();
-      
-      database = env.getDatabase(DB_NAME);
-
-      assertContainsPair(id, bytes, 1);     
-   }
-   
-   public void testPutTransactionalRollback() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      BDBJETransaction tx = env.createTransaction();
-      
-      database.put(tx, id, bytes, offset, bytes.length);
-      
-      tx.rollback();
-      
-      assertStoreEmpty();            
-   }
-   
-   public void testPutXARollback() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      env.rollback(xid);
-      
-      assertStoreEmpty();            
-   }
-      
-   public void testRemoveTransactionalRollback() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      assertContainsPair(id, bytes, 1);
-                        
-      BDBJETransaction tx = env.createTransaction();
-      
-      database.remove(tx, id);
-      
-      tx.rollback();
-      
-      assertContainsPair(id, bytes, 1);            
-   }
-   
-   public void testRemoveXARollback() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      assertContainsPair(id, bytes, 1);
-                        
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.remove(null, id);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      env.rollback(xid);
-      
-      assertContainsPair(id, bytes, 1);            
-   }
-   
-   
-   public void testPutAndRemoveMultipleTransactionalCommit() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-      
-      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
-      
-      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
-       
-      long id1 = 1;
-      
-      long id2 = 2;
-      
-      long id3 = 3;
-      
-      long id4 = 4;
-      
-      int offset = 0;
-      
-      database.put(null, id1, bytes1, offset, bytes1.length);
-      
-      database.put(null, id2, bytes2, offset, bytes2.length);
-                 
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id2, bytes2, 2);
-      
-      BDBJETransaction tx = env.createTransaction();
-      
-      database.put(tx, id3, bytes3, offset, bytes3.length);
-      
-      database.put(tx, id4, bytes4, offset, bytes4.length);
-      
-      database.remove(tx, id1);
-      
-      database.remove(tx, id2);
-      
-      tx.commit();
-      
-      assertContainsPair(id3, bytes3, 2);
-      
-      assertContainsPair(id4, bytes4, 2);        
-   }
-   
-   public void testPutAndRemoveMultipleXACommit() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-      
-      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
-      
-      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
-       
-      long id1 = 1;
-      
-      long id2 = 2;
-      
-      long id3 = 3;
-      
-      long id4 = 4;
-      
-      int offset = 0;
-      
-      database.put(null, id1, bytes1, offset, bytes1.length);
-      
-      database.put(null, id2, bytes2, offset, bytes2.length);
-                 
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id2, bytes2, 2);
-      
-      XidImpl xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.put(null, id3, bytes3, offset, bytes3.length);
-      
-      database.put(null, id4, bytes4, offset, bytes4.length);
-      
-      database.remove(null, id1);
-      
-      database.remove(null, id2);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      env.commit(xid);
-      
-      assertContainsPair(id3, bytes3, 2);
-      
-      assertContainsPair(id4, bytes4, 2);        
-   }
-   
-   /*
-    * As above but we use different but equal() XidImpl instances at each point
-    */
-   public void testPutAndRemoveMultipleXACommitWithCopy() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-      
-      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
-      
-      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
-       
-      long id1 = 1;
-      
-      long id2 = 2;
-      
-      long id3 = 3;
-      
-      long id4 = 4;
-      
-      int offset = 0;
-      
-      database.put(null, id1, bytes1, offset, bytes1.length);
-      
-      database.put(null, id2, bytes2, offset, bytes2.length);
-                 
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id2, bytes2, 2);
-      
-      XidImpl xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.put(null, id3, bytes3, offset, bytes3.length);
-      
-      database.put(null, id4, bytes4, offset, bytes4.length);
-      
-      database.remove(null, id1);
-      
-      database.remove(null, id2);
-      
-      xid = new XidImpl(xid);
-            
-      env.endWork(xid, false);
-      
-      xid = new XidImpl(xid);      
-      
-      env.prepare(xid);
-      
-      xid = new XidImpl(xid);
-      
-      env.commit(xid);
-      
-      assertContainsPair(id3, bytes3, 2);
-      
-      assertContainsPair(id4, bytes4, 2);        
-   }
-   
-   public void testPutAndRemoveMultipleXACommitDifferentThread() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-      
-      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
-      
-      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
-       
-      long id1 = 1;
-      
-      long id2 = 2;
-      
-      long id3 = 3;
-      
-      long id4 = 4;
-      
-      int offset = 0;
-      
-      database.put(null, id1, bytes1, offset, bytes1.length);
-      
-      database.put(null, id2, bytes2, offset, bytes2.length);
-                 
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id2, bytes2, 2);
-      
-      final XidImpl xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.put(null, id3, bytes3, offset, bytes3.length);
-      
-      database.put(null, id4, bytes4, offset, bytes4.length);
-      
-      database.remove(null, id1);
-      
-      database.remove(null, id2);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      //Commit on a different thread
-      
-      class MyThread extends Thread
-      {
-         volatile boolean failed;
-         
-         public void run()
-         {
-            try
-            {
-               env.commit(xid);
-            }
-            catch (Exception e)
-            {
-               failed = true;
-            }
-         }         
-      }
-      
-      MyThread t = new MyThread();
-      
-      t.start();
-      
-      t.join();
-      
-      assertFalse(t.failed);
-      
-      assertContainsPair(id3, bytes3, 2);
-      
-      assertContainsPair(id4, bytes4, 2);        
-   }
-   
-   public void testPutAndRemoveMultipleXAWithRestart() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-      
-      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
-      
-      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
-       
-      long id1 = 1;
-      
-      long id2 = 2;
-      
-      long id3 = 3;
-      
-      long id4 = 4;
-      
-      int offset = 0;
-      
-      database.put(null, id1, bytes1, offset, bytes1.length);
-      
-      database.put(null, id2, bytes2, offset, bytes2.length);
-                 
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id2, bytes2, 2);
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.put(null, id3, bytes3, offset, bytes3.length);
-      
-      database.put(null, id4, bytes4, offset, bytes4.length);
-      
-      database.remove(null, id1);
-      
-      database.remove(null, id2);
-      
-      env.endWork(xid, false);
-      
-      // Now restart
-      
-      database.close();
-      
-      env.stop();
-      
-      env.start();
-      
-      database = env.getDatabase(DB_NAME);
-      
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id2, bytes2, 2);      
-   }
-   
-   public void testPutAndRemoveMultipleTransactionalRollback() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-      
-      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
-      
-      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
-       
-      long id1 = 1;
-      
-      long id2 = 2;
-      
-      long id3 = 3;
-      
-      long id4 = 4;
-      
-      int offset = 0;
-      
-      database.put(null, id1, bytes1, offset, bytes1.length);
-      
-      database.put(null, id2, bytes2, offset, bytes2.length);
-                 
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id2, bytes2, 2);
-      
-      BDBJETransaction tx = env.createTransaction();
-      
-      database.put(tx, id3, bytes3, offset, bytes3.length);
-      
-      database.put(tx, id4, bytes4, offset, bytes4.length);
-      
-      database.remove(tx, id1);
-      
-      database.remove(tx, id2);
-      
-      tx.rollback();
-      
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id2, bytes2, 2);            
-   }
-   
-   public void testPutAndRemoveMultipleXARollback() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-      
-      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
-      
-      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
-       
-      long id1 = 1;
-      
-      long id2 = 2;
-      
-      long id3 = 3;
-      
-      long id4 = 4;
-      
-      int offset = 0;
-      
-      database.put(null, id1, bytes1, offset, bytes1.length);
-      
-      database.put(null, id2, bytes2, offset, bytes2.length);
-                 
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id2, bytes2, 2);
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.put(null, id3, bytes3, offset, bytes3.length);
-      
-      database.put(null, id4, bytes4, offset, bytes4.length);
-      
-      database.remove(null, id1);
-      
-      database.remove(null, id2);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      env.rollback(xid);
-      
-      assertContainsPair(id1, bytes1, 2);
-      
-      assertContainsPair(id2, bytes2, 2);            
-   }
-   
-   public void testOverwiteNonTransactional() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      database.put(null, id, bytes1, offset, bytes1.length);
-      
-      assertContainsPair(id, bytes1, 1);
-      
-      database.put(null, id, bytes2, offset, bytes1.length);
-      
-      assertContainsPair(id, bytes2, 1);
-            
-      database.remove(null, 1);
-      
-      assertStoreEmpty();
-   }
-   
-   public void testOverwiteTransactionalCommit() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      BDBJETransaction tx = env.createTransaction();
-            
-      database.put(tx, id, bytes1, offset, bytes1.length);
-      
-      database.put(tx, id, bytes2, offset, bytes1.length);
-      
-      tx.commit();
-      
-      assertContainsPair(id, bytes2, 1);
-            
-      database.remove(null, 1);
-      
-      assertStoreEmpty();
-   }
-   
-   public void testOverwiteXACommit() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-      
-      database.put(null, id, bytes1, offset, bytes1.length);
-      
-      database.put(null, id, bytes2, offset, bytes1.length);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      env.commit(xid);
-      
-      assertContainsPair(id, bytes2, 1);
-            
-      database.remove(null, 1);
-      
-      assertStoreEmpty();
-   }
-   
-   public void testOverwiteTransactionalRollback() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      BDBJETransaction tx = env.createTransaction();
-            
-      database.put(tx, id, bytes1, offset, bytes1.length);
-      
-      database.put(tx, id, bytes2, offset, bytes1.length);
-      
-      tx.rollback();
-      
-      assertStoreEmpty();
-   }
-   
-   public void testOverwiteXARollback() throws Exception
-   {
-      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      Xid xid = generateXid();
-      
-      env.startWork(xid);      
-      
-      database.put(null, id, bytes1, offset, bytes1.length);
-      
-      database.put(null, id, bytes2, offset, bytes1.length);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      env.rollback(xid);
-      
-      assertStoreEmpty();
-   }
-   
-   public void testPutAndRemovePartialNonTransactional() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 20, 21, 22, 23 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      database.put(null, id, bytes, offset, bytes.length);
-      
-      assertContainsPair(id, bytes, 1);
-      
-      database.put(null, id, bytes2, 10, bytes2.length);
-      
-      byte[] bytes3 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 21, 22, 23 };
-      
-      assertContainsPair(id, bytes3, 1);  
-            
-      database.put(null, id, bytes2, 3, bytes2.length);
-      
-      byte[] bytes4 = new byte[] { 1, 2, 3, 20, 21, 22, 23, 8, 9, 10, 20, 21, 22, 23 };
-      
-      assertContainsPair(id, bytes4, 1);  
-      
-      byte[] bytes5 = new byte[0];
-      
-      //blank out 4 bytes
-      database.put(null, id, bytes5, 5, 4);
-      
-      byte[] bytes6 = new byte[] { 1, 2, 3, 20, 21, 10, 20, 21, 22, 23 };
-      
-      assertContainsPair(id, bytes6, 1);  
-      
-      
-      database.put(null, id, new byte[0], 0, 4);
-      
-      byte[] bytes7 = new byte[] { 21, 10, 20, 21, 22, 23 };
-      
-      assertContainsPair(id, bytes7, 1);  
-                        
-      database.remove(null, 1);
-      
-      assertStoreEmpty();
-   }
-   
-   public void testPutAndRemovePartialTransactional() throws Exception
-   {
-      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      
-      byte[] bytes2 = new byte[] { 20, 21, 22, 23 };
-       
-      long id = 1;
-      
-      int offset = 0;
-      
-      BDBJETransaction tx = env.createTransaction();
-            
-      database.put(tx, id, bytes, offset, bytes.length);
-      
-      tx.commit();
-      
-      assertContainsPair(id, bytes, 1);
-      
-      tx = env.createTransaction();
-      
-      database.put(tx, id, bytes2, 10, bytes2.length);
-      
-      tx.commit();
-      
-      byte[] bytes3 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 21, 22, 23 };
-      
-      assertContainsPair(id, bytes3, 1);  
-      
-      tx = env.createTransaction();
-            
-      database.put(tx, id, bytes2, 3, bytes2.length);
-      
-      tx.commit();
-      
-      byte[] bytes4 = new byte[] { 1, 2, 3, 20, 21, 22, 23, 8, 9, 10, 20, 21, 22, 23 };
-      
-      assertContainsPair(id, bytes4, 1);  
-      
-      byte[] bytes5 = new byte[0];
-      
-      tx = env.createTransaction();
-      
-      //blank out 4 bytes
-      database.put(tx, id, bytes5, 5, 4);
-      
-      tx.commit();
-      
-      byte[] bytes6 = new byte[] { 1, 2, 3, 20, 21, 10, 20, 21, 22, 23 };
-      
-      assertContainsPair(id, bytes6, 1);  
-      
-      database.put(null, id, new byte[0], 0, 4);
-      
-      byte[] bytes7 = new byte[] { 21, 10, 20, 21, 22, 23 };
-      
-      assertContainsPair(id, bytes7, 1);  
-                  
-      database.remove(null, 1);
-      
-      assertStoreEmpty();
-   }
-   
-   public void testSetAndGetEnvironment() throws Exception   
-   {
-      try
-      {
-         env.setEnvironmentPath("blah");
-         
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //OK
-      }
-      
-      assertEquals(ENV_DIR, env.getEnvironmentPath());
-      
-      env.stop();
-      
-      final String path2 = HOME_DIR + "/test-path123651";
-      
-      env.setEnvironmentPath(path2);
-      
-      assertEquals(path2, env.getEnvironmentPath());
-      
-      env.start();
-   }
-   
-   
-   public void testSetAndGetTransacted() throws Exception   
-   {
-      env.stop();
-            
-      env.setTransacted(false);
-      
-      assertFalse(env.isTransacted());
-      
-      env.setTransacted(true);
-      
-      assertTrue(env.isTransacted());
-      
-      env.start();
-      
-      try
-      {
-         env.setTransacted(true);
-         
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //OK
-      }
-      
-      assertTrue(env.isTransacted());
-      
-      env.stop();
-      
-      env.setTransacted(false);
-      
-      assertFalse(env.isTransacted());  
-   }
-   
-   public void testSetAndGetSyncOS() throws Exception   
-   {
-      env.stop();
-      
-      assertFalse(env.isSyncOS());
-      
-      env.setSyncOS(true);
-      
-      assertTrue(env.isSyncOS());
-      
-      env.start();
-      
-      try
-      {
-         env.setSyncOS(true);
-         
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //OK
-      }
-      
-      assertTrue(env.isSyncOS());
-      
-      env.stop();
-      
-      env.setSyncOS(false);
-      
-      assertFalse(env.isSyncOS());  
-   }
-   
-   public void testSetAndGetSyncVM() throws Exception   
-   {
-      env.stop();
-      
-      assertFalse(env.isSyncVM());
-      
-      env.setSyncVM(true);
-      
-      assertTrue(env.isSyncVM());
-      
-      env.start();
-      
-      try
-      {
-         env.setSyncVM(true);
-         
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //OK
-      }
-      
-      assertTrue(env.isSyncVM());
-      
-      env.stop();
-      
-      env.setSyncVM(false);
-      
-      assertFalse(env.isSyncVM());  
-   }      
-   
-   public void testSetAndGetMemoryCacheSize() throws Exception   
-   {
-      env.stop();
-      
-      assertEquals(-1, env.getMemoryCacheSize());
-      
-      final long size = 16251762;
-      
-      env.setMemoryCacheSize(size);
-      
-      assertEquals(size, env.getMemoryCacheSize());
-      
-      env.start();
-      
-      try
-      {
-         env.setMemoryCacheSize(1897291289);
-         
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //OK
-      }
-      
-      assertEquals(size, env.getMemoryCacheSize());
-      
-      env.stop();
-      
-      final long size2 = 1625534783;
-      
-      env.setMemoryCacheSize(size2);
-      
-      assertEquals(size2, env.getMemoryCacheSize());
-   }
-   
-
-   public void testStartAndStop() throws Exception
-   {      
-      try
-      {
-         env.start();
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //OK
-      }
-      
-      env.stop();
-      
-      final String path = HOME_DIR + "/test-path123";
-      
-      createDir(path);
-      
-      env.setEnvironmentPath(path);      
-      
-      env.start();
-      
-      try
-      {
-         env.start();
-         
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //OK
-      }
-      
-      env.stop();
-      
-      try
-      {
-         env.stop();
-         
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //OK
-      }
-   }
-   
-   /*
-    * This test only makes sense for the RealBDBJEEnvironment, not the fake one
-    */
-   public void testCreateEnvironment() throws Exception
-   {      
-      if (isFake())
-      {
-         return;
-      }
-      
-      env.stop();
-      
-      env.setCreateEnvironment(false);
-      
-      String dir = HOME_DIR + "/blah678";
-      
-      deleteDirectory(new File(dir));
-      
-      env.setEnvironmentPath(dir);
-      
-      try
-      {
-         env.start();
-         fail("Should throw exception");
-      }
-      catch (IllegalArgumentException e)
-      {
-         //OK
-      }
-      
-      this.createDir(dir);
-      
-      try
-      {
-         env.start();         
-      }
-      catch (DatabaseException e)
-      {
-         //Ok - this will still fail since there is no actual BDB environment in the directory even though
-         //the directory exists
-      }
-      
-      env.setCreateEnvironment(true);
-      
-      env.start();
-     
-      env.stop();
-      
-      deleteDirectory(new File(dir));
-      
-      env.start();             
-   }
-   
-   public void testWrongOrderCommit() throws Exception
-   {
-      testXAWrongOrder(true);
-   }
-   
-   public void testWrongOrderRollback() throws Exception
-   {
-      testXAWrongOrder(false);
-   }
-   
-   public void testXAWrongXidCommit() throws Exception
-   {
-      testXAWrongXid(true);
-   }
-   
-   public void testXAWrongXidRollback() throws Exception
-   {
-      testXAWrongXid(false);
-   }
-   
-   private void testXAWrongXid(boolean commit) throws Exception
-   {
-      Xid xid = generateXid();
-      
-      env.startWork(xid);
-      
-      Xid xid2 = generateXid();
-      
-      try
-      {
-         env.endWork(xid2, false);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      //do some work
-      
-      database.put(null, 23, new byte[10], 0, 10);
-            
-      env.endWork(xid, false);
-      
-      try
-      {
-         env.prepare(xid2);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      env.prepare(xid);
-      
-      if (commit)
-      {
-         try
-         {
-            env.commit(xid2);
-            fail("Should throw exception");
-         }
-         catch (IllegalStateException e)
-         {
-            //Ok
-         }
-         env.commit(xid);
-      }
-      else
-      {
-         try
-         {
-            env.rollback(xid2);
-            fail("Should throw exception");
-         }
-         catch (IllegalStateException e)
-         {
-            //Ok
-         }
-         env.rollback(xid);
-      }
-   }
-   
-   private void testXAWrongOrder(boolean commit) throws Exception
-   {
-      Xid xid = generateXid();
-      
-      try
-      {
-         env.endWork(xid, false);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.prepare(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.commit(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.rollback(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      env.startWork(xid);
-      
-      //do some work
-      
-      database.put(null, 23, new byte[10], 0, 10);
-      
-      try
-      {
-         env.startWork(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.prepare(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.commit(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.rollback(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      env.endWork(xid, false);
-      
-      try
-      {
-         env.startWork(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.endWork(xid, false);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.commit(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.rollback(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      env.prepare(xid);
-      
-      try
-      {
-         env.startWork(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.endWork(xid, false);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      if (commit)
-      {
-         env.commit(xid);
-      }
-      else
-      {
-         env.rollback(xid);
-      }
-      
-      try
-      {
-         env.endWork(xid, false);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.prepare(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.commit(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      try
-      {
-         env.rollback(xid);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      env.startWork(xid);
-      
-      database.put(null, 23, new byte[10], 0, 10);
-      
-      env.endWork(xid, false);
-      
-      env.prepare(xid);
-      
-      env.rollback(xid);
-      
-   }
-     
-   // Private -------------------------------------------------------------------------------------
-   
-   private void assertContainsPair(long id, byte[] bytes, long size) throws Exception
-   {
-      byte[] b = database.get(id);
-      
-      assertNotNull(b);
-      
-      assertByteArraysEquivalent(bytes, b);
-      
-      assertEquals(size, database.size());
-   }
-   
-   private void assertStoreEmpty() throws Exception
-   {
-      assertEquals(0, database.size());
-   }               
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,1154 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * 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.core.impl.bdbje.test.unit;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.transaction.xa.Xid;
-
-import org.jboss.messaging.core.filter.impl.FilterImpl;
-import org.jboss.messaging.core.impl.bdbje.test.unit.fakes.FakeBDBJEEnvironment;
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEDatabase;
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEPersistenceManager;
-import org.jboss.messaging.core.server.Binding;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.impl.BindingImpl;
-import org.jboss.messaging.core.server.impl.MessageImpl;
-import org.jboss.messaging.core.server.impl.QueueFactoryImpl;
-import org.jboss.messaging.core.server.impl.QueueImpl;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- * 
- * A BDBJEPersistenceManagerTest
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class BDBJEPersistenceManagerTest extends UnitTestCase
-{
-   protected static final String ENV_DIR = "test-env";
-   
-   protected BDBJEPersistenceManager pm;
-      
-   protected BDBJEEnvironment bdb;
-   
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-      
-      bdb = new FakeBDBJEEnvironment();
-      
-      bdb.setEnvironmentPath(ENV_DIR);
-      
-      bdb.start();
-      
-      pm = new BDBJEPersistenceManager();
-      
-      pm.setEnvironment(bdb);
-      
-      pm.start();
-   }
-   
-   protected void tearDown() throws Exception
-   {
-      super.tearDown();
-      
-      pm.stop();
-   }
-   
-   private Queue createQueue(int i)
-   {
-      return new QueueImpl(i, "blah" + i, null, false, true, false, -1);
-   }
-   
-   // The tests ----------------------------------------------------------------
-              
-   public void testAddMessage() throws Exception
-   {      
-      Queue queue = createQueue(67);
-            
-      Message m = createMessageWithRefs(1, queue);
-      
-      pm.addMessage(m);
-      
-      assertMessageInStore(m, queue); 
-      
-      try
-      {
-         pm.addMessage(null);
-         
-         fail("Should throw exception");
-      }
-      catch (NullPointerException ok)
-      {
-         //ok
-      }
-   }
-   
-   public void testAddNonReliableMessage() throws Exception
-   {      
-      Queue queue = createQueue(67);
-            
-      Message m = createMessageWithRefs(1, queue);
-      
-      m.setDurable(false);
-      
-      pm.addMessage(m);
-      
-      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
-      
-      BDBJEDatabase refDB = bdb.getDatabase(BDBJEPersistenceManager.REFERENCE_DB_NAME);
-      
-      byte[] msgBytes = msgDB.get(m.getMessageID());
-      
-      assertNull(msgBytes);
-      
-      byte[] refBytes = refDB.get(m.getMessageID());
-      
-      assertNull(refBytes);      
-   }
-         
-   public void testDeleteReference() throws Exception
-   {            
-      Queue queue = createQueue(67);
-      
-      Message m = createMessageWithRefs(1, queue);
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>(m.getReferences());
-      
-      
-      pm.addMessage(m);
-      
-      assertMessageInStore(m, queue);
-      
-      
-      pm.deleteReference(refs.get(2));
-      
-      assertMessageInStore(m, queue);
-                      
-      assertEquals(3, m.getReferences().size());
-      
-      assertTrue(m.getReferences().contains(refs.get(0)));
-      assertTrue(m.getReferences().contains(refs.get(1)));
-      assertTrue(m.getReferences().contains(refs.get(3)));
-      
-      
-      pm.deleteReference(refs.get(1));
-      
-      assertMessageInStore(m, queue);
-      
-      assertEquals(2, m.getReferences().size());
-      
-      assertTrue(m.getReferences().contains(refs.get(0)));
-      assertTrue(m.getReferences().contains(refs.get(3)));
-      
-      
-                
-      pm.deleteReference(refs.get(3));
-      
-      assertMessageInStore(m, queue);
-      
-      assertEquals(1, m.getReferences().size());
-      
-      assertTrue(m.getReferences().contains(refs.get(0)));
-            
-      
-      pm.deleteReference(refs.get(0));
-            
-      assertMessageNotInStore(m);         
-      
-      assertStoreEmpty();
-      
-      try
-      {
-         pm.deleteReference(null);
-         
-         fail("Should throw exception");
-      }
-      catch (NullPointerException ok)
-      {
-         //ok
-      }
-   }
-   
-   public void testCommitTransaction() throws Exception
-   {      
-      List<Message> msgs = new ArrayList<Message>();
-          
-      Queue queue = createQueue(67);
-            
-      Message m1 = createMessageWithRefs(1, queue);
-      List<MessageReference> m1Refs = new ArrayList<MessageReference>(m1.getReferences());
-    
-      msgs.add(m1);
-      
-      Message m2 = createMessageWithRefs(2, queue);
-      
-      msgs.add(m2);
-      
-      Message m3 = createMessageWithRefs(3, queue);
-      List<MessageReference> m3Refs = new ArrayList<MessageReference>(m3.getReferences());
-      
-      msgs.add(m3);
-      
-      pm.commitTransaction(msgs, null);
-       
-      assertMessageInStore(m1, queue);
-      
-      assertMessageInStore(m2, queue);
-      
-      assertMessageInStore(m3, queue);
-      
-      
-      //Add a couple more
-      
-      List<Message> msgsMore = new ArrayList<Message>();
-            
-      Message m4 = createMessageWithRefs(4, queue);      
-      msgsMore.add(m4);
-      
-      Message m5 = createMessageWithRefs(5, queue);      
-      msgsMore.add(m5);
-      
-      //Delete some refs
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      refsToRemove.add(m1.getReferences().get(0));
-      refsToRemove.add(m1.getReferences().get(3));
-      
-      refsToRemove.add(m2.getReferences().get(0));
-      refsToRemove.add(m2.getReferences().get(1));
-      refsToRemove.add(m2.getReferences().get(2));
-      refsToRemove.add(m2.getReferences().get(3));
-      
-      refsToRemove.add(m3.getReferences().get(2));
-      
-      pm.commitTransaction(msgsMore, refsToRemove);
-      
-      assertMessageInStore(m1, queue);
-      assertEquals(2, m1.getReferences().size());
-      assertTrue(m1.getReferences().contains(m1Refs.get(1)));
-      assertTrue(m1.getReferences().contains(m1Refs.get(2)));
-      
-      assertMessageNotInStore(m2);
-      
-      assertMessageInStore(m3, queue);
-      assertEquals(3, m3.getReferences().size());
-      assertTrue(m3.getReferences().contains(m3Refs.get(0)));
-      assertTrue(m3.getReferences().contains(m3Refs.get(1)));
-      assertTrue(m3.getReferences().contains(m3Refs.get(3)));
-      
-      assertMessageInStore(m4, queue);
-      assertEquals(4, m4.getReferences().size());
-      
-      assertMessageInStore(m5, queue);
-      assertEquals(4, m5.getReferences().size());
-      
-      //Delete the rest
-      refsToRemove.clear();
-      refsToRemove.addAll(m1.getReferences());
-      refsToRemove.addAll(m3.getReferences());
-      refsToRemove.addAll(m4.getReferences());
-      refsToRemove.addAll(m5.getReferences());
-      
-      pm.commitTransaction(null, refsToRemove);
-      
-      assertMessageNotInStore(m1);
-      assertMessageNotInStore(m2);
-      assertMessageNotInStore(m4);
-      assertMessageNotInStore(m5);
-      assertMessageNotInStore(m5);
-      
-      //try with nulls
-      try
-      {
-         pm.commitTransaction(null, null);
-         
-         fail("Should throw exception");
-      }      
-      catch (IllegalArgumentException e)
-      {
-         //OK
-      }
-      
-   }     
-   
-   public void testCommitTransactionMixtureOfPersistentAndNonPersistent() throws Exception
-   {      
-      Message msg = generateMessage(1);
-      
-      Queue queue1 = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      assertTrue(queue1.isDurable());
-      
-      Queue queue2 = new QueueImpl(1, "queue1", null, false, false, false, -1);
-      assertFalse(queue2.isDurable());
-      
-      Queue queue3 = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      assertTrue(queue3.isDurable());
-      
-      Queue queue4 = new QueueImpl(1, "queue1", null, false, false, false, -1);
-      assertFalse(queue4.isDurable());
-     
-      MessageReference ref1 = msg.createReference(queue1);
-      
-      MessageReference ref2 = msg.createReference(queue2);
-      
-      MessageReference ref3 = msg.createReference(queue3);
-      
-      MessageReference ref4 = msg.createReference(queue4);
-      
-      List<Message> msgs = new ArrayList<Message>();
-      
-      msgs.add(msg);
-            
-      pm.commitTransaction(msgs, null);
-      
-      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
-      
-      BDBJEDatabase refDB = bdb.getDatabase(BDBJEPersistenceManager.REFERENCE_DB_NAME);
-      
-      byte[] msgBytes = msgDB.get(msg.getMessageID());
-      
-      assertNotNull(msgBytes);
-      
-      byte[] refBytes = refDB.get(msg.getMessageID());
-      
-      assertNotNull(refBytes);
-      
-      Map<Long, Queue> queues = new HashMap<Long, Queue>();
-      
-      queues.put(queue1.getPersistenceID(), queue1);
-      
-      queues.put(queue2.getPersistenceID(), queue2);
-      
-      queues.put(queue3.getPersistenceID(), queue3);
-      
-      queues.put(queue4.getPersistenceID(), queue4);
-      
-      Message msg2 = extractMessage(queues, msg.getMessageID(), msgBytes, refBytes);
-      
-      //Should only have two refs since only two of the queues were durable
-      
-      List<MessageReference> refs = msg2.getReferences();
-      
-      assertEquals(2, refs.size());
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      refsToRemove.add(ref1);
-      
-      refsToRemove.add(ref2);
-      
-      refsToRemove.add(ref3);
-      
-      refsToRemove.add(ref4);
-      
-      pm.commitTransaction(null, refsToRemove);
-      
-      msgBytes = msgDB.get(msg.getMessageID());
-      
-      assertNull(msgBytes);
-      
-      refBytes = refDB.get(msg.getMessageID());
-      
-      assertNull(refBytes);
-   }     
-   
-   
-   
-   public void testPrepareAndCommitTransaction() throws Exception
-   {      
-      List<Message> msgs = new ArrayList<Message>();
-          
-      Queue queue = createQueue(67);
-           
-      Message m1 = createMessageWithRefs(1, queue);
-      List<MessageReference> m1Refs = new ArrayList<MessageReference>(m1.getReferences());
-    
-      msgs.add(m1);
-      
-      Message m2 = createMessageWithRefs(2, queue);
-
-      msgs.add(m2);
-      
-      Message m3 = createMessageWithRefs(3, queue);
-      List<MessageReference> m3Refs = new ArrayList<MessageReference>(m3.getReferences());
-      
-      msgs.add(m3);
-      
-      pm.commitTransaction(msgs, null);
-       
-      assertMessageInStore(m1, queue);
-      
-      assertMessageInStore(m2, queue);
-      
-      assertMessageInStore(m3, queue);
-      
-      
-      //Add a couple more
-      
-      List<Message> msgsMore = new ArrayList<Message>();
-            
-      Message m4 = createMessageWithRefs(4, queue);
-      msgsMore.add(m4);
-      
-      Message m5 = createMessageWithRefs(5, queue);
-
-      msgsMore.add(m5);
-      
-      //Delete some refs
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      refsToRemove.add(m1.getReferences().get(0));
-      refsToRemove.add(m1.getReferences().get(3));
-      
-      refsToRemove.add(m2.getReferences().get(0));
-      refsToRemove.add(m2.getReferences().get(1));
-      refsToRemove.add(m2.getReferences().get(2));
-      refsToRemove.add(m2.getReferences().get(3));
-      
-      refsToRemove.add(m3.getReferences().get(2));
-      
-      Xid xid = generateXid();
-      
-      pm.prepareTransaction(xid, msgsMore, refsToRemove);
-      
-      pm.commitPreparedTransaction(xid);
-      
-      assertMessageInStore(m1, queue);
-      assertEquals(2, m1.getReferences().size());
-      assertTrue(m1.getReferences().contains(m1Refs.get(1)));
-      assertTrue(m1.getReferences().contains(m1Refs.get(2)));
-      
-      assertMessageNotInStore(m2);
-      
-      assertMessageInStore(m3, queue);
-      assertEquals(3, m3.getReferences().size());
-      assertTrue(m3.getReferences().contains(m3Refs.get(0)));
-      assertTrue(m3.getReferences().contains(m3Refs.get(1)));
-      assertTrue(m3.getReferences().contains(m3Refs.get(3)));
-      
-      assertMessageInStore(m4, queue);
-      assertEquals(4, m4.getReferences().size());
-      
-      assertMessageInStore(m5, queue);
-      assertEquals(4, m5.getReferences().size());
-      
-      //Delete the rest
-      refsToRemove.clear();
-      refsToRemove.addAll(m1.getReferences());
-      refsToRemove.addAll(m3.getReferences());
-      refsToRemove.addAll(m4.getReferences());
-      refsToRemove.addAll(m5.getReferences());
-      
-      xid = generateXid();
-      
-      pm.prepareTransaction(xid, null, refsToRemove);
-      
-      pm.commitPreparedTransaction(xid);
-      
-      assertMessageNotInStore(m1);
-      assertMessageNotInStore(m2);
-      assertMessageNotInStore(m4);
-      assertMessageNotInStore(m5);
-      assertMessageNotInStore(m5);
-      
-      //try with nulls
-      xid = generateXid();
-      try
-      {
-         pm.prepareTransaction(xid, null, null);
-         fail("Should throw exception");
-      }
-      catch (IllegalArgumentException e)
-      {
-         //Ok
-      }
-   }     
-      
-   public void testPrepareAndCommitTransactionWithNoPersistentMessages() throws Exception
-   {      
-      List<Message> msgs = new ArrayList<Message>();
-          
-      Queue queue = createQueue(67);
-           
-      Message m1 = createMessageWithRefs(1, queue);
-      m1.setDurable(false);
-      List<MessageReference> m1Refs = new ArrayList<MessageReference>(m1.getReferences());
-    
-      msgs.add(m1);
-      
-      Message m2 = createMessageWithRefs(2, queue);
-      m2.setDurable(false);
-
-      msgs.add(m2);
-      
-      Message m3 = createMessageWithRefs(3, queue);
-      m3.setDurable(false);
-      List<MessageReference> m3Refs = new ArrayList<MessageReference>(m3.getReferences());
-      
-      msgs.add(m3);
-      
-      //Delete some refs
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      refsToRemove.add(m1.getReferences().get(0));
-      refsToRemove.add(m1.getReferences().get(3));
-      
-      refsToRemove.add(m2.getReferences().get(0));
-      refsToRemove.add(m2.getReferences().get(1));
-      refsToRemove.add(m2.getReferences().get(2));
-      refsToRemove.add(m2.getReferences().get(3));
-      
-      refsToRemove.add(m3.getReferences().get(2));
-      
-      Xid xid = generateXid();
-      
-      try
-      {
-         //Nothing to be persisted in the tx - which is illegal
-         
-         pm.prepareTransaction(xid, msgs, refsToRemove);
-         
-         fail("Should throw exception");
-      }
-      catch (IllegalArgumentException e)
-      {
-         //Ok
-      }
-            
-      
-   }     
-   
-   public void testPrepareAndUnprepareTransaction() throws Exception
-   {      
-      List<Message> msgs = new ArrayList<Message>();
-          
-      Queue queue = createQueue(67);
-        
-      Message m1 = createMessageWithRefs(1, queue);
-
-      msgs.add(m1);
-      
-      Message m2 = createMessageWithRefs(2, queue);
-
-      msgs.add(m2);
-      
-      Message m3 = createMessageWithRefs(3, queue);
-
-      msgs.add(m3);
-      
-      pm.commitTransaction(msgs, null);
-       
-      assertMessageInStore(m1, queue);
-      
-      assertMessageInStore(m2, queue);
-      
-      assertMessageInStore(m3, queue);
-      
-      
-      //Add a couple more
-      
-      List<Message> msgsMore = new ArrayList<Message>();
-            
-      Message m4 = createMessageWithRefs(4, queue);
-      msgsMore.add(m4);
-      
-      Message m5 = createMessageWithRefs(5, queue);
-      msgsMore.add(m5);
-      
-      //Delete some refs
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      refsToRemove.add(m1.getReferences().get(0));
-      refsToRemove.add(m1.getReferences().get(3));
-      
-      refsToRemove.add(m2.getReferences().get(0));
-      refsToRemove.add(m2.getReferences().get(1));
-      refsToRemove.add(m2.getReferences().get(2));
-      refsToRemove.add(m2.getReferences().get(3));
-      
-      refsToRemove.add(m3.getReferences().get(2));
-      
-      Xid xid = generateXid();
-      
-      pm.prepareTransaction(xid, msgsMore, refsToRemove);
-      
-      pm.unprepareTransaction(xid, msgsMore, refsToRemove);
-                  
-      assertNumMessagesInStore(3);      
-   }     
-   
-   public void testUpdateDeliveryCount() throws Exception
-   {
-      Queue queue = createQueue(67);
-      
-      Message m1 = createMessageWithRefs(1, queue);
-      
-      assertEquals(0, m1.getReferences().get(0).getDeliveryCount());
-      assertEquals(0, m1.getReferences().get(1).getDeliveryCount());
-      assertEquals(0, m1.getReferences().get(2).getDeliveryCount());
-      assertEquals(0, m1.getReferences().get(3).getDeliveryCount());
-      
-      pm.addMessage(m1);
-      
-      final int delCount = 77;
-      m1.getReferences().get(1).setDeliveryCount(delCount);
-      pm.updateDeliveryCount(queue, m1.getReferences().get(1));
-      
-      final int delCount2 = 423;
-      
-      m1.getReferences().get(3).setDeliveryCount(delCount2);
-      pm.updateDeliveryCount(queue, m1.getReferences().get(3));
-      
-      assertMessageInStore(m1, queue);
-   }
-   
-   public void testRefsWithDifferentQueues() throws Exception
-   {
-      final int numQueues = 10;
-      
-      List<Message> msgs = new ArrayList<Message>();
-                  
-      for (int i = 0; i < numQueues; i++)
-      {
-         Queue queue = createQueue(i);
-         
-         MessageReference ref = generateReference(queue, i);
-         
-         msgs.add(ref.getMessage());
-         
-         pm.addMessage(ref.getMessage());   
-         
-         assertEquals(queue, ref.getQueue());
-      }
-      
-      for (Message msg: msgs)
-      {
-         assertMessageInStore(msg, msg.getReferences().get(0).getQueue());
-      }            
-   }
-       
-   public void testAddRemoveBindings() throws Exception
-   {
-      Queue queue1 = new QueueImpl(1, "queue1", new FilterImpl("a=1"), false, true, false, -1);
-      
-      Queue queue2 = new QueueImpl(2, "queue2", new FilterImpl("a=1"), false, true, false, -1);
-            
-      Queue queue3 = new QueueImpl(3, "queue3", new FilterImpl("a=1"), false, true, false, -1);
-      
-      Queue queue4 = new QueueImpl(4, "queue4", new FilterImpl("a=1"), false, true, false, -1);
-      
-      String condition1 = "queue.condition1";
-      
-      Binding binding1 = new BindingImpl(1, condition1, queue1);
-      
-      String condition2 = "queue.condition2";
-      
-      Binding binding2 = new BindingImpl(1, condition2, queue2);
-      
-      String condition3 = "queue.condition3";
-      
-      Binding binding3 = new BindingImpl(3, condition3, queue3);
-      
-      //same condition
-      String condition4 = "queue.condition3";
-      
-      Binding binding4 = new BindingImpl(3, condition4, queue4);
-      
-      
-      pm.addBinding(binding1);
-      
-      pm.addBinding(binding2);
-      
-      pm.addBinding(binding3);
-      
-      pm.addBinding(binding4);
-      
-      List<Binding> bindings = pm.loadBindings(new QueueFactoryImpl());
-      
-      assertEquals(4, bindings.size());
-      
-      assertEquivalent(bindings.get(0), binding1);
-      
-      assertEquivalent(bindings.get(1), binding2);
-      
-      assertEquivalent(bindings.get(2), binding3);
-      
-      assertEquivalent(bindings.get(3), binding4);
-      
-      assertEquals(0, bindings.get(0).getQueue().getMessageCount());
-      
-      assertEquals(0, bindings.get(0).getQueue().getPersistenceID());
-      
-      assertEquals(0, bindings.get(1).getQueue().getMessageCount());
-      
-      assertEquals(1, bindings.get(1).getQueue().getPersistenceID());
-      
-      assertEquals(0, bindings.get(2).getQueue().getMessageCount());
-      
-      assertEquals(2, bindings.get(2).getQueue().getPersistenceID());
-      
-      assertEquals(0, bindings.get(3).getQueue().getMessageCount());
-      
-      assertEquals(3, bindings.get(3).getQueue().getPersistenceID());
-      
-      
-      pm.deleteBinding(binding2);
-      
-      bindings = pm.loadBindings(new QueueFactoryImpl());
-      
-      assertEquals(3, bindings.size());
-      
-      assertEquivalent(bindings.get(0), binding1);
-      
-      assertEquivalent(bindings.get(1), binding3);
-      
-      assertEquivalent(bindings.get(2), binding4);
-      
-      
-      pm.deleteBinding(binding3);
-      
-      pm.deleteBinding(binding4);
-      
-      pm.deleteBinding(binding1);
-      
-      bindings = pm.loadBindings(new QueueFactoryImpl());
-      
-      assertEquals(0, bindings.size());                          
-   }  
-   
-   public void testLoadBindings() throws Exception
-   {
-      Queue queue1 = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      Queue queue2 = new QueueImpl(2, "queue2", null, false, true, false, -1);
-            
-      Queue queue3 = new QueueImpl(3, "queue3", null, false, true, false, -1);
-      
-      Queue queue4 = new QueueImpl(4, "queue4", null, false, true, false, -1);
-      
-      String condition1 = "queue.condition1";
-      
-      Binding binding1 = new BindingImpl(1, condition1, queue1);
-      
-      String condition2 = "queue.condition2";
-      
-      Binding binding2 = new BindingImpl(1, condition2, queue2);
-      
-      String condition3 = "queue.condition3";
-      
-      Binding binding3 = new BindingImpl(3, condition3, queue3);
-      
-      //same condition
-      String condition4 = "queue.condition3";
-      
-      Binding binding4 = new BindingImpl(3, condition4, queue4);
-                        
-      pm.addBinding(binding1);
-      
-      pm.addBinding(binding2);
-      
-      pm.addBinding(binding3);
-      
-      pm.addBinding(binding4);
-            
-      final int numMessages = 10;            
-               
-      List<Message> msgs = new ArrayList<Message>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         Message msg = this.generateMessage(i);
-         
-         msgs.add(msg);
-         
-         msg.createReference(queue1);
-         
-         msg.createReference(queue2);
-         
-         msg.createReference(queue3);
-         
-         msg.createReference(queue4);
-         
-         pm.addMessage(msg);   
-      }         
-      
-      List<Binding> bindings = pm.loadBindings(new QueueFactoryImpl());
-      
-      assertEquals(4, bindings.size());
-      
-      assertEquivalent(bindings.get(0), binding1);
-      
-      assertEquivalent(bindings.get(1), binding2);
-      
-      assertEquivalent(bindings.get(2), binding3);
-      
-      assertEquivalent(bindings.get(3), binding4);
-      
-      checkQueue(bindings.get(0).getQueue(), msgs);
-      
-      checkQueue(bindings.get(1).getQueue(), msgs);
-      
-      checkQueue(bindings.get(2).getQueue(), msgs);
-      
-      checkQueue(bindings.get(3).getQueue(), msgs);
-   }  
-   
-   
-   public void testGetInDoubtXids() throws Exception
-   {
-      Queue queue = createQueue(67);
-      
-      Message message1 = createMessageWithRefs(1, queue);
-      
-      List<Message> msgs = new ArrayList<Message>();
-      
-      msgs.add(message1);
-      
-      Xid xid1 = generateXid();
-      
-      pm.prepareTransaction(xid1, msgs, null);    
-      
-      pm.setInRecoveryMode(true);
-      
-      List<Xid> xids = pm.getInDoubtXids();
-      
-      assertNotNull(xids);
-      
-      assertEquals(1, xids.size());
-      
-      assertEquals(xid1, xids.get(0));
-      
-      
-      
-      Message message2 = createMessageWithRefs(2, queue);
-      
-      msgs.clear();
-      
-      msgs.add(message2);
-      
-      Xid xid2 = generateXid();
-      
-      pm.prepareTransaction(xid2, msgs, null);    
-      
-      xids = pm.getInDoubtXids();
-      
-      assertNotNull(xids);
-      
-      assertEquals(2, xids.size());
-      
-      assertTrue(xids.contains(xid1));
-      
-      assertTrue(xids.contains(xid2));
-      
-      
-      pm.commitPreparedTransaction(xid1);
-      
-      pm.commitPreparedTransaction(xid2);
-      
-      xids = pm.getInDoubtXids();
-      
-      assertNotNull(xids);
-      
-      assertEquals(0, xids.size());            
-   }
-   
-   public void testGetInDoubtXidsWithRestart() throws Exception
-   {
-      Queue queue = createQueue(67);
-      
-      Message message1 = createMessageWithRefs(1, queue);
-      
-      List<Message> msgs = new ArrayList<Message>();
-      
-      msgs.add(message1);
-      
-      Xid xid1 = generateXid();
-      
-      pm.prepareTransaction(xid1, msgs, null);   
-      
-      pm.setInRecoveryMode(true);
-      
-      List<Xid> xids = pm.getInDoubtXids();
-      
-      assertNotNull(xids);
-      
-      assertEquals(1, xids.size());
-      
-      assertEquals(xid1, xids.get(0));
-      
-      
-      
-      Message message2 = createMessageWithRefs(2, queue);
-      
-      msgs.clear();
-      
-      msgs.add(message2);
-      
-      Xid xid2 = generateXid();
-      
-      pm.prepareTransaction(xid2, msgs, null);    
-      
-      xids = pm.getInDoubtXids();
-      
-      assertNotNull(xids);
-      
-      assertEquals(2, xids.size());
-      
-      assertTrue(xids.contains(xid1));
-      
-      assertTrue(xids.contains(xid2));
-      
-      pm.getEnvironment().stop();
-            
-      pm.stop();
-      
-      pm.getEnvironment().start();
-      
-      pm.start();
-      
-      pm.setInRecoveryMode(true);
-      
-      xids = pm.getInDoubtXids();
-      
-      assertNotNull(xids);
-      
-      assertEquals(2, xids.size());
-      
-      assertTrue(xids.contains(xid1));
-      
-      assertTrue(xids.contains(xid2));
-      
-      
-      pm.commitPreparedTransaction(xid1);
-      
-      pm.commitPreparedTransaction(xid2);
-      
-      xids = pm.getInDoubtXids();
-      
-      assertNotNull(xids);
-      
-      assertEquals(0, xids.size());            
-   }
-   
-   public void testSetGetRecoveryMode() throws Exception
-   {
-      assertFalse(pm.isInRecoveryMode());
-                 
-      try
-      {
-         pm.getInDoubtXids();
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-      
-      pm.setInRecoveryMode(true);
-      
-      assertTrue(pm.isInRecoveryMode());
-      
-      pm.getInDoubtXids();
-      
-      pm.setInRecoveryMode(false);
-      
-      assertFalse(pm.isInRecoveryMode());
-   }
-   
-   // Private --------------------------------------------------------------------
-   
-   private void checkQueue(Queue queue, List<Message> messages)
-   {
-      assertEquals(messages.size(), queue.getMessageCount());
-      
-      List<MessageReference> refs = queue.list(null);
-      
-      int i = 0;
-      for (MessageReference ref: refs)
-      {
-         assertEquivalent(messages.get(i++), ref.getMessage(), false);
-      } 
-   }
-   
-   private void assertEquivalent(Binding b1, Binding b2)
-   {
-      assertEquals(b1.getNodeID(), b2.getNodeID());
-      
-      assertEquals(b1.getAddress(), b2.getAddress());
-      
-      Queue queue1 = b1.getQueue();
-      
-      Queue queue2 = b2.getQueue();
-      
-      assertEquals(queue1.getPersistenceID(), queue2.getPersistenceID());
-      
-      assertEquals(queue1.getName(), queue2.getName());
-      
-      assertEquals(queue1.isClustered(), queue2.isClustered());
-      
-      assertEquals(queue1.isDurable(), queue2.isDurable());
-      
-      assertEquals(queue1.isTemporary(), queue2.isTemporary());
-   }
-   
-   private Message extractMessage(Map<Long, Queue> queues, long id, byte[] msgBytes, byte[] refBytes) throws Exception
-   {
-      ByteBuffer buffer = ByteBuffer.wrap(msgBytes);
-      
-      int type = buffer.getInt();
-      
-      long expiration = buffer.getLong();
-      
-      long timestamp = buffer.getLong();
-      
-      byte priority = buffer.get();
-      
-      int headerSize = buffer.getInt();
-      
-      byte[] headers = new byte[headerSize];
-      
-      buffer.get(headers);
-      
-      int payloadSize = buffer.getInt();
-      
-      byte[] payload = null;
-      
-      if (payloadSize != 0)
-      {
-         payload = new byte[payloadSize];
-         
-         buffer.get(payload);
-      }
-      
-      Message message = new MessageImpl(id, type, true, expiration, timestamp, priority,
-                                        headers, payload);
-      
-      buffer = ByteBuffer.wrap(refBytes);
-      
-      while (buffer.hasRemaining())
-      {
-         long queueID = buffer.getLong();
-         
-         int deliveryCount = buffer.getInt();
-         
-         long scheduledDeliveryTime = buffer.getLong();
-         
-         MessageReference reference = message.createReference(queues.get(queueID));
-         
-         reference.setDeliveryCount(deliveryCount);
-         
-         reference.setScheduledDeliveryTime(scheduledDeliveryTime);
-      } 
-      
-      return message;
-   }
-   
-   private void assertMessageInStore(Message m, Queue queue) throws Exception
-   {
-      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
-      
-      BDBJEDatabase refDB = bdb.getDatabase(BDBJEPersistenceManager.REFERENCE_DB_NAME);
-      
-      byte[] msgBytes = msgDB.get(m.getMessageID());
-      
-      assertNotNull(msgBytes);
-      
-      byte[] refBytes = refDB.get(m.getMessageID());
-      
-      assertNotNull(refBytes);
-      
-      Map<Long, Queue> queues = new HashMap<Long, Queue>();
-      
-      queues.put(queue.getPersistenceID(), queue);
-      
-      Message m2 = extractMessage(queues, m.getMessageID(), msgBytes, refBytes);
-       
-      assertEquivalent(m, m2);               
-   }
-   
-   private void assertNumMessagesInStore(int num) throws Exception
-   {
-      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
-      
-      assertEquals(num, msgDB.size());                    
-   }
-   
-   private void assertMessageNotInStore(Message m) throws Exception
-   {
-      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
-      
-      BDBJEDatabase refDB = bdb.getDatabase(BDBJEPersistenceManager.REFERENCE_DB_NAME);
-      
-      
-      byte[] msgBytes = msgDB.get(m.getMessageID());
-      
-      assertNull(msgBytes);
-      
-      byte[] refBytes = refDB.get(m.getMessageID());
-      
-      assertNull(refBytes);         
-   }
-   
-   private void assertStoreEmpty() throws Exception
-   {
-      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
-      
-      BDBJEDatabase refDB = bdb.getDatabase(BDBJEPersistenceManager.REFERENCE_DB_NAME);
-      
-      assertEquals(0, msgDB.size());
-      
-      assertEquals(0, refDB.size());
-   }
-   
-   private Message createMessageWithRefs(long id, Queue queue)
-   {
-      Message m = generateMessage(id);
-      
-      m.createReference(queue);
-      
-      m.createReference(queue);
-      
-      m.createReference(queue);
-      
-      m.createReference(queue);
-      
-      return m;
-   }
-   
-
-   // Inner classes ---------------------------------------------------------------
-        
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/FakeBDBJEEnvironmentTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/FakeBDBJEEnvironmentTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/FakeBDBJEEnvironmentTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,38 +0,0 @@
-package org.jboss.messaging.core.impl.bdbje.test.unit;
-
-import org.jboss.messaging.core.impl.bdbje.test.unit.fakes.FakeBDBJEEnvironment;
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
-
-/**
- * 
- * A FakeBDBJEEnvironmentTest
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class FakeBDBJEEnvironmentTest extends BDBJEEnvironmentTestBase
-{
-   protected BDBJEEnvironment createEnvironment() throws Exception
-   {
-      BDBJEEnvironment env = new FakeBDBJEEnvironment();
-      
-      return env;
-   }   
-   
-   protected void createDir(String path)
-   {      
-   }
-   
-   protected void copyEnvironment()
-   {      
-   }
-   
-   protected void copyBackEnvironment()
-   {      
-   }    
-   
-   protected boolean isFake()
-   {
-      return true;
-   }
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/fakes/FakeBDBJEEnvironment.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/fakes/FakeBDBJEEnvironment.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/fakes/FakeBDBJEEnvironment.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,550 +0,0 @@
-package org.jboss.messaging.core.impl.bdbje.test.unit.fakes;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.transaction.xa.Xid;
-
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJECursor;
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEDatabase;
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
-import org.jboss.messaging.core.persistence.impl.bdbje.BDBJETransaction;
-import org.jboss.messaging.util.Pair;
-
-/**
- * 
- * A FakeBDBJEEnvironment
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class FakeBDBJEEnvironment implements BDBJEEnvironment
-{
-   private String environmentPath;
-   
-   private Map<String, FakeBDBJETransaction> transactions = new HashMap<String, FakeBDBJETransaction>();
-   
-   private boolean transacted;
-   
-   private boolean syncOS;
-   
-   private boolean syncVM;     
-
-   private long memoryCacheSize = -1;
-   
-   private boolean started;
-         
-   private Map<Thread, FakeBDBJETransaction> implicitTXs = new ConcurrentHashMap<Thread, FakeBDBJETransaction>();
-   
-   private Map<String, BDBJEDatabase> databases = new HashMap<String, BDBJEDatabase>();
-                     
-   public boolean isSyncOS()
-   {
-      return syncOS;
-   }
-
-   public void setSyncOS(boolean sync)
-   {
-      if (started)
-      {
-         throw new IllegalStateException("Cannot set SyncOS when started");
-      }
-      syncOS = sync;
-   }
-
-   public boolean isSyncVM()
-   {
-      return syncVM;
-   }
-   
-   public void setSyncVM(boolean sync)
-   {
-      if (started)
-      {
-         throw new IllegalStateException("Cannot set SyncVM when started");
-      }
-      syncVM = sync;
-   }
-
-   public boolean isTransacted()
-   {
-      return transacted;
-   }
-   
-   public void setTransacted(boolean transacted)
-   {
-      if (started)
-      {
-         throw new IllegalStateException("Cannot set transacted when started");
-      }
-      this.transacted = transacted;
-   }
-
-   public long getMemoryCacheSize()
-   {
-      return memoryCacheSize;
-   }  
-
-   public void setMemoryCacheSize(long size)
-   {
-      if (started)
-      {
-         throw new IllegalStateException("Cannot set memory cache size when started");
-      }
-      this.memoryCacheSize = size;
-   }
-   
-   public void setEnvironmentPath(String environmentPath)
-   {
-      if (started)
-      {
-         throw new IllegalStateException("Cannot set environmentPath when started");
-      }
-      this.environmentPath = environmentPath;
-   }
-   
-   private boolean createEnvironment;
-   
-   public boolean isCreateEnvironment()
-   {
-      return createEnvironment;
-   }
-
-   public void setCreateEnvironment(boolean create)
-   {
-      this.createEnvironment = create;
-   }
-   
-   public String getEnvironmentPath()
-   {
-      return environmentPath;
-   }
-   
-   public void start() throws Exception
-   {
-      if (environmentPath == null)
-      {
-         throw new IllegalStateException("Must set environmentPath before starting");
-      }
-      if (started)
-      {
-         throw new IllegalStateException("Already started");
-      }
-      started = true;
-   }
-
-   public void stop() throws Exception
-   {
-      if (!started)
-      {
-         throw new IllegalStateException("Not started");
-      }
-      started = false;
-   }
-   
-   public boolean isStarted()
-   {
-      return started;
-   }
-   
-   public BDBJETransaction createTransaction() throws Exception
-   {
-      return createTransactionInternal(null);
-   }
-   
-   public synchronized BDBJEDatabase getDatabase(String databaseName) throws Exception
-   {
-      BDBJEDatabase database = databases.get(databaseName);
-      
-      if (database == null)
-      {
-         database = new FakeBDBJEDatabase();
-         
-         databases.put(databaseName, database);
-      }
-      
-      return database;
-   }
-
-   public List<Xid> getInDoubtXids() throws Exception
-   {
-      List<Xid> xids = new ArrayList<Xid>();
-      
-      for (FakeBDBJETransaction tx: transactions.values())
-      {
-         if (tx.isPrepared())
-         {
-            xids.add(tx.getXid());
-         }
-      }
-      
-      return xids;
-   }
-   
-   public void startWork(Xid xid) throws Exception
-   {
-      checkStartWork(xid);
-      
-      implicitTXs.put(Thread.currentThread(), createTransactionInternal(xid));            
-   }
-   
-   public void endWork(Xid xid, boolean fail) throws Exception
-   {
-      checkEndWork(xid);
-      
-      implicitTXs.remove(Thread.currentThread());
-   }
-   
-   public void prepare(Xid xid) throws Exception
-   {
-      FakeBDBJETransaction tx = findTXForXid(xid);
-      
-      checkPrepare(tx);
-      
-      tx.prepare();
-   }
-   
-   public void commit(Xid xid) throws Exception
-   {      
-      FakeBDBJETransaction tx = findTXForXid(xid);
-      
-      checkCommitRollback(tx);
-            
-      tx.commit();
-   }
-
-   public void rollback(Xid xid) throws Exception
-   {
-      FakeBDBJETransaction tx = findTXForXid(xid);
-      
-      checkCommitRollback(tx);
-                  
-      tx.rollback();   
-   }
-         
-   // Private -----------------------------------------------------------------------
-   
-   private FakeBDBJETransaction createTransactionInternal(Xid xid) throws Exception
-   {
-      FakeBDBJETransaction tx = new FakeBDBJETransaction(xid);
-      
-      transactions.put(tx.id, tx);
-      
-      return tx;
-   }      
-   
-   private FakeBDBJETransaction findTXForXid(Xid xid)
-   {
-      for (FakeBDBJETransaction tx: transactions.values())
-      {
-         if (xid.equals(tx.xid))
-         {
-            return tx;
-         }
-      }
-      return null;
-   }
-   
-   private void checkStartWork(Xid xid)
-   {
-      if (implicitTXs.get(Thread.currentThread()) != null)
-      {
-         throw new IllegalStateException("Already implicit transaction");
-      }
-      
-      if (findTXForXid(xid) != null)
-      {
-         throw new IllegalStateException("Already tx for xid");
-      }            
-   }
-   
-   private void checkEndWork(Xid xid)
-   {
-      FakeBDBJETransaction tx = implicitTXs.get(Thread.currentThread());
-      
-      if (tx == null)
-      {
-         throw new IllegalStateException("No implicit tx");
-      }            
-      
-      if (!tx.xid.equals(xid))
-      {
-         throw new IllegalStateException("Wrong xid");
-      }
-   }
-
-   
-   private void checkPrepare(FakeBDBJETransaction tx)
-   {
-      if (tx == null)
-      {
-         throw new IllegalStateException("Cannot find tx for xid");
-      }
-      
-      if (implicitTXs.containsKey(Thread.currentThread()))
-      {
-         throw new IllegalStateException("Work not ended");
-      }
-   }
-   
-   
-   private void checkCommitRollback(FakeBDBJETransaction tx)
-   {
-      if (tx == null)
-      {
-         throw new IllegalStateException("Cannot find tx for xid");
-      }
-      
-      if (!tx.prepared)
-      {
-         throw new IllegalStateException("Tx not prepared");
-      }
-      
-      if (implicitTXs.containsKey(Thread.currentThread()))
-      {
-         throw new IllegalStateException("Work not ended");
-      }
-   }
-   
-   
-   // Inner classes ------------------------------------------------------------------
-   
-   private class FakeBDBJETransaction implements BDBJETransaction
-   {
-      private String id = java.util.UUID.randomUUID().toString();
-      
-      private Xid xid;
-      
-      private List<Action> actions = new ArrayList<Action>();
-      
-      private boolean prepared;
-      
-      FakeBDBJETransaction(Xid xid)
-      {
-         this.xid = xid;
-      }
-      
-      public void commit() throws Exception
-      {
-         for (Action action : actions)
-         {
-            if (action.put)
-            {
-               action.database.put(null, action.id, action.bytes, action.offset, action.length);
-            }
-            else
-            {
-               action.database.remove(null, action.id);
-            }
-         }
-         
-         actions.clear();
-         
-         transactions.remove(id);
-      }
-
-      public void prepare() throws Exception
-      {                
-         prepared = true;
-      }
-
-      public void rollback() throws Exception
-      {
-         actions.clear(); 
-         
-         transactions.remove(id);
-      }
-      
-      public boolean isPrepared()
-      {
-         return prepared;
-      }
-      
-      public Xid getXid()
-      {
-         return xid;
-      }
-            
-   }
-   
-   private class Action
-   {
-      public BDBJEDatabase database;
-      
-      public boolean put;
-      
-      public long id;
-      
-      public byte[] bytes;
-      
-      public int offset;
-      
-      public int length;
-      
-      public Action(BDBJEDatabase database, boolean put, long id, byte[] bytes, int offset, int length)
-      {
-         this.database = database;
-         
-         this.put = put;
-         
-         this.id = id;
-         
-         this.bytes = bytes;
-         
-         this.offset = offset;
-         
-         this.length = length;
-      }
-   }
-   
-   private class FakeBDBJEDatabase implements BDBJEDatabase
-   {     
-      private Map<Long, byte[]> store = new LinkedHashMap<Long, byte[]>();
-      
-      private AtomicInteger cursorCount = new AtomicInteger(0);
-      
-      public void close() throws Exception
-      {
-         if (cursorCount.get() != 0)
-         {
-            throw new IllegalStateException("Cannot close. There are cursors open");
-         }
-      }
-
-      public BDBJECursor cursor() throws Exception
-      {
-         return new FakeBDBJECursor();
-      }
-
-      private BDBJETransaction getTx(BDBJETransaction tx)
-      {
-         if (tx == null)
-         {            
-            tx = implicitTXs.get(Thread.currentThread());
-         }
-         return tx;
-      }
-      
-      public void put(BDBJETransaction tx, long id, byte[] bytes, int offset,
-            int length) throws Exception
-      {
-         tx = getTx(tx);
-         
-         if (tx == null)
-         {
-            if (offset == 0 && bytes.length == length)
-            {               
-               store.put(id, bytes);
-            }
-            else
-            {
-               byte[] currentBytes = store.get(id);
-               
-               if (offset == currentBytes.length)
-               {
-                  byte[] newBytes = new byte[currentBytes.length + bytes.length];
-                  
-                  ByteBuffer buffer = ByteBuffer.wrap(newBytes);
-                  
-                  buffer.put(currentBytes);
-                  
-                  buffer.put(bytes);
-                  
-                  store.put(id, newBytes);
-               }
-               else if (offset < currentBytes.length)
-               {                 
-                  if (offset + length > currentBytes.length)
-                  {
-                     throw new IllegalStateException("Invalid offset/length");
-                  }
-                  
-                  byte[] newBytes = new byte[currentBytes.length - (length - bytes.length)];
-                  
-                  System.arraycopy(currentBytes, 0, newBytes, 0, offset);
-                  
-                  System.arraycopy(bytes, 0, newBytes, offset, bytes.length);
-                                 
-                  System.arraycopy(currentBytes, offset + length, newBytes,
-                                   offset + bytes.length, currentBytes.length - (offset + length));
-                  
-                  store.put(id, newBytes);
-               }
-               else
-               {
-                  throw new IllegalStateException("Invalid offset " + offset);
-               }
-            }            
-         }
-         else
-         {
-            FakeBDBJETransaction ftx = (FakeBDBJETransaction)tx;
-            
-            ftx.actions.add(new Action(this, true, id, bytes, offset, length));
-         }
-         
-      }
-
-      public void remove(BDBJETransaction tx, long id) throws Exception
-      {
-         tx = getTx(tx);
-         
-         if (tx == null)
-         {
-            store.remove(id);
-         }
-         else
-         {
-            FakeBDBJETransaction ftx = (FakeBDBJETransaction)tx;
-            
-            ftx.actions.add(new Action(this, false, id, null, -1, -1));
-         }
-      }
-      
-      public byte[] get(long id) throws Exception
-      {
-         return store.get(id);
-      }
-
-      public long size() throws Exception
-      {
-         return store.size();
-      }
-      
-      private class FakeBDBJECursor implements BDBJECursor
-      {
-         private Iterator<Map.Entry<Long,byte[]>> iterator = store.entrySet().iterator();
-         
-         FakeBDBJECursor()
-         {
-            cursorCount.incrementAndGet();
-         }
-
-         public void close() throws Exception
-         {         
-            cursorCount.decrementAndGet();
-         }
-
-         public Pair<Long, byte[]> getNext() throws Exception
-         {
-            if (iterator.hasNext())
-            {
-               Map.Entry<Long,byte[]> entry = iterator.next();
-               
-               return new Pair<Long, byte[]>(entry.getKey(), entry.getValue());
-            }
-            else
-            {
-               return null;
-            }
-         }      
-      }
-   }
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/filter/test/unit/FilterParserTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/filter/test/unit/FilterParserTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/filter/test/unit/FilterParserTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,332 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * 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.core.impl.filter.test.unit;
-
-import java.io.ByteArrayInputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.messaging.core.filter.impl.Identifier;
-import org.jboss.messaging.core.filter.impl.Operator;
-import org.jboss.messaging.core.filter.impl.FilterParser;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- Tests of the JavaCC LL(1) parser for the JBoss Messaging filters
- 
- @author Scott.Stark at jboss.org
- @author d_jencks at users.sourceforge.net
- @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- 
- @version $Revision: 3465 $
- 
- * (david jencks)  Used constructor of SelectorParser taking a stream
- * to avoid reInit npe in all tests.  Changed to JBossTestCase and logging.
- */
-public class FilterParserTest extends UnitTestCase
-{
-   private static final Logger log = Logger.getLogger(FilterParserTest.class);
-   
-   private Map<String, Identifier> identifierMap;
-   
-   private FilterParser parser;
-    
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-      
-      identifierMap = new HashMap<String, Identifier>();
-      
-      parser = new FilterParser(new ByteArrayInputStream(new byte[0]));      
-   }
- 
-   public void testSimpleUnary() throws Exception
-   {
-      // Neg Long
-      log.trace("parse(-12345 = -1 * 12345)");
-      Operator result = (Operator) parser.parse("-12345 = -1 * 12345", identifierMap);
-      log.trace("result -> "+result);
-      Boolean b = (Boolean) result.apply();
-      assertTrue("is true", b.booleanValue());
-
-      // Neg Double
-      log.trace("parse(-1 * 12345.67 = -12345.67)");
-      result = (Operator) parser.parse("-1 * 12345.67 = -12345.67", identifierMap);
-      log.trace("result -> "+result);
-      b = (Boolean) result.apply();
-      assertTrue("is true", b.booleanValue());
-
-      log.trace("parse(-(1 * 12345.67) = -12345.67)");
-      result = (Operator) parser.parse("-(1 * 12345.67) = -12345.67", identifierMap);
-      log.trace("result -> "+result);
-      b = (Boolean) result.apply();
-      assertTrue("is true", b.booleanValue());
-   }
-   
-   public void testPrecedenceNAssoc() throws Exception
-   {
-      log.trace("parse(4 + 2 * 3 / 2 = 7)");
-      Operator result = (Operator) parser.parse("4 + 2 * 3 / 2 = 7", identifierMap);
-      log.trace("result -> "+result);
-      Boolean b = (Boolean) result.apply();
-      assertTrue("is true", b.booleanValue());
-      
-      log.trace("parse(4 + ((2 * 3) / 2) = 7)");
-      result = (Operator) parser.parse("4 + ((2 * 3) / 2) = 7", identifierMap);
-      log.trace("result -> "+result);
-      b = (Boolean) result.apply();
-      assertTrue("is true", b.booleanValue());
-      
-      log.trace("parse(4 * -2 / -1 - 4 = 4)");
-      result = (Operator) parser.parse("4 * -2 / -1 - 4 = 4", identifierMap);
-      log.trace("result -> "+result);
-      b = (Boolean) result.apply();
-      assertTrue("is true", b.booleanValue());
-      
-      log.trace("parse(4 * ((-2 / -1) - 4) = -8)");
-      result = (Operator) parser.parse("4 * ((-2 / -1) - 4) = -8", identifierMap);
-      log.trace("result -> "+result);
-      b = (Boolean) result.apply();
-      assertTrue("is true", b.booleanValue());
-   }
-   
-   public void testIds() throws Exception
-   {
-      log.trace("parse(a + b * c / d = e)");
-      Operator result = (Operator) parser.parse("a + b * c / d = e", identifierMap);
-      // 4 + 2 * 3 / 2 = 7
-      Identifier a = identifierMap.get("a");
-      a.setValue(new Long(4));
-      Identifier b = identifierMap.get("b");
-      b.setValue(new Long(2));
-      Identifier c = identifierMap.get("c");
-      c.setValue(new Long(3));
-      Identifier d = identifierMap.get("d");
-      d.setValue(new Long(2));
-      Identifier e = identifierMap.get("e");
-      e.setValue(new Long(7));
-      log.trace("result -> "+result);
-      Boolean bool = (Boolean) result.apply();
-      assertTrue("is true", bool.booleanValue());
-      
-   }
-   
-   public void testTrueINOperator() throws Exception
-   {
-      log.trace("parse(Status IN ('new', 'cleared', 'acknowledged'))");
-      Operator result = (Operator) parser.parse("Status IN ('new', 'cleared', 'acknowledged')", identifierMap);
-      Identifier a = identifierMap.get("Status");
-      a.setValue("new");
-      log.trace("result -> "+result);
-      Boolean bool = (Boolean) result.apply();
-      assertTrue("is true", bool.booleanValue());
-   }
-   public void testFalseINOperator() throws Exception
-   {
-      log.trace("parse(Status IN ('new', 'cleared', 'acknowledged'))");
-      Operator result = (Operator) parser.parse("Status IN ('new', 'cleared', 'acknowledged')", identifierMap);
-      Identifier a = identifierMap.get("Status");
-      a.setValue("none");
-      log.trace("result -> "+result);
-      Boolean bool = (Boolean) result.apply();
-      assertTrue("is false", !bool.booleanValue());
-   }
-   
-   public void testTrueOROperator() throws Exception
-   {
-      log.trace("parse((Status = 'new') OR (Status = 'cleared') OR (Status = 'acknowledged'))");
-      Operator result = (Operator) parser.parse("(Status = 'new') OR (Status = 'cleared') OR (Status= 'acknowledged')", identifierMap);
-      Identifier a = identifierMap.get("Status");
-      a.setValue("new");
-      log.trace("result -> "+result);
-      Boolean bool = (Boolean) result.apply();
-      assertTrue("is true", bool.booleanValue());
-   }
-   public void testFalseOROperator() throws Exception
-   {
-      log.trace("parse((Status = 'new') OR (Status = 'cleared') OR (Status = 'acknowledged'))");
-      Operator result = (Operator) parser.parse("(Status = 'new') OR (Status = 'cleared') OR (Status = 'acknowledged')", identifierMap);
-      Identifier a = identifierMap.get("Status");
-      a.setValue("none");
-      log.trace("result -> "+result);
-      Boolean bool = (Boolean) result.apply();
-      assertTrue("is false", !bool.booleanValue());
-   }
-   
-   public void testInvalidSelector() throws Exception
-   {
-      log.trace("parse(definitely not a message selector!)");
-      try
-      {
-         Object result = parser.parse("definitely not a message selector!", identifierMap);
-         log.trace("result -> "+result);
-         fail("Should throw an Exception.\n");
-      }
-      catch (Exception e)
-      {
-         log.trace("testInvalidSelector failed as expected", e);
-      }
-   }
- 
-   /**
-    * Test diffent syntax for approximate numeric literal (+6.2, -95.7, 7.)
-    */
-   public void testApproximateNumericLiteral1()
-   {
-      try
-      {
-         log.trace("parse(average = +6.2)");
-         Object result = parser.parse("average = +6.2", identifierMap);
-         log.trace("result -> "+result);
-      } catch (Exception e)
-      {
-         fail(""+e);
-      }
-   }
-   
-   public void testApproximateNumericLiteral2()
-   {
-      try
-      {
-         log.trace("parse(average = -95.7)");
-         Object result = parser.parse("average = -95.7", identifierMap);
-         log.trace("result -> "+result);
-      } catch (Exception e)
-      {
-         fail(""+e);
-      }
-   }
-   public void testApproximateNumericLiteral3()
-   {
-      try
-      {
-         log.trace("parse(average = 7.)");
-         Object result = parser.parse("average = 7.", identifierMap);
-         log.trace("result -> "+result);
-      } catch (Exception e)
-      {
-         fail(""+e);
-      }
-   }
-   
-   public void testGTExact()
-   {
-      try
-      {
-         log.trace("parse(weight > 2500)");
-         Operator result = (Operator)parser.parse("weight > 2500", identifierMap);
-         (identifierMap.get("weight")).setValue(new Integer(3000));
-         log.trace("result -> "+result);
-         Boolean bool = (Boolean) result.apply();
-         assertTrue("is true", bool.booleanValue());
-      } catch (Exception e)
-      {
-         log.trace("failed", e);
-         fail(""+e);
-      }
-   }
-
-   public void testGTFloat()
-   {
-      try
-      {
-         log.trace("parse(weight > 2500)");
-         Operator result = (Operator)parser.parse("weight > 2500", identifierMap);
-         (identifierMap.get("weight")).setValue(new Float(3000));
-         log.trace("result -> "+result);
-         Boolean bool = (Boolean) result.apply();
-         assertTrue("is true", bool.booleanValue());
-      } catch (Exception e)
-      {
-         log.trace("failed", e);
-         fail(""+e);
-      }
-   }
-
-   public void testLTDouble()
-   {
-      try
-      {
-         log.trace("parse(weight < 1.5)");
-         Operator result = (Operator)parser.parse("weight < 1.5", identifierMap);
-         (identifierMap.get("weight")).setValue(new Double(1.2));
-         log.trace("result -> "+result);
-         Boolean bool = (Boolean) result.apply();
-         assertTrue("is true", bool.booleanValue());
-      } catch (Exception e)
-      {
-         log.trace("failed", e);
-         fail(""+e);
-      }
-   }
-
-   public void testAndCombination()
-   {
-      try
-      {
-         log.trace("parse(JMSType = 'car' AND color = 'blue' AND weight > 2500)");
-         Operator result = (Operator)parser.parse("JMSType = 'car' AND color = 'blue' AND weight > 2500", identifierMap);
-         (identifierMap.get("JMSType")).setValue("car");
-         (identifierMap.get("color")).setValue("blue");
-         (identifierMap.get("weight")).setValue("3000");
-         
-         log.trace("result -> "+result);
-         Boolean bool = (Boolean) result.apply();
-         assertTrue("is false", !bool.booleanValue());
-      } catch (Exception e)
-      {
-         log.trace("failed", e);
-         fail(""+e);
-      }
-   }
-   
-   public void testINANDCombination()
-   {
-      try
-      {
-         log.trace("parse(Cateogry IN ('category1') AND Rating >= 2");
-         Operator result = (Operator)parser.parse("Cateogry IN ('category1') AND Rating >= 2", identifierMap);
-         (identifierMap.get("Cateogry")).setValue("category1");
-         (identifierMap.get("Rating")).setValue(new Integer(3));
-         log.trace("result -> "+result);
-         Boolean bool = (Boolean) result.apply();
-         assertTrue("is true", bool.booleanValue());
-      } catch (Exception e)
-      {
-         log.trace("failed", e);
-         fail(""+e);
-      }
-   }
-
-   /** This testcase does not use the JBossServer so override
-   the testServerFound to be a noop
-   */
-   public void testServerFound()
-   {
-   }
-
-   public static void main(java.lang.String[] args)
-   {
-      junit.textui.TestRunner.run(FilterParserTest.class);
-   }
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/filter/test/unit/FilterTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/filter/test/unit/FilterTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/filter/test/unit/FilterTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,615 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * 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.core.impl.filter.test.unit;
-
-import org.jboss.messaging.core.filter.impl.FilterImpl;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessagingException;
-import org.jboss.messaging.core.server.impl.MessageImpl;
-import org.jboss.test.messaging.JBMBaseTestCase;
-
-/**
- * Tests the compliance with the JBoss Messaging Filter syntax.
- *
- * <p>Needs a lot of work...
- *
- * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version $Revision: 3514 $
- */
-public class FilterTest  extends JBMBaseTestCase
-{
-   private Filter filter;
-   
-   private Message message;
-   
-   public FilterTest(String name)
-   {
-      super(name);
-   }
-   
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-      
-      message = new MessageImpl();
-   }
-   
-   public void testInvalidString() throws Exception
-   {
-      testInvalidFilter("invalid");
-      
-      testInvalidFilter("color = 'red");
-      
-      testInvalidFilter("3");
-      
-      testInvalidFilter(null);
-   }
-   
-   public void testJBMDurable() throws Exception
-   {
-      filter = new FilterImpl("JBMDurable='DURABLE'");
-      
-      Message message = new MessageImpl();
-      message.setDurable(true);
-      
-      assertTrue(filter.match(message));
-      
-      message.setDurable(false);
-      
-      assertFalse(filter.match(message));
-      
-      filter = new FilterImpl("JBMDurable='NON_DURABLE'");
-      
-      message = new MessageImpl();
-      message.setDurable(true);
-      
-      assertFalse(filter.match(message));
-      
-      message.setDurable(false);
-      
-      assertTrue(filter.match(message));
-      
-   }
-
-   public void testJBMPriority() throws Exception
-   {
-      filter = new FilterImpl("JBMPriority=3");
-      
-      Message message = new MessageImpl();
-      
-      for (int i = 0; i < 10; i++)
-      {         
-         message.setPriority((byte)i);
-         
-         if (i == 3)
-         {
-            assertTrue(filter.match(message));
-         }
-         else
-         {
-            assertFalse(filter.match(message));
-         }                     
-      }
-   }
-   
-   public void testJBMMessageID() throws Exception
-   {
-      filter = new FilterImpl("JBMMessageID=11223344");
-      
-      Message message = new MessageImpl();
-      
-      message.setMessageID(78676);
-      
-      assertFalse(filter.match(message));
-      
-      message.setMessageID(11223344);
-      
-      assertTrue(filter.match(message));
-   }
-   
-   public void testJBMTimestamp() throws Exception
-   {
-      filter = new FilterImpl("JBMTimestamp=12345678");
-      
-      Message message = new MessageImpl();
-      
-      message.setTimestamp(87654321);
-      
-      assertFalse(filter.match(message));
-      
-      message.setTimestamp(12345678);
-      
-      assertTrue(filter.match(message));
-   }
-         
-   public void testBooleanTrue() throws Exception
-   {
-      filter = new FilterImpl("MyBoolean=true");
-      
-      testBoolean("MyBoolean", true);
-   }
-   
-   public void testBooleanFalse() throws Exception
-   {
-      filter = new FilterImpl("MyBoolean=false");
-      testBoolean("MyBoolean", false);
-   }
-   
-   private void testBoolean(String name, boolean flag) throws Exception
-   {
-      message.putHeader(name, flag);
-      assertTrue(filter.match(message));
-      
-      message.putHeader(name, !flag);
-      assertTrue(!filter.match(message));
-   }
-   
-   public void testStringEquals() throws Exception
-   {
-      // First, simple test of string equality and inequality
-      filter = new FilterImpl("MyString='astring'");
-      
-      message.putHeader("MyString", "astring");
-      assertTrue(filter.match(message));
-      
-      message.putHeader("MyString", "NOTastring");
-      assertTrue(!filter.match(message));
-      
-      // test empty string
-      filter = new FilterImpl("MyString=''");
-      
-      message.putHeader("MyString", "");
-      assertTrue("test 1", filter.match(message));
-      
-      message.putHeader("MyString", "NOTastring");
-      assertTrue("test 2", !filter.match(message));
-      
-      // test literal apostrophes (which are escaped using two apostrophes
-      // in selectors)
-      filter = new FilterImpl("MyString='test JBoss''s filter'");
-      
-      // note: apostrophes are not escaped in string properties
-      message.putHeader("MyString", "test JBoss's filter");
-      // this test fails -- bug 530120
-      //assertTrue("test 3", filter.match(message));
-      
-      message.putHeader("MyString", "NOTastring");
-      assertTrue("test 4", !filter.match(message));
-      
-   }
-   
-   public void testStringLike() throws Exception
-   {
-      // test LIKE operator with no wildcards
-      filter = new FilterImpl("MyString LIKE 'astring'");
-      
-      // test where LIKE operand matches
-      message.putHeader("MyString", "astring");
-      assertTrue(filter.match(message));
-      
-      // test one character string
-      filter = new FilterImpl("MyString LIKE 'a'");
-      message.putHeader("MyString","a");
-      assertTrue(filter.match(message));
-      
-      // test empty string
-      filter = new FilterImpl("MyString LIKE ''");
-      message.putHeader("MyString", "");
-      assertTrue(filter.match(message));
-      
-      // tests where operand does not match
-      filter = new FilterImpl("MyString LIKE 'astring'");
-      
-      // test with extra characters at beginning
-      message.putHeader("MyString", "NOTastring");
-      assertTrue(!filter.match(message));
-      
-      // test with extra characters at end
-      message.putHeader("MyString", "astringNOT");
-      assertTrue(!filter.match(message));
-      
-      // test with extra characters in the middle
-      message.putHeader("MyString", "astNOTring");
-      assertTrue(!filter.match(message));
-      
-      // test where operand is entirely different
-      message.putHeader("MyString", "totally different");
-      assertTrue(!filter.match(message));
-      
-      // test case sensitivity
-      message.putHeader("MyString", "ASTRING");
-      assertTrue(!filter.match(message));
-      
-      // test empty string
-      message.putHeader("MyString", "");
-      assertTrue(!filter.match(message));
-      
-      
-      // test lower-case 'like' operator?
-   }
-   
-   public void testStringLikeUnderbarWildcard() throws Exception
-   {
-      // test LIKE operator with the _ wildcard, which
-      // matches any single character
-      
-      // first, some tests with the wildcard by itself
-      filter = new FilterImpl("MyString LIKE '_'");
-      
-      // test match against single character
-      message.putHeader("MyString", "a");
-      assertTrue(filter.match(message));
-      
-      // test match failure against multiple characters
-      message.putHeader("MyString", "aaaaa");
-      assertTrue(!filter.match(message));
-      
-      // test match failure against the empty string
-      message.putHeader("MyString", "");
-      assertTrue(!filter.match(message));
-      
-      
-      // next, tests with wildcard at the beginning of the string
-      filter = new FilterImpl("MyString LIKE '_bcdf'");
-      
-      // test match at beginning of string
-      message.putHeader("MyString", "abcdf");
-      assertTrue(filter.match(message));
-      
-      // match failure in first character after wildcard
-      message.putHeader("MyString", "aXcdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in middle character
-      message.putHeader("MyString", "abXdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in last character
-      message.putHeader("MyString", "abcdX");
-      assertTrue(!filter.match(message));
-      
-      // match failure with empty string
-      message.putHeader("MyString", "");
-      assertTrue(!filter.match(message));
-      
-      // match failure due to extra characters at beginning
-      message.putHeader("MyString", "XXXabcdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure due to extra characters at the end
-      message.putHeader("MyString", "abcdfXXX");
-      assertTrue(!filter.match(message));
-      
-      // test that the _ wildcard does not match the 'empty' character
-      message.putHeader("MyString", "bcdf");
-      assertTrue(!filter.match(message));
-      
-      // next, tests with wildcard at the end of the string
-      filter = new FilterImpl("MyString LIKE 'abcd_'");
-      
-      // test match at end of string
-      message.putHeader("MyString", "abcdf");
-      assertTrue(filter.match(message));
-      
-      // match failure in first character before wildcard
-      message.putHeader("MyString", "abcXf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in middle character
-      message.putHeader("MyString", "abXdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in first character
-      message.putHeader("MyString", "Xbcdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure with empty string
-      message.putHeader("MyString", "");
-      assertTrue(!filter.match(message));
-      
-      // match failure due to extra characters at beginning
-      message.putHeader("MyString", "XXXabcdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure due to extra characters at the end
-      message.putHeader("MyString", "abcdfXXX");
-      assertTrue(!filter.match(message));
-      
-      // test that the _ wildcard does not match the 'empty' character
-      message.putHeader("MyString", "abcd");
-      assertTrue(!filter.match(message));
-      
-      // test match in middle of string
-      
-      // next, tests with wildcard in the middle of the string
-      filter = new FilterImpl("MyString LIKE 'ab_df'");
-      
-      // test match in the middle of string
-      message.putHeader("MyString", "abcdf");
-      assertTrue(filter.match(message));
-      
-      // match failure in first character before wildcard
-      message.putHeader("MyString", "aXcdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in first character after wildcard
-      message.putHeader("MyString", "abcXf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in last character
-      message.putHeader("MyString", "abcdX");
-      assertTrue(!filter.match(message));
-      
-      // match failure with empty string
-      message.putHeader("MyString", "");
-      assertTrue(!filter.match(message));
-      
-      // match failure due to extra characters at beginning
-      message.putHeader("MyString", "XXXabcdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure due to extra characters at the end
-      message.putHeader("MyString", "abcdfXXX");
-      assertTrue(!filter.match(message));
-      
-      // test that the _ wildcard does not match the 'empty' character
-      message.putHeader("MyString", "abdf");
-      assertTrue(!filter.match(message));
-      
-      // test match failures
-   }
-   
-   public void testStringLikePercentWildcard() throws Exception
-   {
-      // test LIKE operator with the % wildcard, which
-      // matches any sequence of characters
-      // note many of the tests are similar to those for _
-      
-      
-      // first, some tests with the wildcard by itself
-      filter = new FilterImpl("MyString LIKE '%'");
-      
-      // test match against single character
-      message.putHeader("MyString", "a");
-      assertTrue(filter.match(message));
-      
-      // test match against multiple characters
-      message.putHeader("MyString", "aaaaa");
-      assertTrue(filter.match(message));
-      
-      message.putHeader("MyString", "abcdf");
-      assertTrue(filter.match(message));
-      
-      // test match against the empty string
-      message.putHeader("MyString", "");
-      assertTrue(filter.match(message));
-      
-      
-      // next, tests with wildcard at the beginning of the string
-      filter = new FilterImpl("MyString LIKE '%bcdf'");
-      
-      // test match with single character at beginning of string
-      message.putHeader("MyString", "Xbcdf");
-      assertTrue(filter.match(message));
-      
-      // match with multiple characters at beginning
-      message.putHeader("MyString", "XXbcdf");
-      assertTrue(filter.match(message));
-      
-      // match failure in middle character
-      message.putHeader("MyString", "abXdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in last character
-      message.putHeader("MyString", "abcdX");
-      assertTrue(!filter.match(message));
-      
-      // match failure with empty string
-      message.putHeader("MyString", "");
-      assertTrue(!filter.match(message));
-      
-      // match failure due to extra characters at the end
-      message.putHeader("MyString", "abcdfXXX");
-      assertTrue(!filter.match(message));
-      
-      // test that the % wildcard matches the empty string
-      message.putHeader("MyString", "bcdf");
-      assertTrue(filter.match(message));
-      
-      // next, tests with wildcard at the end of the string
-      filter = new FilterImpl("MyString LIKE 'abcd%'");
-      
-      // test match of single character at end of string
-      message.putHeader("MyString", "abcdf");
-      assertTrue(filter.match(message));
-      
-      // test match of multiple characters at end of string
-      message.putHeader("MyString", "abcdfgh");
-      assertTrue(filter.match(message));
-      
-      // match failure in first character before wildcard
-      message.putHeader("MyString", "abcXf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in middle character
-      message.putHeader("MyString", "abXdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in first character
-      message.putHeader("MyString", "Xbcdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure with empty string
-      message.putHeader("MyString", "");
-      assertTrue(!filter.match(message));
-      
-      // match failure due to extra characters at beginning
-      message.putHeader("MyString", "XXXabcdf");
-      assertTrue(!filter.match(message));
-      
-      // test that the % wildcard matches the empty string
-      message.putHeader("MyString", "abcd");
-      assertTrue(filter.match(message));
-      
-      // next, tests with wildcard in the middle of the string
-      filter = new FilterImpl("MyString LIKE 'ab%df'");
-      
-      // test match with single character in the middle of string
-      message.putHeader("MyString", "abXdf");
-      assertTrue(filter.match(message));
-      
-      // test match with multiple characters in the middle of string
-      message.putHeader("MyString", "abXXXdf");
-      assertTrue(filter.match(message));
-      
-      // match failure in first character before wildcard
-      message.putHeader("MyString", "aXcdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in first character after wildcard
-      message.putHeader("MyString", "abcXf");
-      assertTrue(!filter.match(message));
-      
-      // match failure in last character
-      message.putHeader("MyString", "abcdX");
-      assertTrue(!filter.match(message));
-      
-      // match failure with empty string
-      message.putHeader("MyString", "");
-      assertTrue(!filter.match(message));
-      
-      // match failure due to extra characters at beginning
-      message.putHeader("MyString", "XXXabcdf");
-      assertTrue(!filter.match(message));
-      
-      // match failure due to extra characters at the end
-      message.putHeader("MyString", "abcdfXXX");
-      assertTrue(!filter.match(message));
-      
-      // test that the % wildcard matches the empty string
-      message.putHeader("MyString", "abdf");
-      assertTrue(filter.match(message));
-      
-   }
-   
-   public void testStringLikePunctuation() throws Exception
-   {
-      // test proper handling of some punctuation characters.
-      // non-trivial since the underlying implementation might
-      // (and in fact currently does) use a general-purpose
-      // RE library, which has a different notion of which
-      // characters are wildcards
-      
-      // the particular tests here are motivated by the
-      // wildcards of the current underlying RE engine,
-      // GNU regexp.
-      
-      filter = new FilterImpl("MyString LIKE 'a^$b'");
-      message.putHeader("MyString", "a^$b");
-      assertTrue(filter.match(message));
-      
-      // this one has a double backslash since backslash
-      // is interpreted specially by Java
-      filter = new FilterImpl("MyString LIKE 'a\\dc'");
-      message.putHeader("MyString", "a\\dc");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE 'a.c'");
-      message.putHeader("MyString", "abc");
-      assertTrue(!filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '[abc]'");
-      message.putHeader("MyString", "[abc]");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '[^abc]'");
-      message.putHeader("MyString", "[^abc]");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '[a-c]'");
-      message.putHeader("MyString", "[a-c]");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '[:alpha]'");
-      message.putHeader("MyString", "[:alpha]");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '(abc)'");
-      message.putHeader("MyString", "(abc)");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE 'a|bc'");
-      message.putHeader("MyString", "a|bc");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '(abc)?'");
-      message.putHeader("MyString", "(abc)?");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '(abc)*'");
-      message.putHeader("MyString", "(abc)*");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '(abc)+'");
-      message.putHeader("MyString", "(abc)+");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '(abc){3}'");
-      message.putHeader("MyString", "(abc){3}");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '(abc){3,5}'");
-      message.putHeader("MyString", "(abc){3,5}");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '(abc){3,}'");
-      message.putHeader("MyString", "(abc){3,}");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '(?=abc)'");
-      message.putHeader("MyString", "(?=abc)");
-      assertTrue(filter.match(message));
-      
-      filter = new FilterImpl("MyString LIKE '(?!abc)'");
-      message.putHeader("MyString", "(?!abc)");
-      assertTrue(filter.match(message));
-   }
-   
-   // Private -----------------------------------------------------------------------------------
-   
-   private void testInvalidFilter(String filterString) throws Exception
-   {
-      try
-      {
-         filter = new FilterImpl(filterString);
-         
-         fail("Should throw exception");
-      }
-      catch (MessagingException e)
-      {
-         assertEquals(MessagingException.INVALID_FILTER_EXPRESSION, e.getCode());
-      }            
-   }
-   
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,331 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * 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.core.impl.postoffice.test.unit;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.easymock.EasyMock;
-import org.jboss.messaging.core.filter.impl.FilterImpl;
-import org.jboss.messaging.core.server.Binding;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.PersistenceManager;
-import org.jboss.messaging.core.server.PostOffice;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.QueueFactory;
-import org.jboss.messaging.core.server.Transaction;
-import org.jboss.messaging.core.server.impl.BindingImpl;
-import org.jboss.messaging.core.server.impl.PostOfficeImpl;
-import org.jboss.messaging.core.server.impl.QueueFactoryImpl;
-import org.jboss.messaging.core.server.impl.QueueImpl;
-import org.jboss.messaging.core.server.impl.TransactionImpl;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- * 
- * A PostOfficeTest
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class PostOfficeTest extends UnitTestCase
-{
-   //TODO  test all methods!!!
-   
-   @Override
-   protected void setUp() throws Exception
-   {
-   }
-
-   @Override
-   protected void tearDown() throws Exception
-   {
-   }
-   
-   public void testAddQueue() throws Exception
-   {
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      QueueFactory qf = EasyMock.createStrictMock(QueueFactory.class);
-      
-      final int nodeID = 21;
-      
-      PostOffice po = new PostOfficeImpl(nodeID, pm, qf, false);
-      
-      final long id = 324;
-      final String name = "wibb22";
-      final Filter filter = new FilterImpl("eek");
-      final boolean clustered = true;
-      final boolean durable = true;
-      final boolean temporary = true;
-      
-      Queue queue = new QueueImpl(id, name, filter, clustered, durable, temporary, -1);
-      
-      EasyMock.expect(qf.createQueue(-1, name, filter, durable, temporary)).andReturn(queue);
-            
-      final String condition = "queue.wibble";
-
-      Binding expected = new BindingImpl(nodeID, condition, queue);
-      
-      pm.addBinding(EasyMock.eq(expected));
-      
-      EasyMock.replay(qf);
-      
-      EasyMock.replay(pm);
-      
-      po.addBinding(condition, name, filter, durable, temporary);
-      
-      EasyMock.verify(qf);
-      
-      EasyMock.verify(pm);
-      
-      EasyMock.reset(qf);
-      
-      EasyMock.reset(pm);
-      
-      final boolean durable2 = false;
-      
-      queue = new QueueImpl(id, name, filter, clustered, durable2, temporary, -1);
-      
-      EasyMock.expect(qf.createQueue(-1, name, filter, durable2, temporary)).andReturn(queue);
-      
-      EasyMock.replay(qf);
-      
-      EasyMock.replay(pm);
-      
-      po.addBinding(condition, name, filter, durable2, temporary);
-      
-      EasyMock.verify(qf);
-      
-      EasyMock.verify(pm);
-   }   
-   
-   public void testRemoveQueue() throws Exception
-   {
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      QueueFactory qf = EasyMock.createStrictMock(QueueFactory.class);
-      
-      final int nodeID = 21;
-      
-      PostOffice po = new PostOfficeImpl(nodeID, pm, qf, false);
-      
-      final long id = 324;
-      final String name = "wibb22";
-      final Filter filter = new FilterImpl("eek");
-      final boolean clustered = true;
-      final boolean durable = true;
-      final boolean temporary = true;
-      
-      Queue queue = new QueueImpl(id, name, filter, clustered, durable, temporary, -1);
-      
-      EasyMock.expect(qf.createQueue(-1, name, filter, durable, temporary)).andReturn(queue);
-            
-      final String condition = "queue.wibble";
- 
-      Binding expected = new BindingImpl(nodeID, condition, queue);
-      
-      pm.addBinding(EasyMock.eq(expected));
-      
-      pm.deleteBinding(EasyMock.eq(expected));
-      
-      EasyMock.replay(qf);
-      
-      EasyMock.replay(pm);
-      
-      po.addBinding(condition, name, filter, durable, temporary);
-      
-      po.removeBinding(name);
-      
-      EasyMock.verify(qf);
-      
-      EasyMock.verify(pm);
-      
-      EasyMock.reset(qf);
-      
-      EasyMock.reset(pm);
-      
-      final boolean durable2 = false;
-      
-      queue = new QueueImpl(id, name, filter, clustered, durable2, temporary, -1);
-      
-      EasyMock.expect(qf.createQueue(-1, name, filter, durable2, temporary)).andReturn(queue);
-      
-      EasyMock.replay(qf);
-      
-      EasyMock.replay(pm);
-      
-      po.addBinding(condition, name, filter, durable2, temporary);
-      
-      po.removeBinding(name);
-      
-      EasyMock.verify(qf);
-      
-      EasyMock.verify(pm);
-   }   
-   
-   public void testAddRemoveMultipleWithDifferentConditions() throws Exception
-   {
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      QueueFactory qf = new QueueFactoryImpl();
-      
-      final int nodeID = 21;
-      
-      PostOffice po = new PostOfficeImpl(nodeID, pm, qf, false);
-      
-      final String condition1 = "queue.wibble";      
-                
-      po.addBinding(condition1, "queue1", null, false, false);      
-      Map<String, List<Binding>> mappings = po.getMappings();      
-      assertEquals(1, mappings.size());
-      
-      po.addBinding(condition1, "queue2", null, false, false);     
-      mappings = po.getMappings();      
-      assertEquals(1, mappings.size());
-      
-      po.addBinding(condition1, "queue3", null, false, false); 
-      mappings = po.getMappings();      
-      assertEquals(1, mappings.size());
-      
-      List<Binding> bindings = mappings.get(condition1);
-      assertNotNull(bindings);
-      assertEquals(3, bindings.size());
-      
-      Binding binding1 = bindings.get(0);
-      Queue queue1 = binding1.getQueue();
-      assertEquals("queue1", queue1.getName());
-            
-      Binding binding2 = bindings.get(1);
-      Queue queue2 = binding2.getQueue();
-      assertEquals("queue2", queue2.getName());
-      
-      Binding binding3 = bindings.get(2);
-      Queue queue3 = binding3.getQueue();
-      assertEquals("queue3", queue3.getName());
-      
-      final String condition2 = "queue.wibble2"; 
-      
-      po.addBinding(condition2, "queue4", null, false, false);       
-      mappings = po.getMappings();      
-      assertEquals(2, mappings.size());
-      
-      po.addBinding(condition2, "queue5", null, false, false); 
-      mappings = po.getMappings();      
-      assertEquals(2, mappings.size());
-      
-      final String condition3 = "topic.wibblexyz"; 
-      
-      po.addBinding(condition3, "queue6", null, false, false);       
-      mappings = po.getMappings();      
-      assertEquals(3, mappings.size());
-      
-      po.removeBinding("queue6");
-      mappings = po.getMappings();      
-      assertEquals(2, mappings.size());
-      
-      po.removeBinding("queue4");
-      mappings = po.getMappings();      
-      assertEquals(2, mappings.size());
-      
-      po.removeBinding("queue5");
-      mappings = po.getMappings();      
-      assertEquals(1, mappings.size());
-      
-      po.removeBinding("queue1");
-      mappings = po.getMappings();      
-      assertEquals(1, mappings.size());
-      
-      po.removeBinding("queue2");
-      mappings = po.getMappings();      
-      assertEquals(1, mappings.size());
-      
-      po.removeBinding("queue3");
-      mappings = po.getMappings();      
-      assertEquals(0, mappings.size());      
-   }
-   
-   public void testRouteNoTransaction() throws Exception
-   {
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      QueueFactory qf = new QueueFactoryImpl();
-      
-      PostOffice po = new PostOfficeImpl(1, pm, qf, false);
-      
-      Message message = this.generateMessage(1);
-      
-      try
-      {
-         po.route("queue.eek", message);
-         fail("Should throw exception");
-      }
-      catch (NullPointerException e)
-      {
-         //OK
-      }
-   }
-   
-   public void testRouteNPMessage_NDQueue() throws Exception
-   {
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      QueueFactory qf = new QueueFactoryImpl();
-      
-      PostOffice po = new PostOfficeImpl(1, pm, qf, false);
-      
-      String condition = "queue.queue1";
-      
-      po.addBinding(condition, "queue1", null, false, false);
-      
-      Message message = this.generateMessage(1);
-      
-      message.setDurable(false);
-      
-      List<Message> msgs = new ArrayList<Message>();
-      
-      msgs.add(message);
-      
-      po.route("queue.queue1", message);
-      
-      if (message.getNumDurableReferences() != 0)
-      {
-         //Need to route in a transaction
-         Transaction tx = new TransactionImpl();
-      }
-      
-      
-      
-      Map<String, List<Binding>> mappings = po.getMappings();
-      
-      Binding binding = mappings.get(condition).get(0);
-      
-      Queue queue = binding.getQueue();
-      
-      assertEquals(1, queue.getMessageCount());
-      
-      assertTrue(message == queue.list(null).get(0).getMessage());
-
-   }      
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/test/concurrent/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/concurrent/QueueTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/concurrent/QueueTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,204 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * 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.core.impl.test.concurrent;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.messaging.core.impl.test.unit.fakes.FakeConsumer;
-import org.jboss.messaging.core.server.HandleStatus;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.impl.QueueImpl;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- * 
- * A concurrent QueueTest
- * 
- * All the concurrent queue tests go in here 
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class QueueTest extends UnitTestCase
-{
-   // The tests ----------------------------------------------------------------
-
-   /*
-    * Concurrent set consumer not busy, busy then, call deliver while messages are being added and consumed
-    */
-   public void testConcurrentAddsDeliver() throws Exception
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      FakeConsumer consumer = new FakeConsumer();
-      
-      queue.addConsumer(consumer);
-      
-      final long testTime = 5000;
-      
-      Sender sender = new Sender(queue, testTime);
-      
-      Toggler toggler = new Toggler(queue, consumer, testTime);
-      
-      sender.start();
-      
-      toggler.start();
-      
-      sender.join();
-      
-      toggler.join();
-      
-      consumer.setStatusImmediate(HandleStatus.HANDLED);
-      
-      queue.deliver();
-      
-      if (sender.getException() != null)
-      {
-         throw sender.getException();
-      }
-      
-      if (toggler.getException() != null)
-      {
-         throw toggler.getException();
-      }
-      
-      assertRefListsIdenticalRefs(sender.getReferences(), consumer.getReferences());
-      
-      System.out.println("num refs: " + sender.getReferences().size());
-      
-      System.out.println("num toggles: " + toggler.getNumToggles());
-      
-   }
-   
-   // Inner classes ---------------------------------------------------------------
-   
-   class Sender extends Thread
-   {
-      private volatile Exception e;
-      
-      private Queue queue;
-      
-      private long testTime;
-      
-      private volatile int i;
-      
-      public Exception getException()
-      {
-         return e;
-      }
-      
-      private List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      public List<MessageReference> getReferences()
-      {
-         return refs;
-      }
-      
-      Sender(Queue queue, long testTime)
-      {
-         this.testTime = testTime;
-         
-         this.queue = queue;
-      }
-      
-      public void run()
-      {
-         long start = System.currentTimeMillis();
-         
-         while (System.currentTimeMillis() - start < testTime)
-         {
-            Message message = generateMessage(i);
-            
-            MessageReference ref = message.createReference(queue);
-            
-            queue.addLast(ref);
-            
-            refs.add(ref);
-            
-            i++;
-         }
-      }
-   }
-   
-   class Toggler extends Thread
-   {
-      private volatile Exception e;
-      
-      private Queue queue;
-      
-      private FakeConsumer consumer;
-      
-      private long testTime;
-      
-      private boolean toggle;
-      
-      private volatile int numToggles;
-      
-      public int getNumToggles()
-      {
-         return numToggles;
-      }
-      
-      public Exception getException()
-      {
-         return e;
-      }
-      
-      Toggler(Queue queue, FakeConsumer consumer, long testTime)
-      {
-         this.testTime = testTime;
-         
-         this.queue = queue;
-         
-         this.consumer = consumer;
-      }
-      
-      public void run()
-      {
-         long start = System.currentTimeMillis();
-         
-         while (System.currentTimeMillis() - start < testTime)
-         {
-            if (toggle)
-            {
-               consumer.setStatusImmediate(HandleStatus.BUSY);              
-            }
-            else
-            {
-               consumer.setStatusImmediate(HandleStatus.HANDLED);
-               
-               queue.deliver();
-            }
-            toggle = !toggle;
-            
-            numToggles++;
-         }
-      }
-   }
-      
-}
-
-
-

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/test/timing/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/timing/QueueTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/timing/QueueTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,245 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * 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.core.impl.test.timing;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-
-import org.jboss.messaging.core.impl.test.unit.fakes.FakeConsumer;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.impl.QueueImpl;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- * 
- * A timing-sensitive QueueTest
- * 
- * All the queue tests which are timing sensitive - go in here 
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class QueueTest extends UnitTestCase
-{
-   private static final long TIMEOUT = 10000;
-   
-   private static final Logger log = Logger.getLogger(QueueTest.class);
-   
-   private ScheduledExecutorService scheduledExecutor;
-   
-   public void setUp() throws Exception
-   {
-   	super.setUp();
-   	
-   	scheduledExecutor = new ScheduledThreadPoolExecutor(1);
-   }
-   
-   public void tearDown() throws Exception
-   {
-   	super.tearDown();
-   	
-   	scheduledExecutor.shutdownNow();
-   }
-   
-   // The tests ----------------------------------------------------------------
-
-   public void testScheduledDirect()
-   {
-      testScheduled(true); 
-   }
-   
-   public void testScheduledQueueing()
-   {
-      testScheduled(false); 
-   }
-   
-   public void testScheduledNoConsumer() throws Exception
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor);
-           
-      //Send one scheduled
-      
-      long now = System.currentTimeMillis();
-      
-      MessageReference ref1 = generateReference(queue, 1);         
-      ref1.setScheduledDeliveryTime(now + 7000);      
-      queue.addLast(ref1);
-      
-      //Send some non scheduled messages
-      
-      MessageReference ref2 = generateReference(queue, 2);              
-      queue.addLast(ref2);
-      MessageReference ref3 = generateReference(queue, 3);             
-      queue.addLast(ref3);
-      MessageReference ref4 = generateReference(queue, 4);               
-      queue.addLast(ref4);
-      
-      
-      //Now send some more scheduled messages   
-           
-      MessageReference ref5 = generateReference(queue, 5); 
-      ref5.setScheduledDeliveryTime(now + 5000);
-      queue.addLast(ref5);
-      
-      MessageReference ref6 = generateReference(queue, 6); 
-      ref6.setScheduledDeliveryTime(now + 4000);
-      queue.addLast(ref6);
-      
-      MessageReference ref7 = generateReference(queue, 7); 
-      ref7.setScheduledDeliveryTime(now + 3000);
-      queue.addLast(ref7); 
-      
-      MessageReference ref8 = generateReference(queue, 8); 
-      ref8.setScheduledDeliveryTime(now + 6000);
-      queue.addLast(ref8);
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      //Scheduled refs are added back to *FRONT* of queue - otherwise if there were many messages in the queue
-      //They may get stranded behind a big backlog
-      
-      refs.add(ref1);
-      refs.add(ref8);
-      refs.add(ref5);
-      refs.add(ref6);
-      refs.add(ref7);
-      
-      refs.add(ref2);
-      refs.add(ref3);
-      refs.add(ref4);
-      
-      Thread.sleep(7500);
-      
-      FakeConsumer consumer = new FakeConsumer();
-      
-      queue.addConsumer(consumer);
-      
-      queue.deliver();
-      
-      assertRefListsIdenticalRefs(refs, consumer.getReferences());               
-   }
-   
-   private void testScheduled(boolean direct)
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor);
-      
-      FakeConsumer consumer = null;
-      
-      if (direct)
-      {
-         consumer = new FakeConsumer();
-         
-         queue.addConsumer(consumer);
-      }
-      
-      //Send one scheduled
-      
-      long now = System.currentTimeMillis();
-      
-      MessageReference ref1 = generateReference(queue, 1);         
-      ref1.setScheduledDeliveryTime(now + 7000);      
-      queue.addLast(ref1);
-      
-      //Send some non scheduled messages
-      
-      MessageReference ref2 = generateReference(queue, 2);              
-      queue.addLast(ref2);
-      MessageReference ref3 = generateReference(queue, 3);             
-      queue.addLast(ref3);
-      MessageReference ref4 = generateReference(queue, 4);               
-      queue.addLast(ref4);
-      
-      
-      //Now send some more scheduled messages   
-           
-      MessageReference ref5 = generateReference(queue, 5); 
-      ref5.setScheduledDeliveryTime(now + 5000);
-      queue.addLast(ref5);
-      
-      MessageReference ref6 = generateReference(queue, 6); 
-      ref6.setScheduledDeliveryTime(now + 4000);
-      queue.addLast(ref6);
-      
-      MessageReference ref7 = generateReference(queue, 7); 
-      ref7.setScheduledDeliveryTime(now + 3000);
-      queue.addLast(ref7); 
-      
-      MessageReference ref8 = generateReference(queue, 8); 
-      ref8.setScheduledDeliveryTime(now + 6000);
-      queue.addLast(ref8);
-      
-      if (!direct)
-      {
-         consumer = new FakeConsumer();
-         
-         queue.addConsumer(consumer);
-         
-         queue.deliver();
-      }
-
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      refs.add(ref2);
-      refs.add(ref3);
-      refs.add(ref4);
-      
-      assertRefListsIdenticalRefs(refs, consumer.getReferences());
-      
-      refs.clear();
-      consumer.getReferences().clear();
-                  
-      MessageReference ref = consumer.waitForNextReference(TIMEOUT);
-      assertEquals(ref7, ref);
-      long now2 = System.currentTimeMillis();
-      assertTrue(now2 - now >= 3000);
-      
-      ref = consumer.waitForNextReference(TIMEOUT);
-      assertEquals(ref6, ref);
-      now2 = System.currentTimeMillis();
-      assertTrue(now2 - now >= 4000);
-      
-      ref = consumer.waitForNextReference(TIMEOUT);
-      assertEquals(ref5, ref);
-      now2 = System.currentTimeMillis();
-      assertTrue(now2 - now >= 5000);
-      
-      ref = consumer.waitForNextReference(TIMEOUT);
-      assertEquals(ref8, ref);
-      now2 = System.currentTimeMillis();
-      assertTrue(now2 - now >= 6000);
-      
-      ref = consumer.waitForNextReference(TIMEOUT);
-      assertEquals(ref1, ref);
-      now2 = System.currentTimeMillis();
-      assertTrue(now2 - now >= 7000);
-      
-      assertTrue(consumer.getReferences().isEmpty());            
-   }
-   
-   // Inner classes ---------------------------------------------------------------
-      
-}
-

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/test/unit/MessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/unit/MessageTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/unit/MessageTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,421 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * 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.core.impl.test.unit;
-
-import static org.jboss.messaging.test.unit.RandomUtil.randomByte;
-import static org.jboss.messaging.test.unit.RandomUtil.randomInt;
-import static org.jboss.messaging.test.unit.RandomUtil.randomLong;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.impl.MessageImpl;
-import org.jboss.messaging.core.server.impl.QueueImpl;
-import org.jboss.messaging.test.unit.UnitTestCase;
-import org.jboss.messaging.util.StreamUtils;
-
-/**
- * 
- * Tests for Message and MessageReference
- * 
- * TODO - Test streaming and destreaming
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class MessageTest extends UnitTestCase
-{
-
-   public void testCreateMessage()
-   {
-      long id = 56465;
-      int type = 655;
-      boolean reliable = true;
-      long expiration = 6712671;
-      long timestamp = 82798172;
-      byte priority = 32;
-      
-      Message message = new MessageImpl(type, reliable, expiration, timestamp, priority);
-      message.setMessageID(id);
-      
-      assertEquals(id, message.getMessageID());
-      assertEquals(type, message.getType());
-      assertEquals(reliable, message.isDurable());
-      assertEquals(timestamp, message.getTimestamp());
-      assertEquals(priority, message.getPriority());
-      
-      reliable = false;
-      
-      message = new MessageImpl(type, reliable, expiration, timestamp, priority);
-      message.setMessageID(id);
-      
-      assertEquals(id, message.getMessageID());
-      assertEquals(type, message.getType());
-      assertEquals(reliable, message.isDurable());
-      assertEquals(timestamp, message.getTimestamp());
-      assertEquals(priority, message.getPriority());
-   }
-   
-   public void testCreateMessageFromStorage() throws Exception
-   {
-      long id = 56465;
-      int type = 655;
-      boolean reliable = true;
-      long expiration = 6712671;
-      long timestamp = 82798172;
-      byte priority = 32;
-      
-      byte[] bytes = "blah blah blah".getBytes();
- 
-      Message message = new MessageImpl(id, type, reliable, expiration, timestamp, priority,
-            null, bytes);
-      
-      assertEquals(id, message.getMessageID());
-      assertEquals(type, message.getType());
-      assertEquals(reliable, message.isDurable());
-      assertEquals(timestamp, message.getTimestamp());
-      assertEquals(priority, message.getPriority());     
-      
-      assertByteArraysEquivalent(bytes, message.getPayload());   
-      
-      //TODO - headers - they should really be combined into single blob
-   }
-   
-   public void testCopy()
-   {
-      long id = 56465;
-      int type = 655;
-      boolean reliable = true;
-      long expiration = 6712671;
-      long timestamp = 82798172;
-      byte priority = 32;
-      
-      Message message = new MessageImpl(type, reliable, expiration, timestamp, priority);
-      message.setMessageID(id);
-      
-      Message message2 = message.copy();
-      
-      assertEquivalent(message, message2);
-   }
-   
-   public void testSetAndGetMessageID()
-   {
-      Message message = new MessageImpl();
-      
-      assertEquals(0, message.getMessageID());
-      
-      message = new MessageImpl(655, true, 767676, 989898, (byte)32);
-      
-      assertEquals(0, message.getMessageID());
-      
-      long id = 765432;
-      message.setMessageID(id);
-      assertEquals(id, message.getMessageID());
-   }
-   
-   public void testSetAndGetReliable()
-   {
-      Message message = new MessageImpl();
-      
-      boolean reliable = true;
-      message.setDurable(reliable);
-      assertEquals(reliable, message.isDurable());
-      
-      reliable = false;
-      message.setDurable(reliable);
-      assertEquals(reliable, message.isDurable());
-   }
-    
-   public void testSetAndGetExpiration()
-   {
-      Message message = new MessageImpl();
-      
-      long expiration = System.currentTimeMillis() + 10000;
-      message.setExpiration(expiration);
-      assertEquals(expiration, message.getExpiration());
-      assertFalse(message.isExpired());
-      message.setExpiration(System.currentTimeMillis() - 1);
-      assertTrue(message.isExpired());
-      
-      expiration = 0; //O means never expire
-      message.setExpiration(expiration);
-      assertEquals(expiration, message.getExpiration());
-      assertFalse(message.isExpired());
-   }
-      
-   public void testSetAndGetTimestamp()
-   {
-      Message message = new MessageImpl();
-      
-      long timestamp = System.currentTimeMillis();
-      message.setTimestamp(timestamp);
-      assertEquals(timestamp, message.getTimestamp());
-   }
-   
-   public void testSetAndGetPriority()
-   {
-      Message message = new MessageImpl();
-      byte priority = 7;
-      message.setPriority(priority);
-      assertEquals(priority, message.getPriority());
-   }
-   
-   public void testSetAndGetConnectionID()
-   {
-      Message message = new MessageImpl();
-      
-      assertNull(message.getConnectionID());
-      String connectionID = "conn123";
-      message.setConnectionID(connectionID);
-      assertEquals(connectionID, message.getConnectionID());      
-   }
-   
-   public void testSetAndGetPayload()
-   {
-      Message message = new MessageImpl();
-      
-      assertNull(message.getPayload());
-      
-      byte[] bytes = "blah blah blah".getBytes();
-      message.setPayload(bytes);
-      
-      assertByteArraysEquivalent(bytes, message.getPayload());            
-   }
-   
-   public void testHeaders()
-   {
-      Message message = new MessageImpl();
-      
-      assertNotNull(message.getHeaders());
-      assertTrue(message.getHeaders().isEmpty());
-      
-      String key1 = "key1";
-      String val1 = "wibble";
-      String key2 = "key2";
-      Object val2 = new Object();
-      String key3 = "key3";
-      Double val3 = new Double(123.456);
-      Long val4 = new Long(77777);
-      message.putHeader(key1, val1);
-      assertEquals(val1, message.getHeaders().get(key1));
-      assertEquals(1, message.getHeaders().size());
-      assertTrue(message.containsHeader(key1));
-      assertFalse(message.containsHeader("does not exist"));
-      message.putHeader(key2, val2);
-      assertEquals(val2, message.getHeaders().get(key2));
-      assertEquals(2, message.getHeaders().size());
-      assertTrue(message.containsHeader(key2));
-      message.putHeader(key3, val3);
-      assertEquals(val3, message.getHeaders().get(key3));
-      assertEquals(3, message.getHeaders().size());
-      assertTrue(message.containsHeader(key3));
-      message.putHeader(key3, val4);
-      assertEquals(val4, message.getHeaders().get(key3));
-      assertEquals(3, message.getHeaders().size());
-      assertEquals(val2, message.removeHeader(key2));
-      assertEquals(2, message.getHeaders().size());
-      assertFalse(message.containsHeader(key2));
-      assertNull(message.removeHeader("does not exist"));
-      assertEquals(val1, message.removeHeader(key1));
-      assertFalse(message.containsHeader(key2));
-      assertEquals(1, message.getHeaders().size());
-      assertEquals(val4, message.removeHeader(key3));
-      assertFalse(message.containsHeader(key3));
-      assertTrue(message.getHeaders().isEmpty());
-   }
-   
-   public void testEquals()
-   {
-      Message message1 = new MessageImpl();
-      message1.setMessageID(1);
-      
-      Message message2 = new MessageImpl();
-      message2.setMessageID(2);
-      
-      Message message3 = new MessageImpl();
-      message3.setMessageID(1);
-      
-      assertTrue(message1.equals(message1));
-      assertTrue(message2.equals(message2));
-      assertTrue(message3.equals(message3));
-      
-      assertFalse(message1.equals(message2));
-      assertFalse(message2.equals(message1));
-      
-      assertFalse(message2.equals(message3));
-      assertFalse(message3.equals(message2));
-      
-      assertTrue(message1.equals(message3));
-      assertTrue(message3.equals(message1));
-      
-   }
-   
-   public void testHashcode()
-   {
-      long id1 = 6567575;
-      Message message1 = new MessageImpl();
-      message1.setMessageID(id1);
-      
-      assertEquals((int) ((id1 >>> 32) ^ id1), message1.hashCode());
-   }
-   
-   public void testMessageReference()
-   {
-      Message message = new MessageImpl();
-      
-      assertTrue(message.getReferences().isEmpty());
-      
-      Queue queue1 = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      Queue queue2 = new QueueImpl(2, "queue2", null, false, true, false, -1);
-
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      MessageReference ref1 = message.createReference(queue1);
-      refs.add(ref1);
-      MessageReference ref2 = message.createReference(queue2);
-      refs.add(ref2);
-      MessageReference ref3 = message.createReference(queue1);
-      refs.add(ref3);
-      MessageReference ref4 = message.createReference(queue2);
-      refs.add(ref4);
-      
-      assertRefListsIdenticalRefs(refs, message.getReferences());
-      
-      assertEquals(queue1, ref1.getQueue());
-      assertEquals(queue2, ref2.getQueue());
-      assertEquals(queue1, ref3.getQueue());
-      assertEquals(queue2, ref4.getQueue());
-      
-      int deliveryCount = 65235;
-      ref1.setDeliveryCount(deliveryCount);
-      assertEquals(deliveryCount, ref1.getDeliveryCount());
-      
-      long scheduledDeliveryTime = 908298123;
-      ref1.setScheduledDeliveryTime(scheduledDeliveryTime);
-      assertEquals(scheduledDeliveryTime, ref1.getScheduledDeliveryTime());
-      
-      Queue queue3 = new QueueImpl(3, "queue3", null, false, true, false, -1);
-      MessageReference ref5 = ref1.copy(queue3);
-      
-      assertEquals(deliveryCount, ref5.getDeliveryCount());
-      assertEquals(scheduledDeliveryTime, ref5.getScheduledDeliveryTime());
-      assertEquals(queue3, ref5.getQueue());
-   }
-   
-
-   public void testDurableReferences()
-   {
-      Message messageDurable = new MessageImpl();
-      messageDurable.setDurable(true);
-      
-      Message messageNonDurable = new MessageImpl();
-      messageNonDurable.setDurable(false);
-        
-      //Durable queue
-      Queue queue1 = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      //Non durable queue
-      Queue queue2 = new QueueImpl(2, "queue2", null, false, false, false, -1);
-      
-      assertEquals(0, messageDurable.getNumDurableReferences());
-      
-      MessageReference ref1 = messageDurable.createReference(queue1);
-      
-      assertEquals(1, messageDurable.getNumDurableReferences());
-      
-      MessageReference ref2 = messageDurable.createReference(queue2);
-      
-      assertEquals(1, messageDurable.getNumDurableReferences());
-      
-      assertEquals(0, messageNonDurable.getNumDurableReferences());
-      
-      MessageReference ref3 = messageNonDurable.createReference(queue1);
-      
-      assertEquals(0, messageNonDurable.getNumDurableReferences());
-      
-      MessageReference ref4 = messageNonDurable.createReference(queue2);
-      
-      assertEquals(0, messageNonDurable.getNumDurableReferences());
-                  
-   }
-   
-   public void testDurableReferencePos()
-   {
-      Message messageDurable = new MessageImpl();
-      messageDurable.setDurable(true);
-      
-      //Durable queue
-      Queue queue1 = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      //Non durable queue
-      Queue queue2 = new QueueImpl(2, "queue2", null, false, false, false, -1);
-      
-      
-      MessageReference ref1 = messageDurable.createReference(queue1);
-      
-      MessageReference ref2 = messageDurable.createReference(queue2);
-      
-      MessageReference ref3 = messageDurable.createReference(queue2);
-      
-      MessageReference ref4 = messageDurable.createReference(queue1);
-      
-      MessageReference ref5 = messageDurable.createReference(queue1);
-      
-      MessageReference ref6 = messageDurable.createReference(queue2);
-      
-      MessageReference ref7 = messageDurable.createReference(queue1);
-      
-      MessageReference ref8 = messageDurable.createReference(queue2);
-      
-      assertEquals(0, messageDurable.getDurableReferencePos(ref1));
-      
-      assertEquals(1, messageDurable.getDurableReferencePos(ref4));
-      
-      assertEquals(2, messageDurable.getDurableReferencePos(ref5));
-      
-      assertEquals(3, messageDurable.getDurableReferencePos(ref7));
-             
-   }
-   
-   public void testMarshalling() throws Exception
-   {
-      Message msg = new MessageImpl(randomLong(), randomInt(), true, randomLong(), randomLong(), randomByte(),null, null);
-      msg.setDeliveryCount(randomInt());
-      
-      byte[] bytes = StreamUtils.toBytes(msg);
-      Message unmarshalledMsg = new MessageImpl();
-      StreamUtils.fromBytes(unmarshalledMsg, bytes);
-      
-      assertEquals(msg, unmarshalledMsg);
-      assertEquals("messageID", msg.getMessageID(), unmarshalledMsg.getMessageID());
-      assertEquals("type", msg.getType(), unmarshalledMsg.getType());
-      assertEquals("durable", msg.isDurable(), unmarshalledMsg.isDurable());
-      assertEquals("expiration", msg.getExpiration(), unmarshalledMsg.getExpiration());
-      assertEquals("timestamp", msg.getTimestamp(), unmarshalledMsg.getTimestamp());
-      assertEquals("priority", msg.getPriority(), unmarshalledMsg.getPriority());
-      assertEquals("deliveryCount", msg.getDeliveryCount(), unmarshalledMsg.getDeliveryCount()); 
-   }
-   
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/test/unit/PriorityLinkedListTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/unit/PriorityLinkedListTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/unit/PriorityLinkedListTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,607 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * 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.core.impl.test.unit;
-
-import java.util.Iterator;
-import java.util.ListIterator;
-
-import org.jboss.messaging.core.list.PriorityLinkedList;
-import org.jboss.messaging.core.list.impl.PriorityLinkedListImpl;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- * @author <a href="tim.fox at jboss.com>Tim Fox</a>
- *
- * $Id$
- */
-public class PriorityLinkedListTest extends UnitTestCase
-{
-   protected PriorityLinkedList<Wibble> list;
-   
-   protected Wibble a;
-   protected Wibble b;
-   protected Wibble c;
-   protected Wibble d;
-   protected Wibble e;   
-   protected Wibble f;
-   protected Wibble g;
-   protected Wibble h;
-   protected Wibble i;
-   protected Wibble j;
-   protected Wibble k;
-   protected Wibble l;
-   protected Wibble m;
-   protected Wibble n;
-   protected Wibble o;   
-   protected Wibble p;
-   protected Wibble q;
-   protected Wibble r;
-   protected Wibble s;
-   protected Wibble t;
-   protected Wibble u;
-   protected Wibble v;
-   protected Wibble w;
-   protected Wibble x;
-   protected Wibble y;   
-   protected Wibble z;
-   
-   public void setUp() throws Exception
-   {
-      super.setUp();
-      
-      list = new PriorityLinkedListImpl<Wibble>(10);
-      
-      a = new Wibble("a");
-      b = new Wibble("b");
-      c = new Wibble("c");
-      d = new Wibble("d");
-      e = new Wibble("e");
-      f = new Wibble("f");
-      g = new Wibble("g");
-      h = new Wibble("h");
-      i = new Wibble("i");
-      j = new Wibble("j");
-      k = new Wibble("k");
-      l = new Wibble("l");
-      m = new Wibble("m");
-      n = new Wibble("n");
-      o = new Wibble("o");
-      p = new Wibble("p");
-      q = new Wibble("q");
-      r = new Wibble("r");
-      s = new Wibble("s");
-      t = new Wibble("t");
-      u = new Wibble("u");
-      v = new Wibble("v");
-      w = new Wibble("w");
-      x = new Wibble("x");
-      y = new Wibble("y");
-      z = new Wibble("z");
-   }
-   
-   
-   public void tearDown() throws Exception
-   {
-      super.tearDown();
-   }
-         
-   public void testAddFirst() throws Exception
-   {
-      list.addFirst(a, 0);
-      list.addFirst(b, 0);
-      list.addFirst(c, 0);
-      list.addFirst(d, 0);
-      list.addFirst(e, 0);
-
-
-      assertEquals(e, list.removeFirst());
-      assertEquals(d, list.removeFirst());
-      assertEquals(c, list.removeFirst());
-      assertEquals(b, list.removeFirst());
-      assertEquals(a, list.removeFirst());
-      assertNull(list.removeFirst());
-   }
-   
-   public void testAddLast() throws Exception
-   {
-      list.addLast(a, 0);
-      list.addLast(b, 0);
-      list.addLast(c, 0);
-      list.addLast(d, 0);
-      list.addLast(e, 0);
-      
-      assertEquals(a, list.removeFirst());
-      assertEquals(b, list.removeFirst());
-      assertEquals(c, list.removeFirst());
-      assertEquals(d, list.removeFirst());
-      assertEquals(e, list.removeFirst());
-      assertNull(list.removeFirst());
-
-   }
-   
-   
-   public void testRemoveFirst() throws Exception
-   {
-      list.addLast(a, 0);
-      list.addLast(b, 1);
-      list.addLast(c, 2);
-      list.addLast(d, 3);
-      list.addLast(e, 4);
-      list.addLast(f, 5);
-      list.addLast(g, 6);
-      list.addLast(h, 7);
-      list.addLast(i, 8);
-      list.addLast(j, 9);
-      
-      assertEquals(j, list.removeFirst());
-      assertEquals(i, list.removeFirst());
-      assertEquals(h, list.removeFirst());
-      assertEquals(g, list.removeFirst());
-      assertEquals(f, list.removeFirst());
-      assertEquals(e, list.removeFirst());
-      assertEquals(d, list.removeFirst());
-      assertEquals(c, list.removeFirst());
-      assertEquals(b, list.removeFirst());
-      assertEquals(a, list.removeFirst());
-    
-      assertNull(list.removeFirst());
-      
-      list.addLast(a, 9);
-      list.addLast(b, 8);
-      list.addLast(c, 7);
-      list.addLast(d, 6);
-      list.addLast(e, 5);
-      list.addLast(f, 4);
-      list.addLast(g, 3);
-      list.addLast(h, 2);
-      list.addLast(i, 1);
-      list.addLast(j, 0);
-      
-      assertEquals(a, list.removeFirst());
-      assertEquals(b, list.removeFirst());
-      assertEquals(c, list.removeFirst());
-      assertEquals(d, list.removeFirst());
-      assertEquals(e, list.removeFirst());
-      assertEquals(f, list.removeFirst());
-      assertEquals(g, list.removeFirst());
-      assertEquals(h, list.removeFirst());
-      assertEquals(i, list.removeFirst());
-      assertEquals(j, list.removeFirst());
-    
-      assertNull(list.removeFirst());
-      
-      list.addLast(a, 9);
-      list.addLast(b, 0);
-      list.addLast(c, 8);
-      list.addLast(d, 1);
-      list.addLast(e, 7);
-      list.addLast(f, 2);
-      list.addLast(g, 6);
-      list.addLast(h, 3);
-      list.addLast(i, 5);
-      list.addLast(j, 4);
-      
-      assertEquals(a, list.removeFirst());
-      assertEquals(c, list.removeFirst());
-      assertEquals(e, list.removeFirst());
-      assertEquals(g, list.removeFirst());
-      assertEquals(i, list.removeFirst());
-      assertEquals(j, list.removeFirst());
-      assertEquals(h, list.removeFirst());
-      assertEquals(f, list.removeFirst());
-      assertEquals(d, list.removeFirst());
-      assertEquals(b, list.removeFirst());
-      
-      assertNull(list.removeFirst());
-      
-      list.addLast(a, 0);
-      list.addLast(b, 3);
-      list.addLast(c, 3);
-      list.addLast(d, 3);
-      list.addLast(e, 6);
-      list.addLast(f, 6);
-      list.addLast(g, 6);
-      list.addLast(h, 9);
-      list.addLast(i, 9);
-      list.addLast(j, 9);
-      
-      assertEquals(h, list.removeFirst());
-      assertEquals(i, list.removeFirst());
-      assertEquals(j, list.removeFirst());
-      assertEquals(e, list.removeFirst());
-      assertEquals(f, list.removeFirst());
-      assertEquals(g, list.removeFirst());
-      assertEquals(b, list.removeFirst());
-      assertEquals(c, list.removeFirst());
-      assertEquals(d, list.removeFirst());
-      assertEquals(a, list.removeFirst());
-      
-      assertNull(list.removeFirst());
-      
-      list.addLast(a, 5);
-      list.addLast(b, 5);
-      list.addLast(c, 5);
-      list.addLast(d, 5);
-      list.addLast(e, 5);
-      list.addLast(f, 5);
-      list.addLast(g, 5);
-      list.addLast(h, 5);
-      list.addLast(i, 5);
-      list.addLast(j, 5);
-      
-      assertEquals(a, list.removeFirst());
-      assertEquals(b, list.removeFirst());
-      assertEquals(c, list.removeFirst());
-      assertEquals(d, list.removeFirst());
-      assertEquals(e, list.removeFirst());
-      assertEquals(f, list.removeFirst());
-      assertEquals(g, list.removeFirst());
-      assertEquals(h, list.removeFirst());
-      assertEquals(i, list.removeFirst());
-      assertEquals(j, list.removeFirst());
-      
-      assertNull(list.removeFirst());
-      
-      list.addLast(j, 5);
-      list.addLast(i, 5);
-      list.addLast(h, 5);
-      list.addLast(g, 5);
-      list.addLast(f, 5);
-      list.addLast(e, 5);
-      list.addLast(d, 5);
-      list.addLast(c, 5);
-      list.addLast(b, 5);
-      list.addLast(a, 5);
-      
-      assertEquals(j, list.removeFirst());
-      assertEquals(i, list.removeFirst());
-      assertEquals(h, list.removeFirst());
-      assertEquals(g, list.removeFirst());
-      assertEquals(f, list.removeFirst());
-      assertEquals(e, list.removeFirst());
-      assertEquals(d, list.removeFirst());
-      assertEquals(c, list.removeFirst());
-      assertEquals(b, list.removeFirst());
-      assertEquals(a, list.removeFirst());
-      
-      assertNull(list.removeFirst());
-      
-   }
-   
-   public void testGetAll() throws Exception
-   {
-      list.addLast(a, 0);
-      list.addLast(b, 3);
-      list.addLast(c, 3);
-      list.addLast(d, 3);
-      list.addLast(e, 6);
-      list.addLast(f, 6);
-      list.addLast(g, 6);
-      list.addLast(h, 9);
-      list.addLast(i, 9);
-      list.addLast(j, 9);
-      
-      
-      Iterator iter = list.getAll().iterator();
-      int count = 0;
-      while (iter.hasNext())
-      {
-         Object o = iter.next();
-         if (count == 0)
-         {
-            assertEquals(h, o);
-         }
-         if (count == 1)
-         {
-            assertEquals(i, o);
-         }
-         if (count == 2)
-         {
-            assertEquals(j, o);
-         }
-         if (count == 3)
-         {
-            assertEquals(e, o);
-         }
-         if (count == 4)
-         {
-            assertEquals(f, o);
-         }
-         if (count == 5)
-         {
-            assertEquals(g, o);
-         }
-         if (count == 6)
-         {
-            assertEquals(b, o);
-         }
-         if (count == 7)
-         {
-            assertEquals(c, o);
-         }
-         if (count == 8)
-         {
-            assertEquals(d, o);
-         }
-         if (count == 9)
-         {
-            assertEquals(a, o);
-         }
-         count++;
-      }
-      assertEquals(10, count);
-   }
-   
-   public void testIterator()
-   {
-      list.addLast(a, 9);
-      list.addLast(b, 9);
-      list.addLast(c, 8);
-      list.addLast(d, 8);
-      list.addLast(e, 7);
-      list.addLast(f, 7);
-      list.addLast(g, 7);
-      list.addLast(h, 6);
-      list.addLast(i, 6);
-      list.addLast(j, 6);
-      list.addLast(k, 5);
-      list.addLast(l, 5);
-      list.addLast(m, 4);
-      list.addLast(n, 4);
-      list.addLast(o, 4);
-      list.addLast(p, 3);
-      list.addLast(q, 3);
-      list.addLast(r, 3);
-      list.addLast(s, 2);
-      list.addLast(t, 2);
-      list.addLast(u, 2);
-      list.addLast(v, 1);
-      list.addLast(w, 1);
-      list.addLast(x, 1);
-      list.addLast(y, 0);
-      list.addLast(z, 0);
-      
-      ListIterator iter = list.iterator();
-      
-      int c = 0;
-      while (iter.hasNext())
-      {
-         iter.next();
-         c++;
-      }      
-      assertEquals(c, 26);
-      assertEquals(26, list.size());
-      
-      iter = list.iterator();
-      assertTrue(iter.hasNext());
-      Wibble w = (Wibble)iter.next();
-      assertEquals("a", w.s);      
-      w = (Wibble)iter.next();
-      assertEquals("b", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("c", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("d", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("e", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("f", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("g", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("h", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("i", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("j", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("k", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("l", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("m", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("n", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("o", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("p", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("q", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("r", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("s", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("t", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("u", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("v", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("w", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("x", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("y", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("z", w.s);
-      assertFalse(iter.hasNext());
-      
-      iter = list.iterator();
-      assertTrue(iter.hasNext());
-      w = (Wibble)iter.next();
-      assertEquals("a", w.s);   
-      
-      iter.remove();
-      
-      assertEquals(25, list.size());
-      
-      w = (Wibble)iter.next();
-      assertEquals("b", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("c", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("d", w.s);
-      
-      iter.remove();
-      
-      assertEquals(24, list.size());
-      
-      w = (Wibble)iter.next();
-      assertEquals("e", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("f", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("g", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("h", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("i", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("j", w.s);
-      
-      iter.remove();
-      
-      assertEquals(23, list.size());
-      
-      w = (Wibble)iter.next();
-      assertEquals("k", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("l", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("m", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("n", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("o", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("p", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("q", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("r", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("s", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("t", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("u", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("v", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("w", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("x", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("y", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("z", w.s);
-      iter.remove();
-      assertFalse(iter.hasNext());
-      
-      iter = list.iterator();
-      assertTrue(iter.hasNext());
-      w = (Wibble)iter.next();
-      assertEquals("b", w.s);   
-      w = (Wibble)iter.next();
-      assertEquals("c", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("e", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("f", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("g", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("h", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("i", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("k", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("l", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("m", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("n", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("o", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("p", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("q", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("r", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("s", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("t", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("u", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("v", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("w", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("x", w.s);
-      w = (Wibble)iter.next();
-      assertEquals("y", w.s);     
-      assertFalse(iter.hasNext());
-      
-   }
-      
-     
-   public void testClear()
-   {
-      list.addLast(a, 0);
-      list.addLast(b, 3);
-      list.addLast(c, 3);
-      list.addLast(d, 3);
-      list.addLast(e, 6);
-      list.addLast(f, 6);
-      list.addLast(g, 6);
-      list.addLast(h, 9);
-      list.addLast(i, 9);
-      list.addLast(j, 9);
-      
-      list.clear();
-      
-      assertNull(list.removeFirst());
-      
-      assertTrue(list.getAll().isEmpty());
-   }
-   
-   class Wibble
-   {
-      String s;
-      Wibble(String s)
-      {
-         this.s = s;
-      }
-      public String toString()
-      {
-         return s;
-      }
-   }
-   
-}
-

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/test/unit/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/unit/QueueTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/unit/QueueTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,1186 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * 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.core.impl.test.unit;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.jboss.messaging.core.impl.test.unit.fakes.FakeConsumer;
-import org.jboss.messaging.core.impl.test.unit.fakes.FakeFilter;
-import org.jboss.messaging.core.server.Consumer;
-import org.jboss.messaging.core.server.DistributionPolicy;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.HandleStatus;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.impl.QueueImpl;
-import org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- * 
- * A QueueTest
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class QueueTest extends UnitTestCase
-{
-   // The tests ----------------------------------------------------------------
-
-   public void testID()
-   {
-      final long id = 123;
-      
-      Queue queue = new QueueImpl(id, "queue1", null, false, true, false, -1);
-      
-      assertEquals(id, queue.getPersistenceID());
-      
-      final long id2 = 456;
-      
-      queue.setPersistenceID(id2);
-      
-      assertEquals(id2, queue.getPersistenceID());
-   }
-   
-   public void testName()
-   {
-      final String name = "oobblle";
-      
-      Queue queue = new QueueImpl(1, name, null, false, true, false, -1);
-      
-      assertEquals(name, queue.getName());
-   }
-   
-   public void testClustered()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      assertFalse(queue.isClustered());
-      
-      queue = new QueueImpl(1, "queue1", null, true, true, false, -1);
-      
-      assertTrue(queue.isClustered());
-   }
-   
-   public void testDurable()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, false, false, -1);
-      
-      assertFalse(queue.isDurable());
-      
-      queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      assertTrue(queue.isDurable());
-   }
-   
-   public void testTemporary()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, false, false, -1);
-      
-      assertFalse(queue.isTemporary());
-      
-      queue = new QueueImpl(1, "queue1", null, false, false, true, -1);
-      
-      assertTrue(queue.isTemporary());
-   }
-   
-   public void testGetSetMaxSize()
-   {
-      final int maxSize = 123456;
-      
-      final int id = 123;
-      
-      Queue queue = new QueueImpl(id, "queue1", null, false, true, false, maxSize);
-      
-      assertEquals(id, queue.getPersistenceID());
-      
-      assertEquals(maxSize, queue.getMaxSize());
-      
-      final int maxSize2 = 654321;
-      
-      queue.setMaxSize(maxSize2);
-      
-      assertEquals(maxSize2, queue.getMaxSize());
-   }
-   
-   public void testAddRemoveConsumer()
-   {
-      Consumer cons1 = new FakeConsumer();
-      
-      Consumer cons2 = new FakeConsumer();
-      
-      Consumer cons3 = new FakeConsumer();
-      
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      assertEquals(0, queue.getConsumerCount());
-      
-      queue.addConsumer(cons1);
-      
-      assertEquals(1, queue.getConsumerCount());
-      
-      assertTrue(queue.removeConsumer(cons1));
-       
-      assertEquals(0, queue.getConsumerCount());
-      
-      queue.addConsumer(cons1);
-      
-      queue.addConsumer(cons2);
-      
-      queue.addConsumer(cons3);
-      
-      assertEquals(3, queue.getConsumerCount());
-      
-      assertFalse(queue.removeConsumer(new FakeConsumer()));
-      
-      assertEquals(3, queue.getConsumerCount());
-      
-      assertTrue(queue.removeConsumer(cons1));
-      
-      assertEquals(2, queue.getConsumerCount());
-      
-      assertTrue(queue.removeConsumer(cons2));
-      
-      assertEquals(1, queue.getConsumerCount());
-      
-      assertTrue(queue.removeConsumer(cons3));
-      
-      assertEquals(0, queue.getConsumerCount());
-      
-      assertFalse(queue.removeConsumer(cons3));            
-   }
-   
-   public void testGetSetDistributionPolicy()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      assertNotNull(queue.getDistributionPolicy());
-      
-      assertTrue(queue.getDistributionPolicy() instanceof RoundRobinDistributionPolicy);
-      
-      DistributionPolicy policy = new DummyDistributionPolicy();
-      
-      queue.setDistributionPolicy(policy);
-      
-      assertEquals(policy, queue.getDistributionPolicy());
-   }
-   
-   public void testGetSetFilter()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      assertNull(queue.getFilter());
-      
-      Filter filter = new FakeFilter();
-      
-      queue.setFilter(filter);
-      
-      assertEquals(filter, queue.getFilter());
-      
-      queue = new QueueImpl(1, "queue1", filter, false, true, false, -1);
-      
-      assertEquals(filter, queue.getFilter());
-   }
-   
-   public void testDefaultMaxSize()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      assertEquals(-1, queue.getMaxSize());        
-   }
-   
-   public void testSimpleAddLast()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      final int numMessages = 10;
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(numMessages, queue.getMessageCount());
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      
-   }
-   
-   public void testSimpleDirectDelivery()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      FakeConsumer consumer = new FakeConsumer();
-      
-      queue.addConsumer(consumer);
-      
-      final int numMessages = 10;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(numMessages, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(numMessages, queue.getDeliveringCount());
-      
-      assertRefListsIdenticalRefs(refs, consumer.getReferences());      
-   }
-   
-   public void testSimpleNonDirectDelivery()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      final int numMessages = 10;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(10, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      
-      //Now add a consumer
-      FakeConsumer consumer = new FakeConsumer();
-      
-      queue.addConsumer(consumer);
-      
-      assertTrue(consumer.getReferences().isEmpty());
-      assertEquals(10, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      
-      queue.deliver();
-      
-      assertRefListsIdenticalRefs(refs, consumer.getReferences());     
-      assertEquals(numMessages, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(numMessages, queue.getDeliveringCount()); 
-   }
-   
-   public void testBusyConsumer()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      FakeConsumer consumer = new FakeConsumer();
-      
-      consumer.setStatusImmediate(HandleStatus.BUSY);
-      
-      queue.addConsumer(consumer);
-           
-      final int numMessages = 10;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(10, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      
-      queue.deliver();
-                  
-      assertEquals(10, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      assertTrue(consumer.getReferences().isEmpty());
-      
-      consumer.setStatusImmediate(HandleStatus.HANDLED);
-      
-      queue.deliver();
-      
-      assertRefListsIdenticalRefs(refs, consumer.getReferences());     
-      assertEquals(10, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(10, queue.getDeliveringCount());
-   }
-   
-   public void testBusyConsumerThenAddMoreMessages()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      FakeConsumer consumer = new FakeConsumer();
-      
-      consumer.setStatusImmediate(HandleStatus.BUSY);
-      
-      queue.addConsumer(consumer);
-           
-      final int numMessages = 10;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(10, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      
-      queue.deliver();
-                  
-      assertEquals(10, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      assertTrue(consumer.getReferences().isEmpty());
-      
-      for (int i = numMessages; i < numMessages * 2; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(20, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      assertTrue(consumer.getReferences().isEmpty());
-      
-      consumer.setStatusImmediate(HandleStatus.HANDLED);
-            
-      for (int i = numMessages * 2; i < numMessages * 3; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      queue.deliver();
-      
-      assertRefListsIdenticalRefs(refs, consumer.getReferences());     
-      assertEquals(30, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(30, queue.getDeliveringCount());
-   }
-         
-   public void testAddFirstAddLast()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      final int numMessages = 10;
-      
-      List<MessageReference> refs1 = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs1.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      LinkedList<MessageReference> refs2 = new LinkedList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i + numMessages);
-         
-         refs2.addFirst(ref);
-         
-         queue.addFirst(ref);
-      }
-      
-      List<MessageReference> refs3 = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i + 2 * numMessages);
-         
-         refs3.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      FakeConsumer consumer = new FakeConsumer();
-      
-      queue.addConsumer(consumer);
-      
-      queue.deliver();
-      
-      List<MessageReference> allRefs = new ArrayList<MessageReference>();
-      
-      allRefs.addAll(refs2);
-      allRefs.addAll(refs1);
-      allRefs.addAll(refs3);
-      
-      assertRefListsIdenticalRefs(allRefs, consumer.getReferences());      
-   }
-   
-   
-   public void testChangeConsumersAndDeliver()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-                  
-      final int numMessages = 10;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(numMessages, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      
-      FakeConsumer cons1 = new FakeConsumer();
-      
-      queue.addConsumer(cons1);
-      
-      queue.deliver();
-      
-      assertEquals(numMessages, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(numMessages, queue.getDeliveringCount());
-      
-      assertRefListsIdenticalRefs(refs, cons1.getReferences());
-      
-      FakeConsumer cons2 = new FakeConsumer();
-      
-      queue.addConsumer(cons2);
-      
-      assertEquals(2, queue.getConsumerCount());
-      
-      cons1.getReferences().clear();
-      
-      refs.clear();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         queue.decrementDeliveringCount();
-      }
-      
-      for (int i = 0; i < 2 * numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(numMessages * 2, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(numMessages * 2, queue.getDeliveringCount());
-      
-      assertEquals(numMessages, cons1.getReferences().size());
-      
-      assertEquals(numMessages, cons2.getReferences().size());
-      
-      cons1.getReferences().clear();
-      cons2.getReferences().clear();
-      refs.clear();
-      for (int i = 0; i < 2 * numMessages; i++)
-      {
-         queue.decrementDeliveringCount();
-      }
-      
-      FakeConsumer cons3 = new FakeConsumer();
-      
-      queue.addConsumer(cons3);
-      
-      assertEquals(3, queue.getConsumerCount());
-      
-      for (int i = 0; i < 3 * numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(numMessages * 3, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(numMessages * 3, queue.getDeliveringCount());
-      
-      assertEquals(numMessages, cons1.getReferences().size());
-      
-      assertEquals(numMessages, cons2.getReferences().size());
-      
-      assertEquals(numMessages, cons3.getReferences().size());
-      
-      queue.removeConsumer(cons1);
-      
-      cons3.getReferences().clear();
-      cons2.getReferences().clear();
-      refs.clear();
-      for (int i = 0; i < 3 * numMessages; i++)
-      {
-         queue.decrementDeliveringCount();
-      }
-      
-      for (int i = 0; i < 2 * numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(numMessages * 2, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(numMessages * 2, queue.getDeliveringCount());
-      
-      assertEquals(numMessages, cons2.getReferences().size());
-      
-      assertEquals(numMessages, cons3.getReferences().size());
-      
-      queue.removeConsumer(cons3);
-      
-      cons2.getReferences().clear();
-      refs.clear();
-      for (int i = 0; i < 2 * numMessages; i++)
-      {
-         queue.decrementDeliveringCount();
-      }
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(numMessages, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(numMessages, queue.getDeliveringCount());
-      
-      assertEquals(numMessages, cons2.getReferences().size());
-      
-   }
-   
-   public void testConsumerReturningNull()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      class NullConsumer implements Consumer
-      {
-         public HandleStatus handle(MessageReference reference)
-         {
-            return null;
-         }         
-      }
-      
-      queue.addConsumer(new NullConsumer());
-           
-      MessageReference ref = generateReference(queue, 1);
-         
-      try
-      {
-         queue.addLast(ref);
-         
-         fail("Should throw IllegalStateException");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }
-   }
-   
-   public void testRoundRobinWithQueueing()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      assertTrue(queue.getDistributionPolicy() instanceof RoundRobinDistributionPolicy);
-                  
-      final int numMessages = 10;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      //Test first with queueing
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      FakeConsumer cons1 = new FakeConsumer();
-      
-      FakeConsumer cons2 = new FakeConsumer();
-      
-      queue.addConsumer(cons1);
-      
-      queue.addConsumer(cons2);
-      
-      queue.deliver();
-      
-      assertEquals(numMessages / 2, cons1.getReferences().size());
-      
-      assertEquals(numMessages / 2, cons2.getReferences().size());
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref;
-         
-         ref = (i % 2 == 0) ? cons1.getReferences().get(i / 2) : cons2.getReferences().get(i / 2); 
-         
-         assertEquals(refs.get(i), ref);
-      }      
-   }
-   
-   public void testRoundRobinDirect()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      assertTrue(queue.getDistributionPolicy() instanceof RoundRobinDistributionPolicy);
-                  
-      final int numMessages = 10;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      FakeConsumer cons1 = new FakeConsumer();
-      
-      FakeConsumer cons2 = new FakeConsumer();
-      
-      queue.addConsumer(cons1);
-      
-      queue.addConsumer(cons2);
-      
-      queue.deliver();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-           
-      assertEquals(numMessages / 2, cons1.getReferences().size());
-      
-      assertEquals(numMessages / 2, cons2.getReferences().size());
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref;
-         
-         ref = (i % 2 == 0) ? cons1.getReferences().get(i / 2) : cons2.getReferences().get(i / 2); 
-         
-         assertEquals(refs.get(i), ref);
-      }      
-   }
-   
-   public void testRemoveAllReferences()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      final int numMessages = 10;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         queue.addLast(ref);
-      }
-      
-      assertEquals(numMessages, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      
-      queue.removeAllReferences();
-      
-      assertEquals(0, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      
-      FakeConsumer consumer = new FakeConsumer();
-      
-      queue.addConsumer(consumer);
-      
-      queue.deliver();
-      
-      assertTrue(consumer.getReferences().isEmpty());      
-   }
-   
-   public void testMaxSize()
-   {
-      final int maxSize = 20;
-      
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, maxSize);
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < maxSize; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         assertEquals(HandleStatus.HANDLED, queue.addLast(ref));
-      }
-      
-      assertEquals(maxSize, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      
-      //Try to add more
-      
-      for (int i = 0; i < 10; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         assertEquals(HandleStatus.BUSY, queue.addLast(ref));
-      }
-      
-      assertEquals(maxSize, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      
-      // Try to add at front too
-      
-      for (int i = 0; i < 10; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         assertEquals(HandleStatus.BUSY, queue.addLast(ref));
-      }
-    
-      //Increase the max size
-      
-      queue.setMaxSize(2 * queue.getMaxSize());
-      
-      for (int i = 0; i < maxSize; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         refs.add(ref);
-         
-         assertEquals(HandleStatus.HANDLED, queue.addLast(ref));
-      }
-      
-      assertEquals(maxSize * 2, queue.getMessageCount());   
-      assertEquals(0, queue.getScheduledCount());
-      assertEquals(0, queue.getDeliveringCount());
-      
-      //Now try and decrease maxSize
-      
-      try
-      {
-         queue.setMaxSize(maxSize);
-         
-         fail("Should throw exception");
-      }
-      catch (IllegalArgumentException e)
-      {
-         //Ok
-      }
-      
-      assertEquals(2 * maxSize, queue.getMaxSize());      
-   }
-   
-   public void testWithPriorities()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      final int numMessages = 10;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         ref.getMessage().setPriority((byte)i);
-         
-         refs.add(ref);
-         
-         assertEquals(HandleStatus.HANDLED, queue.addLast(ref));
-      }
-      
-      FakeConsumer consumer = new FakeConsumer();
-      
-      queue.addConsumer(consumer);
-      
-      queue.deliver();
-      
-      List<MessageReference> receivedRefs = consumer.getReferences();
-      
-      //Should be in reverse order
-      
-      assertEquals(refs.size(), receivedRefs.size());
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         assertEquals(refs.get(i), receivedRefs.get(9 - i));
-      }
-            
-      //But if we send more - since we are now in direct mode - the order will be the send order
-      //since the refs don't get queued
-      
-      consumer.clearReferences();
-      
-      refs.clear();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         ref.getMessage().setPriority((byte)i);
-         
-         refs.add(ref);
-         
-         assertEquals(HandleStatus.HANDLED, queue.addLast(ref));
-      }
-      
-      assertRefListsIdenticalRefs(refs, consumer.getReferences());      
-   }
-   
-   public void testConsumerWithFiltersDirect()
-   {
-      testConsumerWithFilters(true);
-   }
-   
-   public void testConsumerWithFiltersQueueing()
-   {
-      testConsumerWithFilters(false);
-   }
-   
-   public void testConsumerWithFilterAddAndRemove()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      Filter filter = new FakeFilter("fruit", "orange");
-      
-      FakeConsumer consumer = new FakeConsumer(filter);
-   }
-   
-   public void testList()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      final int numMessages = 20;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         queue.addLast(ref);
-         
-         refs.add(ref);
-      }
-      
-      assertEquals(numMessages, queue.getMessageCount());
-      
-      List<MessageReference> list = queue.list(null);
-      
-      assertRefListsIdenticalRefs(refs, list);
-   }
-   
-   public void testListWithFilter()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      final int numMessages = 20;
-      
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = generateReference(queue, i);
-         
-         if (i % 2 == 0)
-         {
-            ref.getMessage().putHeader("god", "dog");
-         }
-         
-         queue.addLast(ref);
-         
-         refs.add(ref);
-      }
-      
-      assertEquals(numMessages, queue.getMessageCount());
-      
-      Filter filter = new FakeFilter("god", "dog");
-      
-      List<MessageReference> list = queue.list(filter);
-      
-      assertEquals(numMessages / 2, list.size());
-      
-      for (int i = 0; i < numMessages; i += 2)
-      {
-         assertEquals(refs.get(i), list.get(i / 2));
-      }      
-   }
-   
-   /*
-   public void testQuickSpeedTest()
-   {
-      Queue queue = new QueueImpl(1);
-      
-      final int numMessages = 1000000;
-      
-      FakeConsumer cons = new FakeConsumer();
-      
-      queue.addConsumer(cons);
-      
-      long start = System.currentTimeMillis();
-      
-      for (int i = 0; i < numMessages; i++)
-      {
-         MessageReference ref = this.generateReference(1);
-         
-         queue.addLast(ref);
-      }
-      
-      long end = System.currentTimeMillis();
-      
-      double rate = 1000 * (double)numMessages / (end - start); 
-      
-      System.out.println("Rate: " + rate);
-      
-      assertEquals(numMessages, cons.getReferences().size());
-   }
-   */
-   
-   public void testConsumeWithFiltersAddAndRemoveConsumer()
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      Filter filter = new FakeFilter("fruit", "orange");
-      
-      FakeConsumer consumer = new FakeConsumer(filter);
-      
-      queue.addConsumer(consumer);
-                        
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      MessageReference ref1 = generateReference(queue, 1);
-      
-      ref1.getMessage().putHeader("fruit", "banana");
-      
-      assertEquals(HandleStatus.HANDLED, queue.addLast(ref1));
-      
-      MessageReference ref2 = generateReference(queue, 2);
-      
-      ref2.getMessage().putHeader("fruit", "orange");
-      
-      assertEquals(HandleStatus.HANDLED, queue.addLast(ref2));     
-      
-      refs.add(ref2);
-      
-     
-      assertEquals(2, queue.getMessageCount());
-      
-      assertEquals(1, consumer.getReferences().size());
-      
-      assertEquals(1, queue.getDeliveringCount());
-            
-      assertRefListsIdenticalRefs(refs, consumer.getReferences()); 
-      
-      queue.decrementDeliveringCount();
-
-      queue.removeConsumer(consumer);
-            
-      queue.addConsumer(consumer);
-      
-      queue.deliver();
-      
-
-      refs.clear();
-      
-      consumer.clearReferences();
-      
-      MessageReference ref3 = generateReference(queue, 3);
-      
-      ref3.getMessage().putHeader("fruit", "banana");
-      
-      assertEquals(HandleStatus.HANDLED, queue.addLast(ref3));
-      
-      MessageReference ref4 = generateReference(queue, 4);
-      
-      ref4.getMessage().putHeader("fruit", "orange");
-      
-      assertEquals(HandleStatus.HANDLED, queue.addLast(ref4)); 
-       
-      refs.add(ref4);
-      
-      assertEquals(3, queue.getMessageCount());
-      
-      assertEquals(1, consumer.getReferences().size());
-      
-      assertEquals(1, queue.getDeliveringCount());
-      
-      assertRefListsIdenticalRefs(refs, consumer.getReferences());
-   }
-   
-   // Private ------------------------------------------------------------------------------
-   
-   private void testConsumerWithFilters(boolean direct)
-   {
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      Filter filter = new FakeFilter("fruit", "orange");
-      
-      FakeConsumer consumer = new FakeConsumer(filter);
-      
-      if (direct)
-      {
-         queue.addConsumer(consumer);
-      }      
-            
-      List<MessageReference> refs = new ArrayList<MessageReference>();
-      
-      MessageReference ref1 = generateReference(queue, 1);
-      
-      ref1.getMessage().putHeader("fruit", "banana");
-      
-      assertEquals(HandleStatus.HANDLED, queue.addLast(ref1));
-      
-      MessageReference ref2 = generateReference(queue, 2);
-      
-      ref2.getMessage().putHeader("cheese", "stilton");
-      
-      assertEquals(HandleStatus.HANDLED, queue.addLast(ref2));      
-      
-      MessageReference ref3 = generateReference(queue, 3);
-      
-      ref3.getMessage().putHeader("cake", "sponge");
-      
-      assertEquals(HandleStatus.HANDLED, queue.addLast(ref3));
-            
-      MessageReference ref4 = generateReference(queue, 4);
-      
-      ref4.getMessage().putHeader("fruit", "orange");
-      
-      refs.add(ref4);
-      
-      assertEquals(HandleStatus.HANDLED, queue.addLast(ref4));      
-      
-      MessageReference ref5 = generateReference(queue, 5);
-      
-      ref5.getMessage().putHeader("fruit", "apple");
-      
-      assertEquals(HandleStatus.HANDLED, queue.addLast(ref5));
-            
-      MessageReference ref6 = generateReference(queue, 6);
-      
-      ref6.getMessage().putHeader("fruit", "orange");
-      
-      refs.add(ref6);
-      
-      assertEquals(HandleStatus.HANDLED, queue.addLast(ref6));      
-      
-      if (!direct)
-      {
-         queue.addConsumer(consumer);
-         
-         queue.deliver();
-      }
-      
-      assertEquals(6, queue.getMessageCount());
-      
-      assertEquals(2, consumer.getReferences().size());
-      
-      assertEquals(2, queue.getDeliveringCount());
-            
-      assertRefListsIdenticalRefs(refs, consumer.getReferences()); 
-      
-      queue.decrementDeliveringCount();
-      queue.decrementDeliveringCount();
-      
-      queue.removeConsumer(consumer);
-      
-      consumer = new FakeConsumer();
-      
-      queue.addConsumer(consumer);
-      
-      queue.deliver();
-      
-      assertEquals(4, queue.getMessageCount());
-      
-      assertEquals(4, consumer.getReferences().size());
-      
-      assertEquals(4, queue.getDeliveringCount());
-   }
-   
-   
-   
-  
-   
-   
-   
-   // Inner classes ---------------------------------------------------------------
-        
-   class DummyDistributionPolicy implements DistributionPolicy
-   {
-      public int select(List<Consumer> consumers, int lastPos)
-      {
-         return 0;
-      }      
-   }
-   
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/test/unit/RoundRobinDistributionPolicyTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/unit/RoundRobinDistributionPolicyTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/unit/RoundRobinDistributionPolicyTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,74 +0,0 @@
-package org.jboss.messaging.core.impl.test.unit;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.messaging.core.impl.test.unit.fakes.FakeConsumer;
-import org.jboss.messaging.core.server.Consumer;
-import org.jboss.messaging.core.server.DistributionPolicy;
-import org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- * 
- * A RoundRobinDistributionPolicyTest
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class RoundRobinDistributionPolicyTest extends UnitTestCase
-{
-
-   public void testNoConsumers()
-   {
-      List<Consumer> consumers = new ArrayList<Consumer>();
-      
-      DistributionPolicy dp = new RoundRobinDistributionPolicy();
-      
-      int pos = dp.select(consumers, -1);
-      
-      assertEquals(0, pos);
-   }
-   
-   public void testConsumers()
-   {
-      List<Consumer> consumers = new ArrayList<Consumer>();
-      
-      consumers.add(new FakeConsumer());
-      consumers.add(new FakeConsumer());
-      consumers.add(new FakeConsumer());
-      
-      DistributionPolicy dp = new RoundRobinDistributionPolicy();
-            
-      int pos = -1;
-      
-      pos = dp.select(consumers, pos);
-      
-      assertEquals(0, pos);
-      
-      pos = dp.select(consumers, pos);
-      
-      assertEquals(1, pos);
-      
-      pos = dp.select(consumers, pos);
-      
-      assertEquals(2, pos);
-      
-      pos = dp.select(consumers, pos);
-      
-      assertEquals(0, pos);
-      
-      pos = dp.select(consumers, pos);
-      
-      assertEquals(1, pos);
-      
-      pos = dp.select(consumers, pos);
-      
-      assertEquals(2, pos);
-      
-      pos = dp.select(consumers, pos);
-      
-      assertEquals(0, pos);
-   }
-   
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,355 +0,0 @@
-package org.jboss.messaging.core.impl.test.unit;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.transaction.xa.Xid;
-
-import org.easymock.EasyMock;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.PersistenceManager;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.Transaction;
-import org.jboss.messaging.core.server.TransactionSynchronization;
-import org.jboss.messaging.core.server.impl.QueueImpl;
-import org.jboss.messaging.core.server.impl.TransactionImpl;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- * 
- * A TransactionTest
- * 
- * TODO test with persistent and non persistent
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class TransactionTest extends UnitTestCase
-{
-   
-   public void test1PCCommit() throws Exception
-   {
-      List<Message> msgsToAdd = new ArrayList<Message>();
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      MessageReference ref1 = this.generateReference(queue, 1);
-      msgsToAdd.add(ref1.getMessage());
-      
-      MessageReference ref2 = this.generateReference(queue, 2);
-      refsToRemove.add(ref2);
-                  
-      Transaction tx = new TransactionImpl();
-      
-      tx.addMessage(ref1.getMessage());
-      tx.addAcknowledgement(ref2);
-      
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      pm.commitTransaction(msgsToAdd, refsToRemove);
-      
-      EasyMock.replay(pm);
-      
-      tx.commit(true, pm);
-      
-      EasyMock.verify(pm);
-      
-      assertEquals(ref1, queue.list(null).get(0));
-   }
-   
-   public void test1PCRollback() throws Exception
-   {
-      List<Message> msgsToAdd = new ArrayList<Message>();
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      MessageReference ref1 = this.generateReference(queue, 1);
-      msgsToAdd.add(ref1.getMessage());
-      
-      MessageReference ref2 = this.generateReference(queue, 2);
-      refsToRemove.add(ref2);
-                  
-      Transaction tx = new TransactionImpl();
-      tx.addMessage(ref1.getMessage());
-      tx.addAcknowledgement(ref2);
-      
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      pm.updateDeliveryCount(queue, ref2);
-      
-      EasyMock.replay(pm);
-      
-      tx.rollback(pm);
-      
-      EasyMock.verify(pm);
- 
-      assertEquals(ref2, queue.list(null).get(0));
-   }
-   
-   public void test1PCPrepare() throws Exception
-   {
-      List<Message> msgsToAdd = new ArrayList<Message>();
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      MessageReference ref1 = this.generateReference(queue, 1);
-      msgsToAdd.add(ref1.getMessage());
-      
-      MessageReference ref2 = this.generateReference(queue, 2);
-      refsToRemove.add(ref2);
-                  
-      Transaction tx = new TransactionImpl();
-      tx.addMessage(ref1.getMessage());
-      tx.addAcknowledgement(ref2);
-      
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      try
-      {
-         tx.prepare(pm);
-         fail("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //OK
-      }   
-      
-      assertTrue(queue.list(null).isEmpty());
-   }
-   
-   public void test2PCPrepareCommit() throws Exception
-   {
-      List<Message> msgsToAdd = new ArrayList<Message>();
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      MessageReference ref1 = this.generateReference(queue, 1);
-      msgsToAdd.add(ref1.getMessage());
-      
-      MessageReference ref2 = this.generateReference(queue, 2);
-      refsToRemove.add(ref2);
-      
-      Xid xid = generateXid();
-                  
-      Transaction tx = new TransactionImpl(xid);
-      tx.addMessage(ref1.getMessage());
-      tx.addAcknowledgement(ref2);
-      
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      pm.prepareTransaction(xid, msgsToAdd, refsToRemove);
-      
-      EasyMock.replay(pm);
-      
-      tx.prepare(pm);
-      
-      EasyMock.verify(pm);
-      
-      EasyMock.reset(pm);
-      
-      pm.commitPreparedTransaction(xid);
-      
-      EasyMock.replay(pm);
-      
-      tx.commit(false, pm);
-      
-      EasyMock.verify(pm);
-   }
-   
-   public void test2PCCommitBeforePrepare() throws Exception
-   {
-      List<Message> msgsToAdd = new ArrayList<Message>();
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      MessageReference ref1 = this.generateReference(queue, 1);
-      msgsToAdd.add(ref1.getMessage());
-      
-      MessageReference ref2 = this.generateReference(queue, 2);
-      refsToRemove.add(ref2);
-          
-      Xid xid = generateXid();
-      
-      Transaction tx = new TransactionImpl(xid);
-      tx.addMessage(ref1.getMessage());
-      tx.addAcknowledgement(ref2);
-      
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      try
-      {    
-         tx.commit(false, pm);
-         
-         fail ("Should throw exception");
-      }
-      catch (IllegalStateException e)
-      {
-         //Ok
-      }      
-   }
-   
-   public void test2PCPrepareRollback() throws Exception
-   {
-      List<Message> msgsToAdd = new ArrayList<Message>();
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      MessageReference ref1 = this.generateReference(queue, 1);
-      msgsToAdd.add(ref1.getMessage());
-      
-      MessageReference ref2 = this.generateReference(queue, 2);
-      refsToRemove.add(ref2);
-      
-      Xid xid = generateXid();
-                  
-      Transaction tx = new TransactionImpl(xid);
-      tx.addMessage(ref1.getMessage());
-      tx.addAcknowledgement(ref2);
-      
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      pm.prepareTransaction(xid, msgsToAdd, refsToRemove);
-      
-      EasyMock.replay(pm);
-      
-      tx.prepare(pm);
-      
-      EasyMock.verify(pm);
-      
-      EasyMock.reset(pm);
-      
-      pm.unprepareTransaction(xid, msgsToAdd, refsToRemove);
-      
-      pm.updateDeliveryCount(queue, ref2);
-      
-      EasyMock.replay(pm);
-      
-      tx.rollback(pm);
-      
-      EasyMock.verify(pm);
-   }
-   
-   public void testSynchronizations() throws Exception
-   {
-      List<Message> msgsToAdd = new ArrayList<Message>();
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      MessageReference ref1 = this.generateReference(queue, 1);
-      msgsToAdd.add(ref1.getMessage());
-      
-      MessageReference ref2 = this.generateReference(queue, 2);
-      refsToRemove.add(ref2);
-                  
-      Transaction tx = new TransactionImpl();
-      tx.addMessage(ref1.getMessage());
-      tx.addAcknowledgement(ref2);
-      
-      TransactionSynchronization sync = EasyMock.createStrictMock(TransactionSynchronization.class);
-      
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      tx.addSynchronization(sync);
-      
-      sync.beforeCommit();
-      sync.afterCommit();
-      
-      EasyMock.replay(sync);
-      
-      tx.commit(true, pm);
-      
-      EasyMock.verify(sync);
-      
-      EasyMock.reset(sync);
-      
-      tx = new TransactionImpl();
-      tx.addMessage(ref1.getMessage());
-      tx.addAcknowledgement(ref2);
-      
-      tx.addSynchronization(sync);
-      
-      sync.beforeRollback();
-      sync.afterRollback();
-      
-      EasyMock.replay(sync);
-      
-      tx.rollback(pm);
-      
-      EasyMock.verify(sync);            
-   }
-   
-   public void testSynchronizations2PC() throws Exception
-   {
-      List<Message> msgsToAdd = new ArrayList<Message>();
-      
-      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
-      
-      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1);
-      
-      MessageReference ref1 = this.generateReference(queue, 1);
-      msgsToAdd.add(ref1.getMessage());
-      
-      MessageReference ref2 = this.generateReference(queue, 2);
-      refsToRemove.add(ref2);
-      
-      Xid xid = generateXid();
-                  
-      Transaction tx = new TransactionImpl(xid);
-      tx.addMessage(ref1.getMessage());
-      tx.addAcknowledgement(ref2);
-      
-      TransactionSynchronization sync = EasyMock.createStrictMock(TransactionSynchronization.class);
-      
-      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
-      
-      tx.addSynchronization(sync);
-      
-      sync.beforeCommit();
-      sync.afterCommit();
-      
-      EasyMock.replay(sync);
-      
-      tx.prepare(pm);
-      tx.commit(false, pm);
-      
-      EasyMock.verify(sync);
-      
-      EasyMock.reset(sync);
-      
-      xid = generateXid();
-      
-      tx = new TransactionImpl(xid);
-      tx.addMessage(ref1.getMessage());
-      tx.addAcknowledgement(ref2);
-      
-      tx.addSynchronization(sync);
-      
-      sync.beforeRollback();
-      sync.afterRollback();
-      
-      EasyMock.replay(sync);
-      
-      tx.prepare(pm);
-      tx.rollback(pm);
-      
-      EasyMock.verify(sync);            
-   }
-   
-   // Inner classes -----------------------------------------------------------------------
-   
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/test/unit/fakes/FakeConsumer.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/unit/fakes/FakeConsumer.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/unit/fakes/FakeConsumer.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,144 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * 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.core.impl.test.unit.fakes;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.jboss.messaging.core.server.Consumer;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.HandleStatus;
-import org.jboss.messaging.core.server.MessageReference;
-
-/**
- * 
- * A FakeConsumer
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class FakeConsumer implements Consumer
-{
-   private HandleStatus statusToReturn = HandleStatus.HANDLED;
-   
-   private HandleStatus newStatus;
-   
-   private int delayCountdown = 0;
-   
-   private LinkedList<MessageReference> references = new LinkedList<MessageReference>();
-   
-   private Filter filter;
-   
-   public FakeConsumer()
-   {         
-   }
-   
-   public FakeConsumer(Filter filter)
-   {
-      this.filter = filter;
-   }
-   
-   public synchronized MessageReference waitForNextReference(long timeout)
-   {
-      while (references.isEmpty() && timeout > 0)
-      {
-         long start = System.currentTimeMillis(); 
-         try
-         {
-            wait();
-         }
-         catch (InterruptedException e)
-         {                 
-         }
-         timeout -= (System.currentTimeMillis() - start);
-      }
-      
-      if (timeout <= 0)
-      {
-         throw new IllegalStateException("Timed out waiting for reference");
-      }
-      
-      return references.removeFirst();
-   }
-   
-   public synchronized void setStatusImmediate(HandleStatus newStatus)
-   {
-      this.statusToReturn = newStatus;
-   }
-   
-   public synchronized void setStatusDelayed(HandleStatus newStatus, int numReferences)
-   {
-      this.newStatus = newStatus;
-      
-      this.delayCountdown = numReferences;
-   }
-   
-   public synchronized List<MessageReference> getReferences()
-   {
-      return references;
-   }
-   
-   public synchronized void clearReferences()
-   {
-      this.references.clear();
-   }
-   
-   public synchronized HandleStatus handle(MessageReference reference)
-   {
-      if (filter != null)
-      {
-         if (filter.match(reference.getMessage()))
-         {
-            references.addLast(reference);
-            notify();
-            
-            return HandleStatus.HANDLED;
-         }
-         else
-         {
-            return HandleStatus.NO_MATCH;
-         }
-      }
-      
-      if (newStatus != null)
-      {           
-         if (delayCountdown == 0)
-         {
-            statusToReturn = newStatus;
-            
-            newStatus = null;
-         }
-         else
-         {            
-            delayCountdown--;
-         }
-      }
-      
-      if (statusToReturn == HandleStatus.HANDLED)
-      {
-         references.addLast(reference);
-         notify();
-      }
-      
-      return statusToReturn;
-   }
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/impl/test/unit/fakes/FakeFilter.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/unit/fakes/FakeFilter.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/unit/fakes/FakeFilter.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * 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.core.impl.test.unit.fakes;
-
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
-
-/**
- * 
- * A FakeFilter
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class FakeFilter implements Filter
-{
-   private String headerName;
-   
-   private Object headerValue;
-         
-   public FakeFilter(String headerName, Object headerValue)
-   {
-      this.headerName = headerName;
-      
-      this.headerValue = headerValue;
-   }
-   
-   public FakeFilter()
-   {         
-   }
-   
-   public boolean match(Message message)
-   {
-      if (headerName != null)
-      {
-         Object value = message.getHeader(headerName);
-         
-         if (value != null && headerValue.equals(value))
-         {
-            return true;
-         }
-         
-         return false;
-      }
-      
-      return true;
-   }
-
-   public String getFilterString()
-   {
-      return null;
-   }      
-}

Copied: trunk/tests/src/org/jboss/messaging/core/list/impl/test/unit/PriorityLinkedListTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/test/unit/PriorityLinkedListTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/list/impl/test/unit/PriorityLinkedListTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/list/impl/test/unit/PriorityLinkedListTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,607 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * 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.core.list.impl.test.unit;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+
+import org.jboss.messaging.core.list.PriorityLinkedList;
+import org.jboss.messaging.core.list.impl.PriorityLinkedListImpl;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ * @author <a href="tim.fox at jboss.com>Tim Fox</a>
+ *
+ * $Id$
+ */
+public class PriorityLinkedListTest extends UnitTestCase
+{
+   protected PriorityLinkedList<Wibble> list;
+   
+   protected Wibble a;
+   protected Wibble b;
+   protected Wibble c;
+   protected Wibble d;
+   protected Wibble e;   
+   protected Wibble f;
+   protected Wibble g;
+   protected Wibble h;
+   protected Wibble i;
+   protected Wibble j;
+   protected Wibble k;
+   protected Wibble l;
+   protected Wibble m;
+   protected Wibble n;
+   protected Wibble o;   
+   protected Wibble p;
+   protected Wibble q;
+   protected Wibble r;
+   protected Wibble s;
+   protected Wibble t;
+   protected Wibble u;
+   protected Wibble v;
+   protected Wibble w;
+   protected Wibble x;
+   protected Wibble y;   
+   protected Wibble z;
+   
+   public void setUp() throws Exception
+   {
+      super.setUp();
+      
+      list = new PriorityLinkedListImpl<Wibble>(10);
+      
+      a = new Wibble("a");
+      b = new Wibble("b");
+      c = new Wibble("c");
+      d = new Wibble("d");
+      e = new Wibble("e");
+      f = new Wibble("f");
+      g = new Wibble("g");
+      h = new Wibble("h");
+      i = new Wibble("i");
+      j = new Wibble("j");
+      k = new Wibble("k");
+      l = new Wibble("l");
+      m = new Wibble("m");
+      n = new Wibble("n");
+      o = new Wibble("o");
+      p = new Wibble("p");
+      q = new Wibble("q");
+      r = new Wibble("r");
+      s = new Wibble("s");
+      t = new Wibble("t");
+      u = new Wibble("u");
+      v = new Wibble("v");
+      w = new Wibble("w");
+      x = new Wibble("x");
+      y = new Wibble("y");
+      z = new Wibble("z");
+   }
+   
+   
+   public void tearDown() throws Exception
+   {
+      super.tearDown();
+   }
+         
+   public void testAddFirst() throws Exception
+   {
+      list.addFirst(a, 0);
+      list.addFirst(b, 0);
+      list.addFirst(c, 0);
+      list.addFirst(d, 0);
+      list.addFirst(e, 0);
+
+
+      assertEquals(e, list.removeFirst());
+      assertEquals(d, list.removeFirst());
+      assertEquals(c, list.removeFirst());
+      assertEquals(b, list.removeFirst());
+      assertEquals(a, list.removeFirst());
+      assertNull(list.removeFirst());
+   }
+   
+   public void testAddLast() throws Exception
+   {
+      list.addLast(a, 0);
+      list.addLast(b, 0);
+      list.addLast(c, 0);
+      list.addLast(d, 0);
+      list.addLast(e, 0);
+      
+      assertEquals(a, list.removeFirst());
+      assertEquals(b, list.removeFirst());
+      assertEquals(c, list.removeFirst());
+      assertEquals(d, list.removeFirst());
+      assertEquals(e, list.removeFirst());
+      assertNull(list.removeFirst());
+
+   }
+   
+   
+   public void testRemoveFirst() throws Exception
+   {
+      list.addLast(a, 0);
+      list.addLast(b, 1);
+      list.addLast(c, 2);
+      list.addLast(d, 3);
+      list.addLast(e, 4);
+      list.addLast(f, 5);
+      list.addLast(g, 6);
+      list.addLast(h, 7);
+      list.addLast(i, 8);
+      list.addLast(j, 9);
+      
+      assertEquals(j, list.removeFirst());
+      assertEquals(i, list.removeFirst());
+      assertEquals(h, list.removeFirst());
+      assertEquals(g, list.removeFirst());
+      assertEquals(f, list.removeFirst());
+      assertEquals(e, list.removeFirst());
+      assertEquals(d, list.removeFirst());
+      assertEquals(c, list.removeFirst());
+      assertEquals(b, list.removeFirst());
+      assertEquals(a, list.removeFirst());
+    
+      assertNull(list.removeFirst());
+      
+      list.addLast(a, 9);
+      list.addLast(b, 8);
+      list.addLast(c, 7);
+      list.addLast(d, 6);
+      list.addLast(e, 5);
+      list.addLast(f, 4);
+      list.addLast(g, 3);
+      list.addLast(h, 2);
+      list.addLast(i, 1);
+      list.addLast(j, 0);
+      
+      assertEquals(a, list.removeFirst());
+      assertEquals(b, list.removeFirst());
+      assertEquals(c, list.removeFirst());
+      assertEquals(d, list.removeFirst());
+      assertEquals(e, list.removeFirst());
+      assertEquals(f, list.removeFirst());
+      assertEquals(g, list.removeFirst());
+      assertEquals(h, list.removeFirst());
+      assertEquals(i, list.removeFirst());
+      assertEquals(j, list.removeFirst());
+    
+      assertNull(list.removeFirst());
+      
+      list.addLast(a, 9);
+      list.addLast(b, 0);
+      list.addLast(c, 8);
+      list.addLast(d, 1);
+      list.addLast(e, 7);
+      list.addLast(f, 2);
+      list.addLast(g, 6);
+      list.addLast(h, 3);
+      list.addLast(i, 5);
+      list.addLast(j, 4);
+      
+      assertEquals(a, list.removeFirst());
+      assertEquals(c, list.removeFirst());
+      assertEquals(e, list.removeFirst());
+      assertEquals(g, list.removeFirst());
+      assertEquals(i, list.removeFirst());
+      assertEquals(j, list.removeFirst());
+      assertEquals(h, list.removeFirst());
+      assertEquals(f, list.removeFirst());
+      assertEquals(d, list.removeFirst());
+      assertEquals(b, list.removeFirst());
+      
+      assertNull(list.removeFirst());
+      
+      list.addLast(a, 0);
+      list.addLast(b, 3);
+      list.addLast(c, 3);
+      list.addLast(d, 3);
+      list.addLast(e, 6);
+      list.addLast(f, 6);
+      list.addLast(g, 6);
+      list.addLast(h, 9);
+      list.addLast(i, 9);
+      list.addLast(j, 9);
+      
+      assertEquals(h, list.removeFirst());
+      assertEquals(i, list.removeFirst());
+      assertEquals(j, list.removeFirst());
+      assertEquals(e, list.removeFirst());
+      assertEquals(f, list.removeFirst());
+      assertEquals(g, list.removeFirst());
+      assertEquals(b, list.removeFirst());
+      assertEquals(c, list.removeFirst());
+      assertEquals(d, list.removeFirst());
+      assertEquals(a, list.removeFirst());
+      
+      assertNull(list.removeFirst());
+      
+      list.addLast(a, 5);
+      list.addLast(b, 5);
+      list.addLast(c, 5);
+      list.addLast(d, 5);
+      list.addLast(e, 5);
+      list.addLast(f, 5);
+      list.addLast(g, 5);
+      list.addLast(h, 5);
+      list.addLast(i, 5);
+      list.addLast(j, 5);
+      
+      assertEquals(a, list.removeFirst());
+      assertEquals(b, list.removeFirst());
+      assertEquals(c, list.removeFirst());
+      assertEquals(d, list.removeFirst());
+      assertEquals(e, list.removeFirst());
+      assertEquals(f, list.removeFirst());
+      assertEquals(g, list.removeFirst());
+      assertEquals(h, list.removeFirst());
+      assertEquals(i, list.removeFirst());
+      assertEquals(j, list.removeFirst());
+      
+      assertNull(list.removeFirst());
+      
+      list.addLast(j, 5);
+      list.addLast(i, 5);
+      list.addLast(h, 5);
+      list.addLast(g, 5);
+      list.addLast(f, 5);
+      list.addLast(e, 5);
+      list.addLast(d, 5);
+      list.addLast(c, 5);
+      list.addLast(b, 5);
+      list.addLast(a, 5);
+      
+      assertEquals(j, list.removeFirst());
+      assertEquals(i, list.removeFirst());
+      assertEquals(h, list.removeFirst());
+      assertEquals(g, list.removeFirst());
+      assertEquals(f, list.removeFirst());
+      assertEquals(e, list.removeFirst());
+      assertEquals(d, list.removeFirst());
+      assertEquals(c, list.removeFirst());
+      assertEquals(b, list.removeFirst());
+      assertEquals(a, list.removeFirst());
+      
+      assertNull(list.removeFirst());
+      
+   }
+   
+   public void testGetAll() throws Exception
+   {
+      list.addLast(a, 0);
+      list.addLast(b, 3);
+      list.addLast(c, 3);
+      list.addLast(d, 3);
+      list.addLast(e, 6);
+      list.addLast(f, 6);
+      list.addLast(g, 6);
+      list.addLast(h, 9);
+      list.addLast(i, 9);
+      list.addLast(j, 9);
+      
+      
+      Iterator iter = list.getAll().iterator();
+      int count = 0;
+      while (iter.hasNext())
+      {
+         Object o = iter.next();
+         if (count == 0)
+         {
+            assertEquals(h, o);
+         }
+         if (count == 1)
+         {
+            assertEquals(i, o);
+         }
+         if (count == 2)
+         {
+            assertEquals(j, o);
+         }
+         if (count == 3)
+         {
+            assertEquals(e, o);
+         }
+         if (count == 4)
+         {
+            assertEquals(f, o);
+         }
+         if (count == 5)
+         {
+            assertEquals(g, o);
+         }
+         if (count == 6)
+         {
+            assertEquals(b, o);
+         }
+         if (count == 7)
+         {
+            assertEquals(c, o);
+         }
+         if (count == 8)
+         {
+            assertEquals(d, o);
+         }
+         if (count == 9)
+         {
+            assertEquals(a, o);
+         }
+         count++;
+      }
+      assertEquals(10, count);
+   }
+   
+   public void testIterator()
+   {
+      list.addLast(a, 9);
+      list.addLast(b, 9);
+      list.addLast(c, 8);
+      list.addLast(d, 8);
+      list.addLast(e, 7);
+      list.addLast(f, 7);
+      list.addLast(g, 7);
+      list.addLast(h, 6);
+      list.addLast(i, 6);
+      list.addLast(j, 6);
+      list.addLast(k, 5);
+      list.addLast(l, 5);
+      list.addLast(m, 4);
+      list.addLast(n, 4);
+      list.addLast(o, 4);
+      list.addLast(p, 3);
+      list.addLast(q, 3);
+      list.addLast(r, 3);
+      list.addLast(s, 2);
+      list.addLast(t, 2);
+      list.addLast(u, 2);
+      list.addLast(v, 1);
+      list.addLast(w, 1);
+      list.addLast(x, 1);
+      list.addLast(y, 0);
+      list.addLast(z, 0);
+      
+      ListIterator iter = list.iterator();
+      
+      int c = 0;
+      while (iter.hasNext())
+      {
+         iter.next();
+         c++;
+      }      
+      assertEquals(c, 26);
+      assertEquals(26, list.size());
+      
+      iter = list.iterator();
+      assertTrue(iter.hasNext());
+      Wibble w = (Wibble)iter.next();
+      assertEquals("a", w.s);      
+      w = (Wibble)iter.next();
+      assertEquals("b", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("c", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("d", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("e", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("f", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("g", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("h", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("i", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("j", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("k", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("l", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("m", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("n", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("o", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("p", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("q", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("r", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("s", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("t", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("u", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("v", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("w", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("x", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("y", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("z", w.s);
+      assertFalse(iter.hasNext());
+      
+      iter = list.iterator();
+      assertTrue(iter.hasNext());
+      w = (Wibble)iter.next();
+      assertEquals("a", w.s);   
+      
+      iter.remove();
+      
+      assertEquals(25, list.size());
+      
+      w = (Wibble)iter.next();
+      assertEquals("b", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("c", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("d", w.s);
+      
+      iter.remove();
+      
+      assertEquals(24, list.size());
+      
+      w = (Wibble)iter.next();
+      assertEquals("e", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("f", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("g", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("h", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("i", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("j", w.s);
+      
+      iter.remove();
+      
+      assertEquals(23, list.size());
+      
+      w = (Wibble)iter.next();
+      assertEquals("k", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("l", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("m", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("n", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("o", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("p", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("q", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("r", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("s", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("t", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("u", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("v", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("w", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("x", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("y", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("z", w.s);
+      iter.remove();
+      assertFalse(iter.hasNext());
+      
+      iter = list.iterator();
+      assertTrue(iter.hasNext());
+      w = (Wibble)iter.next();
+      assertEquals("b", w.s);   
+      w = (Wibble)iter.next();
+      assertEquals("c", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("e", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("f", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("g", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("h", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("i", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("k", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("l", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("m", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("n", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("o", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("p", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("q", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("r", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("s", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("t", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("u", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("v", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("w", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("x", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("y", w.s);     
+      assertFalse(iter.hasNext());
+      
+   }
+      
+     
+   public void testClear()
+   {
+      list.addLast(a, 0);
+      list.addLast(b, 3);
+      list.addLast(c, 3);
+      list.addLast(d, 3);
+      list.addLast(e, 6);
+      list.addLast(f, 6);
+      list.addLast(g, 6);
+      list.addLast(h, 9);
+      list.addLast(i, 9);
+      list.addLast(j, 9);
+      
+      list.clear();
+      
+      assertNull(list.removeFirst());
+      
+      assertTrue(list.getAll().isEmpty());
+   }
+   
+   class Wibble
+   {
+      String s;
+      Wibble(String s)
+      {
+         this.s = s;
+      }
+      public String toString()
+      {
+         return s;
+      }
+   }
+   
+}
+

Copied: trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/test/unit/BDBSpeedTest.java (from rev 3798, trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/BDBSpeedTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/test/unit/BDBSpeedTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/test/unit/BDBSpeedTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,647 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.core.persistence.impl.bdbje.integration.test.unit;
+
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ * 
+ * A BDBSpeedTest
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class BDBSpeedTest extends UnitTestCase
+{
+   
+   public void test1()
+   {      
+   }
+   
+//   public void testCommitMessage() throws Exception
+//   {
+//      String envPath = "/home/tim/test-env";
+//      
+//      File file = new File(envPath);
+//      
+//      deleteDirectory(file);
+//      
+//      file.mkdir();
+//      
+//      final int numMessages = 5000;
+//      
+//      final int numRefs = 10;
+//      
+//      BDBJEPersistenceManager2 bdb = new BDBJEPersistenceManager2(envPath);
+//      
+//      bdb.start();
+//      
+//      Queue queue = new QueueImpl(1);
+//      
+//      //List<Message> messages = new ArrayList<Message>();
+//      
+//      long start = System.currentTimeMillis();
+//      
+//      byte[] payload = new byte[1 * 1024];
+//      
+//      for (int i = 0; i < numMessages; i++)
+//      {
+//         Message message = new MessageImpl(i, 0, true, 0, System.currentTimeMillis(), (byte)4);
+//         
+//         for (int j = 0; j < numRefs; j++)
+//         {
+//            message.createReference(queue);
+//            
+//            message.setPayload(payload);
+//         }
+//         
+//         //messages.add(message);
+//         
+//         bdb.commitMessage(message);
+//      }
+//      
+//      long end = System.currentTimeMillis();
+//      
+//      double rate = 1000 * (double)numMessages / (end - start);
+//      
+//      System.out.println("Insert Rate: " + rate);
+//      
+//   }
+//   
+//   public void testCommitMessages() throws Exception
+//   {
+//      String envPath = "/home/tim/test-env";
+//      
+//      File file = new File(envPath);
+//      
+//      deleteDirectory(file);
+//      
+//      file.mkdir();
+//      
+//      final int numMessages = 5000;
+//      
+//      final int numRefs = 10;
+//      
+//      BDBJEPersistenceManager2 bdb = new BDBJEPersistenceManager2(envPath);
+//      
+//      bdb.start();
+//      
+//      Queue queue = new QueueImpl(1);
+//      
+//      List<Message> messages = new ArrayList<Message>();
+//      
+//      long start = System.currentTimeMillis();
+//      
+//      byte[] payload = new byte[1 * 1024];
+//                  
+//      for (int i = 0; i < numMessages; i++)
+//      {
+//         Message message = new MessageImpl(i, 0, true, 0, System.currentTimeMillis(), (byte)4);
+//         
+//         for (int j = 0; j < numRefs; j++)
+//         {
+//            message.createReference(queue);
+//            
+//            message.setPayload(payload);
+//         }
+//         
+//         messages.add(message);
+//         
+//         if (i % 100 == 0)
+//         {
+//            bdb.commitMessages(messages);
+//            
+//            messages.clear();
+//         }         
+//      }
+//      bdb.commitMessages(messages);
+//      
+//      long end = System.currentTimeMillis();
+//      
+//      double rate = 1000 * (double)numMessages / (end - start);
+//      
+//      System.out.println("Insert Rate: " + rate);
+//      
+//   }
+//   
+//   public void testDeleteReferences() throws Exception
+//   {
+//      String envPath = "/home/tim/test-env";
+//      
+//      File file = new File(envPath);
+//      
+//      deleteDirectory(file);
+//      
+//      file.mkdir();
+//      
+//      final int numMessages = 5000;
+//      
+//      final int numRefs = 10;
+//      
+//      BDBJEPersistenceManager2 bdb = new BDBJEPersistenceManager2(envPath);
+//      
+//      bdb.start();
+//      
+//      Queue queue = new QueueImpl(1);
+//      
+//      List<Message> messages = new ArrayList<Message>();
+//      
+//      byte[] payload = new byte[1 * 1024];
+//      
+//      List<MessageReference> refs = new ArrayList<MessageReference>();
+//                  
+//      for (int i = 0; i < numMessages; i++)
+//      {
+//         Message message = new MessageImpl(i, 0, true, 0, System.currentTimeMillis(), (byte)4);
+//         
+//         for (int j = 0; j < numRefs; j++)
+//         {
+//            MessageReference ref = message.createReference(queue);
+//            
+//            message.setPayload(payload);
+//            
+//            refs.add(ref);
+//         }
+//         
+//         messages.add(message);
+//         
+//         if (i % 100 == 0)
+//         {
+//            bdb.commitMessages(messages);
+//            
+//            messages.clear();
+//         }         
+//      }
+//      bdb.commitMessages(messages);
+//      
+//      long start = System.currentTimeMillis();
+//      
+//      //Now delete them
+//      
+//      bdb.deleteReferences(refs);      
+//      
+//      long end = System.currentTimeMillis();
+//      
+//      double rate = 1000 * (double)numMessages / (end - start);
+//      
+//      System.out.println("Delete Rate: " + rate);
+//      
+//   }
+//   
+//   public void testDeleteReference() throws Exception
+//   {
+//      String envPath = "/home/tim/test-env";
+//      
+//      File file = new File(envPath);
+//      
+//      deleteDirectory(file);
+//      
+//      file.mkdir();
+//      
+//      final int numMessages = 5000;
+//      
+//      final int numRefs = 1;
+//      
+//      BDBJEPersistenceManager bdb = new BDBJEPersistenceManager(envPath);
+//      
+//      bdb.start();
+//      
+//      Queue queue = new QueueImpl(1);
+//      
+//      List<Message> messages = new ArrayList<Message>();
+//      
+//      byte[] payload = new byte[1 * 1024];
+//      
+//      List<MessageReference> refs = new ArrayList<MessageReference>();
+//                  
+//      for (int i = 0; i < numMessages; i++)
+//      {
+//         Message message = new MessageImpl(i, 0, true, 0, System.currentTimeMillis(), (byte)4);
+//         
+//         for (int j = 0; j < numRefs; j++)
+//         {
+//            MessageReference ref = message.createReference(queue);
+//            
+//            message.setPayload(payload);
+//            
+//            refs.add(ref);
+//         }
+//         
+//         messages.add(message);
+//         
+//         if (i % 100 == 0)
+//         {
+//            bdb.commitMessages(messages);
+//            
+//            messages.clear();
+//         }         
+//      }
+//      bdb.commitMessages(messages);
+//      
+//      System.out.println("Added them");
+//      
+//      long start = System.currentTimeMillis();
+//      
+//      //Now delete them
+//      
+//      for (MessageReference ref: refs)
+//      {      
+//         bdb.deleteReference(ref);
+//      }
+//      
+//      long end = System.currentTimeMillis();
+//      
+//      double rate = 1000 * (double)numMessages / (end - start);
+//      
+//      System.out.println("Delete Rate: " + rate);
+//      
+//   }
+//   
+//   
+//   public void testPrepareMessages() throws Exception
+//   {
+//      String envPath = "/home/tim/test-env";
+//      
+//      File file = new File(envPath);
+//      
+//      deleteDirectory(file);
+//      
+//      file.mkdir();
+//      
+//      final int numMessages = 5000;
+//      
+//      final int numRefs = 10;
+//      
+//      BDBJEPersistenceManager2 bdb = new BDBJEPersistenceManager2(envPath);
+//      
+//      bdb.start();
+//      
+//      Queue queue = new QueueImpl(1);
+//      
+//      List<Message> messages = new ArrayList<Message>();
+//      
+//      long start = System.currentTimeMillis();
+//      
+//      byte[] payload = new byte[1 * 1024];
+//                  
+//      for (int i = 0; i < numMessages; i++)
+//      {
+//         Message message = new MessageImpl(i, 0, true, 0, System.currentTimeMillis(), (byte)4);
+//         
+//         for (int j = 0; j < numRefs; j++)
+//         {
+//            message.createReference(queue);
+//            
+//            message.setPayload(payload);
+//         }
+//         
+//         messages.add(message);
+//         
+//         if (i % 100 == 0)
+//         {
+//            Xid xid = this.generateXid();
+//            
+//            bdb.prepareMessages(xid, messages);
+//            
+//            bdb.commitPreparedMessages(xid);
+//            
+//            messages.clear();
+//         }         
+//      }
+//      
+//      Xid xid = this.generateXid();
+//      
+//      bdb.prepareMessages(xid, messages);
+//      
+//      bdb.commitPreparedMessages(xid);
+//      
+//      long end = System.currentTimeMillis();
+//      
+//      double rate = 1000 * (double)numMessages / (end - start);
+//      
+//      System.out.println("Insert Rate: " + rate);
+//      
+//   }
+   
+//   /*
+//    * Test with message and ref in separate databases
+//    */
+//   public void testMsgandRefsDifferentDBSNoXA() throws Exception
+//   {
+//      File file = new File("/home/tim/test-env");
+//      
+//      deleteDirectory(file);
+//      
+//      file.mkdir();
+//      
+//      EnvironmentConfig envConfig = new EnvironmentConfig();
+//        
+//      envConfig.setAllowCreate(true);
+//      
+//      envConfig.setTransactional(true);
+//      
+////      envConfig.setTxnNoSync(true);
+////      
+////      envConfig.setTxnWriteNoSync(true);
+//      
+//      Environment env1 = new Environment(file, envConfig);
+//
+//      DatabaseConfig dbConfig1 = new DatabaseConfig();
+//      
+//      dbConfig1.setTransactional(true);
+//      
+//      dbConfig1.setAllowCreate(true);
+//      
+//      Database msgDB = env1.openDatabase(null, "message", dbConfig1);
+//      
+//      DatabaseConfig dbConfig2 = new DatabaseConfig();
+//      
+//      dbConfig2.setTransactional(true);
+//      
+//      dbConfig2.setAllowCreate(true);
+//      
+//      Database refDB = env1.openDatabase(null, "ref", dbConfig2);
+//      
+//      
+//      DatabaseConfig dbConfig3 = new DatabaseConfig();
+//      
+//      dbConfig3.setTransactional(true);
+//      
+//      dbConfig3.setAllowCreate(true);
+//      
+//      Database txDB = env1.openDatabase(null, "tx", dbConfig3);
+//      
+//      
+//      
+//      final int numMessages = 5000;
+//      
+//      byte[] msgBytes = new byte[256];
+//      
+//      final int numRefs = 10;
+//      
+//      byte[] refBytes = new byte[numRefs * 20];
+//      
+//      byte[] txBytes = new byte[numRefs * 50];
+//      
+//      
+//      long start = System.currentTimeMillis();
+//      
+//      for (int i = 0; i < numMessages; i++)
+//      {
+//         byte[] keyBytes = new byte[8];
+//         
+//         ByteBuffer buffer = ByteBuffer.wrap(keyBytes);
+//         
+//         buffer.putLong(i);
+//         
+//         DatabaseEntry key = new DatabaseEntry(keyBytes);
+//         
+//         
+//         //Prepare refs
+//         
+//         DatabaseEntry refVal = new DatabaseEntry(refBytes);
+//         
+//         Transaction tx = env1.beginTransaction(null, null);
+//                  
+//         refDB.put(tx, key, refVal);
+//         
+//         // Message
+//         
+//         DatabaseEntry msgVal = new DatabaseEntry(msgBytes);
+//         
+//         msgDB.put(tx, key, msgVal);
+//         
+//         //Write a tx record
+//         
+//         DatabaseEntry txVal = new DatabaseEntry(txBytes);
+//         
+//         txDB.put(tx, key, txVal);
+//               
+//         //Commit the prepare
+//         
+//         tx.commit();    
+//         
+//         tx = env1.beginTransaction(null, null);
+//         
+//         //Now commit the refs
+//                  
+//         refVal = new DatabaseEntry(refBytes);
+//         
+//         refDB.put(tx, key, refVal);
+//         
+//         //And delete the tx record
+//         
+//         txDB.delete(tx, key);
+//                  
+//         tx.commit();         
+//      }
+//      
+//      long end = System.currentTimeMillis();
+//      
+//      double rate = 1000 * (double)numMessages / (end - start);
+//      
+//      System.out.println("Insert Rate: " + rate);
+//      
+//    
+//   }
+//   
+//   public void testMsgandRefsDifferentDBSXA() throws Exception
+//   {
+//      File file = new File("/home/tim/test-env");
+//      
+//      deleteDirectory(file);
+//      
+//      file.mkdir();
+//      
+//      EnvironmentConfig envConfig = new EnvironmentConfig();
+//        
+//      envConfig.setAllowCreate(true);
+//      
+//      envConfig.setTransactional(true);
+//      
+//      XAEnvironment env1 = new XAEnvironment(file, envConfig);
+//
+//      DatabaseConfig dbConfig1 = new DatabaseConfig();
+//      
+//      dbConfig1.setTransactional(true);
+//      
+//      dbConfig1.setAllowCreate(true);
+//      
+//      Database msgDB = env1.openDatabase(null, "message", dbConfig1);
+//      
+//      DatabaseConfig dbConfig2 = new DatabaseConfig();
+//      
+//      dbConfig2.setTransactional(true);
+//      
+//      dbConfig2.setAllowCreate(true);
+//      
+//      Database refDB = env1.openDatabase(null, "ref", dbConfig2);
+//      
+//      
+//      
+//      final int numMessages = 5000;
+//      
+//      byte[] msgBytes = new byte[256];
+//      
+//      final int numRefs = 10;
+//      
+//      byte[] refBytes = new byte[numRefs * 20];
+//      
+//      long start = System.currentTimeMillis();
+//      
+//      for (int i = 0; i < numMessages; i++)
+//      {
+//         Xid xid = generateXid();
+//         
+//         env1.start(xid, XAResource.TMNOFLAGS);
+//         
+//         byte[] keyBytes = new byte[8];
+//         
+//         ByteBuffer buffer = ByteBuffer.wrap(keyBytes);
+//         
+//         buffer.putLong(i);
+//         
+//         DatabaseEntry key = new DatabaseEntry(keyBytes);
+//         
+//         DatabaseEntry msgVal = new DatabaseEntry(msgBytes);
+//         
+//         Transaction tx = env1.beginTransaction(null, null);
+//         
+//         msgDB.put(null, key, msgVal);
+//         
+//         //Now the refs
+//                  
+//         DatabaseEntry refVal = new DatabaseEntry(refBytes);
+//         
+//         refDB.put(null, key, refVal);
+//         
+//         env1.end(xid, XAResource.TMSUCCESS);
+//         
+//         env1.prepare(xid);
+//         
+//         env1.commit(xid, false);
+//                  
+//        // tx.commit();         
+//      }
+//      
+//      long end = System.currentTimeMillis();
+//      
+//      double rate = 1000 * (double)numMessages / (end - start);
+//      
+//      System.out.println("Insert Rate: " + rate);
+//      
+//      start = System.currentTimeMillis();
+//   }
+//   
+//   private Xid generateXid()
+//   {      
+//      String id = java.util.UUID.randomUUID().toString();
+//      
+//      Xid xid = new XidImpl("blah".getBytes(), 123, id.getBytes());
+//      
+//      return xid;
+//   }
+//   
+//   
+//// This is very slow   
+////   public void testMsgandRefsSameDBSNoXA() throws Exception
+////   {
+////      File file = new File("/home/tim/test-env");
+////      
+////      deleteDirectory(file);
+////      
+////      file.mkdir();
+////      
+////      EnvironmentConfig envConfig = new EnvironmentConfig();
+////        
+////      envConfig.setAllowCreate(true);
+////      
+////      envConfig.setTransactional(true);
+////      
+////      Environment env1 = new Environment(file, envConfig);
+////
+////      DatabaseConfig dbConfig1 = new DatabaseConfig();
+////      
+////      dbConfig1.setTransactional(true);
+////      
+////      dbConfig1.setAllowCreate(true);
+////      
+////      Database msgDB = env1.openDatabase(null, "message", dbConfig1);      
+////     
+////      final int numMessages = 5000;
+////      
+////      byte[] msgBytes = new byte[10 * 1024];
+////      
+////      byte[] refBytes = new byte[24];
+////      
+////      long start = System.currentTimeMillis();
+////      
+////      for (int i = 0; i < numMessages; i++)
+////      {
+////         byte[] keyBytes = new byte[8];
+////         
+////         ByteBuffer buffer = ByteBuffer.wrap(keyBytes);
+////         
+////         buffer.putLong(i);
+////         
+////         DatabaseEntry key = new DatabaseEntry(keyBytes);
+////         
+////         DatabaseEntry msgVal = new DatabaseEntry(msgBytes);
+////         
+////         Transaction tx = env1.beginTransaction(null, null);
+////         
+////         msgDB.put(tx, key, msgVal);
+////         
+////         //Now the refs
+////         
+////         final int numRefs = 50;
+////         
+////         for (int j = 0; j < numRefs; j++)
+////         {
+////            keyBytes = new byte[8];
+////            
+////            buffer = ByteBuffer.wrap(keyBytes);
+////            
+////            buffer.putLong(j);
+////            
+////            key = new DatabaseEntry(keyBytes);
+////                                    
+////            DatabaseEntry value = new DatabaseEntry();
+////            
+////            value.setPartial(0, refBytes.length, true);
+////                        
+////            value.setData(refBytes);
+////            
+////            msgDB.put(tx, key, value);
+////         }
+////         
+////         tx.commit();
+////         
+////      }
+////      
+////      long end = System.currentTimeMillis();
+////      
+////      double rate = 1000 * (double)numMessages / (end - start);
+////      
+////      System.out.println("Rate: " + rate);
+////   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/test/unit/RealBDBJEEnvironmentTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/bdbje/integration/test/unit/RealBDBJEEnvironmentTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/test/unit/RealBDBJEEnvironmentTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/integration/test/unit/RealBDBJEEnvironmentTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,94 @@
+package org.jboss.messaging.core.persistence.impl.bdbje.integration.test.unit;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
+import org.jboss.messaging.core.persistence.impl.bdbje.integration.RealBDBJEEnvironment;
+import org.jboss.messaging.core.persistence.impl.bdbje.test.unit.BDBJEEnvironmentTestBase;
+
+/**
+ * 
+ * A RealBDBJEEnvironmentTest
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class RealBDBJEEnvironmentTest extends BDBJEEnvironmentTestBase
+{
+   protected void setUp() throws Exception
+   {   
+      createDir(ENV_DIR);
+      
+      env = createEnvironment();
+      
+      env.setEnvironmentPath(ENV_DIR);
+      
+      env.setCreateEnvironment(true);
+      
+      env.start();
+      
+      database = env.getDatabase("test-db");            
+   }
+   
+   protected BDBJEEnvironment createEnvironment() throws Exception
+   {
+      BDBJEEnvironment env = new RealBDBJEEnvironment(true);
+      
+      env.setTransacted(true);
+      
+      return env;
+   }    
+   
+   protected void createDir(String path)
+   {  
+      File file = new File(path);
+      
+      deleteDirectory(file);
+      
+      file.mkdir();
+   }
+   
+   protected void copyEnvironment() throws Exception
+   {
+      File envDir = new File(ENV_DIR);
+      
+      File envCopyDir = new File(ENV_COPY_DIR);
+      
+      deleteDirectory(envCopyDir);
+      
+      copyRecursive(envDir, envCopyDir);
+      
+      deleteDirectory(envDir);
+      
+      //Need to sync
+      
+      FileOutputStream fos = new FileOutputStream(ENV_COPY_DIR + "/je.lck");
+      
+      fos.getFD().sync();
+   }
+   
+   protected void copyBackEnvironment() throws Exception
+   {
+      File envDir = new File(ENV_DIR);
+      
+      File envCopyDir = new File(ENV_COPY_DIR);
+      
+      deleteDirectory(envDir);
+      
+      copyRecursive(envCopyDir, envDir);
+      
+      deleteDirectory(envCopyDir);
+      
+      //Need to sync
+      
+      FileOutputStream fos = new FileOutputStream(ENV_DIR + "/je.lck");
+      
+      fos.getFD().sync();
+   }    
+   
+   protected boolean isFake()
+   {
+      return false;
+   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,1918 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.core.persistence.impl.bdbje.test.unit;
+
+import java.io.File;
+import java.util.List;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEDatabase;
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJETransaction;
+import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+import com.sleepycat.je.DatabaseException;
+
+/**
+ * 
+ * Base for tests for BDBJEEnvironment and BDBJEDatabase
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public abstract class BDBJEEnvironmentTestBase extends UnitTestCase
+{
+   protected BDBJEEnvironment env;
+   
+   protected BDBJEDatabase database;
+   
+   protected static final String HOME_DIR = System.getProperty("user.home");
+   
+   protected static final String ENV_DIR = HOME_DIR + "/test-bdb-environment";
+      
+   protected static final String ENV_COPY_DIR = HOME_DIR + "/test-bdb-environment-copy";
+   
+   protected static final String DB_NAME = "test-db";
+   
+   @Override
+   protected void setUp() throws Exception
+   {   
+      super.setUp();
+      
+      env = createEnvironment();
+      
+      env.setCreateEnvironment(true);
+      
+      env.setEnvironmentPath(ENV_DIR);
+      
+      env.start();
+      
+      database = env.getDatabase(DB_NAME);      
+   }
+   
+   protected abstract void createDir(String path);
+   
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      if (env.isStarted())
+      {
+         env.stop();
+      }
+   }
+   
+   protected abstract BDBJEEnvironment createEnvironment() throws Exception;
+   
+   protected abstract void copyEnvironment() throws Exception;
+
+   protected abstract void copyBackEnvironment() throws Exception;
+   
+   protected abstract boolean isFake();
+   
+
+   // The tests ----------------------------------------------------------------
+      
+   public void testGetInDoubtXidsCompleteWithCommit() throws Exception
+   {
+      List<Xid> xids = env.getInDoubtXids();
+      
+      assertTrue(xids.isEmpty());
+      
+      Xid xid1 = generateXid();
+      
+      env.startWork(xid1);
+      
+      database.put(null, 1, new byte[10], 0, 10);
+      
+      env.endWork(xid1, false);
+      
+      env.prepare(xid1);
+      
+      xids = env.getInDoubtXids();
+      
+      assertEquals(xid1, xids.get(0));
+      
+      env.commit(xid1);
+      
+      xids = env.getInDoubtXids();
+      
+      assertTrue(xids.isEmpty());
+   }
+      
+   public void testGetInDoubtXidsCompleteWithRollback() throws Exception
+   {
+      List<Xid> xids = env.getInDoubtXids();
+      
+      assertTrue(xids.isEmpty());
+      
+      Xid xid1 = generateXid();
+      
+      env.startWork(xid1);
+      
+      database.put(null, 1, new byte[10], 0, 10);
+      
+      env.endWork(xid1, false);
+      
+      env.prepare(xid1);
+      
+      xids = env.getInDoubtXids();
+      
+      assertEquals(xid1, xids.get(0));
+      
+      env.rollback(xid1);
+      
+      xids = env.getInDoubtXids();
+      
+      assertTrue(xids.isEmpty());
+   }
+   
+   
+   public void testGetInDoubtXidsMultiple() throws Exception
+   {
+      List<Xid> xids = env.getInDoubtXids();
+      
+      assertTrue(xids.isEmpty());
+      
+      Xid xid1 = generateXid();      
+      env.startWork(xid1);      
+      database.put(null, 1, new byte[10], 0, 10);      
+      env.endWork(xid1, false); 
+      
+      env.prepare(xid1);      
+      xids = env.getInDoubtXids();      
+      assertEquals(xid1, xids.get(0));
+      
+      
+      Xid xid2 = generateXid();      
+      env.startWork(xid2);      
+      database.put(null, 2, new byte[10], 0, 10);      
+      env.endWork(xid2, false); 
+      
+      env.prepare(xid2);      
+      xids = env.getInDoubtXids();      
+      assertTrue(xids.contains(xid1));
+      assertTrue(xids.contains(xid2));
+      
+      Xid xid3 = generateXid();      
+      env.startWork(xid3);      
+      database.put(null, 3, new byte[10], 0, 10);      
+      env.endWork(xid3, false); 
+      
+      env.prepare(xid3);      
+      xids = env.getInDoubtXids();      
+      assertTrue(xids.contains(xid1));
+      assertTrue(xids.contains(xid2));
+      assertTrue(xids.contains(xid3));
+      
+      env.commit(xid1);
+      
+      env.commit(xid2);
+      
+      env.commit(xid3);
+     
+   }
+   
+   // Commented out until http://jira.jboss.org/jira/browse/JBMESSAGING-1192 is complete   
+//   public void testGetInDoubtXidsMultipleWithRestart() throws Exception
+//   {
+//      List<Xid> xids = env.getInDoubtXids();
+//      
+//      assertTrue(xids.isEmpty());
+//      
+//      Xid xid1 = generateXid();      
+//      env.startWork(xid1);      
+//      database.put(null, 1, new byte[10], 0, 10);      
+//      env.endWork(xid1, false); 
+//      
+//      env.prepare(xid1);      
+//      xids = env.getInDoubtXids();      
+//      assertEquals(xid1, xids.get(0));
+//      
+//      
+//      Xid xid2 = generateXid();      
+//      env.startWork(xid2);      
+//      database.put(null, 2, new byte[10], 0, 10);      
+//      env.endWork(xid2, false); 
+//      
+//      env.prepare(xid2);      
+//      xids = env.getInDoubtXids();      
+//      assertTrue(xids.contains(xid1));
+//      assertTrue(xids.contains(xid2));
+//      
+//      Xid xid3 = generateXid();      
+//      env.startWork(xid3);      
+//      database.put(null, 3, new byte[10], 0, 10);      
+//      env.endWork(xid3, false); 
+//      
+//      env.prepare(xid3);      
+//      xids = env.getInDoubtXids();      
+//      assertTrue(xids.contains(xid1));
+//      assertTrue(xids.contains(xid2));
+//      assertTrue(xids.contains(xid3));
+//      
+//      //Now to simulate a crash we copy the environment directory from under BDB, then close
+//      //BDB. Then start it again with the copied config.
+//      //We can't just stop the environment and restart it since on stopping cleanly BDB will abort any open
+//      //transactions
+//      
+//      copyEnvironment();
+//      
+//      database.close();
+//      
+//      env.stop();
+//      
+//      copyBackEnvironment();
+//      
+//      env.start();
+//                 
+//      database = env.getDatabase(DB_NAME);
+//      
+//      xids = env.getInDoubtXids();      
+//      assertTrue(xids.contains(xid1));
+//      assertTrue(xids.contains(xid2));
+//      assertTrue(xids.contains(xid3));
+//      
+//      env.commit(xid1);
+//      env.commit(xid2);
+//      env.commit(xid3);
+//      
+//      xids = env.getInDoubtXids();
+//      
+//      assertTrue(xids.isEmpty());     
+//   }
+      
+      
+   public void testPutAndRemoveNonTransactional() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      assertContainsPair(id, bytes, 1);
+      
+      database.remove(null, 1);
+      
+      assertStoreEmpty();
+   }
+   
+   public void testPutAndRemoveNonTransactionalWithRestart() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      long id = 1;
+      
+      int offset = 0;
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      assertContainsPair(id, bytes, 1);
+      
+      database.close();
+      
+      env.stop();
+      
+      env.start();
+      
+      database = env.getDatabase(DB_NAME);
+      
+      assertContainsPair(id, bytes, 1);
+   }
+   
+   public void testPutAndRemoveMultipleNonTransactional() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+      
+      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
+       
+      long id1 = 1;
+      
+      long id2 = 2;
+      
+      long id3 = 3;
+      
+      int offset = 0;
+      
+      database.put(null, id1, bytes1, offset, bytes1.length);
+      
+      database.put(null, id2, bytes2, offset, bytes2.length);
+      
+      database.put(null, id3, bytes3, offset, bytes3.length);
+      
+      assertContainsPair(id1, bytes1, 3);
+      
+      assertContainsPair(id2, bytes2, 3);
+      
+      assertContainsPair(id3, bytes3, 3);
+                       
+      database.remove(null, id2);
+      
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id3, bytes3, 2);
+            
+      database.remove(null, id3);
+      
+      assertContainsPair(id1, bytes1, 1);
+      
+      database.remove(null, id1);
+      
+      assertStoreEmpty();      
+   }
+            
+   public void testPutTransactionalCommit() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      BDBJETransaction tx = env.createTransaction();
+      
+      database.put(tx, id, bytes, offset, bytes.length);
+      
+      tx.commit();
+      
+      assertContainsPair(id, bytes, 1);
+      
+      database.remove(null, 1);
+      
+      assertStoreEmpty();            
+   }
+   
+   public void testPutTransactionalWithRestart() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      BDBJETransaction tx = env.createTransaction();
+      
+      database.put(tx, id, bytes, offset, bytes.length);
+      
+      //Now restart before committing
+      
+      database.close();
+      
+      //This will abort the transaction
+      env.stop();
+
+      env.start();
+      
+      database = env.getDatabase(DB_NAME);
+      
+      assertStoreEmpty();            
+   }
+   
+   public void testPutXACommit() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      env.commit(xid);
+      
+      assertContainsPair(id, bytes, 1);
+      
+      database.remove(null, 1);
+      
+      assertStoreEmpty();            
+   }
+   
+   public void testPutXAWithRestart() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      env.endWork(xid, false);
+      
+      // Now restart
+      
+      database.close();
+      
+      env.stop();
+      
+      env.start();
+      
+      database = env.getDatabase(DB_NAME);
+      
+      assertStoreEmpty();            
+   }
+   
+   
+   public void testPutXAWithRestartAfterPrepare() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      // Now restart
+      
+      database.close();
+      
+      env.stop();
+      
+      env.start();
+      
+      database = env.getDatabase(DB_NAME);
+      
+      assertStoreEmpty();            
+   }
+   
+   public void testRemoveTransactional() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      assertContainsPair(id, bytes, 1);
+                        
+      BDBJETransaction tx = env.createTransaction();
+      
+      database.remove(tx, id);
+      
+      tx.commit();
+      
+      assertStoreEmpty();        
+   }
+   
+   public void testRemoveTransactionalWithRestart() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      assertContainsPair(id, bytes, 1);
+                        
+      BDBJETransaction tx = env.createTransaction();
+      
+      database.remove(tx, id);
+      
+      // Now restart
+      
+      database.close();
+      
+      env.stop();
+      
+      env.start();
+      
+      database = env.getDatabase(DB_NAME);
+      
+      assertContainsPair(id, bytes, 1);       
+   }
+   
+   public void testRemoveXACommit() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+            
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      assertContainsPair(id, bytes, 1);
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+                             
+      database.remove(null, id);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      env.commit(xid);
+
+      assertStoreEmpty();        
+   }
+   
+   public void testRemoveXAWithRestart() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+            
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      assertContainsPair(id, bytes, 1);
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+                             
+      database.remove(null, id);
+      
+      env.endWork(xid, false);
+      
+      // Now restart
+      
+      database.close();
+      
+      env.stop();
+      
+      env.start();
+      
+      database = env.getDatabase(DB_NAME);
+
+      assertContainsPair(id, bytes, 1);     
+   }
+   
+   public void testRemoveXAWithRestartAfterPrepare() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+            
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      assertContainsPair(id, bytes, 1);
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+                             
+      database.remove(null, id);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      // Now restart
+      
+      database.close();
+      
+      env.stop();
+      
+      env.start();
+      
+      database = env.getDatabase(DB_NAME);
+
+      assertContainsPair(id, bytes, 1);     
+   }
+   
+   public void testPutTransactionalRollback() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      BDBJETransaction tx = env.createTransaction();
+      
+      database.put(tx, id, bytes, offset, bytes.length);
+      
+      tx.rollback();
+      
+      assertStoreEmpty();            
+   }
+   
+   public void testPutXARollback() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      env.rollback(xid);
+      
+      assertStoreEmpty();            
+   }
+      
+   public void testRemoveTransactionalRollback() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      assertContainsPair(id, bytes, 1);
+                        
+      BDBJETransaction tx = env.createTransaction();
+      
+      database.remove(tx, id);
+      
+      tx.rollback();
+      
+      assertContainsPair(id, bytes, 1);            
+   }
+   
+   public void testRemoveXARollback() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      assertContainsPair(id, bytes, 1);
+                        
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.remove(null, id);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      env.rollback(xid);
+      
+      assertContainsPair(id, bytes, 1);            
+   }
+   
+   
+   public void testPutAndRemoveMultipleTransactionalCommit() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+      
+      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
+      
+      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
+       
+      long id1 = 1;
+      
+      long id2 = 2;
+      
+      long id3 = 3;
+      
+      long id4 = 4;
+      
+      int offset = 0;
+      
+      database.put(null, id1, bytes1, offset, bytes1.length);
+      
+      database.put(null, id2, bytes2, offset, bytes2.length);
+                 
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id2, bytes2, 2);
+      
+      BDBJETransaction tx = env.createTransaction();
+      
+      database.put(tx, id3, bytes3, offset, bytes3.length);
+      
+      database.put(tx, id4, bytes4, offset, bytes4.length);
+      
+      database.remove(tx, id1);
+      
+      database.remove(tx, id2);
+      
+      tx.commit();
+      
+      assertContainsPair(id3, bytes3, 2);
+      
+      assertContainsPair(id4, bytes4, 2);        
+   }
+   
+   public void testPutAndRemoveMultipleXACommit() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+      
+      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
+      
+      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
+       
+      long id1 = 1;
+      
+      long id2 = 2;
+      
+      long id3 = 3;
+      
+      long id4 = 4;
+      
+      int offset = 0;
+      
+      database.put(null, id1, bytes1, offset, bytes1.length);
+      
+      database.put(null, id2, bytes2, offset, bytes2.length);
+                 
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id2, bytes2, 2);
+      
+      XidImpl xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.put(null, id3, bytes3, offset, bytes3.length);
+      
+      database.put(null, id4, bytes4, offset, bytes4.length);
+      
+      database.remove(null, id1);
+      
+      database.remove(null, id2);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      env.commit(xid);
+      
+      assertContainsPair(id3, bytes3, 2);
+      
+      assertContainsPair(id4, bytes4, 2);        
+   }
+   
+   /*
+    * As above but we use different but equal() XidImpl instances at each point
+    */
+   public void testPutAndRemoveMultipleXACommitWithCopy() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+      
+      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
+      
+      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
+       
+      long id1 = 1;
+      
+      long id2 = 2;
+      
+      long id3 = 3;
+      
+      long id4 = 4;
+      
+      int offset = 0;
+      
+      database.put(null, id1, bytes1, offset, bytes1.length);
+      
+      database.put(null, id2, bytes2, offset, bytes2.length);
+                 
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id2, bytes2, 2);
+      
+      XidImpl xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.put(null, id3, bytes3, offset, bytes3.length);
+      
+      database.put(null, id4, bytes4, offset, bytes4.length);
+      
+      database.remove(null, id1);
+      
+      database.remove(null, id2);
+      
+      xid = new XidImpl(xid);
+            
+      env.endWork(xid, false);
+      
+      xid = new XidImpl(xid);      
+      
+      env.prepare(xid);
+      
+      xid = new XidImpl(xid);
+      
+      env.commit(xid);
+      
+      assertContainsPair(id3, bytes3, 2);
+      
+      assertContainsPair(id4, bytes4, 2);        
+   }
+   
+   public void testPutAndRemoveMultipleXACommitDifferentThread() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+      
+      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
+      
+      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
+       
+      long id1 = 1;
+      
+      long id2 = 2;
+      
+      long id3 = 3;
+      
+      long id4 = 4;
+      
+      int offset = 0;
+      
+      database.put(null, id1, bytes1, offset, bytes1.length);
+      
+      database.put(null, id2, bytes2, offset, bytes2.length);
+                 
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id2, bytes2, 2);
+      
+      final XidImpl xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.put(null, id3, bytes3, offset, bytes3.length);
+      
+      database.put(null, id4, bytes4, offset, bytes4.length);
+      
+      database.remove(null, id1);
+      
+      database.remove(null, id2);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      //Commit on a different thread
+      
+      class MyThread extends Thread
+      {
+         volatile boolean failed;
+         
+         public void run()
+         {
+            try
+            {
+               env.commit(xid);
+            }
+            catch (Exception e)
+            {
+               failed = true;
+            }
+         }         
+      }
+      
+      MyThread t = new MyThread();
+      
+      t.start();
+      
+      t.join();
+      
+      assertFalse(t.failed);
+      
+      assertContainsPair(id3, bytes3, 2);
+      
+      assertContainsPair(id4, bytes4, 2);        
+   }
+   
+   public void testPutAndRemoveMultipleXAWithRestart() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+      
+      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
+      
+      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
+       
+      long id1 = 1;
+      
+      long id2 = 2;
+      
+      long id3 = 3;
+      
+      long id4 = 4;
+      
+      int offset = 0;
+      
+      database.put(null, id1, bytes1, offset, bytes1.length);
+      
+      database.put(null, id2, bytes2, offset, bytes2.length);
+                 
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id2, bytes2, 2);
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.put(null, id3, bytes3, offset, bytes3.length);
+      
+      database.put(null, id4, bytes4, offset, bytes4.length);
+      
+      database.remove(null, id1);
+      
+      database.remove(null, id2);
+      
+      env.endWork(xid, false);
+      
+      // Now restart
+      
+      database.close();
+      
+      env.stop();
+      
+      env.start();
+      
+      database = env.getDatabase(DB_NAME);
+      
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id2, bytes2, 2);      
+   }
+   
+   public void testPutAndRemoveMultipleTransactionalRollback() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+      
+      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
+      
+      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
+       
+      long id1 = 1;
+      
+      long id2 = 2;
+      
+      long id3 = 3;
+      
+      long id4 = 4;
+      
+      int offset = 0;
+      
+      database.put(null, id1, bytes1, offset, bytes1.length);
+      
+      database.put(null, id2, bytes2, offset, bytes2.length);
+                 
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id2, bytes2, 2);
+      
+      BDBJETransaction tx = env.createTransaction();
+      
+      database.put(tx, id3, bytes3, offset, bytes3.length);
+      
+      database.put(tx, id4, bytes4, offset, bytes4.length);
+      
+      database.remove(tx, id1);
+      
+      database.remove(tx, id2);
+      
+      tx.rollback();
+      
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id2, bytes2, 2);            
+   }
+   
+   public void testPutAndRemoveMultipleXARollback() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+      
+      byte[] bytes3 = new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
+      
+      byte[] bytes4 = new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
+       
+      long id1 = 1;
+      
+      long id2 = 2;
+      
+      long id3 = 3;
+      
+      long id4 = 4;
+      
+      int offset = 0;
+      
+      database.put(null, id1, bytes1, offset, bytes1.length);
+      
+      database.put(null, id2, bytes2, offset, bytes2.length);
+                 
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id2, bytes2, 2);
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.put(null, id3, bytes3, offset, bytes3.length);
+      
+      database.put(null, id4, bytes4, offset, bytes4.length);
+      
+      database.remove(null, id1);
+      
+      database.remove(null, id2);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      env.rollback(xid);
+      
+      assertContainsPair(id1, bytes1, 2);
+      
+      assertContainsPair(id2, bytes2, 2);            
+   }
+   
+   public void testOverwiteNonTransactional() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      database.put(null, id, bytes1, offset, bytes1.length);
+      
+      assertContainsPair(id, bytes1, 1);
+      
+      database.put(null, id, bytes2, offset, bytes1.length);
+      
+      assertContainsPair(id, bytes2, 1);
+            
+      database.remove(null, 1);
+      
+      assertStoreEmpty();
+   }
+   
+   public void testOverwiteTransactionalCommit() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      BDBJETransaction tx = env.createTransaction();
+            
+      database.put(tx, id, bytes1, offset, bytes1.length);
+      
+      database.put(tx, id, bytes2, offset, bytes1.length);
+      
+      tx.commit();
+      
+      assertContainsPair(id, bytes2, 1);
+            
+      database.remove(null, 1);
+      
+      assertStoreEmpty();
+   }
+   
+   public void testOverwiteXACommit() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+      
+      database.put(null, id, bytes1, offset, bytes1.length);
+      
+      database.put(null, id, bytes2, offset, bytes1.length);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      env.commit(xid);
+      
+      assertContainsPair(id, bytes2, 1);
+            
+      database.remove(null, 1);
+      
+      assertStoreEmpty();
+   }
+   
+   public void testOverwiteTransactionalRollback() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      BDBJETransaction tx = env.createTransaction();
+            
+      database.put(tx, id, bytes1, offset, bytes1.length);
+      
+      database.put(tx, id, bytes2, offset, bytes1.length);
+      
+      tx.rollback();
+      
+      assertStoreEmpty();
+   }
+   
+   public void testOverwiteXARollback() throws Exception
+   {
+      byte[] bytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      Xid xid = generateXid();
+      
+      env.startWork(xid);      
+      
+      database.put(null, id, bytes1, offset, bytes1.length);
+      
+      database.put(null, id, bytes2, offset, bytes1.length);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      env.rollback(xid);
+      
+      assertStoreEmpty();
+   }
+   
+   public void testPutAndRemovePartialNonTransactional() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 20, 21, 22, 23 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      database.put(null, id, bytes, offset, bytes.length);
+      
+      assertContainsPair(id, bytes, 1);
+      
+      database.put(null, id, bytes2, 10, bytes2.length);
+      
+      byte[] bytes3 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 21, 22, 23 };
+      
+      assertContainsPair(id, bytes3, 1);  
+            
+      database.put(null, id, bytes2, 3, bytes2.length);
+      
+      byte[] bytes4 = new byte[] { 1, 2, 3, 20, 21, 22, 23, 8, 9, 10, 20, 21, 22, 23 };
+      
+      assertContainsPair(id, bytes4, 1);  
+      
+      byte[] bytes5 = new byte[0];
+      
+      //blank out 4 bytes
+      database.put(null, id, bytes5, 5, 4);
+      
+      byte[] bytes6 = new byte[] { 1, 2, 3, 20, 21, 10, 20, 21, 22, 23 };
+      
+      assertContainsPair(id, bytes6, 1);  
+      
+      
+      database.put(null, id, new byte[0], 0, 4);
+      
+      byte[] bytes7 = new byte[] { 21, 10, 20, 21, 22, 23 };
+      
+      assertContainsPair(id, bytes7, 1);  
+                        
+      database.remove(null, 1);
+      
+      assertStoreEmpty();
+   }
+   
+   public void testPutAndRemovePartialTransactional() throws Exception
+   {
+      byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      
+      byte[] bytes2 = new byte[] { 20, 21, 22, 23 };
+       
+      long id = 1;
+      
+      int offset = 0;
+      
+      BDBJETransaction tx = env.createTransaction();
+            
+      database.put(tx, id, bytes, offset, bytes.length);
+      
+      tx.commit();
+      
+      assertContainsPair(id, bytes, 1);
+      
+      tx = env.createTransaction();
+      
+      database.put(tx, id, bytes2, 10, bytes2.length);
+      
+      tx.commit();
+      
+      byte[] bytes3 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 21, 22, 23 };
+      
+      assertContainsPair(id, bytes3, 1);  
+      
+      tx = env.createTransaction();
+            
+      database.put(tx, id, bytes2, 3, bytes2.length);
+      
+      tx.commit();
+      
+      byte[] bytes4 = new byte[] { 1, 2, 3, 20, 21, 22, 23, 8, 9, 10, 20, 21, 22, 23 };
+      
+      assertContainsPair(id, bytes4, 1);  
+      
+      byte[] bytes5 = new byte[0];
+      
+      tx = env.createTransaction();
+      
+      //blank out 4 bytes
+      database.put(tx, id, bytes5, 5, 4);
+      
+      tx.commit();
+      
+      byte[] bytes6 = new byte[] { 1, 2, 3, 20, 21, 10, 20, 21, 22, 23 };
+      
+      assertContainsPair(id, bytes6, 1);  
+      
+      database.put(null, id, new byte[0], 0, 4);
+      
+      byte[] bytes7 = new byte[] { 21, 10, 20, 21, 22, 23 };
+      
+      assertContainsPair(id, bytes7, 1);  
+                  
+      database.remove(null, 1);
+      
+      assertStoreEmpty();
+   }
+   
+   public void testSetAndGetEnvironment() throws Exception   
+   {
+      try
+      {
+         env.setEnvironmentPath("blah");
+         
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //OK
+      }
+      
+      assertEquals(ENV_DIR, env.getEnvironmentPath());
+      
+      env.stop();
+      
+      final String path2 = HOME_DIR + "/test-path123651";
+      
+      env.setEnvironmentPath(path2);
+      
+      assertEquals(path2, env.getEnvironmentPath());
+      
+      env.start();
+   }
+   
+   
+   public void testSetAndGetTransacted() throws Exception   
+   {
+      env.stop();
+            
+      env.setTransacted(false);
+      
+      assertFalse(env.isTransacted());
+      
+      env.setTransacted(true);
+      
+      assertTrue(env.isTransacted());
+      
+      env.start();
+      
+      try
+      {
+         env.setTransacted(true);
+         
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //OK
+      }
+      
+      assertTrue(env.isTransacted());
+      
+      env.stop();
+      
+      env.setTransacted(false);
+      
+      assertFalse(env.isTransacted());  
+   }
+   
+   public void testSetAndGetSyncOS() throws Exception   
+   {
+      env.stop();
+      
+      assertFalse(env.isSyncOS());
+      
+      env.setSyncOS(true);
+      
+      assertTrue(env.isSyncOS());
+      
+      env.start();
+      
+      try
+      {
+         env.setSyncOS(true);
+         
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //OK
+      }
+      
+      assertTrue(env.isSyncOS());
+      
+      env.stop();
+      
+      env.setSyncOS(false);
+      
+      assertFalse(env.isSyncOS());  
+   }
+   
+   public void testSetAndGetSyncVM() throws Exception   
+   {
+      env.stop();
+      
+      assertFalse(env.isSyncVM());
+      
+      env.setSyncVM(true);
+      
+      assertTrue(env.isSyncVM());
+      
+      env.start();
+      
+      try
+      {
+         env.setSyncVM(true);
+         
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //OK
+      }
+      
+      assertTrue(env.isSyncVM());
+      
+      env.stop();
+      
+      env.setSyncVM(false);
+      
+      assertFalse(env.isSyncVM());  
+   }      
+   
+   public void testSetAndGetMemoryCacheSize() throws Exception   
+   {
+      env.stop();
+      
+      assertEquals(-1, env.getMemoryCacheSize());
+      
+      final long size = 16251762;
+      
+      env.setMemoryCacheSize(size);
+      
+      assertEquals(size, env.getMemoryCacheSize());
+      
+      env.start();
+      
+      try
+      {
+         env.setMemoryCacheSize(1897291289);
+         
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //OK
+      }
+      
+      assertEquals(size, env.getMemoryCacheSize());
+      
+      env.stop();
+      
+      final long size2 = 1625534783;
+      
+      env.setMemoryCacheSize(size2);
+      
+      assertEquals(size2, env.getMemoryCacheSize());
+   }
+   
+
+   public void testStartAndStop() throws Exception
+   {      
+      try
+      {
+         env.start();
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //OK
+      }
+      
+      env.stop();
+      
+      final String path = HOME_DIR + "/test-path123";
+      
+      createDir(path);
+      
+      env.setEnvironmentPath(path);      
+      
+      env.start();
+      
+      try
+      {
+         env.start();
+         
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //OK
+      }
+      
+      env.stop();
+      
+      try
+      {
+         env.stop();
+         
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //OK
+      }
+   }
+   
+   /*
+    * This test only makes sense for the RealBDBJEEnvironment, not the fake one
+    */
+   public void testCreateEnvironment() throws Exception
+   {      
+      if (isFake())
+      {
+         return;
+      }
+      
+      env.stop();
+      
+      env.setCreateEnvironment(false);
+      
+      String dir = HOME_DIR + "/blah678";
+      
+      deleteDirectory(new File(dir));
+      
+      env.setEnvironmentPath(dir);
+      
+      try
+      {
+         env.start();
+         fail("Should throw exception");
+      }
+      catch (IllegalArgumentException e)
+      {
+         //OK
+      }
+      
+      this.createDir(dir);
+      
+      try
+      {
+         env.start();         
+      }
+      catch (DatabaseException e)
+      {
+         //Ok - this will still fail since there is no actual BDB environment in the directory even though
+         //the directory exists
+      }
+      
+      env.setCreateEnvironment(true);
+      
+      env.start();
+     
+      env.stop();
+      
+      deleteDirectory(new File(dir));
+      
+      env.start();             
+   }
+   
+   public void testWrongOrderCommit() throws Exception
+   {
+      testXAWrongOrder(true);
+   }
+   
+   public void testWrongOrderRollback() throws Exception
+   {
+      testXAWrongOrder(false);
+   }
+   
+   public void testXAWrongXidCommit() throws Exception
+   {
+      testXAWrongXid(true);
+   }
+   
+   public void testXAWrongXidRollback() throws Exception
+   {
+      testXAWrongXid(false);
+   }
+   
+   private void testXAWrongXid(boolean commit) throws Exception
+   {
+      Xid xid = generateXid();
+      
+      env.startWork(xid);
+      
+      Xid xid2 = generateXid();
+      
+      try
+      {
+         env.endWork(xid2, false);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      //do some work
+      
+      database.put(null, 23, new byte[10], 0, 10);
+            
+      env.endWork(xid, false);
+      
+      try
+      {
+         env.prepare(xid2);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      env.prepare(xid);
+      
+      if (commit)
+      {
+         try
+         {
+            env.commit(xid2);
+            fail("Should throw exception");
+         }
+         catch (IllegalStateException e)
+         {
+            //Ok
+         }
+         env.commit(xid);
+      }
+      else
+      {
+         try
+         {
+            env.rollback(xid2);
+            fail("Should throw exception");
+         }
+         catch (IllegalStateException e)
+         {
+            //Ok
+         }
+         env.rollback(xid);
+      }
+   }
+   
+   private void testXAWrongOrder(boolean commit) throws Exception
+   {
+      Xid xid = generateXid();
+      
+      try
+      {
+         env.endWork(xid, false);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.prepare(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.commit(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.rollback(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      env.startWork(xid);
+      
+      //do some work
+      
+      database.put(null, 23, new byte[10], 0, 10);
+      
+      try
+      {
+         env.startWork(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.prepare(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.commit(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.rollback(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      env.endWork(xid, false);
+      
+      try
+      {
+         env.startWork(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.endWork(xid, false);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.commit(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.rollback(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      env.prepare(xid);
+      
+      try
+      {
+         env.startWork(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.endWork(xid, false);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      if (commit)
+      {
+         env.commit(xid);
+      }
+      else
+      {
+         env.rollback(xid);
+      }
+      
+      try
+      {
+         env.endWork(xid, false);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.prepare(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.commit(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      try
+      {
+         env.rollback(xid);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      env.startWork(xid);
+      
+      database.put(null, 23, new byte[10], 0, 10);
+      
+      env.endWork(xid, false);
+      
+      env.prepare(xid);
+      
+      env.rollback(xid);
+      
+   }
+     
+   // Private -------------------------------------------------------------------------------------
+   
+   private void assertContainsPair(long id, byte[] bytes, long size) throws Exception
+   {
+      byte[] b = database.get(id);
+      
+      assertNotNull(b);
+      
+      assertByteArraysEquivalent(bytes, b);
+      
+      assertEquals(size, database.size());
+   }
+   
+   private void assertStoreEmpty() throws Exception
+   {
+      assertEquals(0, database.size());
+   }               
+}

Copied: trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,1154 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.core.persistence.impl.bdbje.test.unit;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.filter.impl.FilterImpl;
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEDatabase;
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEPersistenceManager;
+import org.jboss.messaging.core.persistence.impl.bdbje.test.unit.fakes.FakeBDBJEEnvironment;
+import org.jboss.messaging.core.server.Binding;
+import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.impl.BindingImpl;
+import org.jboss.messaging.core.server.impl.MessageImpl;
+import org.jboss.messaging.core.server.impl.QueueImpl;
+import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeQueueFactory;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ * 
+ * A BDBJEPersistenceManagerTest
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class BDBJEPersistenceManagerTest extends UnitTestCase
+{
+   protected static final String ENV_DIR = "test-env";
+   
+   protected BDBJEPersistenceManager pm;
+      
+   protected BDBJEEnvironment bdb;
+   
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      bdb = new FakeBDBJEEnvironment();
+      
+      bdb.setEnvironmentPath(ENV_DIR);
+      
+      bdb.start();
+      
+      pm = new BDBJEPersistenceManager();
+      
+      pm.setEnvironment(bdb);
+      
+      pm.start();
+   }
+   
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      pm.stop();
+   }
+   
+   private Queue createQueue(int i)
+   {
+      return new QueueImpl(i, "blah" + i, null, false, true, false, -1, null, null);
+   }
+   
+   // The tests ----------------------------------------------------------------
+              
+   public void testAddMessage() throws Exception
+   {      
+      Queue queue = createQueue(67);
+            
+      Message m = createMessageWithRefs(1, queue);
+      
+      pm.addMessage(m);
+      
+      assertMessageInStore(m, queue); 
+      
+      try
+      {
+         pm.addMessage(null);
+         
+         fail("Should throw exception");
+      }
+      catch (NullPointerException ok)
+      {
+         //ok
+      }
+   }
+   
+   public void testAddNonReliableMessage() throws Exception
+   {      
+      Queue queue = createQueue(67);
+            
+      Message m = createMessageWithRefs(1, queue);
+      
+      m.setDurable(false);
+      
+      pm.addMessage(m);
+      
+      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
+      
+      BDBJEDatabase refDB = bdb.getDatabase(BDBJEPersistenceManager.REFERENCE_DB_NAME);
+      
+      byte[] msgBytes = msgDB.get(m.getMessageID());
+      
+      assertNull(msgBytes);
+      
+      byte[] refBytes = refDB.get(m.getMessageID());
+      
+      assertNull(refBytes);      
+   }
+         
+   public void testDeleteReference() throws Exception
+   {            
+      Queue queue = createQueue(67);
+      
+      Message m = createMessageWithRefs(1, queue);
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>(m.getReferences());
+      
+      
+      pm.addMessage(m);
+      
+      assertMessageInStore(m, queue);
+      
+      
+      pm.deleteReference(refs.get(2));
+      
+      assertMessageInStore(m, queue);
+                      
+      assertEquals(3, m.getReferences().size());
+      
+      assertTrue(m.getReferences().contains(refs.get(0)));
+      assertTrue(m.getReferences().contains(refs.get(1)));
+      assertTrue(m.getReferences().contains(refs.get(3)));
+      
+      
+      pm.deleteReference(refs.get(1));
+      
+      assertMessageInStore(m, queue);
+      
+      assertEquals(2, m.getReferences().size());
+      
+      assertTrue(m.getReferences().contains(refs.get(0)));
+      assertTrue(m.getReferences().contains(refs.get(3)));
+      
+      
+                
+      pm.deleteReference(refs.get(3));
+      
+      assertMessageInStore(m, queue);
+      
+      assertEquals(1, m.getReferences().size());
+      
+      assertTrue(m.getReferences().contains(refs.get(0)));
+            
+      
+      pm.deleteReference(refs.get(0));
+            
+      assertMessageNotInStore(m);         
+      
+      assertStoreEmpty();
+      
+      try
+      {
+         pm.deleteReference(null);
+         
+         fail("Should throw exception");
+      }
+      catch (NullPointerException ok)
+      {
+         //ok
+      }
+   }
+   
+   public void testCommitTransaction() throws Exception
+   {      
+      List<Message> msgs = new ArrayList<Message>();
+          
+      Queue queue = createQueue(67);
+            
+      Message m1 = createMessageWithRefs(1, queue);
+      List<MessageReference> m1Refs = new ArrayList<MessageReference>(m1.getReferences());
+    
+      msgs.add(m1);
+      
+      Message m2 = createMessageWithRefs(2, queue);
+      
+      msgs.add(m2);
+      
+      Message m3 = createMessageWithRefs(3, queue);
+      List<MessageReference> m3Refs = new ArrayList<MessageReference>(m3.getReferences());
+      
+      msgs.add(m3);
+      
+      pm.commitTransaction(msgs, null);
+       
+      assertMessageInStore(m1, queue);
+      
+      assertMessageInStore(m2, queue);
+      
+      assertMessageInStore(m3, queue);
+      
+      
+      //Add a couple more
+      
+      List<Message> msgsMore = new ArrayList<Message>();
+            
+      Message m4 = createMessageWithRefs(4, queue);      
+      msgsMore.add(m4);
+      
+      Message m5 = createMessageWithRefs(5, queue);      
+      msgsMore.add(m5);
+      
+      //Delete some refs
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      refsToRemove.add(m1.getReferences().get(0));
+      refsToRemove.add(m1.getReferences().get(3));
+      
+      refsToRemove.add(m2.getReferences().get(0));
+      refsToRemove.add(m2.getReferences().get(1));
+      refsToRemove.add(m2.getReferences().get(2));
+      refsToRemove.add(m2.getReferences().get(3));
+      
+      refsToRemove.add(m3.getReferences().get(2));
+      
+      pm.commitTransaction(msgsMore, refsToRemove);
+      
+      assertMessageInStore(m1, queue);
+      assertEquals(2, m1.getReferences().size());
+      assertTrue(m1.getReferences().contains(m1Refs.get(1)));
+      assertTrue(m1.getReferences().contains(m1Refs.get(2)));
+      
+      assertMessageNotInStore(m2);
+      
+      assertMessageInStore(m3, queue);
+      assertEquals(3, m3.getReferences().size());
+      assertTrue(m3.getReferences().contains(m3Refs.get(0)));
+      assertTrue(m3.getReferences().contains(m3Refs.get(1)));
+      assertTrue(m3.getReferences().contains(m3Refs.get(3)));
+      
+      assertMessageInStore(m4, queue);
+      assertEquals(4, m4.getReferences().size());
+      
+      assertMessageInStore(m5, queue);
+      assertEquals(4, m5.getReferences().size());
+      
+      //Delete the rest
+      refsToRemove.clear();
+      refsToRemove.addAll(m1.getReferences());
+      refsToRemove.addAll(m3.getReferences());
+      refsToRemove.addAll(m4.getReferences());
+      refsToRemove.addAll(m5.getReferences());
+      
+      pm.commitTransaction(null, refsToRemove);
+      
+      assertMessageNotInStore(m1);
+      assertMessageNotInStore(m2);
+      assertMessageNotInStore(m4);
+      assertMessageNotInStore(m5);
+      assertMessageNotInStore(m5);
+      
+      //try with nulls
+      try
+      {
+         pm.commitTransaction(null, null);
+         
+         fail("Should throw exception");
+      }      
+      catch (IllegalArgumentException e)
+      {
+         //OK
+      }
+      
+   }     
+   
+   public void testCommitTransactionMixtureOfPersistentAndNonPersistent() throws Exception
+   {      
+      Message msg = generateMessage(1);
+      
+      Queue queue1 = new QueueImpl(1, "queue1", null, false, true, false, -1, null, null);
+      assertTrue(queue1.isDurable());
+      
+      Queue queue2 = new QueueImpl(1, "queue1", null, false, false, false, -1, null, null);
+      assertFalse(queue2.isDurable());
+      
+      Queue queue3 = new QueueImpl(1, "queue1", null, false, true, false, -1, null, null);
+      assertTrue(queue3.isDurable());
+      
+      Queue queue4 = new QueueImpl(1, "queue1", null, false, false, false, -1, null, null);
+      assertFalse(queue4.isDurable());
+     
+      MessageReference ref1 = msg.createReference(queue1);
+      
+      MessageReference ref2 = msg.createReference(queue2);
+      
+      MessageReference ref3 = msg.createReference(queue3);
+      
+      MessageReference ref4 = msg.createReference(queue4);
+      
+      List<Message> msgs = new ArrayList<Message>();
+      
+      msgs.add(msg);
+            
+      pm.commitTransaction(msgs, null);
+      
+      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
+      
+      BDBJEDatabase refDB = bdb.getDatabase(BDBJEPersistenceManager.REFERENCE_DB_NAME);
+      
+      byte[] msgBytes = msgDB.get(msg.getMessageID());
+      
+      assertNotNull(msgBytes);
+      
+      byte[] refBytes = refDB.get(msg.getMessageID());
+      
+      assertNotNull(refBytes);
+      
+      Map<Long, Queue> queues = new HashMap<Long, Queue>();
+      
+      queues.put(queue1.getPersistenceID(), queue1);
+      
+      queues.put(queue2.getPersistenceID(), queue2);
+      
+      queues.put(queue3.getPersistenceID(), queue3);
+      
+      queues.put(queue4.getPersistenceID(), queue4);
+      
+      Message msg2 = extractMessage(queues, msg.getMessageID(), msgBytes, refBytes);
+      
+      //Should only have two refs since only two of the queues were durable
+      
+      List<MessageReference> refs = msg2.getReferences();
+      
+      assertEquals(2, refs.size());
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      refsToRemove.add(ref1);
+      
+      refsToRemove.add(ref2);
+      
+      refsToRemove.add(ref3);
+      
+      refsToRemove.add(ref4);
+      
+      pm.commitTransaction(null, refsToRemove);
+      
+      msgBytes = msgDB.get(msg.getMessageID());
+      
+      assertNull(msgBytes);
+      
+      refBytes = refDB.get(msg.getMessageID());
+      
+      assertNull(refBytes);
+   }     
+   
+   
+   
+   public void testPrepareAndCommitTransaction() throws Exception
+   {      
+      List<Message> msgs = new ArrayList<Message>();
+          
+      Queue queue = createQueue(67);
+           
+      Message m1 = createMessageWithRefs(1, queue);
+      List<MessageReference> m1Refs = new ArrayList<MessageReference>(m1.getReferences());
+    
+      msgs.add(m1);
+      
+      Message m2 = createMessageWithRefs(2, queue);
+
+      msgs.add(m2);
+      
+      Message m3 = createMessageWithRefs(3, queue);
+      List<MessageReference> m3Refs = new ArrayList<MessageReference>(m3.getReferences());
+      
+      msgs.add(m3);
+      
+      pm.commitTransaction(msgs, null);
+       
+      assertMessageInStore(m1, queue);
+      
+      assertMessageInStore(m2, queue);
+      
+      assertMessageInStore(m3, queue);
+      
+      
+      //Add a couple more
+      
+      List<Message> msgsMore = new ArrayList<Message>();
+            
+      Message m4 = createMessageWithRefs(4, queue);
+      msgsMore.add(m4);
+      
+      Message m5 = createMessageWithRefs(5, queue);
+
+      msgsMore.add(m5);
+      
+      //Delete some refs
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      refsToRemove.add(m1.getReferences().get(0));
+      refsToRemove.add(m1.getReferences().get(3));
+      
+      refsToRemove.add(m2.getReferences().get(0));
+      refsToRemove.add(m2.getReferences().get(1));
+      refsToRemove.add(m2.getReferences().get(2));
+      refsToRemove.add(m2.getReferences().get(3));
+      
+      refsToRemove.add(m3.getReferences().get(2));
+      
+      Xid xid = generateXid();
+      
+      pm.prepareTransaction(xid, msgsMore, refsToRemove);
+      
+      pm.commitPreparedTransaction(xid);
+      
+      assertMessageInStore(m1, queue);
+      assertEquals(2, m1.getReferences().size());
+      assertTrue(m1.getReferences().contains(m1Refs.get(1)));
+      assertTrue(m1.getReferences().contains(m1Refs.get(2)));
+      
+      assertMessageNotInStore(m2);
+      
+      assertMessageInStore(m3, queue);
+      assertEquals(3, m3.getReferences().size());
+      assertTrue(m3.getReferences().contains(m3Refs.get(0)));
+      assertTrue(m3.getReferences().contains(m3Refs.get(1)));
+      assertTrue(m3.getReferences().contains(m3Refs.get(3)));
+      
+      assertMessageInStore(m4, queue);
+      assertEquals(4, m4.getReferences().size());
+      
+      assertMessageInStore(m5, queue);
+      assertEquals(4, m5.getReferences().size());
+      
+      //Delete the rest
+      refsToRemove.clear();
+      refsToRemove.addAll(m1.getReferences());
+      refsToRemove.addAll(m3.getReferences());
+      refsToRemove.addAll(m4.getReferences());
+      refsToRemove.addAll(m5.getReferences());
+      
+      xid = generateXid();
+      
+      pm.prepareTransaction(xid, null, refsToRemove);
+      
+      pm.commitPreparedTransaction(xid);
+      
+      assertMessageNotInStore(m1);
+      assertMessageNotInStore(m2);
+      assertMessageNotInStore(m4);
+      assertMessageNotInStore(m5);
+      assertMessageNotInStore(m5);
+      
+      //try with nulls
+      xid = generateXid();
+      try
+      {
+         pm.prepareTransaction(xid, null, null);
+         fail("Should throw exception");
+      }
+      catch (IllegalArgumentException e)
+      {
+         //Ok
+      }
+   }     
+      
+   public void testPrepareAndCommitTransactionWithNoPersistentMessages() throws Exception
+   {      
+      List<Message> msgs = new ArrayList<Message>();
+          
+      Queue queue = createQueue(67);
+           
+      Message m1 = createMessageWithRefs(1, queue);
+      m1.setDurable(false);
+      List<MessageReference> m1Refs = new ArrayList<MessageReference>(m1.getReferences());
+    
+      msgs.add(m1);
+      
+      Message m2 = createMessageWithRefs(2, queue);
+      m2.setDurable(false);
+
+      msgs.add(m2);
+      
+      Message m3 = createMessageWithRefs(3, queue);
+      m3.setDurable(false);
+      List<MessageReference> m3Refs = new ArrayList<MessageReference>(m3.getReferences());
+      
+      msgs.add(m3);
+      
+      //Delete some refs
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      refsToRemove.add(m1.getReferences().get(0));
+      refsToRemove.add(m1.getReferences().get(3));
+      
+      refsToRemove.add(m2.getReferences().get(0));
+      refsToRemove.add(m2.getReferences().get(1));
+      refsToRemove.add(m2.getReferences().get(2));
+      refsToRemove.add(m2.getReferences().get(3));
+      
+      refsToRemove.add(m3.getReferences().get(2));
+      
+      Xid xid = generateXid();
+      
+      try
+      {
+         //Nothing to be persisted in the tx - which is illegal
+         
+         pm.prepareTransaction(xid, msgs, refsToRemove);
+         
+         fail("Should throw exception");
+      }
+      catch (IllegalArgumentException e)
+      {
+         //Ok
+      }
+            
+      
+   }     
+   
+   public void testPrepareAndUnprepareTransaction() throws Exception
+   {      
+      List<Message> msgs = new ArrayList<Message>();
+          
+      Queue queue = createQueue(67);
+        
+      Message m1 = createMessageWithRefs(1, queue);
+
+      msgs.add(m1);
+      
+      Message m2 = createMessageWithRefs(2, queue);
+
+      msgs.add(m2);
+      
+      Message m3 = createMessageWithRefs(3, queue);
+
+      msgs.add(m3);
+      
+      pm.commitTransaction(msgs, null);
+       
+      assertMessageInStore(m1, queue);
+      
+      assertMessageInStore(m2, queue);
+      
+      assertMessageInStore(m3, queue);
+      
+      
+      //Add a couple more
+      
+      List<Message> msgsMore = new ArrayList<Message>();
+            
+      Message m4 = createMessageWithRefs(4, queue);
+      msgsMore.add(m4);
+      
+      Message m5 = createMessageWithRefs(5, queue);
+      msgsMore.add(m5);
+      
+      //Delete some refs
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      refsToRemove.add(m1.getReferences().get(0));
+      refsToRemove.add(m1.getReferences().get(3));
+      
+      refsToRemove.add(m2.getReferences().get(0));
+      refsToRemove.add(m2.getReferences().get(1));
+      refsToRemove.add(m2.getReferences().get(2));
+      refsToRemove.add(m2.getReferences().get(3));
+      
+      refsToRemove.add(m3.getReferences().get(2));
+      
+      Xid xid = generateXid();
+      
+      pm.prepareTransaction(xid, msgsMore, refsToRemove);
+      
+      pm.unprepareTransaction(xid, msgsMore, refsToRemove);
+                  
+      assertNumMessagesInStore(3);      
+   }     
+   
+   public void testUpdateDeliveryCount() throws Exception
+   {
+      Queue queue = createQueue(67);
+      
+      Message m1 = createMessageWithRefs(1, queue);
+      
+      assertEquals(0, m1.getReferences().get(0).getDeliveryCount());
+      assertEquals(0, m1.getReferences().get(1).getDeliveryCount());
+      assertEquals(0, m1.getReferences().get(2).getDeliveryCount());
+      assertEquals(0, m1.getReferences().get(3).getDeliveryCount());
+      
+      pm.addMessage(m1);
+      
+      final int delCount = 77;
+      m1.getReferences().get(1).setDeliveryCount(delCount);
+      pm.updateDeliveryCount(queue, m1.getReferences().get(1));
+      
+      final int delCount2 = 423;
+      
+      m1.getReferences().get(3).setDeliveryCount(delCount2);
+      pm.updateDeliveryCount(queue, m1.getReferences().get(3));
+      
+      assertMessageInStore(m1, queue);
+   }
+   
+   public void testRefsWithDifferentQueues() throws Exception
+   {
+      final int numQueues = 10;
+      
+      List<Message> msgs = new ArrayList<Message>();
+                  
+      for (int i = 0; i < numQueues; i++)
+      {
+         Queue queue = createQueue(i);
+         
+         MessageReference ref = generateReference(queue, i);
+         
+         msgs.add(ref.getMessage());
+         
+         pm.addMessage(ref.getMessage());   
+         
+         assertEquals(queue, ref.getQueue());
+      }
+      
+      for (Message msg: msgs)
+      {
+         assertMessageInStore(msg, msg.getReferences().get(0).getQueue());
+      }            
+   }
+       
+   public void testAddRemoveBindings() throws Exception
+   {
+      Queue queue1 = new QueueImpl(1, "queue1", new FilterImpl("a=1"), false, true, false, -1, null, null);
+      
+      Queue queue2 = new QueueImpl(2, "queue2", new FilterImpl("a=1"), false, true, false, -1, null, null);
+            
+      Queue queue3 = new QueueImpl(3, "queue3", new FilterImpl("a=1"), false, true, false, -1, null, null);
+      
+      Queue queue4 = new QueueImpl(4, "queue4", new FilterImpl("a=1"), false, true, false, -1, null, null);
+      
+      String condition1 = "queue.condition1";
+      
+      Binding binding1 = new BindingImpl(1, condition1, queue1);
+      
+      String condition2 = "queue.condition2";
+      
+      Binding binding2 = new BindingImpl(1, condition2, queue2);
+      
+      String condition3 = "queue.condition3";
+      
+      Binding binding3 = new BindingImpl(3, condition3, queue3);
+      
+      //same condition
+      String condition4 = "queue.condition3";
+      
+      Binding binding4 = new BindingImpl(3, condition4, queue4);
+      
+      
+      pm.addBinding(binding1);
+      
+      pm.addBinding(binding2);
+      
+      pm.addBinding(binding3);
+      
+      pm.addBinding(binding4);
+      
+      List<Binding> bindings = pm.loadBindings(new FakeQueueFactory());
+      
+      assertEquals(4, bindings.size());
+      
+      assertEquivalent(bindings.get(0), binding1);
+      
+      assertEquivalent(bindings.get(1), binding2);
+      
+      assertEquivalent(bindings.get(2), binding3);
+      
+      assertEquivalent(bindings.get(3), binding4);
+      
+      assertEquals(0, bindings.get(0).getQueue().getMessageCount());
+      
+      assertEquals(0, bindings.get(0).getQueue().getPersistenceID());
+      
+      assertEquals(0, bindings.get(1).getQueue().getMessageCount());
+      
+      assertEquals(1, bindings.get(1).getQueue().getPersistenceID());
+      
+      assertEquals(0, bindings.get(2).getQueue().getMessageCount());
+      
+      assertEquals(2, bindings.get(2).getQueue().getPersistenceID());
+      
+      assertEquals(0, bindings.get(3).getQueue().getMessageCount());
+      
+      assertEquals(3, bindings.get(3).getQueue().getPersistenceID());
+      
+      
+      pm.deleteBinding(binding2);
+      
+      bindings = pm.loadBindings(new FakeQueueFactory());
+      
+      assertEquals(3, bindings.size());
+      
+      assertEquivalent(bindings.get(0), binding1);
+      
+      assertEquivalent(bindings.get(1), binding3);
+      
+      assertEquivalent(bindings.get(2), binding4);
+      
+      
+      pm.deleteBinding(binding3);
+      
+      pm.deleteBinding(binding4);
+      
+      pm.deleteBinding(binding1);
+      
+      bindings = pm.loadBindings(new FakeQueueFactory());
+      
+      assertEquals(0, bindings.size());                          
+   }  
+   
+   public void testLoadBindings() throws Exception
+   {
+      Queue queue1 = new QueueImpl(1, "queue1", null, false, true, false, -1, null, null);
+      
+      Queue queue2 = new QueueImpl(2, "queue2", null, false, true, false, -1, null, null);
+            
+      Queue queue3 = new QueueImpl(3, "queue3", null, false, true, false, -1, null, null);
+      
+      Queue queue4 = new QueueImpl(4, "queue4", null, false, true, false, -1, null, null);
+      
+      String condition1 = "queue.condition1";
+      
+      Binding binding1 = new BindingImpl(1, condition1, queue1);
+      
+      String condition2 = "queue.condition2";
+      
+      Binding binding2 = new BindingImpl(1, condition2, queue2);
+      
+      String condition3 = "queue.condition3";
+      
+      Binding binding3 = new BindingImpl(3, condition3, queue3);
+      
+      //same condition
+      String condition4 = "queue.condition3";
+      
+      Binding binding4 = new BindingImpl(3, condition4, queue4);
+                        
+      pm.addBinding(binding1);
+      
+      pm.addBinding(binding2);
+      
+      pm.addBinding(binding3);
+      
+      pm.addBinding(binding4);
+            
+      final int numMessages = 10;            
+               
+      List<Message> msgs = new ArrayList<Message>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         Message msg = this.generateMessage(i);
+         
+         msgs.add(msg);
+         
+         msg.createReference(queue1);
+         
+         msg.createReference(queue2);
+         
+         msg.createReference(queue3);
+         
+         msg.createReference(queue4);
+         
+         pm.addMessage(msg);   
+      }         
+      
+      List<Binding> bindings = pm.loadBindings(new FakeQueueFactory());
+      
+      assertEquals(4, bindings.size());
+      
+      assertEquivalent(bindings.get(0), binding1);
+      
+      assertEquivalent(bindings.get(1), binding2);
+      
+      assertEquivalent(bindings.get(2), binding3);
+      
+      assertEquivalent(bindings.get(3), binding4);
+      
+      checkQueue(bindings.get(0).getQueue(), msgs);
+      
+      checkQueue(bindings.get(1).getQueue(), msgs);
+      
+      checkQueue(bindings.get(2).getQueue(), msgs);
+      
+      checkQueue(bindings.get(3).getQueue(), msgs);
+   }  
+   
+   
+   public void testGetInDoubtXids() throws Exception
+   {
+      Queue queue = createQueue(67);
+      
+      Message message1 = createMessageWithRefs(1, queue);
+      
+      List<Message> msgs = new ArrayList<Message>();
+      
+      msgs.add(message1);
+      
+      Xid xid1 = generateXid();
+      
+      pm.prepareTransaction(xid1, msgs, null);    
+      
+      pm.setInRecoveryMode(true);
+      
+      List<Xid> xids = pm.getInDoubtXids();
+      
+      assertNotNull(xids);
+      
+      assertEquals(1, xids.size());
+      
+      assertEquals(xid1, xids.get(0));
+      
+      
+      
+      Message message2 = createMessageWithRefs(2, queue);
+      
+      msgs.clear();
+      
+      msgs.add(message2);
+      
+      Xid xid2 = generateXid();
+      
+      pm.prepareTransaction(xid2, msgs, null);    
+      
+      xids = pm.getInDoubtXids();
+      
+      assertNotNull(xids);
+      
+      assertEquals(2, xids.size());
+      
+      assertTrue(xids.contains(xid1));
+      
+      assertTrue(xids.contains(xid2));
+      
+      
+      pm.commitPreparedTransaction(xid1);
+      
+      pm.commitPreparedTransaction(xid2);
+      
+      xids = pm.getInDoubtXids();
+      
+      assertNotNull(xids);
+      
+      assertEquals(0, xids.size());            
+   }
+   
+   public void testGetInDoubtXidsWithRestart() throws Exception
+   {
+      Queue queue = createQueue(67);
+      
+      Message message1 = createMessageWithRefs(1, queue);
+      
+      List<Message> msgs = new ArrayList<Message>();
+      
+      msgs.add(message1);
+      
+      Xid xid1 = generateXid();
+      
+      pm.prepareTransaction(xid1, msgs, null);   
+      
+      pm.setInRecoveryMode(true);
+      
+      List<Xid> xids = pm.getInDoubtXids();
+      
+      assertNotNull(xids);
+      
+      assertEquals(1, xids.size());
+      
+      assertEquals(xid1, xids.get(0));
+      
+      
+      
+      Message message2 = createMessageWithRefs(2, queue);
+      
+      msgs.clear();
+      
+      msgs.add(message2);
+      
+      Xid xid2 = generateXid();
+      
+      pm.prepareTransaction(xid2, msgs, null);    
+      
+      xids = pm.getInDoubtXids();
+      
+      assertNotNull(xids);
+      
+      assertEquals(2, xids.size());
+      
+      assertTrue(xids.contains(xid1));
+      
+      assertTrue(xids.contains(xid2));
+      
+      pm.getEnvironment().stop();
+            
+      pm.stop();
+      
+      pm.getEnvironment().start();
+      
+      pm.start();
+      
+      pm.setInRecoveryMode(true);
+      
+      xids = pm.getInDoubtXids();
+      
+      assertNotNull(xids);
+      
+      assertEquals(2, xids.size());
+      
+      assertTrue(xids.contains(xid1));
+      
+      assertTrue(xids.contains(xid2));
+      
+      
+      pm.commitPreparedTransaction(xid1);
+      
+      pm.commitPreparedTransaction(xid2);
+      
+      xids = pm.getInDoubtXids();
+      
+      assertNotNull(xids);
+      
+      assertEquals(0, xids.size());            
+   }
+   
+   public void testSetGetRecoveryMode() throws Exception
+   {
+      assertFalse(pm.isInRecoveryMode());
+                 
+      try
+      {
+         pm.getInDoubtXids();
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+      
+      pm.setInRecoveryMode(true);
+      
+      assertTrue(pm.isInRecoveryMode());
+      
+      pm.getInDoubtXids();
+      
+      pm.setInRecoveryMode(false);
+      
+      assertFalse(pm.isInRecoveryMode());
+   }
+   
+   // Private --------------------------------------------------------------------
+   
+   private void checkQueue(Queue queue, List<Message> messages)
+   {
+      assertEquals(messages.size(), queue.getMessageCount());
+      
+      List<MessageReference> refs = queue.list(null);
+      
+      int i = 0;
+      for (MessageReference ref: refs)
+      {
+         assertEquivalent(messages.get(i++), ref.getMessage(), false);
+      } 
+   }
+   
+   private void assertEquivalent(Binding b1, Binding b2)
+   {
+      assertEquals(b1.getNodeID(), b2.getNodeID());
+      
+      assertEquals(b1.getAddress(), b2.getAddress());
+      
+      Queue queue1 = b1.getQueue();
+      
+      Queue queue2 = b2.getQueue();
+      
+      assertEquals(queue1.getPersistenceID(), queue2.getPersistenceID());
+      
+      assertEquals(queue1.getName(), queue2.getName());
+      
+      assertEquals(queue1.isClustered(), queue2.isClustered());
+      
+      assertEquals(queue1.isDurable(), queue2.isDurable());
+      
+      assertEquals(queue1.isTemporary(), queue2.isTemporary());
+   }
+   
+   private Message extractMessage(Map<Long, Queue> queues, long id, byte[] msgBytes, byte[] refBytes) throws Exception
+   {
+      ByteBuffer buffer = ByteBuffer.wrap(msgBytes);
+      
+      int type = buffer.getInt();
+      
+      long expiration = buffer.getLong();
+      
+      long timestamp = buffer.getLong();
+      
+      byte priority = buffer.get();
+      
+      int headerSize = buffer.getInt();
+      
+      byte[] headers = new byte[headerSize];
+      
+      buffer.get(headers);
+      
+      int payloadSize = buffer.getInt();
+      
+      byte[] payload = null;
+      
+      if (payloadSize != 0)
+      {
+         payload = new byte[payloadSize];
+         
+         buffer.get(payload);
+      }
+      
+      Message message = new MessageImpl(id, type, true, expiration, timestamp, priority,
+                                        headers, payload);
+      
+      buffer = ByteBuffer.wrap(refBytes);
+      
+      while (buffer.hasRemaining())
+      {
+         long queueID = buffer.getLong();
+         
+         int deliveryCount = buffer.getInt();
+         
+         long scheduledDeliveryTime = buffer.getLong();
+         
+         MessageReference reference = message.createReference(queues.get(queueID));
+         
+         reference.setDeliveryCount(deliveryCount);
+         
+         reference.setScheduledDeliveryTime(scheduledDeliveryTime);
+      } 
+      
+      return message;
+   }
+   
+   private void assertMessageInStore(Message m, Queue queue) throws Exception
+   {
+      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
+      
+      BDBJEDatabase refDB = bdb.getDatabase(BDBJEPersistenceManager.REFERENCE_DB_NAME);
+      
+      byte[] msgBytes = msgDB.get(m.getMessageID());
+      
+      assertNotNull(msgBytes);
+      
+      byte[] refBytes = refDB.get(m.getMessageID());
+      
+      assertNotNull(refBytes);
+      
+      Map<Long, Queue> queues = new HashMap<Long, Queue>();
+      
+      queues.put(queue.getPersistenceID(), queue);
+      
+      Message m2 = extractMessage(queues, m.getMessageID(), msgBytes, refBytes);
+       
+      assertEquivalent(m, m2);               
+   }
+   
+   private void assertNumMessagesInStore(int num) throws Exception
+   {
+      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
+      
+      assertEquals(num, msgDB.size());                    
+   }
+   
+   private void assertMessageNotInStore(Message m) throws Exception
+   {
+      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
+      
+      BDBJEDatabase refDB = bdb.getDatabase(BDBJEPersistenceManager.REFERENCE_DB_NAME);
+      
+      
+      byte[] msgBytes = msgDB.get(m.getMessageID());
+      
+      assertNull(msgBytes);
+      
+      byte[] refBytes = refDB.get(m.getMessageID());
+      
+      assertNull(refBytes);         
+   }
+   
+   private void assertStoreEmpty() throws Exception
+   {
+      BDBJEDatabase msgDB = bdb.getDatabase(BDBJEPersistenceManager.MESSAGE_DB_NAME);
+      
+      BDBJEDatabase refDB = bdb.getDatabase(BDBJEPersistenceManager.REFERENCE_DB_NAME);
+      
+      assertEquals(0, msgDB.size());
+      
+      assertEquals(0, refDB.size());
+   }
+   
+   private Message createMessageWithRefs(long id, Queue queue)
+   {
+      Message m = generateMessage(id);
+      
+      m.createReference(queue);
+      
+      m.createReference(queue);
+      
+      m.createReference(queue);
+      
+      m.createReference(queue);
+      
+      return m;
+   }
+   
+
+   // Inner classes ---------------------------------------------------------------
+        
+}

Copied: trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/FakeBDBJEEnvironmentTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/FakeBDBJEEnvironmentTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/FakeBDBJEEnvironmentTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/FakeBDBJEEnvironmentTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,38 @@
+package org.jboss.messaging.core.persistence.impl.bdbje.test.unit;
+
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
+import org.jboss.messaging.core.persistence.impl.bdbje.test.unit.fakes.FakeBDBJEEnvironment;
+
+/**
+ * 
+ * A FakeBDBJEEnvironmentTest
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class FakeBDBJEEnvironmentTest extends BDBJEEnvironmentTestBase
+{
+   protected BDBJEEnvironment createEnvironment() throws Exception
+   {
+      BDBJEEnvironment env = new FakeBDBJEEnvironment();
+      
+      return env;
+   }   
+   
+   protected void createDir(String path)
+   {      
+   }
+   
+   protected void copyEnvironment()
+   {      
+   }
+   
+   protected void copyBackEnvironment()
+   {      
+   }    
+   
+   protected boolean isFake()
+   {
+      return true;
+   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/fakes/FakeBDBJEEnvironment.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/fakes/FakeBDBJEEnvironment.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/fakes/FakeBDBJEEnvironment.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/fakes/FakeBDBJEEnvironment.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,550 @@
+package org.jboss.messaging.core.persistence.impl.bdbje.test.unit.fakes;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJECursor;
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEDatabase;
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
+import org.jboss.messaging.core.persistence.impl.bdbje.BDBJETransaction;
+import org.jboss.messaging.util.Pair;
+
+/**
+ * 
+ * A FakeBDBJEEnvironment
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class FakeBDBJEEnvironment implements BDBJEEnvironment
+{
+   private String environmentPath;
+   
+   private Map<String, FakeBDBJETransaction> transactions = new HashMap<String, FakeBDBJETransaction>();
+   
+   private boolean transacted;
+   
+   private boolean syncOS;
+   
+   private boolean syncVM;     
+
+   private long memoryCacheSize = -1;
+   
+   private boolean started;
+         
+   private Map<Thread, FakeBDBJETransaction> implicitTXs = new ConcurrentHashMap<Thread, FakeBDBJETransaction>();
+   
+   private Map<String, BDBJEDatabase> databases = new HashMap<String, BDBJEDatabase>();
+                     
+   public boolean isSyncOS()
+   {
+      return syncOS;
+   }
+
+   public void setSyncOS(boolean sync)
+   {
+      if (started)
+      {
+         throw new IllegalStateException("Cannot set SyncOS when started");
+      }
+      syncOS = sync;
+   }
+
+   public boolean isSyncVM()
+   {
+      return syncVM;
+   }
+   
+   public void setSyncVM(boolean sync)
+   {
+      if (started)
+      {
+         throw new IllegalStateException("Cannot set SyncVM when started");
+      }
+      syncVM = sync;
+   }
+
+   public boolean isTransacted()
+   {
+      return transacted;
+   }
+   
+   public void setTransacted(boolean transacted)
+   {
+      if (started)
+      {
+         throw new IllegalStateException("Cannot set transacted when started");
+      }
+      this.transacted = transacted;
+   }
+
+   public long getMemoryCacheSize()
+   {
+      return memoryCacheSize;
+   }  
+
+   public void setMemoryCacheSize(long size)
+   {
+      if (started)
+      {
+         throw new IllegalStateException("Cannot set memory cache size when started");
+      }
+      this.memoryCacheSize = size;
+   }
+   
+   public void setEnvironmentPath(String environmentPath)
+   {
+      if (started)
+      {
+         throw new IllegalStateException("Cannot set environmentPath when started");
+      }
+      this.environmentPath = environmentPath;
+   }
+   
+   private boolean createEnvironment;
+   
+   public boolean isCreateEnvironment()
+   {
+      return createEnvironment;
+   }
+
+   public void setCreateEnvironment(boolean create)
+   {
+      this.createEnvironment = create;
+   }
+   
+   public String getEnvironmentPath()
+   {
+      return environmentPath;
+   }
+   
+   public void start() throws Exception
+   {
+      if (environmentPath == null)
+      {
+         throw new IllegalStateException("Must set environmentPath before starting");
+      }
+      if (started)
+      {
+         throw new IllegalStateException("Already started");
+      }
+      started = true;
+   }
+
+   public void stop() throws Exception
+   {
+      if (!started)
+      {
+         throw new IllegalStateException("Not started");
+      }
+      started = false;
+   }
+   
+   public boolean isStarted()
+   {
+      return started;
+   }
+   
+   public BDBJETransaction createTransaction() throws Exception
+   {
+      return createTransactionInternal(null);
+   }
+   
+   public synchronized BDBJEDatabase getDatabase(String databaseName) throws Exception
+   {
+      BDBJEDatabase database = databases.get(databaseName);
+      
+      if (database == null)
+      {
+         database = new FakeBDBJEDatabase();
+         
+         databases.put(databaseName, database);
+      }
+      
+      return database;
+   }
+
+   public List<Xid> getInDoubtXids() throws Exception
+   {
+      List<Xid> xids = new ArrayList<Xid>();
+      
+      for (FakeBDBJETransaction tx: transactions.values())
+      {
+         if (tx.isPrepared())
+         {
+            xids.add(tx.getXid());
+         }
+      }
+      
+      return xids;
+   }
+   
+   public void startWork(Xid xid) throws Exception
+   {
+      checkStartWork(xid);
+      
+      implicitTXs.put(Thread.currentThread(), createTransactionInternal(xid));            
+   }
+   
+   public void endWork(Xid xid, boolean fail) throws Exception
+   {
+      checkEndWork(xid);
+      
+      implicitTXs.remove(Thread.currentThread());
+   }
+   
+   public void prepare(Xid xid) throws Exception
+   {
+      FakeBDBJETransaction tx = findTXForXid(xid);
+      
+      checkPrepare(tx);
+      
+      tx.prepare();
+   }
+   
+   public void commit(Xid xid) throws Exception
+   {      
+      FakeBDBJETransaction tx = findTXForXid(xid);
+      
+      checkCommitRollback(tx);
+            
+      tx.commit();
+   }
+
+   public void rollback(Xid xid) throws Exception
+   {
+      FakeBDBJETransaction tx = findTXForXid(xid);
+      
+      checkCommitRollback(tx);
+                  
+      tx.rollback();   
+   }
+         
+   // Private -----------------------------------------------------------------------
+   
+   private FakeBDBJETransaction createTransactionInternal(Xid xid) throws Exception
+   {
+      FakeBDBJETransaction tx = new FakeBDBJETransaction(xid);
+      
+      transactions.put(tx.id, tx);
+      
+      return tx;
+   }      
+   
+   private FakeBDBJETransaction findTXForXid(Xid xid)
+   {
+      for (FakeBDBJETransaction tx: transactions.values())
+      {
+         if (xid.equals(tx.xid))
+         {
+            return tx;
+         }
+      }
+      return null;
+   }
+   
+   private void checkStartWork(Xid xid)
+   {
+      if (implicitTXs.get(Thread.currentThread()) != null)
+      {
+         throw new IllegalStateException("Already implicit transaction");
+      }
+      
+      if (findTXForXid(xid) != null)
+      {
+         throw new IllegalStateException("Already tx for xid");
+      }            
+   }
+   
+   private void checkEndWork(Xid xid)
+   {
+      FakeBDBJETransaction tx = implicitTXs.get(Thread.currentThread());
+      
+      if (tx == null)
+      {
+         throw new IllegalStateException("No implicit tx");
+      }            
+      
+      if (!tx.xid.equals(xid))
+      {
+         throw new IllegalStateException("Wrong xid");
+      }
+   }
+
+   
+   private void checkPrepare(FakeBDBJETransaction tx)
+   {
+      if (tx == null)
+      {
+         throw new IllegalStateException("Cannot find tx for xid");
+      }
+      
+      if (implicitTXs.containsKey(Thread.currentThread()))
+      {
+         throw new IllegalStateException("Work not ended");
+      }
+   }
+   
+   
+   private void checkCommitRollback(FakeBDBJETransaction tx)
+   {
+      if (tx == null)
+      {
+         throw new IllegalStateException("Cannot find tx for xid");
+      }
+      
+      if (!tx.prepared)
+      {
+         throw new IllegalStateException("Tx not prepared");
+      }
+      
+      if (implicitTXs.containsKey(Thread.currentThread()))
+      {
+         throw new IllegalStateException("Work not ended");
+      }
+   }
+   
+   
+   // Inner classes ------------------------------------------------------------------
+   
+   private class FakeBDBJETransaction implements BDBJETransaction
+   {
+      private String id = java.util.UUID.randomUUID().toString();
+      
+      private Xid xid;
+      
+      private List<Action> actions = new ArrayList<Action>();
+      
+      private boolean prepared;
+      
+      FakeBDBJETransaction(Xid xid)
+      {
+         this.xid = xid;
+      }
+      
+      public void commit() throws Exception
+      {
+         for (Action action : actions)
+         {
+            if (action.put)
+            {
+               action.database.put(null, action.id, action.bytes, action.offset, action.length);
+            }
+            else
+            {
+               action.database.remove(null, action.id);
+            }
+         }
+         
+         actions.clear();
+         
+         transactions.remove(id);
+      }
+
+      public void prepare() throws Exception
+      {                
+         prepared = true;
+      }
+
+      public void rollback() throws Exception
+      {
+         actions.clear(); 
+         
+         transactions.remove(id);
+      }
+      
+      public boolean isPrepared()
+      {
+         return prepared;
+      }
+      
+      public Xid getXid()
+      {
+         return xid;
+      }
+            
+   }
+   
+   private class Action
+   {
+      public BDBJEDatabase database;
+      
+      public boolean put;
+      
+      public long id;
+      
+      public byte[] bytes;
+      
+      public int offset;
+      
+      public int length;
+      
+      public Action(BDBJEDatabase database, boolean put, long id, byte[] bytes, int offset, int length)
+      {
+         this.database = database;
+         
+         this.put = put;
+         
+         this.id = id;
+         
+         this.bytes = bytes;
+         
+         this.offset = offset;
+         
+         this.length = length;
+      }
+   }
+   
+   private class FakeBDBJEDatabase implements BDBJEDatabase
+   {     
+      private Map<Long, byte[]> store = new LinkedHashMap<Long, byte[]>();
+      
+      private AtomicInteger cursorCount = new AtomicInteger(0);
+      
+      public void close() throws Exception
+      {
+         if (cursorCount.get() != 0)
+         {
+            throw new IllegalStateException("Cannot close. There are cursors open");
+         }
+      }
+
+      public BDBJECursor cursor() throws Exception
+      {
+         return new FakeBDBJECursor();
+      }
+
+      private BDBJETransaction getTx(BDBJETransaction tx)
+      {
+         if (tx == null)
+         {            
+            tx = implicitTXs.get(Thread.currentThread());
+         }
+         return tx;
+      }
+      
+      public void put(BDBJETransaction tx, long id, byte[] bytes, int offset,
+            int length) throws Exception
+      {
+         tx = getTx(tx);
+         
+         if (tx == null)
+         {
+            if (offset == 0 && bytes.length == length)
+            {               
+               store.put(id, bytes);
+            }
+            else
+            {
+               byte[] currentBytes = store.get(id);
+               
+               if (offset == currentBytes.length)
+               {
+                  byte[] newBytes = new byte[currentBytes.length + bytes.length];
+                  
+                  ByteBuffer buffer = ByteBuffer.wrap(newBytes);
+                  
+                  buffer.put(currentBytes);
+                  
+                  buffer.put(bytes);
+                  
+                  store.put(id, newBytes);
+               }
+               else if (offset < currentBytes.length)
+               {                 
+                  if (offset + length > currentBytes.length)
+                  {
+                     throw new IllegalStateException("Invalid offset/length");
+                  }
+                  
+                  byte[] newBytes = new byte[currentBytes.length - (length - bytes.length)];
+                  
+                  System.arraycopy(currentBytes, 0, newBytes, 0, offset);
+                  
+                  System.arraycopy(bytes, 0, newBytes, offset, bytes.length);
+                                 
+                  System.arraycopy(currentBytes, offset + length, newBytes,
+                                   offset + bytes.length, currentBytes.length - (offset + length));
+                  
+                  store.put(id, newBytes);
+               }
+               else
+               {
+                  throw new IllegalStateException("Invalid offset " + offset);
+               }
+            }            
+         }
+         else
+         {
+            FakeBDBJETransaction ftx = (FakeBDBJETransaction)tx;
+            
+            ftx.actions.add(new Action(this, true, id, bytes, offset, length));
+         }
+         
+      }
+
+      public void remove(BDBJETransaction tx, long id) throws Exception
+      {
+         tx = getTx(tx);
+         
+         if (tx == null)
+         {
+            store.remove(id);
+         }
+         else
+         {
+            FakeBDBJETransaction ftx = (FakeBDBJETransaction)tx;
+            
+            ftx.actions.add(new Action(this, false, id, null, -1, -1));
+         }
+      }
+      
+      public byte[] get(long id) throws Exception
+      {
+         return store.get(id);
+      }
+
+      public long size() throws Exception
+      {
+         return store.size();
+      }
+      
+      private class FakeBDBJECursor implements BDBJECursor
+      {
+         private Iterator<Map.Entry<Long,byte[]>> iterator = store.entrySet().iterator();
+         
+         FakeBDBJECursor()
+         {
+            cursorCount.incrementAndGet();
+         }
+
+         public void close() throws Exception
+         {         
+            cursorCount.decrementAndGet();
+         }
+
+         public Pair<Long, byte[]> getNext() throws Exception
+         {
+            if (iterator.hasNext())
+            {
+               Map.Entry<Long,byte[]> entry = iterator.next();
+               
+               return new Pair<Long, byte[]>(entry.getKey(), entry.getValue());
+            }
+            else
+            {
+               return null;
+            }
+         }      
+      }
+   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/test/unit (from rev 3798, trunk/tests/src/org/jboss/messaging/core/remoting/ssl/test/unit)

Deleted: trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/test/unit/SSLSupportTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/ssl/test/unit/SSLSupportTest.java	2008-02-26 08:33:27 UTC (rev 3798)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/test/unit/SSLSupportTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,122 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.ssl.test.unit;
-
-import java.io.File;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.remoting.ssl.SSLSupport;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * 
- * @version <tt>$Revision$</tt>
- * 
- */
-public class SSLSupportTest extends TestCase
-{
-   private String keyStorePath;
-   private String keyStorePassword;
-   private String trustStorePath;
-   private String trustStorePassword;
-
-   // Constants -----------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   @Override
-   protected void setUp() throws Exception
-   {
-      keyStorePath = "messaging.keystore";
-      keyStorePassword = "secureexample";
-      trustStorePath = "messaging.truststore";
-      trustStorePassword = keyStorePassword;
-   }
-
-   public void testServerContextWithRightParameters() throws Exception
-   {
-      SSLSupport.createServerContext(keyStorePath, keyStorePassword,
-            trustStorePath, trustStorePassword);
-   }
-
-   public void testServerContextWithBadKeyStorePath() throws Exception
-   {
-      try
-      {
-         SSLSupport.createServerContext("not a keystore", keyStorePassword,
-               trustStorePath, trustStorePassword);
-         fail();
-      } catch (Exception e)
-      {
-      }
-   }
-
-   public void testServerContextWithKeyStorePathAsRelativePath() throws Exception
-   {
-      // this test is dependent on a path relative to the tests directory.
-      // it will fail if launch from somewhere else (or from an IDE)
-      File currentDir = new File(System.getProperty("user.dir"));
-      if (!currentDir.getAbsolutePath().endsWith("tests"))
-      {
-         return;
-      }
-      
-      SSLSupport.createServerContext("etc/messaging.keystore",
-            keyStorePassword, trustStorePath, trustStorePassword);
-   }
-   
-   public void testServerContextWithBadKeyStorePassword() throws Exception
-   {
-      try
-      {
-         SSLSupport.createServerContext(keyStorePath, "bad password",
-               trustStorePath, trustStorePassword);
-         fail();
-      } catch (Exception e)
-      {
-      }
-   }
-
-   public void testServerContextWithBadTrustStorePath() throws Exception
-   {
-      try
-      {
-         SSLSupport.createServerContext(keyStorePath, keyStorePassword,
-               "not a trust store", trustStorePassword);
-         fail();
-      } catch (Exception e)
-      {
-      }
-   }
-
-   public void testServerContextWithBadTrustStorePassword() throws Exception
-   {
-      try
-      {
-         SSLSupport.createServerContext(keyStorePath, keyStorePassword,
-               trustStorePath, "bad passord");
-         fail();
-      } catch (Exception e)
-      {
-      }
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-}

Copied: trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/test/unit/SSLSupportTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/remoting/ssl/test/unit/SSLSupportTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/test/unit/SSLSupportTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/ssl/test/unit/SSLSupportTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.impl.ssl.test.unit;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.remoting.impl.ssl.SSLSupport;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class SSLSupportTest extends TestCase
+{
+   private String keyStorePath;
+   private String keyStorePassword;
+   private String trustStorePath;
+   private String trustStorePassword;
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      keyStorePath = "messaging.keystore";
+      keyStorePassword = "secureexample";
+      trustStorePath = "messaging.truststore";
+      trustStorePassword = keyStorePassword;
+   }
+
+   public void testServerContextWithRightParameters() throws Exception
+   {
+      SSLSupport.createServerContext(keyStorePath, keyStorePassword,
+            trustStorePath, trustStorePassword);
+   }
+
+   public void testServerContextWithBadKeyStorePath() throws Exception
+   {
+      try
+      {
+         SSLSupport.createServerContext("not a keystore", keyStorePassword,
+               trustStorePath, trustStorePassword);
+         fail();
+      } catch (Exception e)
+      {
+      }
+   }
+
+   public void testServerContextWithKeyStorePathAsRelativePath() throws Exception
+   {
+      // this test is dependent on a path relative to the tests directory.
+      // it will fail if launch from somewhere else (or from an IDE)
+      File currentDir = new File(System.getProperty("user.dir"));
+      if (!currentDir.getAbsolutePath().endsWith("tests"))
+      {
+         return;
+      }
+      
+      SSLSupport.createServerContext("etc/messaging.keystore",
+            keyStorePassword, trustStorePath, trustStorePassword);
+   }
+   
+   public void testServerContextWithBadKeyStorePassword() throws Exception
+   {
+      try
+      {
+         SSLSupport.createServerContext(keyStorePath, "bad password",
+               trustStorePath, trustStorePassword);
+         fail();
+      } catch (Exception e)
+      {
+      }
+   }
+
+   public void testServerContextWithBadTrustStorePath() throws Exception
+   {
+      try
+      {
+         SSLSupport.createServerContext(keyStorePath, keyStorePassword,
+               "not a trust store", trustStorePassword);
+         fail();
+      } catch (Exception e)
+      {
+      }
+   }
+
+   public void testServerContextWithBadTrustStorePassword() throws Exception
+   {
+      try
+      {
+         SSLSupport.createServerContext(keyStorePath, keyStorePassword,
+               trustStorePath, "bad passord");
+         fail();
+      } catch (Exception e)
+      {
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Copied: trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit (from rev 3798, trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit)

Deleted: trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java	2008-02-26 08:33:27 UTC (rev 3798)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,75 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat.test.unit;
-
-import junit.framework.Assert;
-
-import org.jboss.messaging.core.impl.XidImpl;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * 
- * @version <tt>$Revision$</tt>
- * 
- */
-public class CodecAssert extends Assert
-{
-   // Constants -----------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   static void assertSameXids(XidImpl[] expected, XidImpl[] actual)
-   {
-      assertEquals(expected.length, actual.length);
-      for (int i = 0; i < expected.length; i++)
-      {
-         XidImpl expectedXid = expected[i];
-         XidImpl actualXid = actual[i];
-         assertEqualsByteArrays(expectedXid.getBranchQualifier(), actualXid
-               .getBranchQualifier());
-         assertEquals(expectedXid.getFormatId(), actualXid.getFormatId());
-         assertEqualsByteArrays(expectedXid.getGlobalTransactionId(), actualXid
-               .getGlobalTransactionId());
-      }
-   }
-
-   static void assertEqualsByteArrays(byte[] expected, byte[] actual)
-   {
-      assertEquals(expected.length, actual.length);
-      for (int i = 0; i < expected.length; i++)
-      {
-         assertEquals("byte at index " + i, expected[i], actual[i]);
-      }
-   }
-
-   static void assertEqualsByteArrays(int length, byte[] expected, byte[] actual)
-   {
-      // we check only for the given length (the arrays might be
-      // larger)
-      assertTrue(expected.length >= length);
-      assertTrue(actual.length >= length);
-      for (int i = 0; i < length; i++)
-      {
-         assertEquals("byte at index " + i, expected[i], actual[i]);
-      }
-   }
-
-   
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-}

Copied: trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.impl.wireformat.test.unit;
+
+import junit.framework.Assert;
+
+import org.jboss.messaging.core.server.impl.XidImpl;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class CodecAssert extends Assert
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   static void assertSameXids(XidImpl[] expected, XidImpl[] actual)
+   {
+      assertEquals(expected.length, actual.length);
+      for (int i = 0; i < expected.length; i++)
+      {
+         XidImpl expectedXid = expected[i];
+         XidImpl actualXid = actual[i];
+         assertEqualsByteArrays(expectedXid.getBranchQualifier(), actualXid
+               .getBranchQualifier());
+         assertEquals(expectedXid.getFormatId(), actualXid.getFormatId());
+         assertEqualsByteArrays(expectedXid.getGlobalTransactionId(), actualXid
+               .getGlobalTransactionId());
+      }
+   }
+
+   static void assertEqualsByteArrays(byte[] expected, byte[] actual)
+   {
+      assertEquals(expected.length, actual.length);
+      for (int i = 0; i < expected.length; i++)
+      {
+         assertEquals("byte at index " + i, expected[i], actual[i]);
+      }
+   }
+
+   static void assertEqualsByteArrays(int length, byte[] expected, byte[] actual)
+   {
+      // we check only for the given length (the arrays might be
+      // larger)
+      assertTrue(expected.length >= length);
+      assertTrue(actual.length >= length);
+      for (int i = 0; i < length; i++)
+      {
+         assertEquals("byte at index " + i, expected[i], actual[i]);
+      }
+   }
+
+   
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Deleted: trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java	2008-02-26 08:33:27 UTC (rev 3798)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,1571 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat.test.unit;
-
-import static org.jboss.messaging.core.remoting.codec.AbstractPacketCodec.BOOLEAN_LENGTH;
-import static org.jboss.messaging.core.remoting.codec.AbstractPacketCodec.FALSE;
-import static org.jboss.messaging.core.remoting.codec.AbstractPacketCodec.INT_LENGTH;
-import static org.jboss.messaging.core.remoting.codec.AbstractPacketCodec.LONG_LENGTH;
-import static org.jboss.messaging.core.remoting.codec.AbstractPacketCodec.TRUE;
-import static org.jboss.messaging.core.remoting.codec.AbstractPacketCodec.sizeof;
-import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.NOT_NULL_STRING;
-import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.NULL_BYTE;
-import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.NULL_STRING;
-import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.UTF_8_ENCODER;
-import static org.jboss.messaging.core.remoting.wireformat.AbstractPacket.NO_ID_SET;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.BYTES;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.CLOSE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.CONN_CREATESESSION;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.CONN_CREATESESSION_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.CONN_START;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.CONN_STOP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.CONS_FLOWTOKEN;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.CREATECONNECTION;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.CREATECONNECTION_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.NULL;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.PING;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.PONG;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.PROD_SEND;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_ACKNOWLEDGE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_ADD_ADDRESS;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_BINDINGQUERY;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_BINDINGQUERY_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_BROWSER_HASNEXTMESSAGE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_BROWSER_HASNEXTMESSAGE_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_BROWSER_NEXTMESSAGE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_BROWSER_NEXTMESSAGEBLOCK;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_BROWSER_NEXTMESSAGEBLOCK_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_BROWSER_NEXTMESSAGE_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_BROWSER_RESET;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_CANCEL;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_COMMIT;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_CREATEBROWSER;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_CREATEBROWSER_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_CREATECONSUMER;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_CREATECONSUMER_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_CREATEPRODUCER;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_CREATEPRODUCER_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_CREATEQUEUE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_DELETE_QUEUE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_DELIVER;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_QUEUEQUERY;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_QUEUEQUERY_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_RECOVER;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_REMOVE_ADDRESS;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_ROLLBACK;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_COMMIT;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_END;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_FORGET;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_GET_TIMEOUT;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_GET_TIMEOUT_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_INDOUBT_XIDS;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_INDOUBT_XIDS_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_JOIN;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_PREPARE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_RESUME;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_ROLLBACK;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_SET_TIMEOUT;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_SET_TIMEOUT_RESP;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_START;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.SESS_XA_SUSPEND;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.TEXT;
-import static org.jboss.messaging.core.remoting.wireformat.test.unit.CodecAssert.assertEqualsByteArrays;
-import static org.jboss.messaging.test.unit.RandomUtil.randomByte;
-import static org.jboss.messaging.test.unit.RandomUtil.randomBytes;
-import static org.jboss.messaging.test.unit.RandomUtil.randomInt;
-import static org.jboss.messaging.test.unit.RandomUtil.randomLong;
-import static org.jboss.messaging.test.unit.RandomUtil.randomString;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.transaction.xa.Xid;
-
-import org.apache.mina.common.IoBuffer;
-import org.jboss.messaging.core.Message;
-import org.jboss.messaging.core.impl.MessageImpl;
-import org.jboss.messaging.core.remoting.codec.AbstractPacketCodec;
-import org.jboss.messaging.core.remoting.codec.BytesPacketCodec;
-import org.jboss.messaging.core.remoting.codec.ConnectionCreateSessionMessageCodec;
-import org.jboss.messaging.core.remoting.codec.ConnectionCreateSessionResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.ConsumerFlowTokenMessageCodec;
-import org.jboss.messaging.core.remoting.codec.CreateConnectionMessageCodec;
-import org.jboss.messaging.core.remoting.codec.CreateConnectionResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.DeliverMessageCodec;
-import org.jboss.messaging.core.remoting.codec.PingCodec;
-import org.jboss.messaging.core.remoting.codec.PongCodec;
-import org.jboss.messaging.core.remoting.codec.ProducerSendMessageCodec;
-import org.jboss.messaging.core.remoting.codec.RemotingBuffer;
-import org.jboss.messaging.core.remoting.codec.SessionAcknowledgeMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionAddAddressMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionBindingQueryMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionBindingQueryResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionBrowserHasNextMessageResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionBrowserNextMessageBlockMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionBrowserNextMessageBlockResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionBrowserNextMessageResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionCancelMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionCreateBrowserMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionCreateBrowserResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionCreateConsumerMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionCreateConsumerResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionCreateProducerMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionCreateProducerResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionCreateQueueMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionDeleteQueueMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionQueueQueryMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionQueueQueryResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionRemoveAddressMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXACommitMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXAEndMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXAForgetMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXAGetInDoubtXidsResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXAGetTimeoutResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXAJoinMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXAPrepareMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXAResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXAResumeMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXARollbackMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXASetTimeoutMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXASetTimeoutResponseMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SessionXAStartMessageCodec;
-import org.jboss.messaging.core.remoting.codec.TextPacketCodec;
-import org.jboss.messaging.core.remoting.impl.mina.PacketCodecFactory;
-import org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.BufferWrapper;
-import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
-import org.jboss.messaging.core.remoting.wireformat.BytesPacket;
-import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
-import org.jboss.messaging.core.remoting.wireformat.ConnectionCreateSessionMessage;
-import org.jboss.messaging.core.remoting.wireformat.ConnectionCreateSessionResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.ConnectionStartMessage;
-import org.jboss.messaging.core.remoting.wireformat.ConnectionStopMessage;
-import org.jboss.messaging.core.remoting.wireformat.ConsumerFlowTokenMessage;
-import org.jboss.messaging.core.remoting.wireformat.CreateConnectionRequest;
-import org.jboss.messaging.core.remoting.wireformat.CreateConnectionResponse;
-import org.jboss.messaging.core.remoting.wireformat.DeliverMessage;
-import org.jboss.messaging.core.remoting.wireformat.NullPacket;
-import org.jboss.messaging.core.remoting.wireformat.PacketType;
-import org.jboss.messaging.core.remoting.wireformat.Ping;
-import org.jboss.messaging.core.remoting.wireformat.Pong;
-import org.jboss.messaging.core.remoting.wireformat.ProducerSendMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionAcknowledgeMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionAddAddressMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionBindingQueryMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionBindingQueryResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionBrowserHasNextMessageMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionBrowserHasNextMessageResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionBrowserNextMessageBlockMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionBrowserNextMessageBlockResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionBrowserNextMessageMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionBrowserNextMessageResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionBrowserResetMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionCancelMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionCommitMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionCreateBrowserMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionCreateBrowserResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionCreateConsumerMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionCreateConsumerResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionCreateProducerMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionCreateProducerResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionCreateQueueMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionDeleteQueueMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionQueueQueryMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionQueueQueryResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionRecoverMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionRemoveAddressMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionRollbackMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXACommitMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAEndMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAForgetMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAGetInDoubtXidsMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAGetInDoubtXidsResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAGetTimeoutMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAGetTimeoutResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAJoinMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAPrepareMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAResumeMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXARollbackMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXASetTimeoutResponseMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXAStartMessage;
-import org.jboss.messaging.core.remoting.wireformat.SessionXASuspendMessage;
-import org.jboss.messaging.core.remoting.wireformat.TextPacket;
-import org.jboss.messaging.test.unit.RandomUtil;
-import org.jboss.messaging.test.unit.UnitTestCase;
-import org.jboss.messaging.util.Logger;
-import org.jboss.messaging.util.StreamUtils;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- * 
- * @version <tt>$Revision$</tt>
- */
-public class PacketTypeTest extends UnitTestCase
-{
-
-   // Constants -----------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(PacketTypeTest.class);
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   private static ByteBuffer encode(int length, Object... args)
-   {
-      ByteBuffer buffer = ByteBuffer.allocate(length);
-      for (Object arg : args)
-      {
-         if (arg instanceof Byte)
-            buffer.put(((Byte) arg).byteValue());
-         else if (arg instanceof Boolean)
-         {
-            Boolean bool = (Boolean) arg;
-            buffer.put(bool ? TRUE : FALSE);
-         } else if (arg instanceof Integer)
-            buffer.putInt(((Integer) arg).intValue());
-         else if (arg instanceof Long)
-            buffer.putLong(((Long) arg).longValue());
-         else if (arg instanceof Float)
-            buffer.putFloat(((Float) arg).floatValue());
-         else if (arg instanceof String)
-            putNullableString((String) arg, buffer);
-         else if (arg == null)
-            putNullableString(null, buffer);
-         else if (arg instanceof byte[])
-         {
-            byte[] b = (byte[]) arg;
-            buffer.putInt(b.length);
-            buffer.put(b);
-         } else if (arg instanceof long[])
-         {
-            long[] longs = (long[]) arg;
-            for (long l : longs)
-            {
-               buffer.putLong(l);
-            }
-         } else
-         {
-            fail("no encoding defined for " + arg);
-         }
-      }
-      buffer.flip();
-      return buffer;
-   }
-
-   private static void putNullableString(String string, ByteBuffer buffer)
-   {
-      if (string == null)
-      {
-         buffer.put(NULL_STRING);
-      } else
-      {
-         buffer.put(NOT_NULL_STRING);
-         UTF_8_ENCODER.reset();
-         UTF_8_ENCODER.encode(CharBuffer.wrap(string), buffer, true);
-         buffer.put(NULL_BYTE);
-      }
-   }
-
-   private static void checkHeader(SimpleRemotingBuffer buffer,
-         AbstractPacket packet) throws Exception
-   {
-      checkHeaderBytes(packet, buffer.buffer().buf());
-
-      assertEquals(buffer.get(), packet.getType().byteValue());
-
-      String targetID = packet.getTargetID();
-      if (NO_ID_SET.equals(packet.getTargetID()))
-         targetID = null;
-      String callbackID = packet.getCallbackID();
-      if (NO_ID_SET.equals(packet.getCallbackID()))
-         callbackID = null;
-
-      int headerLength = LONG_LENGTH + sizeof(targetID) + sizeof(callbackID)
-            + BOOLEAN_LENGTH;
-      assertEquals(buffer.getInt(), headerLength);
-      assertEquals(buffer.getLong(), packet.getCorrelationID());
-
-      String bufferTargetID = buffer.getNullableString();
-      if (bufferTargetID == null)
-         bufferTargetID = NO_ID_SET;
-      String bufferCallbackID = buffer.getNullableString();
-      if (bufferCallbackID == null)
-         bufferCallbackID = NO_ID_SET;
-      boolean oneWay = buffer.getBoolean();
-
-      assertEquals(bufferTargetID, packet.getTargetID());
-      assertEquals(bufferCallbackID, packet.getCallbackID());
-      assertEquals(oneWay, packet.isOneWay());
-   }
-
-   private static void checkHeaderBytes(AbstractPacket packet, ByteBuffer actual)
-   {
-      String targetID = (packet.getTargetID().equals(NO_ID_SET) ? null : packet
-            .getTargetID());
-      String callbackID = (packet.getCallbackID().equals(NO_ID_SET) ? null
-            : packet.getCallbackID());
-
-      int headerLength = LONG_LENGTH + sizeof(targetID) + sizeof(callbackID)
-            + BOOLEAN_LENGTH;
-      ByteBuffer expected = ByteBuffer.allocate(1 + 1 + INT_LENGTH
-            + headerLength);
-      expected.put(packet.getType().byteValue());
-
-      expected.putInt(headerLength);
-      expected.putLong(packet.getCorrelationID());
-      putNullableString(targetID, expected);
-      putNullableString(callbackID, expected);
-      expected.put(packet.isOneWay() ? TRUE : FALSE);
-      expected.flip();
-
-      assertEqualsByteArrays(expected.remaining(), expected.array(), actual
-            .array());
-   }
-
-   private static void checkBodyIsEmpty(RemotingBuffer buffer)
-   {
-      assertEquals(0, buffer.getInt());
-      // check the buffer has been wholly read
-      assertEquals(0, buffer.remaining());
-   }
-
-   private static void checkBody(RemotingBuffer buffer, Object... bodyObjects)
-   {
-      byte[] actualBody = new byte[buffer.getInt()];
-      buffer.get(actualBody);
-      ByteBuffer expectedBody = encode(actualBody.length, bodyObjects);
-      assertEqualsByteArrays(expectedBody.array(), actualBody);
-      // check the buffer has been wholly read
-      assertEquals(0, buffer.remaining());
-   }
-
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   public void testNullPacket() throws Exception
-   {
-      NullPacket packet = new NullPacket();
-      packet.setCallbackID(randomString());
-      packet.setCorrelationID(randomLong());
-      packet.setTargetID(randomString());
-
-      AbstractPacketCodec<AbstractPacket> codec = PacketCodecFactory
-            .createCodecForEmptyPacket(NULL, NullPacket.class);
-      SimpleRemotingBuffer buffer = encode(packet, codec);
-      checkHeader(buffer, packet);
-      checkBodyIsEmpty(buffer);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof NullPacket);
-      NullPacket p = (NullPacket) decodedPacket;
-
-      assertEquals(NULL, p.getType());
-      assertEquals(packet.getCallbackID(), p.getCallbackID());
-      assertEquals(packet.getCorrelationID(), p.getCorrelationID());
-      assertEquals(packet.getTargetID(), p.getTargetID());
-   }
-
-   public void testPing() throws Exception
-   {
-      Ping ping = new Ping(randomString());
-      AbstractPacketCodec<Ping> codec = new PingCodec();
-      
-      SimpleRemotingBuffer buffer = encode(ping, codec);
-      checkHeader(buffer, ping);
-      checkBody(buffer, ping.getSessionID());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof Ping);
-      Ping decodedPing = (Ping) decodedPacket;
-      assertEquals(PING, decodedPing.getType());
-      assertEquals(ping.getSessionID(), decodedPing.getSessionID());
-   }
-
-   public void testPong() throws Exception
-   {
-      Pong pong = new Pong(randomString(), true);
-      AbstractPacketCodec<Pong> codec = new PongCodec();
-      
-      SimpleRemotingBuffer buffer = encode(pong, codec);
-      checkHeader(buffer, pong);
-      checkBody(buffer, pong.getSessionID(), pong.isSessionFailed());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof Pong);
-      Pong decodedPong = (Pong) decodedPacket;
-      assertEquals(PONG, decodedPong.getType());
-      assertEquals(pong.getSessionID(), decodedPong.getSessionID());
-      assertEquals(pong.isSessionFailed(), decodedPong.isSessionFailed());
-   }
-
-   public void testTextPacket() throws Exception
-   {
-      TextPacket packet = new TextPacket("testTextPacket");
-      AbstractPacketCodec<TextPacket> codec = new TextPacketCodec();
-
-      SimpleRemotingBuffer buffer = encode(packet, codec);
-      checkHeader(buffer, packet);
-      checkBody(buffer, packet.getText());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof TextPacket);
-      TextPacket p = (TextPacket) decodedPacket;
-
-      assertEquals(TEXT, p.getType());
-      assertEquals(packet.getText(), p.getText());
-   }
-   
-   public void testBytesPacket() throws Exception
-   {
-      BytesPacket packet = new BytesPacket(randomBytes());
-
-      AbstractPacketCodec codec = new BytesPacketCodec();
-      SimpleRemotingBuffer buffer = encode(packet, codec);
-      checkHeader(buffer, packet);
-      checkBody(buffer, packet.getBytes());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof BytesPacket);
-      BytesPacket p = (BytesPacket) decodedPacket;
-
-      assertEquals(BYTES, p.getType());
-      assertEqualsByteArrays(packet.getBytes(), p.getBytes());
-   }
-   
-   public void testCreateConnectionRequest() throws Exception
-   {
-      byte version = randomByte();
-      String remotingSessionID = randomString();
-      String clientVMID = randomString();
-      String username = null;
-      String password = null;
-      int prefetchSize = 0;
- 
-      CreateConnectionRequest request = new CreateConnectionRequest(version,
-            remotingSessionID, clientVMID, username, password, prefetchSize);
-
-      AbstractPacketCodec<CreateConnectionRequest> codec = new CreateConnectionMessageCodec();
-      SimpleRemotingBuffer buffer = encode(request, codec);
-      checkHeader(buffer, request);
-      checkBody(buffer, version, remotingSessionID, clientVMID, username,
-            password, prefetchSize);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof CreateConnectionRequest);
-      CreateConnectionRequest decodedRequest = (CreateConnectionRequest) decodedPacket;
-
-      assertEquals(CREATECONNECTION, decodedPacket.getType());
-      assertEquals(request.getVersion(), decodedRequest.getVersion());
-      assertEquals(request.getRemotingSessionID(), decodedRequest
-            .getRemotingSessionID());
-      assertEquals(request.getClientVMID(), decodedRequest.getClientVMID());
-      assertEquals(request.getUsername(), decodedRequest.getUsername());
-      assertEquals(request.getPassword(), decodedRequest.getPassword());
-   }
-
-   public void testCreateConnectionResponse() throws Exception
-   {
-      CreateConnectionResponse response = new CreateConnectionResponse(
-            randomString());
-
-      AbstractPacketCodec<CreateConnectionResponse> codec = new CreateConnectionResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(response, codec);
-      checkHeader(buffer, response);
-      checkBody(buffer, response.getConnectionID());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof CreateConnectionResponse);
-      CreateConnectionResponse decodedResponse = (CreateConnectionResponse) decodedPacket;
-      assertEquals(CREATECONNECTION_RESP, decodedResponse.getType());
-      assertEquals(response.getConnectionID(), decodedResponse
-            .getConnectionID());
-   }
-
-   public void testCreateSessionRequest() throws Exception
-   {
-      //TODO test this more thoroughly
-      
-      ConnectionCreateSessionMessage request = new ConnectionCreateSessionMessage(true, true, true);
-
-      AbstractPacketCodec codec = new ConnectionCreateSessionMessageCodec();
-      SimpleRemotingBuffer buffer = encode(request, codec);
-      checkHeader(buffer, request);
-      checkBody(buffer, request.isXA(), request.isAutoCommitSends(), request.isAutoCommitAcks());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof ConnectionCreateSessionMessage);
-      ConnectionCreateSessionMessage decodedRequest = (ConnectionCreateSessionMessage) decodedPacket;
-      assertEquals(CONN_CREATESESSION, decodedRequest.getType());
-      assertEquals(request.isXA(), decodedRequest.isXA());
-      assertEquals(request.isAutoCommitSends(), decodedRequest.isAutoCommitSends());
-      assertEquals(request.isAutoCommitAcks(), decodedRequest.isAutoCommitAcks());
-      assertEquals(request.isXA(), decodedRequest.isXA());
-   }
-
-   public void testCreateSessionResponse() throws Exception
-   {
-      ConnectionCreateSessionResponseMessage response = new ConnectionCreateSessionResponseMessage(randomString());
-
-      AbstractPacketCodec codec = new ConnectionCreateSessionResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(response, codec);
-      checkHeader(buffer, response);
-      checkBody(buffer, response.getSessionID());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof ConnectionCreateSessionResponseMessage);
-      ConnectionCreateSessionResponseMessage decodedResponse = (ConnectionCreateSessionResponseMessage) decodedPacket;
-      assertEquals(CONN_CREATESESSION_RESP, decodedResponse.getType());
-      assertEquals(response.getSessionID(), decodedResponse.getSessionID());
-   }
-
-   public void testSendMessage() throws Exception
-   {
-      ProducerSendMessage packet = new ProducerSendMessage(randomString(), new MessageImpl());
-
-      AbstractPacketCodec codec = new ProducerSendMessageCodec();
-      SimpleRemotingBuffer buffer = encode(packet, codec);
-      checkHeader(buffer, packet);
-      checkBody(buffer, packet.getAddress(), StreamUtils.toBytes(packet.getMessage()));
-      buffer.rewind();
-
-      AbstractPacket p = codec.decode(buffer);
-
-      assertTrue(p instanceof ProducerSendMessage);
-      ProducerSendMessage decodedPacket = (ProducerSendMessage) p;
-      assertEquals(PROD_SEND, decodedPacket.getType());
-      assertEquals(packet.getAddress(), decodedPacket.getAddress());
-      assertEquals(packet.getMessage().getMessageID(), decodedPacket
-            .getMessage().getMessageID());
-   }
-
-   public void testCreateConsumerRequest() throws Exception
-   {      
-      String destination = "queue.testCreateConsumerRequest";
-      SessionCreateConsumerMessage request = new SessionCreateConsumerMessage(destination,
-            "color = 'red'", false, false);
-
-      AbstractPacketCodec codec = new SessionCreateConsumerMessageCodec();
-      SimpleRemotingBuffer buffer = encode(request, codec);
-      checkHeader(buffer, request);
-      checkBody(buffer, request.getQueueName(), request
-            .getFilterString(), request.isNoLocal(), request.isAutoDeleteQueue());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionCreateConsumerMessage);
-      SessionCreateConsumerMessage decodedRequest = (SessionCreateConsumerMessage) decodedPacket;
-      assertEquals(SESS_CREATECONSUMER, decodedRequest.getType());
-      assertEquals(request.getQueueName(), decodedRequest.getQueueName());
-      assertEquals(request.getFilterString(), decodedRequest.getFilterString());
-      assertEquals(request.isNoLocal(), decodedRequest.isNoLocal());
-      assertEquals(request.isAutoDeleteQueue(), decodedRequest.isAutoDeleteQueue());
-   }
-
-   public void testCreateConsumerResponse() throws Exception
-   {
-
-      SessionCreateConsumerResponseMessage response = new SessionCreateConsumerResponseMessage(
-            randomString(), RandomUtil.randomInt());
-
-      AbstractPacketCodec codec = new SessionCreateConsumerResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(response, codec);
-      checkHeader(buffer, response);
-      checkBody(buffer, response.getConsumerID(), response.getPrefetchSize());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionCreateConsumerResponseMessage);
-      SessionCreateConsumerResponseMessage decodedResponse = (SessionCreateConsumerResponseMessage) decodedPacket;
-      assertEquals(SESS_CREATECONSUMER_RESP, decodedResponse.getType());
-      assertEquals(response.getPrefetchSize(), decodedResponse.getPrefetchSize());
-   }
-   
-   public void testCreateProducerRequest() throws Exception
-   {      
-      String destination = "queue.testCreateProducerRequest";
-      SessionCreateProducerMessage request = new SessionCreateProducerMessage(destination);
-
-      AbstractPacketCodec codec = new SessionCreateProducerMessageCodec();
-      SimpleRemotingBuffer buffer = encode(request, codec);
-      checkHeader(buffer, request);
-      checkBody(buffer, request.getAddress());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionCreateProducerMessage);
-      SessionCreateProducerMessage decodedRequest = (SessionCreateProducerMessage) decodedPacket;
-      assertEquals(SESS_CREATEPRODUCER, decodedRequest.getType());
-      assertEquals(request.getAddress(), decodedRequest.getAddress());
-   }
-   
-   public void testCreateProducerResponse() throws Exception
-   {
-      SessionCreateProducerResponseMessage response = new SessionCreateProducerResponseMessage(randomString());
-
-      AbstractPacketCodec codec = new SessionCreateProducerResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(response, codec);
-      checkHeader(buffer, response);
-      checkBody(buffer, response.getProducerID());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionCreateProducerResponseMessage);
-      SessionCreateProducerResponseMessage decodedResponse = (SessionCreateProducerResponseMessage) decodedPacket;
-      assertEquals(SESS_CREATEPRODUCER_RESP, decodedResponse.getType());
-      assertEquals(response.getProducerID(), decodedResponse.getProducerID());;
-   }
-
-   public void testStartConnectionMessage() throws Exception
-   {
-      ConnectionStartMessage packet = new ConnectionStartMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            CONN_START, ConnectionStartMessage.class);
-      SimpleRemotingBuffer buffer = encode(packet, codec);
-      checkHeader(buffer, packet);
-      checkBodyIsEmpty(buffer);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof ConnectionStartMessage);
-      assertEquals(CONN_START, decodedPacket.getType());
-   }
-
-   public void testStopConnectionMessage() throws Exception
-   {
-      ConnectionStopMessage packet = new ConnectionStopMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            CONN_STOP, ConnectionStopMessage.class);
-      SimpleRemotingBuffer buffer = encode(packet, codec);
-      checkHeader(buffer, packet);
-      checkBodyIsEmpty(buffer);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof ConnectionStopMessage);
-      assertEquals(CONN_STOP, decodedPacket.getType());
-   }
-
-   public void testConsumerFlowTokenMessage() throws Exception
-   {
-      ConsumerFlowTokenMessage message = new ConsumerFlowTokenMessage(10);
-      AbstractPacketCodec codec = new ConsumerFlowTokenMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBody(buffer, message.getTokens());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof ConsumerFlowTokenMessage);
-      ConsumerFlowTokenMessage decodedMessage = (ConsumerFlowTokenMessage) decodedPacket;
-      assertEquals(CONS_FLOWTOKEN, decodedMessage.getType());
-      assertEquals(message.getTokens(), decodedMessage.getTokens());
-   }
-
-   public void testDeliverMessage() throws Exception
-   {
-      Message msg = new MessageImpl();
-      DeliverMessage message = new DeliverMessage(msg, randomLong());
-
-      AbstractPacketCodec codec = new DeliverMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBody(buffer, StreamUtils.toBytes(msg), message.getDeliveryID());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof DeliverMessage);
-      DeliverMessage decodedMessage = (DeliverMessage) decodedPacket;
-      assertEquals(SESS_DELIVER, decodedMessage.getType());
-      assertEquals(message.getMessage().getMessageID(), decodedMessage
-            .getMessage().getMessageID());
-      assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
-   }
-
-   public void testSessionAcknowledgeMessage() throws Exception
-   {
-      SessionAcknowledgeMessage message = new SessionAcknowledgeMessage(
-            randomLong(), true);
-
-      AbstractPacketCodec codec = new SessionAcknowledgeMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBody(buffer, message.getDeliveryID(), message.isAllUpTo());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionAcknowledgeMessage);
-      SessionAcknowledgeMessage decodedMessage = (SessionAcknowledgeMessage) decodedPacket;
-      assertEquals(SESS_ACKNOWLEDGE, decodedMessage.getType());
-      assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
-      assertEquals(message.isAllUpTo(), decodedMessage.isAllUpTo());
-   }
-
-   public void testSessionCancelMessage() throws Exception
-   {
-      SessionCancelMessage message = new SessionCancelMessage(randomLong(),
-            true);
-
-      AbstractPacketCodec codec = new SessionCancelMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBody(buffer, message.getDeliveryID(), message.isExpired());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionCancelMessage);
-      SessionCancelMessage decodedMessage = (SessionCancelMessage) decodedPacket;
-      assertEquals(SESS_CANCEL, decodedMessage.getType());
-      assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
-      assertEquals(message.isExpired(), decodedMessage.isExpired());
-   }
-
-   public void testSessionCommitMessage() throws Exception
-   {
-      SessionCommitMessage message = new SessionCommitMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            SESS_COMMIT, SessionCommitMessage.class);
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBodyIsEmpty(buffer);
-
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionCommitMessage);
-      assertEquals(SESS_COMMIT, decodedPacket.getType());
-   }
-
-   public void testSessionRollbackMessage() throws Exception
-   {
-      SessionRollbackMessage message = new SessionRollbackMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            SESS_ROLLBACK, SessionRollbackMessage.class);
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBodyIsEmpty(buffer);
-
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionRollbackMessage);
-      assertEquals(SESS_ROLLBACK, decodedPacket.getType());
-   }
-   
-   public void testSessionRecoverMessage() throws Exception
-   {
-      SessionRecoverMessage message = new SessionRecoverMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            SESS_RECOVER, SessionRecoverMessage.class);
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBodyIsEmpty(buffer);
-
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionRecoverMessage);
-      assertEquals(SESS_RECOVER, decodedPacket.getType());
-   }
-
-   public void testCloseMessage() throws Exception
-   {
-      CloseMessage message = new CloseMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            CLOSE, CloseMessage.class);
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBodyIsEmpty(buffer);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof CloseMessage);
-      CloseMessage decodedMessage = (CloseMessage) decodedPacket;
-      assertEquals(CLOSE, decodedMessage.getType());
-   }
-
-
-   public void testCreateBrowserRequest() throws Exception
-   {
-      String destination = "queue.testCreateBrowserRequest";
-      SessionCreateBrowserMessage request = new SessionCreateBrowserMessage(destination,
-            "color = 'red'");
-
-      AbstractPacketCodec codec = new SessionCreateBrowserMessageCodec();
-      SimpleRemotingBuffer buffer = encode(request, codec);
-      checkHeader(buffer, request);
-      checkBody(buffer, request.getQueueName(), request.getFilterString());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionCreateBrowserMessage);
-      SessionCreateBrowserMessage decodedRequest = (SessionCreateBrowserMessage) decodedPacket;
-      assertEquals(SESS_CREATEBROWSER, decodedRequest.getType());
-      assertEquals(request.getQueueName(), decodedRequest.getQueueName());
-      assertEquals(request.getFilterString(), decodedRequest.getFilterString());
-   }
-
-   public void testCreateBrowserResponse() throws Exception
-   {
-      SessionCreateBrowserResponseMessage response = new SessionCreateBrowserResponseMessage(randomString());
-
-      AbstractPacketCodec codec = new SessionCreateBrowserResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(response, codec);
-      checkHeader(buffer, response);
-      checkBody(buffer, response.getBrowserID());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionCreateBrowserResponseMessage);
-      SessionCreateBrowserResponseMessage decodedResponse = (SessionCreateBrowserResponseMessage) decodedPacket;
-      assertEquals(SESS_CREATEBROWSER_RESP, decodedResponse.getType());
-      assertEquals(response.getBrowserID(), decodedResponse.getBrowserID());
-   }
-
-   public void testBrowserResetMessage() throws Exception
-   {
-      SessionBrowserResetMessage message = new SessionBrowserResetMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            SESS_BROWSER_RESET, SessionBrowserResetMessage.class);
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBodyIsEmpty(buffer);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionBrowserResetMessage);
-      assertEquals(SESS_BROWSER_RESET, decodedPacket.getType());
-   }
-
-   public void testBrowserHasNextMessageRequest() throws Exception
-   {
-      SessionBrowserHasNextMessageMessage request = new SessionBrowserHasNextMessageMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            SESS_BROWSER_HASNEXTMESSAGE, SessionBrowserHasNextMessageMessage.class);
-      SimpleRemotingBuffer buffer = encode(request, codec);
-      checkHeader(buffer, request);
-      checkBodyIsEmpty(buffer);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionBrowserHasNextMessageMessage);
-      assertEquals(SESS_BROWSER_HASNEXTMESSAGE, decodedPacket.getType());
-   }
-
-   public void testBrowserHasNextMessageResponse() throws Exception
-   {
-      SessionBrowserHasNextMessageResponseMessage response = new SessionBrowserHasNextMessageResponseMessage(
-            false);
-      AbstractPacketCodec codec = new SessionBrowserHasNextMessageResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(response, codec);
-      checkHeader(buffer, response);
-      checkBody(buffer, response.hasNext());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionBrowserHasNextMessageResponseMessage);
-      SessionBrowserHasNextMessageResponseMessage decodedResponse = (SessionBrowserHasNextMessageResponseMessage) decodedPacket;
-      assertEquals(SESS_BROWSER_HASNEXTMESSAGE_RESP, decodedResponse.getType());
-      assertEquals(response.hasNext(), decodedResponse.hasNext());
-   }
-
-   public void testBrowserNextMessageRequest() throws Exception
-   {
-      SessionBrowserNextMessageMessage request = new SessionBrowserNextMessageMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            SESS_BROWSER_NEXTMESSAGE, SessionBrowserNextMessageMessage.class);
-      SimpleRemotingBuffer buffer = encode(request, codec);
-      checkHeader(buffer, request);
-      checkBodyIsEmpty(buffer);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionBrowserNextMessageMessage);
-      assertEquals(SESS_BROWSER_NEXTMESSAGE, decodedPacket.getType());
-   }
-
-   public void testBrowserNextMessageResponse() throws Exception
-   {
-      Message msg = new MessageImpl();
-      SessionBrowserNextMessageResponseMessage response = new SessionBrowserNextMessageResponseMessage(msg);
-
-      AbstractPacketCodec codec = new SessionBrowserNextMessageResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(response, codec);
-      checkHeader(buffer, response);
-      checkBody(buffer, StreamUtils.toBytes(msg));
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionBrowserNextMessageResponseMessage);
-      SessionBrowserNextMessageResponseMessage decodedResponse = (SessionBrowserNextMessageResponseMessage) decodedPacket;
-      assertEquals(SESS_BROWSER_NEXTMESSAGE_RESP, decodedResponse.getType());
-      assertEquals(response.getMessage().getMessageID(), decodedResponse
-            .getMessage().getMessageID());
-   }
-
-   public void testBrowserNextMessageBlockRequest() throws Exception
-   {
-      SessionBrowserNextMessageBlockMessage request = new SessionBrowserNextMessageBlockMessage(
-            randomLong());
-
-      AbstractPacketCodec codec = new SessionBrowserNextMessageBlockMessageCodec();
-      SimpleRemotingBuffer buffer = encode(request, codec);
-      checkHeader(buffer, request);
-      checkBody(buffer, request.getMaxMessages());
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionBrowserNextMessageBlockMessage);
-      SessionBrowserNextMessageBlockMessage decodedRequest = (SessionBrowserNextMessageBlockMessage) decodedPacket;
-      assertEquals(SESS_BROWSER_NEXTMESSAGEBLOCK, decodedPacket.getType());
-      assertEquals(request.getMaxMessages(), decodedRequest.getMaxMessages());
-   }
-
-   public void testBrowserNextMessageBlockResponse() throws Exception
-   {
-      Message[] messages = new Message[] { new MessageImpl(), new MessageImpl() };
-      SessionBrowserNextMessageBlockResponseMessage response = new SessionBrowserNextMessageBlockResponseMessage(
-            messages);
-
-      AbstractPacketCodec codec = new SessionBrowserNextMessageBlockResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(response, codec);
-      checkHeader(buffer, response);
-      checkBody(buffer, messages.length, SessionBrowserNextMessageBlockResponseMessageCodec
-            .encode(messages));
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionBrowserNextMessageBlockResponseMessage);
-      SessionBrowserNextMessageBlockResponseMessage decodedResponse = (SessionBrowserNextMessageBlockResponseMessage) decodedPacket;
-      assertEquals(SESS_BROWSER_NEXTMESSAGEBLOCK_RESP, decodedResponse.getType());
-      assertEquals(response.getMessages()[0].getMessageID(), decodedResponse
-            .getMessages()[0].getMessageID());
-      assertEquals(response.getMessages()[1].getMessageID(), decodedResponse
-            .getMessages()[1].getMessageID());
-   }
-
-  
-   public void testSesssionXACommitMessageOnePhase() throws Exception
-   {
-      this.testSessionXACommitMessage(true);
-   }
-   
-   public void testSessionXACommitMessageNotOnePhase() throws Exception
-   {
-      this.testSessionXACommitMessage(false);
-   }
-   
-   private void testSessionXACommitMessage(boolean onePhase) throws Exception
-   {
-      Xid xid = this.generateXid();
-      SessionXACommitMessage message = new SessionXACommitMessage(xid, onePhase);
-      AbstractPacketCodec codec = new SessionXACommitMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXACommitMessage);
-      SessionXACommitMessage decodedMessage = (SessionXACommitMessage)decodedPacket;
-      assertEquals(SESS_XA_COMMIT, decodedMessage.getType());
-      assertEquals(xid, decodedMessage.getXid());      
-      assertEquals(onePhase, decodedMessage.isOnePhase());
-   }
-   
-   public void testSessionXAEndMessageFailed() throws Exception
-   {
-      this.testSessionXAEndMessage(true);
-   }
-   
-   public void testSessionXAEndMessageNotFailed() throws Exception
-   {
-      this.testSessionXACommitMessage(false);
-   }
-   
-   private void testSessionXAEndMessage(boolean failed) throws Exception
-   {
-      Xid xid = this.generateXid();
-      SessionXAEndMessage message = new SessionXAEndMessage(xid, failed);
-      AbstractPacketCodec codec = new SessionXAEndMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXAEndMessage);
-      SessionXAEndMessage decodedMessage = (SessionXAEndMessage)decodedPacket;
-      assertEquals(SESS_XA_END, decodedMessage.getType());
-      assertEquals(xid, decodedMessage.getXid());      
-      assertEquals(failed, decodedMessage.isFailed());
-   }
-   
-   public void testSessionXAForgetMessage() throws Exception
-   {
-      Xid xid = this.generateXid();
-      SessionXAForgetMessage message = new SessionXAForgetMessage(xid);
-      AbstractPacketCodec codec = new SessionXAForgetMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXAForgetMessage);
-      SessionXAForgetMessage decodedMessage = (SessionXAForgetMessage)decodedPacket;
-      assertEquals(SESS_XA_FORGET, decodedMessage.getType());
-      assertEquals(xid, decodedMessage.getXid());      
-   }
-   
-   public void testSessionXAGetInDoubtXidsMessage() throws Exception
-   {
-      SessionXAGetInDoubtXidsMessage request = new SessionXAGetInDoubtXidsMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            SESS_XA_INDOUBT_XIDS, SessionXAGetInDoubtXidsMessage.class);
-      SimpleRemotingBuffer buffer = encode(request, codec);
-      checkHeader(buffer, request);
-      checkBodyIsEmpty(buffer);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionXAGetInDoubtXidsMessage);
-      assertEquals(SESS_XA_INDOUBT_XIDS, decodedPacket.getType());            
-   }
-   
-   public void testSessionGetInDoubtXidsResponse() throws Exception
-   {
-      final int numXids = 10;
-      List<Xid> xids = new ArrayList<Xid>();
-      for (int i = 0; i < numXids; i++)
-      {
-         xids.add(generateXid());
-      }
-      
-      SessionXAGetInDoubtXidsResponseMessage message = new SessionXAGetInDoubtXidsResponseMessage(xids);
-      AbstractPacketCodec codec = new SessionXAGetInDoubtXidsResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXAGetInDoubtXidsResponseMessage);
-      SessionXAGetInDoubtXidsResponseMessage decodedMessage = (SessionXAGetInDoubtXidsResponseMessage)decodedPacket;
-      assertEquals(SESS_XA_INDOUBT_XIDS_RESP, decodedMessage.getType());
-           
-      List<Xid> decodedXids = decodedMessage.getXids();
-      assertNotNull(decodedXids);
-      assertEquals(xids.size(), decodedXids.size());
-      
-      for (int i = 0; i < numXids; i++)
-      {
-         assertEquals(xids.get(i), decodedXids.get(i));
-      }
-   }
-   
-   public void testSessionXAGetTimeoutMessage() throws Exception
-   {
-      SessionXAGetTimeoutMessage message = new SessionXAGetTimeoutMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            PacketType.SESS_XA_GET_TIMEOUT, SessionXAGetTimeoutMessage.class);
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBodyIsEmpty(buffer);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionXAGetTimeoutMessage);
-      assertEquals(SESS_XA_GET_TIMEOUT, decodedPacket.getType());     
-   }
-   
-   public void testSessionXAGetTimeoutResponse() throws Exception
-   {
-      final int timeout = RandomUtil.randomInt();
-      
-      SessionXAGetTimeoutResponseMessage message = new SessionXAGetTimeoutResponseMessage(timeout);
-      AbstractPacketCodec codec = new SessionXAGetTimeoutResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXAGetTimeoutResponseMessage);
-      SessionXAGetTimeoutResponseMessage decodedMessage = (SessionXAGetTimeoutResponseMessage)decodedPacket;
-      assertEquals(SESS_XA_GET_TIMEOUT_RESP, decodedMessage.getType());
-           
-      assertEquals(timeout, decodedMessage.getTimeoutSeconds());
-   }
-
-   public void testSessionXAJoinMessage() throws Exception
-   {
-      Xid xid = this.generateXid();
-      SessionXAJoinMessage message = new SessionXAJoinMessage(xid);
-      AbstractPacketCodec codec = new SessionXAJoinMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXAJoinMessage);
-      SessionXAJoinMessage decodedMessage = (SessionXAJoinMessage)decodedPacket;
-      assertEquals(SESS_XA_JOIN, decodedMessage.getType());
-      assertEquals(xid, decodedMessage.getXid());      
-   }
-   
-   public void testSessionXAPrepareMessage() throws Exception
-   {
-      Xid xid = this.generateXid();
-      SessionXAPrepareMessage message = new SessionXAPrepareMessage(xid);
-      AbstractPacketCodec codec = new SessionXAPrepareMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXAPrepareMessage);
-      SessionXAPrepareMessage decodedMessage = (SessionXAPrepareMessage)decodedPacket;
-      assertEquals(SESS_XA_PREPARE, decodedMessage.getType());
-      assertEquals(xid, decodedMessage.getXid());      
-   }
-   
-   public void testSessionXAResponseErrorNullString() throws Exception
-   {
-      testSessionXAResponse(true, true);
-   }
-   
-   public void testSessionXAResponseErrorNotNullString() throws Exception
-   {
-      testSessionXAResponse(true, false);
-   }
-   
-   public void testSessionXAResponseNoErrorNullString() throws Exception
-   {
-      testSessionXAResponse(false, true);
-   }
-   
-   public void testSessionXAResponseNoErrorNotNullString() throws Exception
-   {
-      testSessionXAResponse(false, false);
-   }
-   
-   private void testSessionXAResponse(boolean error, boolean nullString) throws Exception
-   {
-      int responseCode = RandomUtil.randomInt();
-      
-      String str = nullString ? null : RandomUtil.randomString();
-      
-      SessionXAResponseMessage message = new SessionXAResponseMessage(error, responseCode, str);
-      AbstractPacketCodec codec = new SessionXAResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXAResponseMessage);
-      SessionXAResponseMessage decodedMessage = (SessionXAResponseMessage)decodedPacket;
-      assertEquals(SESS_XA_RESP, decodedMessage.getType());
-      assertEquals(error, decodedMessage.isError());
-      assertEquals(responseCode, decodedMessage.getResponseCode());
-      assertEquals(str, decodedMessage.getMessage());
-   }
-   
-   public void testSessionXAResumeMessage() throws Exception
-   {
-      Xid xid = this.generateXid();
-      SessionXAResumeMessage message = new SessionXAResumeMessage(xid);
-      AbstractPacketCodec codec = new SessionXAResumeMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXAResumeMessage);
-      SessionXAResumeMessage decodedMessage = (SessionXAResumeMessage)decodedPacket;
-      assertEquals(SESS_XA_RESUME, decodedMessage.getType());
-      assertEquals(xid, decodedMessage.getXid());      
-   }
-   
-   public void testSessionXARollbackMessage() throws Exception
-   {
-      Xid xid = this.generateXid();
-      SessionXARollbackMessage message = new SessionXARollbackMessage(xid);
-      AbstractPacketCodec codec = new SessionXARollbackMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXARollbackMessage);
-      SessionXARollbackMessage decodedMessage = (SessionXARollbackMessage)decodedPacket;
-      assertEquals(SESS_XA_ROLLBACK, decodedMessage.getType());
-      assertEquals(xid, decodedMessage.getXid());      
-   }
-   
-   public void testSessionXASetTimeoutMessage() throws Exception
-   {
-      final int timeout = RandomUtil.randomInt();
-      SessionXASetTimeoutMessage message = new SessionXASetTimeoutMessage(timeout);
-      AbstractPacketCodec codec = new SessionXASetTimeoutMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXASetTimeoutMessage);
-      SessionXASetTimeoutMessage decodedMessage = (SessionXASetTimeoutMessage)decodedPacket;
-      assertEquals(SESS_XA_SET_TIMEOUT, decodedMessage.getType());
-      assertEquals(timeout, decodedMessage.getTimeoutSeconds());      
-   }
-   
-   public void testSessionXASetTimeoutResponseMessageOK() throws Exception
-   {
-      testSessionXASetTimeoutResponseMessage(true);
-   }
-   
-   public void testSessionXASetTimeoutResponseMessageNotOK() throws Exception
-   {
-      testSessionXASetTimeoutResponseMessage(false);
-   }
-   
-   private void testSessionXASetTimeoutResponseMessage(boolean ok) throws Exception
-   {
-      final int timeout = RandomUtil.randomInt();
-      SessionXASetTimeoutResponseMessage message = new SessionXASetTimeoutResponseMessage(ok);
-      AbstractPacketCodec codec = new SessionXASetTimeoutResponseMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXASetTimeoutResponseMessage);
-      SessionXASetTimeoutResponseMessage decodedMessage = (SessionXASetTimeoutResponseMessage)decodedPacket;
-      assertEquals(SESS_XA_SET_TIMEOUT_RESP, decodedMessage.getType());
-      assertEquals(ok, decodedMessage.isOK());      
-   }
-   
-   public void testSessionXAStartMessage() throws Exception
-   {
-      Xid xid = this.generateXid();
-      SessionXAStartMessage message = new SessionXAStartMessage(xid);
-      AbstractPacketCodec codec = new SessionXAStartMessageCodec();
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-      
-      AbstractPacket decodedPacket = codec.decode(buffer);
-      assertTrue(decodedPacket instanceof SessionXAStartMessage);
-      SessionXAStartMessage decodedMessage = (SessionXAStartMessage)decodedPacket;
-      assertEquals(SESS_XA_START, decodedMessage.getType());
-      assertEquals(xid, decodedMessage.getXid());      
-   }
-   
-   public void testSessionXASuspendMessage() throws Exception
-   {
-      SessionXASuspendMessage message = new SessionXASuspendMessage();
-
-      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
-            PacketType.SESS_XA_SUSPEND, SessionXASuspendMessage.class);
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      checkBodyIsEmpty(buffer);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionXASuspendMessage);
-      assertEquals(SESS_XA_SUSPEND, decodedPacket.getType());     
-   }
-   
-   
-   public void testSessionRemoveAddressMessage() throws Exception
-   {
-      SessionRemoveAddressMessage message = new SessionRemoveAddressMessage(randomString());
-
-      AbstractPacketCodec codec = new SessionRemoveAddressMessageCodec();
-      
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionRemoveAddressMessage);
-      SessionRemoveAddressMessage decodedMessage = (SessionRemoveAddressMessage)decodedPacket;
-      assertEquals(SESS_REMOVE_ADDRESS, decodedMessage.getType());
-      
-      assertEquals(message.getAddress(), decodedMessage.getAddress());
-            
-   }
-   
-   public void testSessionCreateQueueRequest() throws Exception
-   {
-      SessionCreateQueueMessage message = new SessionCreateQueueMessage(randomString(), randomString(), randomString(), true, true);
-
-      AbstractPacketCodec codec = new SessionCreateQueueMessageCodec();
-      
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionCreateQueueMessage);
-      SessionCreateQueueMessage decodedMessage = (SessionCreateQueueMessage)decodedPacket;
-      assertEquals(SESS_CREATEQUEUE, decodedMessage.getType());
-      
-      assertEquals(message.getAddress(), decodedMessage.getAddress());
-      assertEquals(message.getQueueName(), decodedMessage.getQueueName());
-      assertEquals(message.getFilterString(), decodedMessage.getFilterString());
-      assertEquals(message.isDurable(), decodedMessage.isDurable());
-      assertEquals(message.isTemporary(), decodedMessage.isDurable());
-            
-   }
-   
-   public void testSessionQueueQueryRequest() throws Exception
-   {
-      SessionQueueQueryMessage message = new SessionQueueQueryMessage(randomString());
-
-      AbstractPacketCodec codec = new SessionQueueQueryMessageCodec();
-      
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionQueueQueryMessage);
-      SessionQueueQueryMessage decodedMessage = (SessionQueueQueryMessage)decodedPacket;
-      assertEquals(SESS_QUEUEQUERY, decodedMessage.getType());
-      
-      assertEquals(message.getQueueName(), decodedMessage.getQueueName());            
-   }
-   
-   public void testSessionQueueQueryResponse() throws Exception
-   {
-      SessionQueueQueryResponseMessage message = new SessionQueueQueryResponseMessage(true, true, randomInt(), randomInt(), randomInt(),
-                                                          randomString(), randomString());
-
-      AbstractPacketCodec codec = new SessionQueueQueryResponseMessageCodec();
-      
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionQueueQueryResponseMessage);
-      SessionQueueQueryResponseMessage decodedMessage = (SessionQueueQueryResponseMessage)decodedPacket;
-      assertEquals(SESS_QUEUEQUERY_RESP, decodedMessage.getType());
-      
-      assertEquals(message.isExists(), decodedMessage.isExists());
-      assertEquals(message.isDurable(), decodedMessage.isDurable());
-      assertEquals(message.isTemporary(), decodedMessage.isTemporary());
-      assertEquals(message.getConsumerCount(), decodedMessage.getConsumerCount());
-      assertEquals(message.getMessageCount(), decodedMessage.getMessageCount());
-      assertEquals(message.getFilterString(), decodedMessage.getFilterString());
-      assertEquals(message.getAddress(), decodedMessage.getAddress());         
-   }
-   
-   public void testSessionAddAddressMessage() throws Exception
-   {
-      SessionAddAddressMessage message = new SessionAddAddressMessage(randomString());
-
-      AbstractPacketCodec codec = new SessionAddAddressMessageCodec();
-      
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionAddAddressMessage);
-      SessionAddAddressMessage decodedMessage = (SessionAddAddressMessage)decodedPacket;
-      assertEquals(SESS_ADD_ADDRESS, decodedMessage.getType());
-      
-      assertEquals(message.getAddress(), decodedMessage.getAddress());        
-   }
-   
-   public void testBindingQueryRequest() throws Exception
-   {
-      SessionBindingQueryMessage message = new SessionBindingQueryMessage(randomString());
-
-      AbstractPacketCodec codec = new SessionBindingQueryMessageCodec();
-      
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionBindingQueryMessage);
-      SessionBindingQueryMessage decodedMessage = (SessionBindingQueryMessage)decodedPacket;
-      assertEquals(SESS_BINDINGQUERY, decodedMessage.getType());
-      
-      assertEquals(message.getAddress(), decodedMessage.getAddress());        
-   }
-   
-   public void testBindingQueryResponse() throws Exception
-   {
-      boolean exists = true;
-      List<String> queueNames = new ArrayList<String>();
-      queueNames.add(randomString());
-      queueNames.add(randomString());
-      queueNames.add(randomString());
-      SessionBindingQueryResponseMessage message = new SessionBindingQueryResponseMessage(exists, queueNames);
-
-      AbstractPacketCodec codec = new SessionBindingQueryResponseMessageCodec();
-      
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionBindingQueryResponseMessage);
-      SessionBindingQueryResponseMessage decodedMessage = (SessionBindingQueryResponseMessage)decodedPacket;
-      assertEquals(SESS_BINDINGQUERY_RESP, decodedMessage.getType());
-      
-      assertEquals(message.isExists(), decodedMessage.isExists());
-      
-      List<String> decodedNames = decodedMessage.getQueueNames();
-      assertEquals(queueNames.size(), decodedNames.size());
-      for (int i = 0; i < queueNames.size(); i++)
-      {
-         assertEquals(queueNames.get(i), decodedNames.get(i));
-      }
-   }
-   
-   
-   public void testDeleteQueueRequest() throws Exception
-   {
-      SessionDeleteQueueMessage message = new SessionDeleteQueueMessage(randomString());
-
-      AbstractPacketCodec codec = new SessionDeleteQueueMessageCodec();
-      
-      SimpleRemotingBuffer buffer = encode(message, codec);
-      checkHeader(buffer, message);
-      buffer.rewind();
-
-      AbstractPacket decodedPacket = codec.decode(buffer);
-
-      assertTrue(decodedPacket instanceof SessionDeleteQueueMessage);
-      SessionDeleteQueueMessage decodedMessage = (SessionDeleteQueueMessage)decodedPacket;
-      assertEquals(SESS_DELETE_QUEUE, decodedMessage.getType());
-      
-      assertEquals(message.getQueueName(), decodedMessage.getQueueName());        
-   }
-   
-   
-   
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   private SimpleRemotingBuffer encode(AbstractPacket packet,
-         AbstractPacketCodec codec) throws Exception
-   {
-      log.debug("encode " + packet);
-
-      IoBuffer b = IoBuffer.allocate(256);
-      b.setAutoExpand(true);
-
-      SimpleRemotingBuffer buf = new SimpleRemotingBuffer(b);
-
-      codec.encode(packet, buf);
-      buf.flip();
-
-      return buf;
-   }
-
-   private final class SimpleRemotingBuffer extends BufferWrapper
-   {
-
-      public SimpleRemotingBuffer(IoBuffer buffer)
-      {
-         super(buffer);
-      }
-
-      IoBuffer buffer()
-      {
-         return buffer;
-      }
-
-      public void flip()
-      {
-         buffer.flip();
-      }
-
-      public void rewind() throws IOException
-      {
-         buffer.rewind();
-      }
-
-      public int remaining()
-      {
-         return buffer.remaining();
-      }
-   }
-}

Copied: trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,1571 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.impl.wireformat.test.unit;
+
+import static org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec.BOOLEAN_LENGTH;
+import static org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec.FALSE;
+import static org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec.INT_LENGTH;
+import static org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec.LONG_LENGTH;
+import static org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec.TRUE;
+import static org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec.sizeof;
+import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.NOT_NULL_STRING;
+import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.NULL_BYTE;
+import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.NULL_STRING;
+import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.UTF_8_ENCODER;
+import static org.jboss.messaging.core.remoting.impl.wireformat.AbstractPacket.NO_ID_SET;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.BYTES;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CLOSE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONN_CREATESESSION;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONN_CREATESESSION_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONN_START;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONN_STOP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONS_FLOWTOKEN;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CREATECONNECTION;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CREATECONNECTION_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.NULL;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.PING;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.PONG;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.PROD_SEND;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_ACKNOWLEDGE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_ADD_ADDRESS;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BINDINGQUERY;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BINDINGQUERY_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BROWSER_HASNEXTMESSAGE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BROWSER_HASNEXTMESSAGE_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BROWSER_NEXTMESSAGE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BROWSER_NEXTMESSAGEBLOCK;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BROWSER_NEXTMESSAGEBLOCK_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BROWSER_NEXTMESSAGE_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BROWSER_RESET;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CANCEL;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_COMMIT;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEBROWSER;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEBROWSER_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATECONSUMER;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATECONSUMER_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEPRODUCER;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEPRODUCER_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEQUEUE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_DELETE_QUEUE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_DELIVER;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_QUEUEQUERY;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_QUEUEQUERY_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_RECOVER;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_REMOVE_ADDRESS;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_ROLLBACK;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_COMMIT;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_END;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_FORGET;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_GET_TIMEOUT;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_GET_TIMEOUT_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_INDOUBT_XIDS;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_INDOUBT_XIDS_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_JOIN;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_PREPARE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_RESUME;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_ROLLBACK;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_SET_TIMEOUT;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_SET_TIMEOUT_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_START;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_SUSPEND;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.TEXT;
+import static org.jboss.messaging.core.remoting.impl.wireformat.test.unit.CodecAssert.assertEqualsByteArrays;
+import static org.jboss.messaging.test.unit.RandomUtil.randomByte;
+import static org.jboss.messaging.test.unit.RandomUtil.randomBytes;
+import static org.jboss.messaging.test.unit.RandomUtil.randomInt;
+import static org.jboss.messaging.test.unit.RandomUtil.randomLong;
+import static org.jboss.messaging.test.unit.RandomUtil.randomString;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.transaction.xa.Xid;
+
+import org.apache.mina.common.IoBuffer;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec;
+import org.jboss.messaging.core.remoting.impl.codec.BytesPacketCodec;
+import org.jboss.messaging.core.remoting.impl.codec.ConnectionCreateSessionMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.ConnectionCreateSessionResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.ConsumerFlowTokenMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.CreateConnectionMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.CreateConnectionResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.DeliverMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.PingCodec;
+import org.jboss.messaging.core.remoting.impl.codec.PongCodec;
+import org.jboss.messaging.core.remoting.impl.codec.ProducerSendMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.RemotingBuffer;
+import org.jboss.messaging.core.remoting.impl.codec.SessionAcknowledgeMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionAddAddressMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionBindingQueryMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionBindingQueryResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionBrowserHasNextMessageResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionBrowserNextMessageBlockMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionBrowserNextMessageBlockResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionBrowserNextMessageResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionCancelMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionCreateBrowserMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionCreateBrowserResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionCreateConsumerMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionCreateConsumerResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionCreateProducerMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionCreateProducerResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionCreateQueueMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionDeleteQueueMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionQueueQueryMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionQueueQueryResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionRemoveAddressMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXACommitMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXAEndMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXAForgetMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXAGetInDoubtXidsResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXAGetTimeoutResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXAJoinMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXAPrepareMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXAResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXAResumeMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXARollbackMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXASetTimeoutMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXASetTimeoutResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.SessionXAStartMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.TextPacketCodec;
+import org.jboss.messaging.core.remoting.impl.mina.PacketCodecFactory;
+import org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.BufferWrapper;
+import org.jboss.messaging.core.remoting.impl.wireformat.AbstractPacket;
+import org.jboss.messaging.core.remoting.impl.wireformat.BytesPacket;
+import org.jboss.messaging.core.remoting.impl.wireformat.CloseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionStartMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionStopMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerFlowTokenMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionRequest;
+import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionResponse;
+import org.jboss.messaging.core.remoting.impl.wireformat.DeliverMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.NullPacket;
+import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.impl.wireformat.Ping;
+import org.jboss.messaging.core.remoting.impl.wireformat.Pong;
+import org.jboss.messaging.core.remoting.impl.wireformat.ProducerSendMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionAcknowledgeMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionAddAddressMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBindingQueryMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBindingQueryResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserHasNextMessageMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserHasNextMessageResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserNextMessageBlockMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserNextMessageBlockResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserNextMessageMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserNextMessageResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserResetMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCancelMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCommitMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateBrowserMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateBrowserResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateConsumerMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateConsumerResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateProducerMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateProducerResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateQueueMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionDeleteQueueMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionQueueQueryMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionQueueQueryResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionRecoverMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionRemoveAddressMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionRollbackMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXACommitMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAEndMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAForgetMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAGetInDoubtXidsMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAGetInDoubtXidsResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAGetTimeoutMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAGetTimeoutResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAJoinMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAPrepareMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAResumeMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXARollbackMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASetTimeoutMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASetTimeoutResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAStartMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASuspendMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.TextPacket;
+import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.server.impl.MessageImpl;
+import org.jboss.messaging.test.unit.RandomUtil;
+import org.jboss.messaging.test.unit.UnitTestCase;
+import org.jboss.messaging.util.StreamUtils;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class PacketTypeTest extends UnitTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(PacketTypeTest.class);
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   private static ByteBuffer encode(int length, Object... args)
+   {
+      ByteBuffer buffer = ByteBuffer.allocate(length);
+      for (Object arg : args)
+      {
+         if (arg instanceof Byte)
+            buffer.put(((Byte) arg).byteValue());
+         else if (arg instanceof Boolean)
+         {
+            Boolean bool = (Boolean) arg;
+            buffer.put(bool ? TRUE : FALSE);
+         } else if (arg instanceof Integer)
+            buffer.putInt(((Integer) arg).intValue());
+         else if (arg instanceof Long)
+            buffer.putLong(((Long) arg).longValue());
+         else if (arg instanceof Float)
+            buffer.putFloat(((Float) arg).floatValue());
+         else if (arg instanceof String)
+            putNullableString((String) arg, buffer);
+         else if (arg == null)
+            putNullableString(null, buffer);
+         else if (arg instanceof byte[])
+         {
+            byte[] b = (byte[]) arg;
+            buffer.putInt(b.length);
+            buffer.put(b);
+         } else if (arg instanceof long[])
+         {
+            long[] longs = (long[]) arg;
+            for (long l : longs)
+            {
+               buffer.putLong(l);
+            }
+         } else
+         {
+            fail("no encoding defined for " + arg);
+         }
+      }
+      buffer.flip();
+      return buffer;
+   }
+
+   private static void putNullableString(String string, ByteBuffer buffer)
+   {
+      if (string == null)
+      {
+         buffer.put(NULL_STRING);
+      } else
+      {
+         buffer.put(NOT_NULL_STRING);
+         UTF_8_ENCODER.reset();
+         UTF_8_ENCODER.encode(CharBuffer.wrap(string), buffer, true);
+         buffer.put(NULL_BYTE);
+      }
+   }
+
+   private static void checkHeader(SimpleRemotingBuffer buffer,
+         AbstractPacket packet) throws Exception
+   {
+      checkHeaderBytes(packet, buffer.buffer().buf());
+
+      assertEquals(buffer.get(), packet.getType().byteValue());
+
+      String targetID = packet.getTargetID();
+      if (NO_ID_SET.equals(packet.getTargetID()))
+         targetID = null;
+      String callbackID = packet.getCallbackID();
+      if (NO_ID_SET.equals(packet.getCallbackID()))
+         callbackID = null;
+
+      int headerLength = LONG_LENGTH + sizeof(targetID) + sizeof(callbackID)
+            + BOOLEAN_LENGTH;
+      assertEquals(buffer.getInt(), headerLength);
+      assertEquals(buffer.getLong(), packet.getCorrelationID());
+
+      String bufferTargetID = buffer.getNullableString();
+      if (bufferTargetID == null)
+         bufferTargetID = NO_ID_SET;
+      String bufferCallbackID = buffer.getNullableString();
+      if (bufferCallbackID == null)
+         bufferCallbackID = NO_ID_SET;
+      boolean oneWay = buffer.getBoolean();
+
+      assertEquals(bufferTargetID, packet.getTargetID());
+      assertEquals(bufferCallbackID, packet.getCallbackID());
+      assertEquals(oneWay, packet.isOneWay());
+   }
+
+   private static void checkHeaderBytes(AbstractPacket packet, ByteBuffer actual)
+   {
+      String targetID = (packet.getTargetID().equals(NO_ID_SET) ? null : packet
+            .getTargetID());
+      String callbackID = (packet.getCallbackID().equals(NO_ID_SET) ? null
+            : packet.getCallbackID());
+
+      int headerLength = LONG_LENGTH + sizeof(targetID) + sizeof(callbackID)
+            + BOOLEAN_LENGTH;
+      ByteBuffer expected = ByteBuffer.allocate(1 + 1 + INT_LENGTH
+            + headerLength);
+      expected.put(packet.getType().byteValue());
+
+      expected.putInt(headerLength);
+      expected.putLong(packet.getCorrelationID());
+      putNullableString(targetID, expected);
+      putNullableString(callbackID, expected);
+      expected.put(packet.isOneWay() ? TRUE : FALSE);
+      expected.flip();
+
+      assertEqualsByteArrays(expected.remaining(), expected.array(), actual
+            .array());
+   }
+
+   private static void checkBodyIsEmpty(RemotingBuffer buffer)
+   {
+      assertEquals(0, buffer.getInt());
+      // check the buffer has been wholly read
+      assertEquals(0, buffer.remaining());
+   }
+
+   private static void checkBody(RemotingBuffer buffer, Object... bodyObjects)
+   {
+      byte[] actualBody = new byte[buffer.getInt()];
+      buffer.get(actualBody);
+      ByteBuffer expectedBody = encode(actualBody.length, bodyObjects);
+      assertEqualsByteArrays(expectedBody.array(), actualBody);
+      // check the buffer has been wholly read
+      assertEquals(0, buffer.remaining());
+   }
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testNullPacket() throws Exception
+   {
+      NullPacket packet = new NullPacket();
+      packet.setCallbackID(randomString());
+      packet.setCorrelationID(randomLong());
+      packet.setTargetID(randomString());
+
+      AbstractPacketCodec<AbstractPacket> codec = PacketCodecFactory
+            .createCodecForEmptyPacket(NULL, NullPacket.class);
+      SimpleRemotingBuffer buffer = encode(packet, codec);
+      checkHeader(buffer, packet);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof NullPacket);
+      NullPacket p = (NullPacket) decodedPacket;
+
+      assertEquals(NULL, p.getType());
+      assertEquals(packet.getCallbackID(), p.getCallbackID());
+      assertEquals(packet.getCorrelationID(), p.getCorrelationID());
+      assertEquals(packet.getTargetID(), p.getTargetID());
+   }
+
+   public void testPing() throws Exception
+   {
+      Ping ping = new Ping(randomString());
+      AbstractPacketCodec<Ping> codec = new PingCodec();
+      
+      SimpleRemotingBuffer buffer = encode(ping, codec);
+      checkHeader(buffer, ping);
+      checkBody(buffer, ping.getSessionID());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof Ping);
+      Ping decodedPing = (Ping) decodedPacket;
+      assertEquals(PING, decodedPing.getType());
+      assertEquals(ping.getSessionID(), decodedPing.getSessionID());
+   }
+
+   public void testPong() throws Exception
+   {
+      Pong pong = new Pong(randomString(), true);
+      AbstractPacketCodec<Pong> codec = new PongCodec();
+      
+      SimpleRemotingBuffer buffer = encode(pong, codec);
+      checkHeader(buffer, pong);
+      checkBody(buffer, pong.getSessionID(), pong.isSessionFailed());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof Pong);
+      Pong decodedPong = (Pong) decodedPacket;
+      assertEquals(PONG, decodedPong.getType());
+      assertEquals(pong.getSessionID(), decodedPong.getSessionID());
+      assertEquals(pong.isSessionFailed(), decodedPong.isSessionFailed());
+   }
+
+   public void testTextPacket() throws Exception
+   {
+      TextPacket packet = new TextPacket("testTextPacket");
+      AbstractPacketCodec<TextPacket> codec = new TextPacketCodec();
+
+      SimpleRemotingBuffer buffer = encode(packet, codec);
+      checkHeader(buffer, packet);
+      checkBody(buffer, packet.getText());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof TextPacket);
+      TextPacket p = (TextPacket) decodedPacket;
+
+      assertEquals(TEXT, p.getType());
+      assertEquals(packet.getText(), p.getText());
+   }
+   
+   public void testBytesPacket() throws Exception
+   {
+      BytesPacket packet = new BytesPacket(randomBytes());
+
+      AbstractPacketCodec codec = new BytesPacketCodec();
+      SimpleRemotingBuffer buffer = encode(packet, codec);
+      checkHeader(buffer, packet);
+      checkBody(buffer, packet.getBytes());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof BytesPacket);
+      BytesPacket p = (BytesPacket) decodedPacket;
+
+      assertEquals(BYTES, p.getType());
+      assertEqualsByteArrays(packet.getBytes(), p.getBytes());
+   }
+   
+   public void testCreateConnectionRequest() throws Exception
+   {
+      int version = randomInt();
+      String remotingSessionID = randomString();
+      String clientVMID = randomString();
+      String username = null;
+      String password = null;
+      int prefetchSize = 0;
+ 
+      CreateConnectionRequest request = new CreateConnectionRequest(version,
+            remotingSessionID, clientVMID, username, password, prefetchSize);
+
+      AbstractPacketCodec<CreateConnectionRequest> codec = new CreateConnectionMessageCodec();
+      SimpleRemotingBuffer buffer = encode(request, codec);
+      checkHeader(buffer, request);
+      checkBody(buffer, version, remotingSessionID, clientVMID, username,
+            password, prefetchSize);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof CreateConnectionRequest);
+      CreateConnectionRequest decodedRequest = (CreateConnectionRequest) decodedPacket;
+
+      assertEquals(CREATECONNECTION, decodedPacket.getType());
+      assertEquals(request.getVersion(), decodedRequest.getVersion());
+      assertEquals(request.getRemotingSessionID(), decodedRequest
+            .getRemotingSessionID());
+      assertEquals(request.getClientVMID(), decodedRequest.getClientVMID());
+      assertEquals(request.getUsername(), decodedRequest.getUsername());
+      assertEquals(request.getPassword(), decodedRequest.getPassword());
+   }
+
+   public void testCreateConnectionResponse() throws Exception
+   {
+      CreateConnectionResponse response = new CreateConnectionResponse(
+            randomString());
+
+      AbstractPacketCodec<CreateConnectionResponse> codec = new CreateConnectionResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(response, codec);
+      checkHeader(buffer, response);
+      checkBody(buffer, response.getConnectionID());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof CreateConnectionResponse);
+      CreateConnectionResponse decodedResponse = (CreateConnectionResponse) decodedPacket;
+      assertEquals(CREATECONNECTION_RESP, decodedResponse.getType());
+      assertEquals(response.getConnectionID(), decodedResponse
+            .getConnectionID());
+   }
+
+   public void testCreateSessionRequest() throws Exception
+   {
+      //TODO test this more thoroughly
+      
+      ConnectionCreateSessionMessage request = new ConnectionCreateSessionMessage(true, true, true);
+
+      AbstractPacketCodec codec = new ConnectionCreateSessionMessageCodec();
+      SimpleRemotingBuffer buffer = encode(request, codec);
+      checkHeader(buffer, request);
+      checkBody(buffer, request.isXA(), request.isAutoCommitSends(), request.isAutoCommitAcks());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof ConnectionCreateSessionMessage);
+      ConnectionCreateSessionMessage decodedRequest = (ConnectionCreateSessionMessage) decodedPacket;
+      assertEquals(CONN_CREATESESSION, decodedRequest.getType());
+      assertEquals(request.isXA(), decodedRequest.isXA());
+      assertEquals(request.isAutoCommitSends(), decodedRequest.isAutoCommitSends());
+      assertEquals(request.isAutoCommitAcks(), decodedRequest.isAutoCommitAcks());
+      assertEquals(request.isXA(), decodedRequest.isXA());
+   }
+
+   public void testCreateSessionResponse() throws Exception
+   {
+      ConnectionCreateSessionResponseMessage response = new ConnectionCreateSessionResponseMessage(randomString());
+
+      AbstractPacketCodec codec = new ConnectionCreateSessionResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(response, codec);
+      checkHeader(buffer, response);
+      checkBody(buffer, response.getSessionID());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof ConnectionCreateSessionResponseMessage);
+      ConnectionCreateSessionResponseMessage decodedResponse = (ConnectionCreateSessionResponseMessage) decodedPacket;
+      assertEquals(CONN_CREATESESSION_RESP, decodedResponse.getType());
+      assertEquals(response.getSessionID(), decodedResponse.getSessionID());
+   }
+
+   public void testSendMessage() throws Exception
+   {
+      ProducerSendMessage packet = new ProducerSendMessage(randomString(), new MessageImpl());
+
+      AbstractPacketCodec codec = new ProducerSendMessageCodec();
+      SimpleRemotingBuffer buffer = encode(packet, codec);
+      checkHeader(buffer, packet);
+      checkBody(buffer, packet.getAddress(), StreamUtils.toBytes(packet.getMessage()));
+      buffer.rewind();
+
+      AbstractPacket p = codec.decode(buffer);
+
+      assertTrue(p instanceof ProducerSendMessage);
+      ProducerSendMessage decodedPacket = (ProducerSendMessage) p;
+      assertEquals(PROD_SEND, decodedPacket.getType());
+      assertEquals(packet.getAddress(), decodedPacket.getAddress());
+      assertEquals(packet.getMessage().getMessageID(), decodedPacket
+            .getMessage().getMessageID());
+   }
+
+   public void testCreateConsumerRequest() throws Exception
+   {      
+      String destination = "queue.testCreateConsumerRequest";
+      SessionCreateConsumerMessage request = new SessionCreateConsumerMessage(destination,
+            "color = 'red'", false, false);
+
+      AbstractPacketCodec codec = new SessionCreateConsumerMessageCodec();
+      SimpleRemotingBuffer buffer = encode(request, codec);
+      checkHeader(buffer, request);
+      checkBody(buffer, request.getQueueName(), request
+            .getFilterString(), request.isNoLocal(), request.isAutoDeleteQueue());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionCreateConsumerMessage);
+      SessionCreateConsumerMessage decodedRequest = (SessionCreateConsumerMessage) decodedPacket;
+      assertEquals(SESS_CREATECONSUMER, decodedRequest.getType());
+      assertEquals(request.getQueueName(), decodedRequest.getQueueName());
+      assertEquals(request.getFilterString(), decodedRequest.getFilterString());
+      assertEquals(request.isNoLocal(), decodedRequest.isNoLocal());
+      assertEquals(request.isAutoDeleteQueue(), decodedRequest.isAutoDeleteQueue());
+   }
+
+   public void testCreateConsumerResponse() throws Exception
+   {
+
+      SessionCreateConsumerResponseMessage response = new SessionCreateConsumerResponseMessage(
+            randomString(), RandomUtil.randomInt());
+
+      AbstractPacketCodec codec = new SessionCreateConsumerResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(response, codec);
+      checkHeader(buffer, response);
+      checkBody(buffer, response.getConsumerID(), response.getPrefetchSize());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionCreateConsumerResponseMessage);
+      SessionCreateConsumerResponseMessage decodedResponse = (SessionCreateConsumerResponseMessage) decodedPacket;
+      assertEquals(SESS_CREATECONSUMER_RESP, decodedResponse.getType());
+      assertEquals(response.getPrefetchSize(), decodedResponse.getPrefetchSize());
+   }
+   
+   public void testCreateProducerRequest() throws Exception
+   {      
+      String destination = "queue.testCreateProducerRequest";
+      SessionCreateProducerMessage request = new SessionCreateProducerMessage(destination);
+
+      AbstractPacketCodec codec = new SessionCreateProducerMessageCodec();
+      SimpleRemotingBuffer buffer = encode(request, codec);
+      checkHeader(buffer, request);
+      checkBody(buffer, request.getAddress());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionCreateProducerMessage);
+      SessionCreateProducerMessage decodedRequest = (SessionCreateProducerMessage) decodedPacket;
+      assertEquals(SESS_CREATEPRODUCER, decodedRequest.getType());
+      assertEquals(request.getAddress(), decodedRequest.getAddress());
+   }
+   
+   public void testCreateProducerResponse() throws Exception
+   {
+      SessionCreateProducerResponseMessage response = new SessionCreateProducerResponseMessage(randomString());
+
+      AbstractPacketCodec codec = new SessionCreateProducerResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(response, codec);
+      checkHeader(buffer, response);
+      checkBody(buffer, response.getProducerID());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionCreateProducerResponseMessage);
+      SessionCreateProducerResponseMessage decodedResponse = (SessionCreateProducerResponseMessage) decodedPacket;
+      assertEquals(SESS_CREATEPRODUCER_RESP, decodedResponse.getType());
+      assertEquals(response.getProducerID(), decodedResponse.getProducerID());;
+   }
+
+   public void testStartConnectionMessage() throws Exception
+   {
+      ConnectionStartMessage packet = new ConnectionStartMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            CONN_START, ConnectionStartMessage.class);
+      SimpleRemotingBuffer buffer = encode(packet, codec);
+      checkHeader(buffer, packet);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof ConnectionStartMessage);
+      assertEquals(CONN_START, decodedPacket.getType());
+   }
+
+   public void testStopConnectionMessage() throws Exception
+   {
+      ConnectionStopMessage packet = new ConnectionStopMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            CONN_STOP, ConnectionStopMessage.class);
+      SimpleRemotingBuffer buffer = encode(packet, codec);
+      checkHeader(buffer, packet);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof ConnectionStopMessage);
+      assertEquals(CONN_STOP, decodedPacket.getType());
+   }
+
+   public void testConsumerFlowTokenMessage() throws Exception
+   {
+      ConsumerFlowTokenMessage message = new ConsumerFlowTokenMessage(10);
+      AbstractPacketCodec codec = new ConsumerFlowTokenMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBody(buffer, message.getTokens());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof ConsumerFlowTokenMessage);
+      ConsumerFlowTokenMessage decodedMessage = (ConsumerFlowTokenMessage) decodedPacket;
+      assertEquals(CONS_FLOWTOKEN, decodedMessage.getType());
+      assertEquals(message.getTokens(), decodedMessage.getTokens());
+   }
+
+   public void testDeliverMessage() throws Exception
+   {
+      Message msg = new MessageImpl();
+      DeliverMessage message = new DeliverMessage(msg, randomLong());
+
+      AbstractPacketCodec codec = new DeliverMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBody(buffer, StreamUtils.toBytes(msg), message.getDeliveryID());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof DeliverMessage);
+      DeliverMessage decodedMessage = (DeliverMessage) decodedPacket;
+      assertEquals(SESS_DELIVER, decodedMessage.getType());
+      assertEquals(message.getMessage().getMessageID(), decodedMessage
+            .getMessage().getMessageID());
+      assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
+   }
+
+   public void testSessionAcknowledgeMessage() throws Exception
+   {
+      SessionAcknowledgeMessage message = new SessionAcknowledgeMessage(
+            randomLong(), true);
+
+      AbstractPacketCodec codec = new SessionAcknowledgeMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBody(buffer, message.getDeliveryID(), message.isAllUpTo());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionAcknowledgeMessage);
+      SessionAcknowledgeMessage decodedMessage = (SessionAcknowledgeMessage) decodedPacket;
+      assertEquals(SESS_ACKNOWLEDGE, decodedMessage.getType());
+      assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
+      assertEquals(message.isAllUpTo(), decodedMessage.isAllUpTo());
+   }
+
+   public void testSessionCancelMessage() throws Exception
+   {
+      SessionCancelMessage message = new SessionCancelMessage(randomLong(),
+            true);
+
+      AbstractPacketCodec codec = new SessionCancelMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBody(buffer, message.getDeliveryID(), message.isExpired());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionCancelMessage);
+      SessionCancelMessage decodedMessage = (SessionCancelMessage) decodedPacket;
+      assertEquals(SESS_CANCEL, decodedMessage.getType());
+      assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
+      assertEquals(message.isExpired(), decodedMessage.isExpired());
+   }
+
+   public void testSessionCommitMessage() throws Exception
+   {
+      SessionCommitMessage message = new SessionCommitMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            SESS_COMMIT, SessionCommitMessage.class);
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBodyIsEmpty(buffer);
+
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionCommitMessage);
+      assertEquals(SESS_COMMIT, decodedPacket.getType());
+   }
+
+   public void testSessionRollbackMessage() throws Exception
+   {
+      SessionRollbackMessage message = new SessionRollbackMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            SESS_ROLLBACK, SessionRollbackMessage.class);
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBodyIsEmpty(buffer);
+
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionRollbackMessage);
+      assertEquals(SESS_ROLLBACK, decodedPacket.getType());
+   }
+   
+   public void testSessionRecoverMessage() throws Exception
+   {
+      SessionRecoverMessage message = new SessionRecoverMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            SESS_RECOVER, SessionRecoverMessage.class);
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBodyIsEmpty(buffer);
+
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionRecoverMessage);
+      assertEquals(SESS_RECOVER, decodedPacket.getType());
+   }
+
+   public void testCloseMessage() throws Exception
+   {
+      CloseMessage message = new CloseMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            CLOSE, CloseMessage.class);
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof CloseMessage);
+      CloseMessage decodedMessage = (CloseMessage) decodedPacket;
+      assertEquals(CLOSE, decodedMessage.getType());
+   }
+
+
+   public void testCreateBrowserRequest() throws Exception
+   {
+      String destination = "queue.testCreateBrowserRequest";
+      SessionCreateBrowserMessage request = new SessionCreateBrowserMessage(destination,
+            "color = 'red'");
+
+      AbstractPacketCodec codec = new SessionCreateBrowserMessageCodec();
+      SimpleRemotingBuffer buffer = encode(request, codec);
+      checkHeader(buffer, request);
+      checkBody(buffer, request.getQueueName(), request.getFilterString());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionCreateBrowserMessage);
+      SessionCreateBrowserMessage decodedRequest = (SessionCreateBrowserMessage) decodedPacket;
+      assertEquals(SESS_CREATEBROWSER, decodedRequest.getType());
+      assertEquals(request.getQueueName(), decodedRequest.getQueueName());
+      assertEquals(request.getFilterString(), decodedRequest.getFilterString());
+   }
+
+   public void testCreateBrowserResponse() throws Exception
+   {
+      SessionCreateBrowserResponseMessage response = new SessionCreateBrowserResponseMessage(randomString());
+
+      AbstractPacketCodec codec = new SessionCreateBrowserResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(response, codec);
+      checkHeader(buffer, response);
+      checkBody(buffer, response.getBrowserID());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionCreateBrowserResponseMessage);
+      SessionCreateBrowserResponseMessage decodedResponse = (SessionCreateBrowserResponseMessage) decodedPacket;
+      assertEquals(SESS_CREATEBROWSER_RESP, decodedResponse.getType());
+      assertEquals(response.getBrowserID(), decodedResponse.getBrowserID());
+   }
+
+   public void testBrowserResetMessage() throws Exception
+   {
+      SessionBrowserResetMessage message = new SessionBrowserResetMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            SESS_BROWSER_RESET, SessionBrowserResetMessage.class);
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionBrowserResetMessage);
+      assertEquals(SESS_BROWSER_RESET, decodedPacket.getType());
+   }
+
+   public void testBrowserHasNextMessageRequest() throws Exception
+   {
+      SessionBrowserHasNextMessageMessage request = new SessionBrowserHasNextMessageMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            SESS_BROWSER_HASNEXTMESSAGE, SessionBrowserHasNextMessageMessage.class);
+      SimpleRemotingBuffer buffer = encode(request, codec);
+      checkHeader(buffer, request);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionBrowserHasNextMessageMessage);
+      assertEquals(SESS_BROWSER_HASNEXTMESSAGE, decodedPacket.getType());
+   }
+
+   public void testBrowserHasNextMessageResponse() throws Exception
+   {
+      SessionBrowserHasNextMessageResponseMessage response = new SessionBrowserHasNextMessageResponseMessage(
+            false);
+      AbstractPacketCodec codec = new SessionBrowserHasNextMessageResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(response, codec);
+      checkHeader(buffer, response);
+      checkBody(buffer, response.hasNext());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionBrowserHasNextMessageResponseMessage);
+      SessionBrowserHasNextMessageResponseMessage decodedResponse = (SessionBrowserHasNextMessageResponseMessage) decodedPacket;
+      assertEquals(SESS_BROWSER_HASNEXTMESSAGE_RESP, decodedResponse.getType());
+      assertEquals(response.hasNext(), decodedResponse.hasNext());
+   }
+
+   public void testBrowserNextMessageRequest() throws Exception
+   {
+      SessionBrowserNextMessageMessage request = new SessionBrowserNextMessageMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            SESS_BROWSER_NEXTMESSAGE, SessionBrowserNextMessageMessage.class);
+      SimpleRemotingBuffer buffer = encode(request, codec);
+      checkHeader(buffer, request);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionBrowserNextMessageMessage);
+      assertEquals(SESS_BROWSER_NEXTMESSAGE, decodedPacket.getType());
+   }
+
+   public void testBrowserNextMessageResponse() throws Exception
+   {
+      Message msg = new MessageImpl();
+      SessionBrowserNextMessageResponseMessage response = new SessionBrowserNextMessageResponseMessage(msg);
+
+      AbstractPacketCodec codec = new SessionBrowserNextMessageResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(response, codec);
+      checkHeader(buffer, response);
+      checkBody(buffer, StreamUtils.toBytes(msg));
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionBrowserNextMessageResponseMessage);
+      SessionBrowserNextMessageResponseMessage decodedResponse = (SessionBrowserNextMessageResponseMessage) decodedPacket;
+      assertEquals(SESS_BROWSER_NEXTMESSAGE_RESP, decodedResponse.getType());
+      assertEquals(response.getMessage().getMessageID(), decodedResponse
+            .getMessage().getMessageID());
+   }
+
+   public void testBrowserNextMessageBlockRequest() throws Exception
+   {
+      SessionBrowserNextMessageBlockMessage request = new SessionBrowserNextMessageBlockMessage(
+            randomLong());
+
+      AbstractPacketCodec codec = new SessionBrowserNextMessageBlockMessageCodec();
+      SimpleRemotingBuffer buffer = encode(request, codec);
+      checkHeader(buffer, request);
+      checkBody(buffer, request.getMaxMessages());
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionBrowserNextMessageBlockMessage);
+      SessionBrowserNextMessageBlockMessage decodedRequest = (SessionBrowserNextMessageBlockMessage) decodedPacket;
+      assertEquals(SESS_BROWSER_NEXTMESSAGEBLOCK, decodedPacket.getType());
+      assertEquals(request.getMaxMessages(), decodedRequest.getMaxMessages());
+   }
+
+   public void testBrowserNextMessageBlockResponse() throws Exception
+   {
+      Message[] messages = new Message[] { new MessageImpl(), new MessageImpl() };
+      SessionBrowserNextMessageBlockResponseMessage response = new SessionBrowserNextMessageBlockResponseMessage(
+            messages);
+
+      AbstractPacketCodec codec = new SessionBrowserNextMessageBlockResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(response, codec);
+      checkHeader(buffer, response);
+      checkBody(buffer, messages.length, SessionBrowserNextMessageBlockResponseMessageCodec
+            .encode(messages));
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionBrowserNextMessageBlockResponseMessage);
+      SessionBrowserNextMessageBlockResponseMessage decodedResponse = (SessionBrowserNextMessageBlockResponseMessage) decodedPacket;
+      assertEquals(SESS_BROWSER_NEXTMESSAGEBLOCK_RESP, decodedResponse.getType());
+      assertEquals(response.getMessages()[0].getMessageID(), decodedResponse
+            .getMessages()[0].getMessageID());
+      assertEquals(response.getMessages()[1].getMessageID(), decodedResponse
+            .getMessages()[1].getMessageID());
+   }
+
+  
+   public void testSesssionXACommitMessageOnePhase() throws Exception
+   {
+      this.testSessionXACommitMessage(true);
+   }
+   
+   public void testSessionXACommitMessageNotOnePhase() throws Exception
+   {
+      this.testSessionXACommitMessage(false);
+   }
+   
+   private void testSessionXACommitMessage(boolean onePhase) throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXACommitMessage message = new SessionXACommitMessage(xid, onePhase);
+      AbstractPacketCodec codec = new SessionXACommitMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXACommitMessage);
+      SessionXACommitMessage decodedMessage = (SessionXACommitMessage)decodedPacket;
+      assertEquals(SESS_XA_COMMIT, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+      assertEquals(onePhase, decodedMessage.isOnePhase());
+   }
+   
+   public void testSessionXAEndMessageFailed() throws Exception
+   {
+      this.testSessionXAEndMessage(true);
+   }
+   
+   public void testSessionXAEndMessageNotFailed() throws Exception
+   {
+      this.testSessionXACommitMessage(false);
+   }
+   
+   private void testSessionXAEndMessage(boolean failed) throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAEndMessage message = new SessionXAEndMessage(xid, failed);
+      AbstractPacketCodec codec = new SessionXAEndMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAEndMessage);
+      SessionXAEndMessage decodedMessage = (SessionXAEndMessage)decodedPacket;
+      assertEquals(SESS_XA_END, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+      assertEquals(failed, decodedMessage.isFailed());
+   }
+   
+   public void testSessionXAForgetMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAForgetMessage message = new SessionXAForgetMessage(xid);
+      AbstractPacketCodec codec = new SessionXAForgetMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAForgetMessage);
+      SessionXAForgetMessage decodedMessage = (SessionXAForgetMessage)decodedPacket;
+      assertEquals(SESS_XA_FORGET, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXAGetInDoubtXidsMessage() throws Exception
+   {
+      SessionXAGetInDoubtXidsMessage request = new SessionXAGetInDoubtXidsMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            SESS_XA_INDOUBT_XIDS, SessionXAGetInDoubtXidsMessage.class);
+      SimpleRemotingBuffer buffer = encode(request, codec);
+      checkHeader(buffer, request);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionXAGetInDoubtXidsMessage);
+      assertEquals(SESS_XA_INDOUBT_XIDS, decodedPacket.getType());            
+   }
+   
+   public void testSessionGetInDoubtXidsResponse() throws Exception
+   {
+      final int numXids = 10;
+      List<Xid> xids = new ArrayList<Xid>();
+      for (int i = 0; i < numXids; i++)
+      {
+         xids.add(generateXid());
+      }
+      
+      SessionXAGetInDoubtXidsResponseMessage message = new SessionXAGetInDoubtXidsResponseMessage(xids);
+      AbstractPacketCodec codec = new SessionXAGetInDoubtXidsResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAGetInDoubtXidsResponseMessage);
+      SessionXAGetInDoubtXidsResponseMessage decodedMessage = (SessionXAGetInDoubtXidsResponseMessage)decodedPacket;
+      assertEquals(SESS_XA_INDOUBT_XIDS_RESP, decodedMessage.getType());
+           
+      List<Xid> decodedXids = decodedMessage.getXids();
+      assertNotNull(decodedXids);
+      assertEquals(xids.size(), decodedXids.size());
+      
+      for (int i = 0; i < numXids; i++)
+      {
+         assertEquals(xids.get(i), decodedXids.get(i));
+      }
+   }
+   
+   public void testSessionXAGetTimeoutMessage() throws Exception
+   {
+      SessionXAGetTimeoutMessage message = new SessionXAGetTimeoutMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            PacketType.SESS_XA_GET_TIMEOUT, SessionXAGetTimeoutMessage.class);
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionXAGetTimeoutMessage);
+      assertEquals(SESS_XA_GET_TIMEOUT, decodedPacket.getType());     
+   }
+   
+   public void testSessionXAGetTimeoutResponse() throws Exception
+   {
+      final int timeout = RandomUtil.randomInt();
+      
+      SessionXAGetTimeoutResponseMessage message = new SessionXAGetTimeoutResponseMessage(timeout);
+      AbstractPacketCodec codec = new SessionXAGetTimeoutResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAGetTimeoutResponseMessage);
+      SessionXAGetTimeoutResponseMessage decodedMessage = (SessionXAGetTimeoutResponseMessage)decodedPacket;
+      assertEquals(SESS_XA_GET_TIMEOUT_RESP, decodedMessage.getType());
+           
+      assertEquals(timeout, decodedMessage.getTimeoutSeconds());
+   }
+
+   public void testSessionXAJoinMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAJoinMessage message = new SessionXAJoinMessage(xid);
+      AbstractPacketCodec codec = new SessionXAJoinMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAJoinMessage);
+      SessionXAJoinMessage decodedMessage = (SessionXAJoinMessage)decodedPacket;
+      assertEquals(SESS_XA_JOIN, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXAPrepareMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAPrepareMessage message = new SessionXAPrepareMessage(xid);
+      AbstractPacketCodec codec = new SessionXAPrepareMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAPrepareMessage);
+      SessionXAPrepareMessage decodedMessage = (SessionXAPrepareMessage)decodedPacket;
+      assertEquals(SESS_XA_PREPARE, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXAResponseErrorNullString() throws Exception
+   {
+      testSessionXAResponse(true, true);
+   }
+   
+   public void testSessionXAResponseErrorNotNullString() throws Exception
+   {
+      testSessionXAResponse(true, false);
+   }
+   
+   public void testSessionXAResponseNoErrorNullString() throws Exception
+   {
+      testSessionXAResponse(false, true);
+   }
+   
+   public void testSessionXAResponseNoErrorNotNullString() throws Exception
+   {
+      testSessionXAResponse(false, false);
+   }
+   
+   private void testSessionXAResponse(boolean error, boolean nullString) throws Exception
+   {
+      int responseCode = RandomUtil.randomInt();
+      
+      String str = nullString ? null : RandomUtil.randomString();
+      
+      SessionXAResponseMessage message = new SessionXAResponseMessage(error, responseCode, str);
+      AbstractPacketCodec codec = new SessionXAResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAResponseMessage);
+      SessionXAResponseMessage decodedMessage = (SessionXAResponseMessage)decodedPacket;
+      assertEquals(SESS_XA_RESP, decodedMessage.getType());
+      assertEquals(error, decodedMessage.isError());
+      assertEquals(responseCode, decodedMessage.getResponseCode());
+      assertEquals(str, decodedMessage.getMessage());
+   }
+   
+   public void testSessionXAResumeMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAResumeMessage message = new SessionXAResumeMessage(xid);
+      AbstractPacketCodec codec = new SessionXAResumeMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAResumeMessage);
+      SessionXAResumeMessage decodedMessage = (SessionXAResumeMessage)decodedPacket;
+      assertEquals(SESS_XA_RESUME, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXARollbackMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXARollbackMessage message = new SessionXARollbackMessage(xid);
+      AbstractPacketCodec codec = new SessionXARollbackMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXARollbackMessage);
+      SessionXARollbackMessage decodedMessage = (SessionXARollbackMessage)decodedPacket;
+      assertEquals(SESS_XA_ROLLBACK, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXASetTimeoutMessage() throws Exception
+   {
+      final int timeout = RandomUtil.randomInt();
+      SessionXASetTimeoutMessage message = new SessionXASetTimeoutMessage(timeout);
+      AbstractPacketCodec codec = new SessionXASetTimeoutMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXASetTimeoutMessage);
+      SessionXASetTimeoutMessage decodedMessage = (SessionXASetTimeoutMessage)decodedPacket;
+      assertEquals(SESS_XA_SET_TIMEOUT, decodedMessage.getType());
+      assertEquals(timeout, decodedMessage.getTimeoutSeconds());      
+   }
+   
+   public void testSessionXASetTimeoutResponseMessageOK() throws Exception
+   {
+      testSessionXASetTimeoutResponseMessage(true);
+   }
+   
+   public void testSessionXASetTimeoutResponseMessageNotOK() throws Exception
+   {
+      testSessionXASetTimeoutResponseMessage(false);
+   }
+   
+   private void testSessionXASetTimeoutResponseMessage(boolean ok) throws Exception
+   {
+      final int timeout = RandomUtil.randomInt();
+      SessionXASetTimeoutResponseMessage message = new SessionXASetTimeoutResponseMessage(ok);
+      AbstractPacketCodec codec = new SessionXASetTimeoutResponseMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXASetTimeoutResponseMessage);
+      SessionXASetTimeoutResponseMessage decodedMessage = (SessionXASetTimeoutResponseMessage)decodedPacket;
+      assertEquals(SESS_XA_SET_TIMEOUT_RESP, decodedMessage.getType());
+      assertEquals(ok, decodedMessage.isOK());      
+   }
+   
+   public void testSessionXAStartMessage() throws Exception
+   {
+      Xid xid = this.generateXid();
+      SessionXAStartMessage message = new SessionXAStartMessage(xid);
+      AbstractPacketCodec codec = new SessionXAStartMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+      
+      AbstractPacket decodedPacket = codec.decode(buffer);
+      assertTrue(decodedPacket instanceof SessionXAStartMessage);
+      SessionXAStartMessage decodedMessage = (SessionXAStartMessage)decodedPacket;
+      assertEquals(SESS_XA_START, decodedMessage.getType());
+      assertEquals(xid, decodedMessage.getXid());      
+   }
+   
+   public void testSessionXASuspendMessage() throws Exception
+   {
+      SessionXASuspendMessage message = new SessionXASuspendMessage();
+
+      AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+            PacketType.SESS_XA_SUSPEND, SessionXASuspendMessage.class);
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBodyIsEmpty(buffer);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionXASuspendMessage);
+      assertEquals(SESS_XA_SUSPEND, decodedPacket.getType());     
+   }
+   
+   
+   public void testSessionRemoveAddressMessage() throws Exception
+   {
+      SessionRemoveAddressMessage message = new SessionRemoveAddressMessage(randomString());
+
+      AbstractPacketCodec codec = new SessionRemoveAddressMessageCodec();
+      
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionRemoveAddressMessage);
+      SessionRemoveAddressMessage decodedMessage = (SessionRemoveAddressMessage)decodedPacket;
+      assertEquals(SESS_REMOVE_ADDRESS, decodedMessage.getType());
+      
+      assertEquals(message.getAddress(), decodedMessage.getAddress());
+            
+   }
+   
+   public void testSessionCreateQueueRequest() throws Exception
+   {
+      SessionCreateQueueMessage message = new SessionCreateQueueMessage(randomString(), randomString(), randomString(), true, true);
+
+      AbstractPacketCodec codec = new SessionCreateQueueMessageCodec();
+      
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionCreateQueueMessage);
+      SessionCreateQueueMessage decodedMessage = (SessionCreateQueueMessage)decodedPacket;
+      assertEquals(SESS_CREATEQUEUE, decodedMessage.getType());
+      
+      assertEquals(message.getAddress(), decodedMessage.getAddress());
+      assertEquals(message.getQueueName(), decodedMessage.getQueueName());
+      assertEquals(message.getFilterString(), decodedMessage.getFilterString());
+      assertEquals(message.isDurable(), decodedMessage.isDurable());
+      assertEquals(message.isTemporary(), decodedMessage.isDurable());
+            
+   }
+   
+   public void testSessionQueueQueryRequest() throws Exception
+   {
+      SessionQueueQueryMessage message = new SessionQueueQueryMessage(randomString());
+
+      AbstractPacketCodec codec = new SessionQueueQueryMessageCodec();
+      
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionQueueQueryMessage);
+      SessionQueueQueryMessage decodedMessage = (SessionQueueQueryMessage)decodedPacket;
+      assertEquals(SESS_QUEUEQUERY, decodedMessage.getType());
+      
+      assertEquals(message.getQueueName(), decodedMessage.getQueueName());            
+   }
+   
+   public void testSessionQueueQueryResponse() throws Exception
+   {
+      SessionQueueQueryResponseMessage message = new SessionQueueQueryResponseMessage(true, true, randomInt(), randomInt(), randomInt(),
+                                                          randomString(), randomString());
+
+      AbstractPacketCodec codec = new SessionQueueQueryResponseMessageCodec();
+      
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionQueueQueryResponseMessage);
+      SessionQueueQueryResponseMessage decodedMessage = (SessionQueueQueryResponseMessage)decodedPacket;
+      assertEquals(SESS_QUEUEQUERY_RESP, decodedMessage.getType());
+      
+      assertEquals(message.isExists(), decodedMessage.isExists());
+      assertEquals(message.isDurable(), decodedMessage.isDurable());
+      assertEquals(message.isTemporary(), decodedMessage.isTemporary());
+      assertEquals(message.getConsumerCount(), decodedMessage.getConsumerCount());
+      assertEquals(message.getMessageCount(), decodedMessage.getMessageCount());
+      assertEquals(message.getFilterString(), decodedMessage.getFilterString());
+      assertEquals(message.getAddress(), decodedMessage.getAddress());         
+   }
+   
+   public void testSessionAddAddressMessage() throws Exception
+   {
+      SessionAddAddressMessage message = new SessionAddAddressMessage(randomString());
+
+      AbstractPacketCodec codec = new SessionAddAddressMessageCodec();
+      
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionAddAddressMessage);
+      SessionAddAddressMessage decodedMessage = (SessionAddAddressMessage)decodedPacket;
+      assertEquals(SESS_ADD_ADDRESS, decodedMessage.getType());
+      
+      assertEquals(message.getAddress(), decodedMessage.getAddress());        
+   }
+   
+   public void testBindingQueryRequest() throws Exception
+   {
+      SessionBindingQueryMessage message = new SessionBindingQueryMessage(randomString());
+
+      AbstractPacketCodec codec = new SessionBindingQueryMessageCodec();
+      
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionBindingQueryMessage);
+      SessionBindingQueryMessage decodedMessage = (SessionBindingQueryMessage)decodedPacket;
+      assertEquals(SESS_BINDINGQUERY, decodedMessage.getType());
+      
+      assertEquals(message.getAddress(), decodedMessage.getAddress());        
+   }
+   
+   public void testBindingQueryResponse() throws Exception
+   {
+      boolean exists = true;
+      List<String> queueNames = new ArrayList<String>();
+      queueNames.add(randomString());
+      queueNames.add(randomString());
+      queueNames.add(randomString());
+      SessionBindingQueryResponseMessage message = new SessionBindingQueryResponseMessage(exists, queueNames);
+
+      AbstractPacketCodec codec = new SessionBindingQueryResponseMessageCodec();
+      
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionBindingQueryResponseMessage);
+      SessionBindingQueryResponseMessage decodedMessage = (SessionBindingQueryResponseMessage)decodedPacket;
+      assertEquals(SESS_BINDINGQUERY_RESP, decodedMessage.getType());
+      
+      assertEquals(message.isExists(), decodedMessage.isExists());
+      
+      List<String> decodedNames = decodedMessage.getQueueNames();
+      assertEquals(queueNames.size(), decodedNames.size());
+      for (int i = 0; i < queueNames.size(); i++)
+      {
+         assertEquals(queueNames.get(i), decodedNames.get(i));
+      }
+   }
+   
+   
+   public void testDeleteQueueRequest() throws Exception
+   {
+      SessionDeleteQueueMessage message = new SessionDeleteQueueMessage(randomString());
+
+      AbstractPacketCodec codec = new SessionDeleteQueueMessageCodec();
+      
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      buffer.rewind();
+
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof SessionDeleteQueueMessage);
+      SessionDeleteQueueMessage decodedMessage = (SessionDeleteQueueMessage)decodedPacket;
+      assertEquals(SESS_DELETE_QUEUE, decodedMessage.getType());
+      
+      assertEquals(message.getQueueName(), decodedMessage.getQueueName());        
+   }
+   
+   
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   private SimpleRemotingBuffer encode(AbstractPacket packet,
+         AbstractPacketCodec codec) throws Exception
+   {
+      log.debug("encode " + packet);
+
+      IoBuffer b = IoBuffer.allocate(256);
+      b.setAutoExpand(true);
+
+      SimpleRemotingBuffer buf = new SimpleRemotingBuffer(b);
+
+      codec.encode(packet, buf);
+      buf.flip();
+
+      return buf;
+   }
+
+   private final class SimpleRemotingBuffer extends BufferWrapper
+   {
+
+      public SimpleRemotingBuffer(IoBuffer buffer)
+      {
+         super(buffer);
+      }
+
+      IoBuffer buffer()
+      {
+         return buffer;
+      }
+
+      public void flip()
+      {
+         buffer.flip();
+      }
+
+      public void rewind() throws IOException
+      {
+         buffer.rewind();
+      }
+
+      public int remaining()
+      {
+         return buffer.remaining();
+      }
+   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/server/impl/test/concurrent/QueueTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/test/concurrent/QueueTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/concurrent/QueueTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/concurrent/QueueTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,205 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.core.server.impl.test.concurrent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.messaging.core.server.HandleStatus;
+import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.QueueFactory;
+import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeConsumer;
+import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeQueueFactory;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ * 
+ * A concurrent QueueTest
+ * 
+ * All the concurrent queue tests go in here 
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class QueueTest extends UnitTestCase
+{
+   private QueueFactory queueFactory = new FakeQueueFactory();
+   
+   /*
+    * Concurrent set consumer not busy, busy then, call deliver while messages are being added and consumed
+    */
+   public void testConcurrentAddsDeliver() throws Exception
+   {
+      Queue queue = queueFactory.createQueue(1, "queue1", null, false, true);
+      
+      FakeConsumer consumer = new FakeConsumer();
+      
+      queue.addConsumer(consumer);
+      
+      final long testTime = 5000;
+      
+      Sender sender = new Sender(queue, testTime);
+      
+      Toggler toggler = new Toggler(queue, consumer, testTime);
+      
+      sender.start();
+      
+      toggler.start();
+      
+      sender.join();
+      
+      toggler.join();
+      
+      consumer.setStatusImmediate(HandleStatus.HANDLED);
+      
+      queue.deliver();
+      
+      if (sender.getException() != null)
+      {
+         throw sender.getException();
+      }
+      
+      if (toggler.getException() != null)
+      {
+         throw toggler.getException();
+      }
+      
+      assertRefListsIdenticalRefs(sender.getReferences(), consumer.getReferences());
+      
+      System.out.println("num refs: " + sender.getReferences().size());
+      
+      System.out.println("num toggles: " + toggler.getNumToggles());
+      
+   }
+   
+   // Inner classes ---------------------------------------------------------------
+   
+   class Sender extends Thread
+   {
+      private volatile Exception e;
+      
+      private Queue queue;
+      
+      private long testTime;
+      
+      private volatile int i;
+      
+      public Exception getException()
+      {
+         return e;
+      }
+      
+      private List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      public List<MessageReference> getReferences()
+      {
+         return refs;
+      }
+      
+      Sender(Queue queue, long testTime)
+      {
+         this.testTime = testTime;
+         
+         this.queue = queue;
+      }
+      
+      public void run()
+      {
+         long start = System.currentTimeMillis();
+         
+         while (System.currentTimeMillis() - start < testTime)
+         {
+            Message message = generateMessage(i);
+            
+            MessageReference ref = message.createReference(queue);
+            
+            queue.addLast(ref);
+            
+            refs.add(ref);
+            
+            i++;
+         }
+      }
+   }
+   
+   class Toggler extends Thread
+   {
+      private volatile Exception e;
+      
+      private Queue queue;
+      
+      private FakeConsumer consumer;
+      
+      private long testTime;
+      
+      private boolean toggle;
+      
+      private volatile int numToggles;
+      
+      public int getNumToggles()
+      {
+         return numToggles;
+      }
+      
+      public Exception getException()
+      {
+         return e;
+      }
+      
+      Toggler(Queue queue, FakeConsumer consumer, long testTime)
+      {
+         this.testTime = testTime;
+         
+         this.queue = queue;
+         
+         this.consumer = consumer;
+      }
+      
+      public void run()
+      {
+         long start = System.currentTimeMillis();
+         
+         while (System.currentTimeMillis() - start < testTime)
+         {
+            if (toggle)
+            {
+               consumer.setStatusImmediate(HandleStatus.BUSY);              
+            }
+            else
+            {
+               consumer.setStatusImmediate(HandleStatus.HANDLED);
+               
+               queue.deliver();
+            }
+            toggle = !toggle;
+            
+            numToggles++;
+         }
+      }
+   }
+      
+}
+
+
+

Copied: trunk/tests/src/org/jboss/messaging/core/server/impl/test/timing/QueueTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/test/timing/QueueTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/timing/QueueTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/timing/QueueTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,245 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.core.server.impl.test.timing;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.impl.QueueImpl;
+import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeConsumer;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ * 
+ * A timing-sensitive QueueTest
+ * 
+ * All the queue tests which are timing sensitive - go in here 
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class QueueTest extends UnitTestCase
+{
+   private static final long TIMEOUT = 10000;
+   
+   private static final Logger log = Logger.getLogger(QueueTest.class);
+   
+   private ScheduledExecutorService scheduledExecutor;
+   
+   public void setUp() throws Exception
+   {
+   	super.setUp();
+   	
+   	scheduledExecutor = new ScheduledThreadPoolExecutor(1);
+   }
+   
+   public void tearDown() throws Exception
+   {
+   	super.tearDown();
+   	
+   	scheduledExecutor.shutdownNow();
+   }
+   
+   // The tests ----------------------------------------------------------------
+
+   public void testScheduledDirect()
+   {
+      testScheduled(true); 
+   }
+   
+   public void testScheduledQueueing()
+   {
+      testScheduled(false); 
+   }
+   
+   public void testScheduledNoConsumer() throws Exception
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, null);
+           
+      //Send one scheduled
+      
+      long now = System.currentTimeMillis();
+      
+      MessageReference ref1 = generateReference(queue, 1);         
+      ref1.setScheduledDeliveryTime(now + 7000);      
+      queue.addLast(ref1);
+      
+      //Send some non scheduled messages
+      
+      MessageReference ref2 = generateReference(queue, 2);              
+      queue.addLast(ref2);
+      MessageReference ref3 = generateReference(queue, 3);             
+      queue.addLast(ref3);
+      MessageReference ref4 = generateReference(queue, 4);               
+      queue.addLast(ref4);
+      
+      
+      //Now send some more scheduled messages   
+           
+      MessageReference ref5 = generateReference(queue, 5); 
+      ref5.setScheduledDeliveryTime(now + 5000);
+      queue.addLast(ref5);
+      
+      MessageReference ref6 = generateReference(queue, 6); 
+      ref6.setScheduledDeliveryTime(now + 4000);
+      queue.addLast(ref6);
+      
+      MessageReference ref7 = generateReference(queue, 7); 
+      ref7.setScheduledDeliveryTime(now + 3000);
+      queue.addLast(ref7); 
+      
+      MessageReference ref8 = generateReference(queue, 8); 
+      ref8.setScheduledDeliveryTime(now + 6000);
+      queue.addLast(ref8);
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      //Scheduled refs are added back to *FRONT* of queue - otherwise if there were many messages in the queue
+      //They may get stranded behind a big backlog
+      
+      refs.add(ref1);
+      refs.add(ref8);
+      refs.add(ref5);
+      refs.add(ref6);
+      refs.add(ref7);
+      
+      refs.add(ref2);
+      refs.add(ref3);
+      refs.add(ref4);
+      
+      Thread.sleep(7500);
+      
+      FakeConsumer consumer = new FakeConsumer();
+      
+      queue.addConsumer(consumer);
+      
+      queue.deliver();
+      
+      assertRefListsIdenticalRefs(refs, consumer.getReferences());               
+   }
+   
+   private void testScheduled(boolean direct)
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, null);
+      
+      FakeConsumer consumer = null;
+      
+      if (direct)
+      {
+         consumer = new FakeConsumer();
+         
+         queue.addConsumer(consumer);
+      }
+      
+      //Send one scheduled
+      
+      long now = System.currentTimeMillis();
+      
+      MessageReference ref1 = generateReference(queue, 1);         
+      ref1.setScheduledDeliveryTime(now + 7000);      
+      queue.addLast(ref1);
+      
+      //Send some non scheduled messages
+      
+      MessageReference ref2 = generateReference(queue, 2);              
+      queue.addLast(ref2);
+      MessageReference ref3 = generateReference(queue, 3);             
+      queue.addLast(ref3);
+      MessageReference ref4 = generateReference(queue, 4);               
+      queue.addLast(ref4);
+      
+      
+      //Now send some more scheduled messages   
+           
+      MessageReference ref5 = generateReference(queue, 5); 
+      ref5.setScheduledDeliveryTime(now + 5000);
+      queue.addLast(ref5);
+      
+      MessageReference ref6 = generateReference(queue, 6); 
+      ref6.setScheduledDeliveryTime(now + 4000);
+      queue.addLast(ref6);
+      
+      MessageReference ref7 = generateReference(queue, 7); 
+      ref7.setScheduledDeliveryTime(now + 3000);
+      queue.addLast(ref7); 
+      
+      MessageReference ref8 = generateReference(queue, 8); 
+      ref8.setScheduledDeliveryTime(now + 6000);
+      queue.addLast(ref8);
+      
+      if (!direct)
+      {
+         consumer = new FakeConsumer();
+         
+         queue.addConsumer(consumer);
+         
+         queue.deliver();
+      }
+
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      refs.add(ref2);
+      refs.add(ref3);
+      refs.add(ref4);
+      
+      assertRefListsIdenticalRefs(refs, consumer.getReferences());
+      
+      refs.clear();
+      consumer.getReferences().clear();
+                  
+      MessageReference ref = consumer.waitForNextReference(TIMEOUT);
+      assertEquals(ref7, ref);
+      long now2 = System.currentTimeMillis();
+      assertTrue(now2 - now >= 3000);
+      
+      ref = consumer.waitForNextReference(TIMEOUT);
+      assertEquals(ref6, ref);
+      now2 = System.currentTimeMillis();
+      assertTrue(now2 - now >= 4000);
+      
+      ref = consumer.waitForNextReference(TIMEOUT);
+      assertEquals(ref5, ref);
+      now2 = System.currentTimeMillis();
+      assertTrue(now2 - now >= 5000);
+      
+      ref = consumer.waitForNextReference(TIMEOUT);
+      assertEquals(ref8, ref);
+      now2 = System.currentTimeMillis();
+      assertTrue(now2 - now >= 6000);
+      
+      ref = consumer.waitForNextReference(TIMEOUT);
+      assertEquals(ref1, ref);
+      now2 = System.currentTimeMillis();
+      assertTrue(now2 - now >= 7000);
+      
+      assertTrue(consumer.getReferences().isEmpty());            
+   }
+   
+   // Inner classes ---------------------------------------------------------------
+      
+}
+

Copied: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessageTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/test/unit/MessageTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessageTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessageTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,423 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.core.server.impl.test.unit;
+
+import static org.jboss.messaging.test.unit.RandomUtil.randomByte;
+import static org.jboss.messaging.test.unit.RandomUtil.randomInt;
+import static org.jboss.messaging.test.unit.RandomUtil.randomLong;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.QueueFactory;
+import org.jboss.messaging.core.server.impl.MessageImpl;
+import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeQueueFactory;
+import org.jboss.messaging.test.unit.UnitTestCase;
+import org.jboss.messaging.util.StreamUtils;
+
+/**
+ * 
+ * Tests for Message and MessageReference
+ * 
+ * TODO - Test streaming and destreaming
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class MessageTest extends UnitTestCase
+{
+	private QueueFactory queueFactory = new FakeQueueFactory();
+   
+   public void testCreateMessage()
+   {
+      long id = 56465;
+      int type = 655;
+      boolean reliable = true;
+      long expiration = 6712671;
+      long timestamp = 82798172;
+      byte priority = 32;
+      
+      Message message = new MessageImpl(type, reliable, expiration, timestamp, priority);
+      message.setMessageID(id);
+      
+      assertEquals(id, message.getMessageID());
+      assertEquals(type, message.getType());
+      assertEquals(reliable, message.isDurable());
+      assertEquals(timestamp, message.getTimestamp());
+      assertEquals(priority, message.getPriority());
+      
+      reliable = false;
+      
+      message = new MessageImpl(type, reliable, expiration, timestamp, priority);
+      message.setMessageID(id);
+      
+      assertEquals(id, message.getMessageID());
+      assertEquals(type, message.getType());
+      assertEquals(reliable, message.isDurable());
+      assertEquals(timestamp, message.getTimestamp());
+      assertEquals(priority, message.getPriority());
+   }
+   
+   public void testCreateMessageFromStorage() throws Exception
+   {
+      long id = 56465;
+      int type = 655;
+      boolean reliable = true;
+      long expiration = 6712671;
+      long timestamp = 82798172;
+      byte priority = 32;
+      
+      byte[] bytes = "blah blah blah".getBytes();
+ 
+      Message message = new MessageImpl(id, type, reliable, expiration, timestamp, priority,
+            null, bytes);
+      
+      assertEquals(id, message.getMessageID());
+      assertEquals(type, message.getType());
+      assertEquals(reliable, message.isDurable());
+      assertEquals(timestamp, message.getTimestamp());
+      assertEquals(priority, message.getPriority());     
+      
+      assertByteArraysEquivalent(bytes, message.getPayload());   
+      
+      //TODO - headers - they should really be combined into single blob
+   }
+   
+   public void testCopy()
+   {
+      long id = 56465;
+      int type = 655;
+      boolean reliable = true;
+      long expiration = 6712671;
+      long timestamp = 82798172;
+      byte priority = 32;
+      
+      Message message = new MessageImpl(type, reliable, expiration, timestamp, priority);
+      message.setMessageID(id);
+      
+      Message message2 = message.copy();
+      
+      assertEquivalent(message, message2);
+   }
+   
+   public void testSetAndGetMessageID()
+   {
+      Message message = new MessageImpl();
+      
+      assertEquals(0, message.getMessageID());
+      
+      message = new MessageImpl(655, true, 767676, 989898, (byte)32);
+      
+      assertEquals(0, message.getMessageID());
+      
+      long id = 765432;
+      message.setMessageID(id);
+      assertEquals(id, message.getMessageID());
+   }
+   
+   public void testSetAndGetReliable()
+   {
+      Message message = new MessageImpl();
+      
+      boolean reliable = true;
+      message.setDurable(reliable);
+      assertEquals(reliable, message.isDurable());
+      
+      reliable = false;
+      message.setDurable(reliable);
+      assertEquals(reliable, message.isDurable());
+   }
+    
+   public void testSetAndGetExpiration()
+   {
+      Message message = new MessageImpl();
+      
+      long expiration = System.currentTimeMillis() + 10000;
+      message.setExpiration(expiration);
+      assertEquals(expiration, message.getExpiration());
+      assertFalse(message.isExpired());
+      message.setExpiration(System.currentTimeMillis() - 1);
+      assertTrue(message.isExpired());
+      
+      expiration = 0; //O means never expire
+      message.setExpiration(expiration);
+      assertEquals(expiration, message.getExpiration());
+      assertFalse(message.isExpired());
+   }
+      
+   public void testSetAndGetTimestamp()
+   {
+      Message message = new MessageImpl();
+      
+      long timestamp = System.currentTimeMillis();
+      message.setTimestamp(timestamp);
+      assertEquals(timestamp, message.getTimestamp());
+   }
+   
+   public void testSetAndGetPriority()
+   {
+      Message message = new MessageImpl();
+      byte priority = 7;
+      message.setPriority(priority);
+      assertEquals(priority, message.getPriority());
+   }
+   
+   public void testSetAndGetConnectionID()
+   {
+      Message message = new MessageImpl();
+      
+      assertNull(message.getConnectionID());
+      String connectionID = "conn123";
+      message.setConnectionID(connectionID);
+      assertEquals(connectionID, message.getConnectionID());      
+   }
+   
+   public void testSetAndGetPayload()
+   {
+      Message message = new MessageImpl();
+      
+      assertNull(message.getPayload());
+      
+      byte[] bytes = "blah blah blah".getBytes();
+      message.setPayload(bytes);
+      
+      assertByteArraysEquivalent(bytes, message.getPayload());            
+   }
+   
+   public void testHeaders()
+   {
+      Message message = new MessageImpl();
+      
+      assertNotNull(message.getHeaders());
+      assertTrue(message.getHeaders().isEmpty());
+      
+      String key1 = "key1";
+      String val1 = "wibble";
+      String key2 = "key2";
+      Object val2 = new Object();
+      String key3 = "key3";
+      Double val3 = new Double(123.456);
+      Long val4 = new Long(77777);
+      message.putHeader(key1, val1);
+      assertEquals(val1, message.getHeaders().get(key1));
+      assertEquals(1, message.getHeaders().size());
+      assertTrue(message.containsHeader(key1));
+      assertFalse(message.containsHeader("does not exist"));
+      message.putHeader(key2, val2);
+      assertEquals(val2, message.getHeaders().get(key2));
+      assertEquals(2, message.getHeaders().size());
+      assertTrue(message.containsHeader(key2));
+      message.putHeader(key3, val3);
+      assertEquals(val3, message.getHeaders().get(key3));
+      assertEquals(3, message.getHeaders().size());
+      assertTrue(message.containsHeader(key3));
+      message.putHeader(key3, val4);
+      assertEquals(val4, message.getHeaders().get(key3));
+      assertEquals(3, message.getHeaders().size());
+      assertEquals(val2, message.removeHeader(key2));
+      assertEquals(2, message.getHeaders().size());
+      assertFalse(message.containsHeader(key2));
+      assertNull(message.removeHeader("does not exist"));
+      assertEquals(val1, message.removeHeader(key1));
+      assertFalse(message.containsHeader(key2));
+      assertEquals(1, message.getHeaders().size());
+      assertEquals(val4, message.removeHeader(key3));
+      assertFalse(message.containsHeader(key3));
+      assertTrue(message.getHeaders().isEmpty());
+   }
+   
+   public void testEquals()
+   {
+      Message message1 = new MessageImpl();
+      message1.setMessageID(1);
+      
+      Message message2 = new MessageImpl();
+      message2.setMessageID(2);
+      
+      Message message3 = new MessageImpl();
+      message3.setMessageID(1);
+      
+      assertTrue(message1.equals(message1));
+      assertTrue(message2.equals(message2));
+      assertTrue(message3.equals(message3));
+      
+      assertFalse(message1.equals(message2));
+      assertFalse(message2.equals(message1));
+      
+      assertFalse(message2.equals(message3));
+      assertFalse(message3.equals(message2));
+      
+      assertTrue(message1.equals(message3));
+      assertTrue(message3.equals(message1));
+      
+   }
+   
+   public void testHashcode()
+   {
+      long id1 = 6567575;
+      Message message1 = new MessageImpl();
+      message1.setMessageID(id1);
+      
+      assertEquals((int) ((id1 >>> 32) ^ id1), message1.hashCode());
+   }
+   
+   public void testMessageReference()
+   {
+      Message message = new MessageImpl();
+      
+      assertTrue(message.getReferences().isEmpty());
+      
+      Queue queue1 = queueFactory.createQueue(1, "queue1", null, false, true);
+      Queue queue2 = queueFactory.createQueue(2, "queue2", null, false, true);
+
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      MessageReference ref1 = message.createReference(queue1);
+      refs.add(ref1);
+      MessageReference ref2 = message.createReference(queue2);
+      refs.add(ref2);
+      MessageReference ref3 = message.createReference(queue1);
+      refs.add(ref3);
+      MessageReference ref4 = message.createReference(queue2);
+      refs.add(ref4);
+      
+      assertRefListsIdenticalRefs(refs, message.getReferences());
+      
+      assertEquals(queue1, ref1.getQueue());
+      assertEquals(queue2, ref2.getQueue());
+      assertEquals(queue1, ref3.getQueue());
+      assertEquals(queue2, ref4.getQueue());
+      
+      int deliveryCount = 65235;
+      ref1.setDeliveryCount(deliveryCount);
+      assertEquals(deliveryCount, ref1.getDeliveryCount());
+      
+      long scheduledDeliveryTime = 908298123;
+      ref1.setScheduledDeliveryTime(scheduledDeliveryTime);
+      assertEquals(scheduledDeliveryTime, ref1.getScheduledDeliveryTime());
+      
+      Queue queue3 = queueFactory.createQueue(3, "queue3", null, false, true);
+      MessageReference ref5 = ref1.copy(queue3);
+      
+      assertEquals(deliveryCount, ref5.getDeliveryCount());
+      assertEquals(scheduledDeliveryTime, ref5.getScheduledDeliveryTime());
+      assertEquals(queue3, ref5.getQueue());
+   }
+   
+
+   public void testDurableReferences()
+   {
+      Message messageDurable = new MessageImpl();
+      messageDurable.setDurable(true);
+      
+      Message messageNonDurable = new MessageImpl();
+      messageNonDurable.setDurable(false);
+        
+      //Durable queue
+      Queue queue1 = queueFactory.createQueue(1, "queue1", null, true, false);
+      
+      //Non durable queue
+      Queue queue2 = queueFactory.createQueue(2, "queue2", null, false, false);
+      
+      assertEquals(0, messageDurable.getNumDurableReferences());
+      
+      MessageReference ref1 = messageDurable.createReference(queue1);
+      
+      assertEquals(1, messageDurable.getNumDurableReferences());
+      
+      MessageReference ref2 = messageDurable.createReference(queue2);
+      
+      assertEquals(1, messageDurable.getNumDurableReferences());
+      
+      assertEquals(0, messageNonDurable.getNumDurableReferences());
+      
+      MessageReference ref3 = messageNonDurable.createReference(queue1);
+      
+      assertEquals(0, messageNonDurable.getNumDurableReferences());
+      
+      MessageReference ref4 = messageNonDurable.createReference(queue2);
+      
+      assertEquals(0, messageNonDurable.getNumDurableReferences());
+                  
+   }
+   
+   public void testDurableReferencePos()
+   {
+      Message messageDurable = new MessageImpl();
+      messageDurable.setDurable(true);
+      
+      //Durable queue
+      Queue queue1 = queueFactory.createQueue(1, "queue1", null, true, false);
+      
+      //Non durable queue
+      Queue queue2 = queueFactory.createQueue(2, "queue2", null, false, false);
+      
+      
+      MessageReference ref1 = messageDurable.createReference(queue1);
+      
+      MessageReference ref2 = messageDurable.createReference(queue2);
+      
+      MessageReference ref3 = messageDurable.createReference(queue2);
+      
+      MessageReference ref4 = messageDurable.createReference(queue1);
+      
+      MessageReference ref5 = messageDurable.createReference(queue1);
+      
+      MessageReference ref6 = messageDurable.createReference(queue2);
+      
+      MessageReference ref7 = messageDurable.createReference(queue1);
+      
+      MessageReference ref8 = messageDurable.createReference(queue2);
+      
+      assertEquals(0, messageDurable.getDurableReferencePos(ref1));
+      
+      assertEquals(1, messageDurable.getDurableReferencePos(ref4));
+      
+      assertEquals(2, messageDurable.getDurableReferencePos(ref5));
+      
+      assertEquals(3, messageDurable.getDurableReferencePos(ref7));
+             
+   }
+   
+   public void testMarshalling() throws Exception
+   {
+      Message msg = new MessageImpl(randomLong(), randomInt(), true, randomLong(), randomLong(), randomByte(),null, null);
+      msg.setDeliveryCount(randomInt());
+      
+      byte[] bytes = StreamUtils.toBytes(msg);
+      Message unmarshalledMsg = new MessageImpl();
+      StreamUtils.fromBytes(unmarshalledMsg, bytes);
+      
+      assertEquals(msg, unmarshalledMsg);
+      assertEquals("messageID", msg.getMessageID(), unmarshalledMsg.getMessageID());
+      assertEquals("type", msg.getType(), unmarshalledMsg.getType());
+      assertEquals("durable", msg.isDurable(), unmarshalledMsg.isDurable());
+      assertEquals("expiration", msg.getExpiration(), unmarshalledMsg.getExpiration());
+      assertEquals("timestamp", msg.getTimestamp(), unmarshalledMsg.getTimestamp());
+      assertEquals("priority", msg.getPriority(), unmarshalledMsg.getPriority());
+      assertEquals("deliveryCount", msg.getDeliveryCount(), unmarshalledMsg.getDeliveryCount()); 
+   }
+   
+}

Copied: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessagingXidTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/tx/test/unit/MessagingXidTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessagingXidTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessagingXidTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,172 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * 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.core.server.impl.test.unit;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.test.unit.RandomUtil;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ * 
+ * A MessagingXidTest
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class MessagingXidTest extends UnitTestCase
+{
+   public void testSerialize() throws Exception
+   {
+      XidImpl xid = new XidImpl(RandomUtil.randomBytes(), RandomUtil.randomInt(),
+                                          RandomUtil.randomBytes());
+      
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      
+      ObjectOutputStream oos = new ObjectOutputStream(baos);
+      
+      oos.writeObject(xid);
+      
+      oos.flush();
+      
+      ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+      
+      Object obj = ois.readObject();
+      
+      assertTrue(obj instanceof XidImpl);
+      
+      XidImpl xid2 = (XidImpl)obj;
+      
+      assertXidsEquivalent(xid, xid2);
+      
+      assertEquals(xid, xid2);     
+   }
+   
+   public void testStandardConstructor()
+   {
+      byte[] bq = RandomUtil.randomBytes();
+      
+      byte[] globalTXID = RandomUtil.randomBytes();
+      
+      int formatID = RandomUtil.randomInt();
+      
+      XidImpl xid1 = new XidImpl(bq, formatID, globalTXID);
+      
+      assertByteArraysEquivalent(bq, xid1.getBranchQualifier());
+      
+      assertByteArraysEquivalent(globalTXID, xid1.getGlobalTransactionId());
+      
+      assertEquals(formatID, xid1.getFormatId());
+   }
+   
+   public void testCopyConstructor()
+   {
+      XidImpl xid1 = new XidImpl(RandomUtil.randomBytes(), RandomUtil.randomInt(),
+                                          RandomUtil.randomBytes());
+      
+      XidImpl xid2 = new XidImpl(xid1);
+      
+      assertXidsEquivalent(xid1, xid2);
+      
+      assertEquals(xid2, xid2);
+   }
+   
+   public void testDefaultConstructor()
+   {
+      XidImpl xid1 = new XidImpl();
+      
+      assertNull(xid1.getBranchQualifier());
+      
+      assertNull(xid1.getGlobalTransactionId());
+      
+      assertEquals(0, xid1.getFormatId());
+   }
+   
+   public void testEqualsWithForeign()
+   {
+      XidImpl xid1 = new XidImpl(RandomUtil.randomBytes(), RandomUtil.randomInt(),
+            RandomUtil.randomBytes());
+
+      Xid foreign = new ForeignXid(xid1.getBranchQualifier(), xid1.getFormatId(), xid1.getGlobalTransactionId());
+      
+      assertTrue(xid1.equals(foreign));
+      
+      foreign = new ForeignXid(RandomUtil.randomBytes(), RandomUtil.randomInt(),
+                               RandomUtil.randomBytes());
+      
+      assertFalse(xid1.equals(foreign));
+      
+   }
+   
+   // Private ---------------------------------------------------------------------------------
+   
+   private void assertXidsEquivalent(Xid xid1, Xid xid2)
+   {
+      assertByteArraysEquivalent(xid1.getBranchQualifier(), xid2.getBranchQualifier());
+      
+      assertEquals(xid1.getFormatId(), xid2.getFormatId());
+      
+      assertByteArraysEquivalent(xid1.getGlobalTransactionId(), xid2.getGlobalTransactionId());
+   }
+   
+   // Inner classes ---------------------------------------------------------------------------
+   
+   class ForeignXid implements Xid
+   {
+      private byte[] branchQualifier;
+      
+      private int formatId;
+      
+      private byte[] globalTransactionId;
+      
+      public ForeignXid(byte[] branchQualifier, int formatId, byte[] globalTransactionId)
+      {
+         this.branchQualifier = branchQualifier;
+         this.formatId = formatId;
+         this.globalTransactionId = globalTransactionId;          
+      }
+           
+      public byte[] getBranchQualifier()
+      {
+         return this.branchQualifier;
+      }
+
+      public int getFormatId()
+      {
+         return this.formatId;
+      }
+
+      public byte[] getGlobalTransactionId()
+      {
+         return this.globalTransactionId;
+      }
+      
+   }
+   
+   
+}

Copied: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/PostOfficeTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/PostOfficeTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/PostOfficeTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,262 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.core.server.impl.test.unit;
+
+import java.util.List;
+import java.util.Map;
+
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.server.Binding;
+import org.jboss.messaging.core.server.Filter;
+import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.server.PersistenceManager;
+import org.jboss.messaging.core.server.PostOffice;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.QueueFactory;
+import org.jboss.messaging.core.server.impl.BindingImpl;
+import org.jboss.messaging.core.server.impl.PostOfficeImpl;
+import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeQueueFactory;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ * 
+ * A PostOfficeTest
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class PostOfficeTest extends UnitTestCase
+{
+	private QueueFactory queueFactory = new FakeQueueFactory();
+   
+   public void testAddQueue() throws Exception
+   {
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      QueueFactory qf = EasyMock.createStrictMock(QueueFactory.class);
+      
+      final int nodeID = 21;
+      
+      PostOffice po = new PostOfficeImpl(nodeID, pm, qf, false);
+      
+      final long id = 324;
+      final String name = "wibb22";
+      final Filter filter = new FakeFilter();
+      final boolean durable = true;
+      final boolean temporary = true;
+      
+      Queue queue = queueFactory.createQueue(id, name, filter, durable, temporary);
+      
+      EasyMock.expect(qf.createQueue(-1, name, filter, durable, temporary)).andReturn(queue);
+            
+      final String condition = "queue.wibble";
+
+      Binding expected = new BindingImpl(nodeID, condition, queue);
+      
+      pm.addBinding(EasyMock.eq(expected));
+      
+      EasyMock.replay(qf);
+      
+      EasyMock.replay(pm);
+      
+      po.addBinding(condition, name, filter, durable, temporary);
+      
+      EasyMock.verify(qf);
+      
+      EasyMock.verify(pm);
+      
+      EasyMock.reset(qf);
+      
+      EasyMock.reset(pm);
+      
+      final boolean durable2 = false;
+      
+      queue = queueFactory.createQueue(id, name, filter, durable2, temporary);
+      
+      EasyMock.expect(qf.createQueue(-1, name, filter, durable2, temporary)).andReturn(queue);
+      
+      EasyMock.replay(qf);
+      
+      EasyMock.replay(pm);      
+   }   
+   
+   public void testRemoveQueue() throws Exception
+   {
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      QueueFactory qf = EasyMock.createStrictMock(QueueFactory.class);
+      
+      final int nodeID = 21;
+      
+      PostOffice po = new PostOfficeImpl(nodeID, pm, qf, false);
+      
+      final long id = 324;
+      final String name = "wibb22";
+      final Filter filter = new FakeFilter();
+      final boolean durable = true;
+      final boolean temporary = true;
+      
+      Queue queue = queueFactory.createQueue(id, name, filter, durable, temporary);
+      
+      EasyMock.expect(qf.createQueue(-1, name, filter, durable, temporary)).andReturn(queue);
+            
+      final String condition = "queue.wibble";
+ 
+      Binding expected = new BindingImpl(nodeID, condition, queue);
+      
+      pm.addBinding(EasyMock.eq(expected));
+      
+      pm.deleteBinding(EasyMock.eq(expected));
+      
+      EasyMock.replay(qf);
+      
+      EasyMock.replay(pm);
+      
+      po.addBinding(condition, name, filter, durable, temporary);
+      
+      po.removeBinding(name);
+      
+      EasyMock.verify(qf);
+      
+      EasyMock.verify(pm);
+      
+      EasyMock.reset(qf);
+      
+      EasyMock.reset(pm);
+      
+      final boolean durable2 = false;
+      
+      queue = queueFactory.createQueue(id, name, filter, durable2, temporary);
+      
+      EasyMock.expect(qf.createQueue(-1, name, filter, durable2, temporary)).andReturn(queue);
+      
+      EasyMock.replay(qf);
+      
+      EasyMock.replay(pm);
+      
+      po.addBinding(condition, name, filter, durable2, temporary);
+      
+      po.removeBinding(name);
+      
+      EasyMock.verify(qf);
+      
+      EasyMock.verify(pm);
+   }   
+   
+   public void testAddRemoveMultipleWithDifferentConditions() throws Exception
+   {
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      QueueFactory qf = new FakeQueueFactory();
+      
+      final int nodeID = 21;
+      
+      PostOffice po = new PostOfficeImpl(nodeID, pm, qf, false);
+      
+      final String condition1 = "queue.wibble";      
+                
+      po.addBinding(condition1, "queue1", null, false, false);      
+      Map<String, List<Binding>> mappings = po.getMappings();      
+      assertEquals(1, mappings.size());
+      
+      po.addBinding(condition1, "queue2", null, false, false);     
+      mappings = po.getMappings();      
+      assertEquals(1, mappings.size());
+      
+      po.addBinding(condition1, "queue3", null, false, false); 
+      mappings = po.getMappings();      
+      assertEquals(1, mappings.size());
+      
+      List<Binding> bindings = mappings.get(condition1);
+      assertNotNull(bindings);
+      assertEquals(3, bindings.size());
+      
+      Binding binding1 = bindings.get(0);
+      Queue queue1 = binding1.getQueue();
+      assertEquals("queue1", queue1.getName());
+            
+      Binding binding2 = bindings.get(1);
+      Queue queue2 = binding2.getQueue();
+      assertEquals("queue2", queue2.getName());
+      
+      Binding binding3 = bindings.get(2);
+      Queue queue3 = binding3.getQueue();
+      assertEquals("queue3", queue3.getName());
+      
+      final String condition2 = "queue.wibble2"; 
+      
+      po.addBinding(condition2, "queue4", null, false, false);       
+      mappings = po.getMappings();      
+      assertEquals(2, mappings.size());
+      
+      po.addBinding(condition2, "queue5", null, false, false); 
+      mappings = po.getMappings();      
+      assertEquals(2, mappings.size());
+      
+      final String condition3 = "topic.wibblexyz"; 
+      
+      po.addBinding(condition3, "queue6", null, false, false);       
+      mappings = po.getMappings();      
+      assertEquals(3, mappings.size());
+      
+      po.removeBinding("queue6");
+      mappings = po.getMappings();      
+      assertEquals(2, mappings.size());
+      
+      po.removeBinding("queue4");
+      mappings = po.getMappings();      
+      assertEquals(2, mappings.size());
+      
+      po.removeBinding("queue5");
+      mappings = po.getMappings();      
+      assertEquals(1, mappings.size());
+      
+      po.removeBinding("queue1");
+      mappings = po.getMappings();      
+      assertEquals(1, mappings.size());
+      
+      po.removeBinding("queue2");
+      mappings = po.getMappings();      
+      assertEquals(1, mappings.size());
+      
+      po.removeBinding("queue3");
+      mappings = po.getMappings();      
+      assertEquals(0, mappings.size());      
+   }
+
+   
+   
+   
+   class FakeFilter implements Filter
+   {
+		public String getFilterString()
+		{
+			return "aardvark";
+		}
+
+		public boolean match(Message message)
+		{
+			return true;
+		}
+   	
+   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/QueueTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/test/unit/QueueTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/QueueTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/QueueTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,1196 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.core.server.impl.test.unit;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.jboss.messaging.core.server.Consumer;
+import org.jboss.messaging.core.server.DistributionPolicy;
+import org.jboss.messaging.core.server.Filter;
+import org.jboss.messaging.core.server.HandleStatus;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.impl.QueueImpl;
+import org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy;
+import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeConsumer;
+import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeFilter;
+import org.jboss.messaging.core.settings.HierarchicalRepository;
+import org.jboss.messaging.core.settings.impl.HierarchicalObjectRepository;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ * 
+ * A QueueTest
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class QueueTest extends UnitTestCase
+{
+   // The tests ----------------------------------------------------------------
+	
+	private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
+
+   private final HierarchicalRepository<QueueSettings> queueSettings = 
+   	new HierarchicalObjectRepository<QueueSettings>();
+	
+   public void testID()
+   {
+      final long id = 123;
+      
+      Queue queue = new QueueImpl(id, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertEquals(id, queue.getPersistenceID());
+      
+      final long id2 = 456;
+      
+      queue.setPersistenceID(id2);
+      
+      assertEquals(id2, queue.getPersistenceID());
+   }
+   
+   public void testName()
+   {
+      final String name = "oobblle";
+      
+      Queue queue = new QueueImpl(1, name, null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertEquals(name, queue.getName());
+   }
+   
+   public void testClustered()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertFalse(queue.isClustered());
+      
+      queue = new QueueImpl(1, "queue1", null, true, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertTrue(queue.isClustered());
+   }
+   
+   public void testDurable()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, false, false, -1, scheduledExecutor, queueSettings);
+      
+      assertFalse(queue.isDurable());
+      
+      queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertTrue(queue.isDurable());
+   }
+   
+   public void testTemporary()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, false, false, -1, scheduledExecutor, queueSettings);
+      
+      assertFalse(queue.isTemporary());
+      
+      queue = new QueueImpl(1, "queue1", null, false, false, true, -1, scheduledExecutor, queueSettings);
+      
+      assertTrue(queue.isTemporary());
+   }
+   
+   public void testGetSetMaxSize()
+   {
+      final int maxSize = 123456;
+      
+      final int id = 123;
+      
+      Queue queue = new QueueImpl(id, "queue1", null, false, true, false, maxSize, scheduledExecutor, queueSettings);
+      
+      assertEquals(id, queue.getPersistenceID());
+      
+      assertEquals(maxSize, queue.getMaxSize());
+      
+      final int maxSize2 = 654321;
+      
+      queue.setMaxSize(maxSize2);
+      
+      assertEquals(maxSize2, queue.getMaxSize());
+   }
+   
+   public void testAddRemoveConsumer()
+   {
+      Consumer cons1 = new FakeConsumer();
+      
+      Consumer cons2 = new FakeConsumer();
+      
+      Consumer cons3 = new FakeConsumer();
+      
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertEquals(0, queue.getConsumerCount());
+      
+      queue.addConsumer(cons1);
+      
+      assertEquals(1, queue.getConsumerCount());
+      
+      assertTrue(queue.removeConsumer(cons1));
+       
+      assertEquals(0, queue.getConsumerCount());
+      
+      queue.addConsumer(cons1);
+      
+      queue.addConsumer(cons2);
+      
+      queue.addConsumer(cons3);
+      
+      assertEquals(3, queue.getConsumerCount());
+      
+      assertFalse(queue.removeConsumer(new FakeConsumer()));
+      
+      assertEquals(3, queue.getConsumerCount());
+      
+      assertTrue(queue.removeConsumer(cons1));
+      
+      assertEquals(2, queue.getConsumerCount());
+      
+      assertTrue(queue.removeConsumer(cons2));
+      
+      assertEquals(1, queue.getConsumerCount());
+      
+      assertTrue(queue.removeConsumer(cons3));
+      
+      assertEquals(0, queue.getConsumerCount());
+      
+      assertFalse(queue.removeConsumer(cons3));            
+   }
+   
+   public void testGetSetDistributionPolicy()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertNotNull(queue.getDistributionPolicy());
+      
+      assertTrue(queue.getDistributionPolicy() instanceof RoundRobinDistributionPolicy);
+      
+      DistributionPolicy policy = new DummyDistributionPolicy();
+      
+      queue.setDistributionPolicy(policy);
+      
+      assertEquals(policy, queue.getDistributionPolicy());
+   }
+   
+   public void testGetSetFilter()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertNull(queue.getFilter());
+      
+      Filter filter = new FakeFilter();
+      
+      queue.setFilter(filter);
+      
+      assertEquals(filter, queue.getFilter());
+      
+      queue = new QueueImpl(1, "queue1", filter, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertEquals(filter, queue.getFilter());
+   }
+   
+   public void testDefaultMaxSize()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertEquals(-1, queue.getMaxSize());        
+   }
+   
+   public void testSimpleAddLast()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      final int numMessages = 10;
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(numMessages, queue.getMessageCount());
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      
+   }
+   
+   public void testSimpleDirectDelivery()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      FakeConsumer consumer = new FakeConsumer();
+      
+      queue.addConsumer(consumer);
+      
+      final int numMessages = 10;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(numMessages, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(numMessages, queue.getDeliveringCount());
+      
+      assertRefListsIdenticalRefs(refs, consumer.getReferences());      
+   }
+   
+   public void testSimpleNonDirectDelivery()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      final int numMessages = 10;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(10, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      
+      //Now add a consumer
+      FakeConsumer consumer = new FakeConsumer();
+      
+      queue.addConsumer(consumer);
+      
+      assertTrue(consumer.getReferences().isEmpty());
+      assertEquals(10, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      
+      queue.deliver();
+      
+      assertRefListsIdenticalRefs(refs, consumer.getReferences());     
+      assertEquals(numMessages, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(numMessages, queue.getDeliveringCount()); 
+   }
+   
+   public void testBusyConsumer()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      FakeConsumer consumer = new FakeConsumer();
+      
+      consumer.setStatusImmediate(HandleStatus.BUSY);
+      
+      queue.addConsumer(consumer);
+           
+      final int numMessages = 10;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(10, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      
+      queue.deliver();
+                  
+      assertEquals(10, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      assertTrue(consumer.getReferences().isEmpty());
+      
+      consumer.setStatusImmediate(HandleStatus.HANDLED);
+      
+      queue.deliver();
+      
+      assertRefListsIdenticalRefs(refs, consumer.getReferences());     
+      assertEquals(10, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(10, queue.getDeliveringCount());
+   }
+   
+   public void testBusyConsumerThenAddMoreMessages()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      FakeConsumer consumer = new FakeConsumer();
+      
+      consumer.setStatusImmediate(HandleStatus.BUSY);
+      
+      queue.addConsumer(consumer);
+           
+      final int numMessages = 10;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(10, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      
+      queue.deliver();
+                  
+      assertEquals(10, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      assertTrue(consumer.getReferences().isEmpty());
+      
+      for (int i = numMessages; i < numMessages * 2; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(20, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      assertTrue(consumer.getReferences().isEmpty());
+      
+      consumer.setStatusImmediate(HandleStatus.HANDLED);
+            
+      for (int i = numMessages * 2; i < numMessages * 3; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      queue.deliver();
+      
+      assertRefListsIdenticalRefs(refs, consumer.getReferences());     
+      assertEquals(30, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(30, queue.getDeliveringCount());
+   }
+         
+   public void testAddFirstAddLast()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      final int numMessages = 10;
+      
+      List<MessageReference> refs1 = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs1.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      LinkedList<MessageReference> refs2 = new LinkedList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i + numMessages);
+         
+         refs2.addFirst(ref);
+         
+         queue.addFirst(ref);
+      }
+      
+      List<MessageReference> refs3 = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i + 2 * numMessages);
+         
+         refs3.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      FakeConsumer consumer = new FakeConsumer();
+      
+      queue.addConsumer(consumer);
+      
+      queue.deliver();
+      
+      List<MessageReference> allRefs = new ArrayList<MessageReference>();
+      
+      allRefs.addAll(refs2);
+      allRefs.addAll(refs1);
+      allRefs.addAll(refs3);
+      
+      assertRefListsIdenticalRefs(allRefs, consumer.getReferences());      
+   }
+   
+   
+   public void testChangeConsumersAndDeliver()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+                  
+      final int numMessages = 10;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(numMessages, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      
+      FakeConsumer cons1 = new FakeConsumer();
+      
+      queue.addConsumer(cons1);
+      
+      queue.deliver();
+      
+      assertEquals(numMessages, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(numMessages, queue.getDeliveringCount());
+      
+      assertRefListsIdenticalRefs(refs, cons1.getReferences());
+      
+      FakeConsumer cons2 = new FakeConsumer();
+      
+      queue.addConsumer(cons2);
+      
+      assertEquals(2, queue.getConsumerCount());
+      
+      cons1.getReferences().clear();
+      
+      refs.clear();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         queue.decrementDeliveringCount();
+      }
+      
+      for (int i = 0; i < 2 * numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(numMessages * 2, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(numMessages * 2, queue.getDeliveringCount());
+      
+      assertEquals(numMessages, cons1.getReferences().size());
+      
+      assertEquals(numMessages, cons2.getReferences().size());
+      
+      cons1.getReferences().clear();
+      cons2.getReferences().clear();
+      refs.clear();
+      for (int i = 0; i < 2 * numMessages; i++)
+      {
+         queue.decrementDeliveringCount();
+      }
+      
+      FakeConsumer cons3 = new FakeConsumer();
+      
+      queue.addConsumer(cons3);
+      
+      assertEquals(3, queue.getConsumerCount());
+      
+      for (int i = 0; i < 3 * numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(numMessages * 3, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(numMessages * 3, queue.getDeliveringCount());
+      
+      assertEquals(numMessages, cons1.getReferences().size());
+      
+      assertEquals(numMessages, cons2.getReferences().size());
+      
+      assertEquals(numMessages, cons3.getReferences().size());
+      
+      queue.removeConsumer(cons1);
+      
+      cons3.getReferences().clear();
+      cons2.getReferences().clear();
+      refs.clear();
+      for (int i = 0; i < 3 * numMessages; i++)
+      {
+         queue.decrementDeliveringCount();
+      }
+      
+      for (int i = 0; i < 2 * numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(numMessages * 2, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(numMessages * 2, queue.getDeliveringCount());
+      
+      assertEquals(numMessages, cons2.getReferences().size());
+      
+      assertEquals(numMessages, cons3.getReferences().size());
+      
+      queue.removeConsumer(cons3);
+      
+      cons2.getReferences().clear();
+      refs.clear();
+      for (int i = 0; i < 2 * numMessages; i++)
+      {
+         queue.decrementDeliveringCount();
+      }
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(numMessages, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(numMessages, queue.getDeliveringCount());
+      
+      assertEquals(numMessages, cons2.getReferences().size());
+      
+   }
+   
+   public void testConsumerReturningNull()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      class NullConsumer implements Consumer
+      {
+         public HandleStatus handle(MessageReference reference)
+         {
+            return null;
+         }         
+      }
+      
+      queue.addConsumer(new NullConsumer());
+           
+      MessageReference ref = generateReference(queue, 1);
+         
+      try
+      {
+         queue.addLast(ref);
+         
+         fail("Should throw IllegalStateException");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }
+   }
+   
+   public void testRoundRobinWithQueueing()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertTrue(queue.getDistributionPolicy() instanceof RoundRobinDistributionPolicy);
+                  
+      final int numMessages = 10;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      //Test first with queueing
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      FakeConsumer cons1 = new FakeConsumer();
+      
+      FakeConsumer cons2 = new FakeConsumer();
+      
+      queue.addConsumer(cons1);
+      
+      queue.addConsumer(cons2);
+      
+      queue.deliver();
+      
+      assertEquals(numMessages / 2, cons1.getReferences().size());
+      
+      assertEquals(numMessages / 2, cons2.getReferences().size());
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref;
+         
+         ref = (i % 2 == 0) ? cons1.getReferences().get(i / 2) : cons2.getReferences().get(i / 2); 
+         
+         assertEquals(refs.get(i), ref);
+      }      
+   }
+   
+   public void testRoundRobinDirect()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      assertTrue(queue.getDistributionPolicy() instanceof RoundRobinDistributionPolicy);
+                  
+      final int numMessages = 10;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      FakeConsumer cons1 = new FakeConsumer();
+      
+      FakeConsumer cons2 = new FakeConsumer();
+      
+      queue.addConsumer(cons1);
+      
+      queue.addConsumer(cons2);
+      
+      queue.deliver();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+           
+      assertEquals(numMessages / 2, cons1.getReferences().size());
+      
+      assertEquals(numMessages / 2, cons2.getReferences().size());
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref;
+         
+         ref = (i % 2 == 0) ? cons1.getReferences().get(i / 2) : cons2.getReferences().get(i / 2); 
+         
+         assertEquals(refs.get(i), ref);
+      }      
+   }
+   
+   public void testRemoveAllReferences()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      final int numMessages = 10;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         queue.addLast(ref);
+      }
+      
+      assertEquals(numMessages, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      
+      queue.removeAllReferences();
+      
+      assertEquals(0, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      
+      FakeConsumer consumer = new FakeConsumer();
+      
+      queue.addConsumer(consumer);
+      
+      queue.deliver();
+      
+      assertTrue(consumer.getReferences().isEmpty());      
+   }
+   
+   public void testMaxSize()
+   {
+      final int maxSize = 20;
+      
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, maxSize, scheduledExecutor, queueSettings);
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < maxSize; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         assertEquals(HandleStatus.HANDLED, queue.addLast(ref));
+      }
+      
+      assertEquals(maxSize, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      
+      //Try to add more
+      
+      for (int i = 0; i < 10; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         assertEquals(HandleStatus.BUSY, queue.addLast(ref));
+      }
+      
+      assertEquals(maxSize, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      
+      // Try to add at front too
+      
+      for (int i = 0; i < 10; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         assertEquals(HandleStatus.BUSY, queue.addLast(ref));
+      }
+    
+      //Increase the max size
+      
+      queue.setMaxSize(2 * queue.getMaxSize());
+      
+      for (int i = 0; i < maxSize; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         refs.add(ref);
+         
+         assertEquals(HandleStatus.HANDLED, queue.addLast(ref));
+      }
+      
+      assertEquals(maxSize * 2, queue.getMessageCount());   
+      assertEquals(0, queue.getScheduledCount());
+      assertEquals(0, queue.getDeliveringCount());
+      
+      //Now try and decrease maxSize
+      
+      try
+      {
+         queue.setMaxSize(maxSize);
+         
+         fail("Should throw exception");
+      }
+      catch (IllegalArgumentException e)
+      {
+         //Ok
+      }
+      
+      assertEquals(2 * maxSize, queue.getMaxSize());      
+   }
+   
+   public void testWithPriorities()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      final int numMessages = 10;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         ref.getMessage().setPriority((byte)i);
+         
+         refs.add(ref);
+         
+         assertEquals(HandleStatus.HANDLED, queue.addLast(ref));
+      }
+      
+      FakeConsumer consumer = new FakeConsumer();
+      
+      queue.addConsumer(consumer);
+      
+      queue.deliver();
+      
+      List<MessageReference> receivedRefs = consumer.getReferences();
+      
+      //Should be in reverse order
+      
+      assertEquals(refs.size(), receivedRefs.size());
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         assertEquals(refs.get(i), receivedRefs.get(9 - i));
+      }
+            
+      //But if we send more - since we are now in direct mode - the order will be the send order
+      //since the refs don't get queued
+      
+      consumer.clearReferences();
+      
+      refs.clear();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         ref.getMessage().setPriority((byte)i);
+         
+         refs.add(ref);
+         
+         assertEquals(HandleStatus.HANDLED, queue.addLast(ref));
+      }
+      
+      assertRefListsIdenticalRefs(refs, consumer.getReferences());      
+   }
+   
+   public void testConsumerWithFiltersDirect()
+   {
+      testConsumerWithFilters(true);
+   }
+   
+   public void testConsumerWithFiltersQueueing()
+   {
+      testConsumerWithFilters(false);
+   }
+   
+   public void testConsumerWithFilterAddAndRemove()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      Filter filter = new FakeFilter("fruit", "orange");
+      
+      FakeConsumer consumer = new FakeConsumer(filter);
+   }
+   
+   public void testList()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      final int numMessages = 20;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         queue.addLast(ref);
+         
+         refs.add(ref);
+      }
+      
+      assertEquals(numMessages, queue.getMessageCount());
+      
+      List<MessageReference> list = queue.list(null);
+      
+      assertRefListsIdenticalRefs(refs, list);
+   }
+   
+   public void testListWithFilter()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      final int numMessages = 20;
+      
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = generateReference(queue, i);
+         
+         if (i % 2 == 0)
+         {
+            ref.getMessage().putHeader("god", "dog");
+         }
+         
+         queue.addLast(ref);
+         
+         refs.add(ref);
+      }
+      
+      assertEquals(numMessages, queue.getMessageCount());
+      
+      Filter filter = new FakeFilter("god", "dog");
+      
+      List<MessageReference> list = queue.list(filter);
+      
+      assertEquals(numMessages / 2, list.size());
+      
+      for (int i = 0; i < numMessages; i += 2)
+      {
+         assertEquals(refs.get(i), list.get(i / 2));
+      }      
+   }
+   
+   /*
+   public void testQuickSpeedTest()
+   {
+      Queue queue = new QueueImpl(1);
+      
+      final int numMessages = 1000000;
+      
+      FakeConsumer cons = new FakeConsumer();
+      
+      queue.addConsumer(cons);
+      
+      long start = System.currentTimeMillis();
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         MessageReference ref = this.generateReference(1);
+         
+         queue.addLast(ref);
+      }
+      
+      long end = System.currentTimeMillis();
+      
+      double rate = 1000 * (double)numMessages / (end - start); 
+      
+      System.out.println("Rate: " + rate);
+      
+      assertEquals(numMessages, cons.getReferences().size());
+   }
+   */
+   
+   public void testConsumeWithFiltersAddAndRemoveConsumer()
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      Filter filter = new FakeFilter("fruit", "orange");
+      
+      FakeConsumer consumer = new FakeConsumer(filter);
+      
+      queue.addConsumer(consumer);
+                        
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      MessageReference ref1 = generateReference(queue, 1);
+      
+      ref1.getMessage().putHeader("fruit", "banana");
+      
+      assertEquals(HandleStatus.HANDLED, queue.addLast(ref1));
+      
+      MessageReference ref2 = generateReference(queue, 2);
+      
+      ref2.getMessage().putHeader("fruit", "orange");
+      
+      assertEquals(HandleStatus.HANDLED, queue.addLast(ref2));     
+      
+      refs.add(ref2);
+      
+     
+      assertEquals(2, queue.getMessageCount());
+      
+      assertEquals(1, consumer.getReferences().size());
+      
+      assertEquals(1, queue.getDeliveringCount());
+            
+      assertRefListsIdenticalRefs(refs, consumer.getReferences()); 
+      
+      queue.decrementDeliveringCount();
+
+      queue.removeConsumer(consumer);
+            
+      queue.addConsumer(consumer);
+      
+      queue.deliver();
+      
+
+      refs.clear();
+      
+      consumer.clearReferences();
+      
+      MessageReference ref3 = generateReference(queue, 3);
+      
+      ref3.getMessage().putHeader("fruit", "banana");
+      
+      assertEquals(HandleStatus.HANDLED, queue.addLast(ref3));
+      
+      MessageReference ref4 = generateReference(queue, 4);
+      
+      ref4.getMessage().putHeader("fruit", "orange");
+      
+      assertEquals(HandleStatus.HANDLED, queue.addLast(ref4)); 
+       
+      refs.add(ref4);
+      
+      assertEquals(3, queue.getMessageCount());
+      
+      assertEquals(1, consumer.getReferences().size());
+      
+      assertEquals(1, queue.getDeliveringCount());
+      
+      assertRefListsIdenticalRefs(refs, consumer.getReferences());
+   }
+   
+   // Private ------------------------------------------------------------------------------
+   
+   private void testConsumerWithFilters(boolean direct)
+   {
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      Filter filter = new FakeFilter("fruit", "orange");
+      
+      FakeConsumer consumer = new FakeConsumer(filter);
+      
+      if (direct)
+      {
+         queue.addConsumer(consumer);
+      }      
+            
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      
+      MessageReference ref1 = generateReference(queue, 1);
+      
+      ref1.getMessage().putHeader("fruit", "banana");
+      
+      assertEquals(HandleStatus.HANDLED, queue.addLast(ref1));
+      
+      MessageReference ref2 = generateReference(queue, 2);
+      
+      ref2.getMessage().putHeader("cheese", "stilton");
+      
+      assertEquals(HandleStatus.HANDLED, queue.addLast(ref2));      
+      
+      MessageReference ref3 = generateReference(queue, 3);
+      
+      ref3.getMessage().putHeader("cake", "sponge");
+      
+      assertEquals(HandleStatus.HANDLED, queue.addLast(ref3));
+            
+      MessageReference ref4 = generateReference(queue, 4);
+      
+      ref4.getMessage().putHeader("fruit", "orange");
+      
+      refs.add(ref4);
+      
+      assertEquals(HandleStatus.HANDLED, queue.addLast(ref4));      
+      
+      MessageReference ref5 = generateReference(queue, 5);
+      
+      ref5.getMessage().putHeader("fruit", "apple");
+      
+      assertEquals(HandleStatus.HANDLED, queue.addLast(ref5));
+            
+      MessageReference ref6 = generateReference(queue, 6);
+      
+      ref6.getMessage().putHeader("fruit", "orange");
+      
+      refs.add(ref6);
+      
+      assertEquals(HandleStatus.HANDLED, queue.addLast(ref6));      
+      
+      if (!direct)
+      {
+         queue.addConsumer(consumer);
+         
+         queue.deliver();
+      }
+      
+      assertEquals(6, queue.getMessageCount());
+      
+      assertEquals(2, consumer.getReferences().size());
+      
+      assertEquals(2, queue.getDeliveringCount());
+            
+      assertRefListsIdenticalRefs(refs, consumer.getReferences()); 
+      
+      queue.decrementDeliveringCount();
+      queue.decrementDeliveringCount();
+      
+      queue.removeConsumer(consumer);
+      
+      consumer = new FakeConsumer();
+      
+      queue.addConsumer(consumer);
+      
+      queue.deliver();
+      
+      assertEquals(4, queue.getMessageCount());
+      
+      assertEquals(4, consumer.getReferences().size());
+      
+      assertEquals(4, queue.getDeliveringCount());
+   }
+   
+   
+   
+  
+   
+   
+   
+   // Inner classes ---------------------------------------------------------------
+        
+   class DummyDistributionPolicy implements DistributionPolicy
+   {
+      public int select(List<Consumer> consumers, int lastPos)
+      {
+         return 0;
+      }      
+   }
+   
+}

Copied: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/RoundRobinDistributionPolicyTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/test/unit/RoundRobinDistributionPolicyTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/RoundRobinDistributionPolicyTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/RoundRobinDistributionPolicyTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,74 @@
+package org.jboss.messaging.core.server.impl.test.unit;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.messaging.core.server.Consumer;
+import org.jboss.messaging.core.server.DistributionPolicy;
+import org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy;
+import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeConsumer;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ * 
+ * A RoundRobinDistributionPolicyTest
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class RoundRobinDistributionPolicyTest extends UnitTestCase
+{
+
+   public void testNoConsumers()
+   {
+      List<Consumer> consumers = new ArrayList<Consumer>();
+      
+      DistributionPolicy dp = new RoundRobinDistributionPolicy();
+      
+      int pos = dp.select(consumers, -1);
+      
+      assertEquals(0, pos);
+   }
+   
+   public void testConsumers()
+   {
+      List<Consumer> consumers = new ArrayList<Consumer>();
+      
+      consumers.add(new FakeConsumer());
+      consumers.add(new FakeConsumer());
+      consumers.add(new FakeConsumer());
+      
+      DistributionPolicy dp = new RoundRobinDistributionPolicy();
+            
+      int pos = -1;
+      
+      pos = dp.select(consumers, pos);
+      
+      assertEquals(0, pos);
+      
+      pos = dp.select(consumers, pos);
+      
+      assertEquals(1, pos);
+      
+      pos = dp.select(consumers, pos);
+      
+      assertEquals(2, pos);
+      
+      pos = dp.select(consumers, pos);
+      
+      assertEquals(0, pos);
+      
+      pos = dp.select(consumers, pos);
+      
+      assertEquals(1, pos);
+      
+      pos = dp.select(consumers, pos);
+      
+      assertEquals(2, pos);
+      
+      pos = dp.select(consumers, pos);
+      
+      assertEquals(0, pos);
+   }
+   
+}

Copied: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/TransactionTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/TransactionTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/TransactionTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,371 @@
+package org.jboss.messaging.core.server.impl.test.unit;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import javax.transaction.xa.Xid;
+
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.PersistenceManager;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.Transaction;
+import org.jboss.messaging.core.server.TransactionSynchronization;
+import org.jboss.messaging.core.server.impl.QueueImpl;
+import org.jboss.messaging.core.server.impl.TransactionImpl;
+import org.jboss.messaging.core.settings.HierarchicalRepository;
+import org.jboss.messaging.core.settings.impl.HierarchicalObjectRepository;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.test.unit.UnitTestCase;
+
+/**
+ * 
+ * A TransactionTest
+ * 
+ * TODO test with persistent and non persistent
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class TransactionTest extends UnitTestCase
+{
+	private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
+
+   private final HierarchicalRepository<QueueSettings> queueSettings = 
+   	new HierarchicalObjectRepository<QueueSettings>();
+	
+   protected void setUp() throws Exception
+   {
+   	super.setUp();
+   	
+   	queueSettings.setDefault(new QueueSettings());
+   }
+   
+   public void test1PCCommit() throws Exception
+   {
+      List<Message> msgsToAdd = new ArrayList<Message>();
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      MessageReference ref1 = this.generateReference(queue, 1);
+      msgsToAdd.add(ref1.getMessage());
+      
+      MessageReference ref2 = this.generateReference(queue, 2);
+      refsToRemove.add(ref2);
+                  
+      Transaction tx = new TransactionImpl();
+      
+      tx.addMessage(ref1.getMessage());
+      tx.addAcknowledgement(ref2);
+      
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      pm.commitTransaction(msgsToAdd, refsToRemove);
+      
+      EasyMock.replay(pm);
+      
+      tx.commit(true, pm);
+      
+      EasyMock.verify(pm);
+      
+      assertEquals(ref1, queue.list(null).get(0));
+   }
+   
+   public void test1PCRollback() throws Exception
+   {
+      List<Message> msgsToAdd = new ArrayList<Message>();
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      MessageReference ref1 = this.generateReference(queue, 1);
+      msgsToAdd.add(ref1.getMessage());
+      
+      MessageReference ref2 = this.generateReference(queue, 2);
+      refsToRemove.add(ref2);
+                  
+      Transaction tx = new TransactionImpl();
+      tx.addMessage(ref1.getMessage());
+      tx.addAcknowledgement(ref2);
+      
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      pm.updateDeliveryCount(queue, ref2);
+      
+      EasyMock.replay(pm);
+      
+      tx.rollback(pm);
+      
+      EasyMock.verify(pm);
+ 
+      assertEquals(ref2, queue.list(null).get(0));
+   }
+   
+   public void test1PCPrepare() throws Exception
+   {
+      List<Message> msgsToAdd = new ArrayList<Message>();
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      MessageReference ref1 = this.generateReference(queue, 1);
+      msgsToAdd.add(ref1.getMessage());
+      
+      MessageReference ref2 = this.generateReference(queue, 2);
+      refsToRemove.add(ref2);
+                  
+      Transaction tx = new TransactionImpl();
+      tx.addMessage(ref1.getMessage());
+      tx.addAcknowledgement(ref2);
+      
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      try
+      {
+         tx.prepare(pm);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //OK
+      }   
+      
+      assertTrue(queue.list(null).isEmpty());
+   }
+   
+   public void test2PCPrepareCommit() throws Exception
+   {
+      List<Message> msgsToAdd = new ArrayList<Message>();
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      MessageReference ref1 = this.generateReference(queue, 1);
+      msgsToAdd.add(ref1.getMessage());
+      
+      MessageReference ref2 = this.generateReference(queue, 2);
+      refsToRemove.add(ref2);
+      
+      Xid xid = generateXid();
+                  
+      Transaction tx = new TransactionImpl(xid);
+      tx.addMessage(ref1.getMessage());
+      tx.addAcknowledgement(ref2);
+      
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      pm.prepareTransaction(xid, msgsToAdd, refsToRemove);
+      
+      EasyMock.replay(pm);
+      
+      tx.prepare(pm);
+      
+      EasyMock.verify(pm);
+      
+      EasyMock.reset(pm);
+      
+      pm.commitPreparedTransaction(xid);
+      
+      EasyMock.replay(pm);
+      
+      tx.commit(false, pm);
+      
+      EasyMock.verify(pm);
+   }
+   
+   public void test2PCCommitBeforePrepare() throws Exception
+   {
+      List<Message> msgsToAdd = new ArrayList<Message>();
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      MessageReference ref1 = this.generateReference(queue, 1);
+      msgsToAdd.add(ref1.getMessage());
+      
+      MessageReference ref2 = this.generateReference(queue, 2);
+      refsToRemove.add(ref2);
+          
+      Xid xid = generateXid();
+      
+      Transaction tx = new TransactionImpl(xid);
+      tx.addMessage(ref1.getMessage());
+      tx.addAcknowledgement(ref2);
+      
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      try
+      {    
+         tx.commit(false, pm);
+         
+         fail ("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok
+      }      
+   }
+   
+   public void test2PCPrepareRollback() throws Exception
+   {
+      List<Message> msgsToAdd = new ArrayList<Message>();
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      MessageReference ref1 = this.generateReference(queue, 1);
+      msgsToAdd.add(ref1.getMessage());
+      
+      MessageReference ref2 = this.generateReference(queue, 2);
+      refsToRemove.add(ref2);
+      
+      Xid xid = generateXid();
+                  
+      Transaction tx = new TransactionImpl(xid);
+      tx.addMessage(ref1.getMessage());
+      tx.addAcknowledgement(ref2);
+      
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      pm.prepareTransaction(xid, msgsToAdd, refsToRemove);
+      
+      EasyMock.replay(pm);
+      
+      tx.prepare(pm);
+      
+      EasyMock.verify(pm);
+      
+      EasyMock.reset(pm);
+      
+      pm.unprepareTransaction(xid, msgsToAdd, refsToRemove);
+      
+      pm.updateDeliveryCount(queue, ref2);
+      
+      EasyMock.replay(pm);
+      
+      tx.rollback(pm);
+      
+      EasyMock.verify(pm);
+   }
+   
+   public void testSynchronizations() throws Exception
+   {
+      List<Message> msgsToAdd = new ArrayList<Message>();
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      MessageReference ref1 = this.generateReference(queue, 1);
+      msgsToAdd.add(ref1.getMessage());
+      
+      MessageReference ref2 = this.generateReference(queue, 2);
+      refsToRemove.add(ref2);
+                  
+      Transaction tx = new TransactionImpl();
+      tx.addMessage(ref1.getMessage());
+      tx.addAcknowledgement(ref2);
+      
+      TransactionSynchronization sync = EasyMock.createStrictMock(TransactionSynchronization.class);
+      
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      tx.addSynchronization(sync);
+      
+      sync.beforeCommit();
+      sync.afterCommit();
+      
+      EasyMock.replay(sync);
+      
+      tx.commit(true, pm);
+      
+      EasyMock.verify(sync);
+      
+      EasyMock.reset(sync);
+      
+      tx = new TransactionImpl();
+      tx.addMessage(ref1.getMessage());
+      tx.addAcknowledgement(ref2);
+      
+      tx.addSynchronization(sync);
+      
+      sync.beforeRollback();
+      sync.afterRollback();
+      
+      EasyMock.replay(sync);
+      
+      tx.rollback(pm);
+      
+      EasyMock.verify(sync);            
+   }
+   
+   public void testSynchronizations2PC() throws Exception
+   {
+      List<Message> msgsToAdd = new ArrayList<Message>();
+      
+      List<MessageReference> refsToRemove = new ArrayList<MessageReference>();
+      
+      Queue queue = new QueueImpl(1, "queue1", null, false, true, false, -1, scheduledExecutor, queueSettings);
+      
+      MessageReference ref1 = this.generateReference(queue, 1);
+      msgsToAdd.add(ref1.getMessage());
+      
+      MessageReference ref2 = this.generateReference(queue, 2);
+      refsToRemove.add(ref2);
+      
+      Xid xid = generateXid();
+                  
+      Transaction tx = new TransactionImpl(xid);
+      tx.addMessage(ref1.getMessage());
+      tx.addAcknowledgement(ref2);
+      
+      TransactionSynchronization sync = EasyMock.createStrictMock(TransactionSynchronization.class);
+      
+      PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+      
+      tx.addSynchronization(sync);
+      
+      sync.beforeCommit();
+      sync.afterCommit();
+      
+      EasyMock.replay(sync);
+      
+      tx.prepare(pm);
+      tx.commit(false, pm);
+      
+      EasyMock.verify(sync);
+      
+      EasyMock.reset(sync);
+      
+      xid = generateXid();
+      
+      tx = new TransactionImpl(xid);
+      tx.addMessage(ref1.getMessage());
+      tx.addAcknowledgement(ref2);
+      
+      tx.addSynchronization(sync);
+      
+      sync.beforeRollback();
+      sync.afterRollback();
+      
+      EasyMock.replay(sync);
+      
+      tx.prepare(pm);
+      tx.rollback(pm);
+      
+      EasyMock.verify(sync);            
+   }
+   
+   // Inner classes -----------------------------------------------------------------------
+   
+}

Copied: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeConsumer.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/test/unit/fakes/FakeConsumer.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeConsumer.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeConsumer.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,144 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.core.server.impl.test.unit.fakes;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.messaging.core.server.Consumer;
+import org.jboss.messaging.core.server.Filter;
+import org.jboss.messaging.core.server.HandleStatus;
+import org.jboss.messaging.core.server.MessageReference;
+
+/**
+ * 
+ * A FakeConsumer
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class FakeConsumer implements Consumer
+{
+   private HandleStatus statusToReturn = HandleStatus.HANDLED;
+   
+   private HandleStatus newStatus;
+   
+   private int delayCountdown = 0;
+   
+   private LinkedList<MessageReference> references = new LinkedList<MessageReference>();
+   
+   private Filter filter;
+   
+   public FakeConsumer()
+   {         
+   }
+   
+   public FakeConsumer(Filter filter)
+   {
+      this.filter = filter;
+   }
+   
+   public synchronized MessageReference waitForNextReference(long timeout)
+   {
+      while (references.isEmpty() && timeout > 0)
+      {
+         long start = System.currentTimeMillis(); 
+         try
+         {
+            wait();
+         }
+         catch (InterruptedException e)
+         {                 
+         }
+         timeout -= (System.currentTimeMillis() - start);
+      }
+      
+      if (timeout <= 0)
+      {
+         throw new IllegalStateException("Timed out waiting for reference");
+      }
+      
+      return references.removeFirst();
+   }
+   
+   public synchronized void setStatusImmediate(HandleStatus newStatus)
+   {
+      this.statusToReturn = newStatus;
+   }
+   
+   public synchronized void setStatusDelayed(HandleStatus newStatus, int numReferences)
+   {
+      this.newStatus = newStatus;
+      
+      this.delayCountdown = numReferences;
+   }
+   
+   public synchronized List<MessageReference> getReferences()
+   {
+      return references;
+   }
+   
+   public synchronized void clearReferences()
+   {
+      this.references.clear();
+   }
+   
+   public synchronized HandleStatus handle(MessageReference reference)
+   {
+      if (filter != null)
+      {
+         if (filter.match(reference.getMessage()))
+         {
+            references.addLast(reference);
+            notify();
+            
+            return HandleStatus.HANDLED;
+         }
+         else
+         {
+            return HandleStatus.NO_MATCH;
+         }
+      }
+      
+      if (newStatus != null)
+      {           
+         if (delayCountdown == 0)
+         {
+            statusToReturn = newStatus;
+            
+            newStatus = null;
+         }
+         else
+         {            
+            delayCountdown--;
+         }
+      }
+      
+      if (statusToReturn == HandleStatus.HANDLED)
+      {
+         references.addLast(reference);
+         notify();
+      }
+      
+      return statusToReturn;
+   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeFilter.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/impl/test/unit/fakes/FakeFilter.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeFilter.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeFilter.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.core.server.impl.test.unit.fakes;
+
+import org.jboss.messaging.core.server.Filter;
+import org.jboss.messaging.core.server.Message;
+
+/**
+ * 
+ * A FakeFilter
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class FakeFilter implements Filter
+{
+   private String headerName;
+   
+   private Object headerValue;
+         
+   public FakeFilter(String headerName, Object headerValue)
+   {
+      this.headerName = headerName;
+      
+      this.headerValue = headerValue;
+   }
+   
+   public FakeFilter()
+   {         
+   }
+   
+   public boolean match(Message message)
+   {
+      if (headerName != null)
+      {
+         Object value = message.getHeader(headerName);
+         
+         if (value != null && headerValue.equals(value))
+         {
+            return true;
+         }
+         
+         return false;
+      }
+      
+      return true;
+   }
+
+   public String getFilterString()
+   {
+      return null;
+   }      
+}

Copied: trunk/tests/src/org/jboss/messaging/core/settings/impl/test/unit/QueueSettingsTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/core/test/unit/QueueSettingsTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/settings/impl/test/unit/QueueSettingsTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/settings/impl/test/unit/QueueSettingsTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,146 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005, JBoss Inc., and individual contributors as indicated
+   * 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.core.settings.impl.test.unit;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.impl.QueueImpl;
+import org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class QueueSettingsTest extends TestCase
+{
+   public void testDefaults()
+   {
+      QueueSettings queueSettings = new QueueSettings();
+      assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
+      assertEquals(queueSettings.getDistributionPolicyClass(), null);
+      assertEquals(queueSettings.getDLQ(), null);
+      assertEquals(queueSettings.isClustered(), Boolean.valueOf(false));
+      assertEquals(queueSettings.getExpiryQueue(), null);
+      assertEquals(queueSettings.getMaxDeliveryAttempts(), QueueSettings.DEFAULT_MAX_DELIVERY_ATTEMPTS);
+      assertEquals(queueSettings.getMaxSize(), QueueSettings.DEFAULT_MAX_SIZE);
+      assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), QueueSettings.DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT);
+      assertEquals(queueSettings.getRedeliveryDelay(), QueueSettings.DEFAULT_REDELIVER_DELAY);
+
+   }
+
+   public void testSingleMerge()
+   {
+      QueueSettings queueSettings = new QueueSettings();
+      QueueSettings queueSettingsToMerge = new QueueSettings();
+      queueSettingsToMerge.setClustered(true);
+      Queue DLQ = new QueueImpl(0,"testDLQ", null, false, false, false, 0, null, null);
+      Queue exp = new QueueImpl(0,"testExpiryQueue", null, false, false, false, 0, null, null);
+      queueSettingsToMerge.setDLQ(DLQ);
+      queueSettingsToMerge.setExpiryQueue(exp);
+      queueSettingsToMerge.setMaxDeliveryAttempts(1000);
+      queueSettingsToMerge.setMaxSize(1001);
+      queueSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
+      queueSettingsToMerge.setRedeliveryDelay((long)1003);
+      queueSettings.merge(queueSettingsToMerge);
+      assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
+      assertEquals(queueSettings.getDistributionPolicyClass(), null);
+      assertEquals(queueSettings.isClustered(), Boolean.valueOf(true));
+      assertEquals(queueSettings.getDLQ(), DLQ);
+      assertEquals(queueSettings.getExpiryQueue(), exp);
+      assertEquals(queueSettings.getMaxDeliveryAttempts(), Integer.valueOf(1000));
+      assertEquals(queueSettings.getMaxSize(), Integer.valueOf(1001));
+      assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), Integer.valueOf(1002));
+      assertEquals(queueSettings.getRedeliveryDelay(), Long.valueOf(1003));
+   }
+
+   public void testMultipleMerge()
+   {
+      QueueSettings queueSettings = new  QueueSettings();
+      QueueSettings queueSettingsToMerge = new QueueSettings();
+      queueSettingsToMerge.setClustered(true);
+       Queue DLQ = new QueueImpl(0,"testDLQ", null, false, false, false, 0, null, null);
+      Queue exp = new QueueImpl(0,"testExpiryQueue", null, false, false, false, 0, null, null);
+      queueSettingsToMerge.setDLQ(DLQ);
+      queueSettingsToMerge.setExpiryQueue(exp);
+      queueSettingsToMerge.setMaxDeliveryAttempts(1000);
+      queueSettingsToMerge.setMaxSize(1001);
+      queueSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
+      queueSettingsToMerge.setRedeliveryDelay((long)1003);
+      queueSettings.merge(queueSettingsToMerge);
+
+      QueueSettings queueSettingsToMerge2 = new QueueSettings();
+      queueSettingsToMerge2.setClustered(true);
+      Queue exp2 = new QueueImpl(0,"testExpiryQueue2", null, false, false, false, 0, null, null);
+      queueSettingsToMerge2.setExpiryQueue(exp2);
+      queueSettingsToMerge2.setMaxSize(2001);
+      queueSettingsToMerge2.setRedeliveryDelay((long)2003);
+      queueSettings.merge(queueSettingsToMerge2);
+
+      assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
+      assertEquals(queueSettings.getDistributionPolicyClass(), null);
+      assertEquals(queueSettings.isClustered(), Boolean.valueOf(true));
+      assertEquals(queueSettings.getDLQ(), DLQ);
+      assertEquals(queueSettings.getExpiryQueue(), exp2);
+      assertEquals(queueSettings.getMaxDeliveryAttempts(), Integer.valueOf(1000));
+      assertEquals(queueSettings.getMaxSize(), Integer.valueOf(2001));
+      assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), Integer.valueOf(1002));
+      assertEquals(queueSettings.getRedeliveryDelay(), Long.valueOf(2003));
+   }
+
+   public void testMultipleMergeAll()
+   {
+      QueueSettings queueSettings = new  QueueSettings();
+      QueueSettings queueSettingsToMerge = new QueueSettings();
+      queueSettingsToMerge.setClustered(true);
+       Queue DLQ = new QueueImpl(0,"testDLQ", null, false, false, false, 0, null, null);
+      Queue exp = new QueueImpl(0,"testExpiryQueue", null, false, false, false, 0, null, null);
+      queueSettingsToMerge.setDLQ(DLQ);
+      queueSettingsToMerge.setExpiryQueue(exp);
+      queueSettingsToMerge.setMaxDeliveryAttempts(1000);
+      queueSettingsToMerge.setMaxSize(1001);
+      queueSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
+      queueSettingsToMerge.setRedeliveryDelay((long)1003);
+      queueSettings.merge(queueSettingsToMerge);
+
+      QueueSettings queueSettingsToMerge2 = new QueueSettings();
+      queueSettingsToMerge2.setClustered(false);
+      Queue exp2 = new QueueImpl(0,"testExpiryQueue2", null, false, false, false, 0, null, null);
+      Queue DLQ2 = new QueueImpl(0,"testDlq2", null, false, false, false, 0, null, null);
+      queueSettingsToMerge2.setExpiryQueue(exp2);
+      queueSettingsToMerge2.setDLQ(DLQ2);
+      queueSettingsToMerge2.setMaxDeliveryAttempts(2000);
+      queueSettingsToMerge2.setMaxSize(2001);
+      queueSettingsToMerge2.setMessageCounterHistoryDayLimit(2002);
+      queueSettingsToMerge2.setRedeliveryDelay((long)2003);
+      queueSettings.merge(queueSettingsToMerge2);
+
+      assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
+      assertEquals(queueSettings.getDistributionPolicyClass(), null);
+      assertEquals(queueSettings.isClustered(), Boolean.valueOf(true));
+      assertEquals(queueSettings.getDLQ(), DLQ2);
+      assertEquals(queueSettings.getExpiryQueue(), exp2);
+      assertEquals(queueSettings.getMaxDeliveryAttempts(), Integer.valueOf(2000));
+      assertEquals(queueSettings.getMaxSize(), Integer.valueOf(2001));
+      assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), Integer.valueOf(2002));
+      assertEquals(queueSettings.getRedeliveryDelay(), Long.valueOf(2003));
+   }
+}

Copied: trunk/tests/src/org/jboss/messaging/core/settings/impl/test/unit/RepositoryTest.java (from rev 3799, trunk/tests/src/org/jboss/messaging/util/test/unit/RepositoryTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/settings/impl/test/unit/RepositoryTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/settings/impl/test/unit/RepositoryTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -0,0 +1,213 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005, JBoss Inc., and individual contributors as indicated
+   * 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.core.settings.impl.test.unit;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.security.Role;
+import org.jboss.messaging.core.settings.HierarchicalRepository;
+import org.jboss.messaging.core.settings.Mergeable;
+import org.jboss.messaging.core.settings.impl.HierarchicalObjectRepository;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class RepositoryTest extends TestCase
+{
+   HierarchicalRepository<HashSet<Role>> securityRepository;
+
+
+   protected void setUp() throws Exception
+   {
+      securityRepository = new HierarchicalObjectRepository<HashSet<Role>>();
+   }
+
+   public void testDefault()
+   {
+      securityRepository.setDefault(new HashSet<Role>());
+      HashSet<Role> roles = securityRepository.getMatch("queues.something");
+
+      assertEquals(roles.size(), 0);
+   }
+
+   public void testSingleMatch()
+   {
+      securityRepository.addMatch("queues.*", new HashSet<Role>());
+      HashSet<Role> hashSet = securityRepository.getMatch("queues.something");
+      assertEquals(hashSet.size(), 0);
+   }
+
+   public void testSingletwo()
+   {
+      securityRepository.addMatch("queues.another.aq.*", new HashSet<Role>());
+      HashSet<Role> roles = new HashSet<Role>(2);
+      roles.add(new Role("test1"));
+      roles.add(new Role("test2"));
+      securityRepository.addMatch("queues.aq", roles);
+      HashSet<Role> roles2 = new HashSet<Role>(2);
+      roles2.add(new Role("test1"));
+      roles2.add(new Role("test2"));
+      roles2.add(new Role("test3"));
+      securityRepository.addMatch("queues.another.andanother", roles2);
+      
+      HashSet<Role> hashSet = securityRepository.getMatch("queues.another.andanother");
+      assertEquals(hashSet.size(), 3);
+   }
+
+   public void testWithoutWildcard()
+   {
+      securityRepository.addMatch("queues.1.*", new HashSet<Role>());
+      HashSet<Role> roles = new HashSet<Role>(2);
+      roles.add(new Role("test1"));
+      roles.add(new Role("test2"));
+      securityRepository.addMatch("queues.2.aq", roles);
+      HashSet<Role> hashSet = securityRepository.getMatch("queues.2.aq");
+      assertEquals(hashSet.size(), 2);
+   }
+
+   public void testMultipleWildcards()
+   {
+      HierarchicalRepository<String> repository = new HierarchicalObjectRepository<String>();
+      repository.addMatch("*", "*");
+      repository.addMatch("a", "a");
+      repository.addMatch("a.*", "a.*");
+      repository.addMatch("a.^", "a.^");
+      repository.addMatch("a.b.c", "a.b.c");
+      repository.addMatch("a.^.c", "a.^.c");
+      repository.addMatch("a.d.c", "a.d.c");
+      repository.addMatch("a.b.*", "a.b.*");
+      repository.addMatch("a.b", "a.b");
+      repository.addMatch("a.b.c.*", "a.b.c.*");
+      repository.addMatch("a.b.c.d", "a.b.c.d");
+      repository.addMatch("a.^.^.d", "a.^.^.d");
+      repository.addMatch("a.^.d.*", "a.^.d.*");
+      String val = repository.getMatch("a");
+      assertEquals("a", val);
+      val = repository.getMatch("a.b");
+      assertEquals("a.b", val);
+      val = repository.getMatch("a.x");
+      assertEquals("a.^", val);
+      val = repository.getMatch("a.b.x");
+      assertEquals("a.b.*", val);
+      val = repository.getMatch("a.b.c");
+      assertEquals("a.b.c", val);
+      val = repository.getMatch("a.d.c");
+      assertEquals("a.d.c", val);
+      val = repository.getMatch("a.x.c");
+      assertEquals("a.^.c", val);
+      val = repository.getMatch("a.b.c.d");
+      assertEquals("a.b.c.d", val);
+      val = repository.getMatch("a.x.c.d");
+      assertEquals("a.^.^.d", val);
+      val = repository.getMatch("a.b.x.d");
+      assertEquals("a.^.^.d", val);
+      val = repository.getMatch("a.d.x.d");
+      assertEquals("a.^.^.d", val);
+      val = repository.getMatch("a.d.d.g");
+      assertEquals("a.^.d.*", val);
+      val = repository.getMatch("zzzz.z.z.z.d.r.g.f.sd.s.fsdfd.fsdfs");
+      assertEquals("*", val);
+   }
+
+   public void testRepositoryMerge()
+   {
+      HierarchicalRepository<DummyMergeable> repository = new HierarchicalObjectRepository<DummyMergeable>();
+      repository.addMatch("*", new DummyMergeable(1));
+      repository.addMatch("a.*", new DummyMergeable(2));
+      repository.addMatch("b.*", new DummyMergeable(3));
+      repository.addMatch("a.b.*", new DummyMergeable(4));
+      repository.addMatch("b.c.*", new DummyMergeable(5));
+      repository.addMatch("a.b.c.*", new DummyMergeable(6));
+      repository.addMatch("a.b.^.d", new DummyMergeable(7));
+      repository.addMatch("a.b.c.^", new DummyMergeable(8));
+      repository.getMatch("a.b.c.d");
+      assertEquals(5, DummyMergeable.timesMerged);
+      assertTrue(DummyMergeable.contains(1));
+      assertTrue(DummyMergeable.contains(2));
+      assertTrue(DummyMergeable.contains(4));
+      assertTrue(DummyMergeable.contains(7));
+      assertTrue(DummyMergeable.contains(8));
+      DummyMergeable.reset();
+      repository.getMatch("a.b.c");
+      assertEquals(2, DummyMergeable.timesMerged);
+      assertTrue(DummyMergeable.contains(1));
+      assertTrue(DummyMergeable.contains(2));
+      assertTrue(DummyMergeable.contains(4));
+      DummyMergeable.reset();
+      repository.getMatch("a");
+      assertEquals(0, DummyMergeable.timesMerged);
+      DummyMergeable.reset();
+   }
+
+   public void testIllegalMatches()
+   {
+      HierarchicalRepository<String> repository = new HierarchicalObjectRepository<String>();
+      try
+      {
+         repository.addMatch("hjhjhjhjh.*.hhh", "test");
+      }
+      catch (IllegalArgumentException e)
+      {
+         //pass
+      }
+      try
+      {
+         repository.addMatch(null, "test");
+      }
+      catch (IllegalArgumentException e)
+      {
+         //pass
+      }
+   }
+
+   static class DummyMergeable implements Mergeable
+   {
+      static int timesMerged = 0;
+      static ArrayList<Integer> merged = new ArrayList<Integer>();
+      private Integer id;
+
+      static void reset()
+      {
+          timesMerged = 0;
+         DummyMergeable.merged = new ArrayList<Integer>();
+      }
+
+      static boolean contains(Integer i)
+      {
+         return DummyMergeable.merged.contains(i);
+      }
+      public DummyMergeable(Integer id)
+      {
+         this.id = id;
+      }
+
+      public void merge(Object merged)
+      {
+         timesMerged++;
+         DummyMergeable.merged.add(id);
+         DummyMergeable.merged.add(((DummyMergeable)merged).id);
+      }
+   }
+}

Deleted: trunk/tests/src/org/jboss/messaging/core/test/unit/QueueSettingsTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/test/unit/QueueSettingsTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/test/unit/QueueSettingsTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,146 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005, JBoss Inc., and individual contributors as indicated
-   * 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.core.test.unit;
-
-import junit.framework.TestCase;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.impl.QueueImpl;
-import org.jboss.messaging.core.server.impl.QueueSettings;
-import org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy;
-
-/**
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class QueueSettingsTest  extends TestCase
-{
-   public void testDefaults()
-   {
-      QueueSettings queueSettings = new QueueSettings();
-      assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
-      assertEquals(queueSettings.getDistributionPolicyClass(), null);
-      assertEquals(queueSettings.getDLQ(), null);
-      assertEquals(queueSettings.isClustered(), Boolean.valueOf(false));
-      assertEquals(queueSettings.getExpiryQueue(), null);
-      assertEquals(queueSettings.getMaxDeliveryAttempts(), QueueSettings.DEFAULT_MAX_DELIVERY_ATTEMPTS);
-      assertEquals(queueSettings.getMaxSize(), QueueSettings.DEFAULT_MAX_SIZE);
-      assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), QueueSettings.DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT);
-      assertEquals(queueSettings.getRedeliveryDelay(), QueueSettings.DEFAULT_REDELIVER_DELAY);
-
-   }
-
-   public void testSingleMerge()
-   {
-      QueueSettings queueSettings = new  QueueSettings();
-      QueueSettings queueSettingsToMerge = new QueueSettings();
-      queueSettingsToMerge.setClustered(true);
-      Queue DLQ = new QueueImpl(0,"testDLQ", null, false, false, false,0);
-      Queue exp = new QueueImpl(0,"testExpiryQueue", null, false, false, false,0);
-      queueSettingsToMerge.setDLQ(DLQ);
-      queueSettingsToMerge.setExpiryQueue(exp);
-      queueSettingsToMerge.setMaxDeliveryAttempts(1000);
-      queueSettingsToMerge.setMaxSize(1001);
-      queueSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
-      queueSettingsToMerge.setRedeliveryDelay((long)1003);
-      queueSettings.merge(queueSettingsToMerge);
-      assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
-      assertEquals(queueSettings.getDistributionPolicyClass(), null);
-      assertEquals(queueSettings.isClustered(), Boolean.valueOf(true));
-      assertEquals(queueSettings.getDLQ(), DLQ);
-      assertEquals(queueSettings.getExpiryQueue(), exp);
-      assertEquals(queueSettings.getMaxDeliveryAttempts(), Integer.valueOf(1000));
-      assertEquals(queueSettings.getMaxSize(), Integer.valueOf(1001));
-      assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), Integer.valueOf(1002));
-      assertEquals(queueSettings.getRedeliveryDelay(), Long.valueOf(1003));
-   }
-
-   public void testMultipleMerge()
-   {
-      QueueSettings queueSettings = new  QueueSettings();
-      QueueSettings queueSettingsToMerge = new QueueSettings();
-      queueSettingsToMerge.setClustered(true);
-       Queue DLQ = new QueueImpl(0,"testDLQ", null, false, false, false,0);
-      Queue exp = new QueueImpl(0,"testExpiryQueue", null, false, false, false,0);
-      queueSettingsToMerge.setDLQ(DLQ);
-      queueSettingsToMerge.setExpiryQueue(exp);
-      queueSettingsToMerge.setMaxDeliveryAttempts(1000);
-      queueSettingsToMerge.setMaxSize(1001);
-      queueSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
-      queueSettingsToMerge.setRedeliveryDelay((long)1003);
-      queueSettings.merge(queueSettingsToMerge);
-
-      QueueSettings queueSettingsToMerge2 = new QueueSettings();
-      queueSettingsToMerge2.setClustered(true);
-      Queue exp2 = new QueueImpl(0,"testExpiryQueue2", null, false, false, false,0);
-      queueSettingsToMerge2.setExpiryQueue(exp2);
-      queueSettingsToMerge2.setMaxSize(2001);
-      queueSettingsToMerge2.setRedeliveryDelay((long)2003);
-      queueSettings.merge(queueSettingsToMerge2);
-
-      assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
-      assertEquals(queueSettings.getDistributionPolicyClass(), null);
-      assertEquals(queueSettings.isClustered(), Boolean.valueOf(true));
-      assertEquals(queueSettings.getDLQ(), DLQ);
-      assertEquals(queueSettings.getExpiryQueue(), exp2);
-      assertEquals(queueSettings.getMaxDeliveryAttempts(), Integer.valueOf(1000));
-      assertEquals(queueSettings.getMaxSize(), Integer.valueOf(2001));
-      assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), Integer.valueOf(1002));
-      assertEquals(queueSettings.getRedeliveryDelay(), Long.valueOf(2003));
-   }
-
-   public void testMultipleMergeAll()
-   {
-      QueueSettings queueSettings = new  QueueSettings();
-      QueueSettings queueSettingsToMerge = new QueueSettings();
-      queueSettingsToMerge.setClustered(true);
-       Queue DLQ = new QueueImpl(0,"testDLQ", null, false, false, false,0);
-      Queue exp = new QueueImpl(0,"testExpiryQueue", null, false, false, false,0);
-      queueSettingsToMerge.setDLQ(DLQ);
-      queueSettingsToMerge.setExpiryQueue(exp);
-      queueSettingsToMerge.setMaxDeliveryAttempts(1000);
-      queueSettingsToMerge.setMaxSize(1001);
-      queueSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
-      queueSettingsToMerge.setRedeliveryDelay((long)1003);
-      queueSettings.merge(queueSettingsToMerge);
-
-      QueueSettings queueSettingsToMerge2 = new QueueSettings();
-      queueSettingsToMerge2.setClustered(false);
-      Queue exp2 = new QueueImpl(0,"testExpiryQueue2", null, false, false, false,0);
-      Queue DLQ2 = new QueueImpl(0,"testDlq2", null, false, false, false,0);
-      queueSettingsToMerge2.setExpiryQueue(exp2);
-      queueSettingsToMerge2.setDLQ(DLQ2);
-      queueSettingsToMerge2.setMaxDeliveryAttempts(2000);
-      queueSettingsToMerge2.setMaxSize(2001);
-      queueSettingsToMerge2.setMessageCounterHistoryDayLimit(2002);
-      queueSettingsToMerge2.setRedeliveryDelay((long)2003);
-      queueSettings.merge(queueSettingsToMerge2);
-
-      assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
-      assertEquals(queueSettings.getDistributionPolicyClass(), null);
-      assertEquals(queueSettings.isClustered(), Boolean.valueOf(true));
-      assertEquals(queueSettings.getDLQ(), DLQ2);
-      assertEquals(queueSettings.getExpiryQueue(), exp2);
-      assertEquals(queueSettings.getMaxDeliveryAttempts(), Integer.valueOf(2000));
-      assertEquals(queueSettings.getMaxSize(), Integer.valueOf(2001));
-      assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), Integer.valueOf(2002));
-      assertEquals(queueSettings.getRedeliveryDelay(), Long.valueOf(2003));
-   }
-}

Deleted: trunk/tests/src/org/jboss/messaging/core/tx/test/unit/MessagingXidTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/tx/test/unit/MessagingXidTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/core/tx/test/unit/MessagingXidTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,172 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * 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.core.tx.test.unit;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import javax.transaction.xa.Xid;
-
-import org.jboss.messaging.core.server.impl.XidImpl;
-import org.jboss.messaging.test.unit.RandomUtil;
-import org.jboss.messaging.test.unit.UnitTestCase;
-
-/**
- * 
- * A MessagingXidTest
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class MessagingXidTest extends UnitTestCase
-{
-   public void testSerialize() throws Exception
-   {
-      XidImpl xid = new XidImpl(RandomUtil.randomBytes(), RandomUtil.randomInt(),
-                                          RandomUtil.randomBytes());
-      
-      ByteArrayOutputStream baos = new ByteArrayOutputStream();
-      
-      ObjectOutputStream oos = new ObjectOutputStream(baos);
-      
-      oos.writeObject(xid);
-      
-      oos.flush();
-      
-      ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
-      
-      Object obj = ois.readObject();
-      
-      assertTrue(obj instanceof XidImpl);
-      
-      XidImpl xid2 = (XidImpl)obj;
-      
-      assertXidsEquivalent(xid, xid2);
-      
-      assertEquals(xid, xid2);     
-   }
-   
-   public void testStandardConstructor()
-   {
-      byte[] bq = RandomUtil.randomBytes();
-      
-      byte[] globalTXID = RandomUtil.randomBytes();
-      
-      int formatID = RandomUtil.randomInt();
-      
-      XidImpl xid1 = new XidImpl(bq, formatID, globalTXID);
-      
-      assertByteArraysEquivalent(bq, xid1.getBranchQualifier());
-      
-      assertByteArraysEquivalent(globalTXID, xid1.getGlobalTransactionId());
-      
-      assertEquals(formatID, xid1.getFormatId());
-   }
-   
-   public void testCopyConstructor()
-   {
-      XidImpl xid1 = new XidImpl(RandomUtil.randomBytes(), RandomUtil.randomInt(),
-                                          RandomUtil.randomBytes());
-      
-      XidImpl xid2 = new XidImpl(xid1);
-      
-      assertXidsEquivalent(xid1, xid2);
-      
-      assertEquals(xid2, xid2);
-   }
-   
-   public void testDefaultConstructor()
-   {
-      XidImpl xid1 = new XidImpl();
-      
-      assertNull(xid1.getBranchQualifier());
-      
-      assertNull(xid1.getGlobalTransactionId());
-      
-      assertEquals(0, xid1.getFormatId());
-   }
-   
-   public void testEqualsWithForeign()
-   {
-      XidImpl xid1 = new XidImpl(RandomUtil.randomBytes(), RandomUtil.randomInt(),
-            RandomUtil.randomBytes());
-
-      Xid foreign = new ForeignXid(xid1.getBranchQualifier(), xid1.getFormatId(), xid1.getGlobalTransactionId());
-      
-      assertTrue(xid1.equals(foreign));
-      
-      foreign = new ForeignXid(RandomUtil.randomBytes(), RandomUtil.randomInt(),
-                               RandomUtil.randomBytes());
-      
-      assertFalse(xid1.equals(foreign));
-      
-   }
-   
-   // Private ---------------------------------------------------------------------------------
-   
-   private void assertXidsEquivalent(Xid xid1, Xid xid2)
-   {
-      assertByteArraysEquivalent(xid1.getBranchQualifier(), xid2.getBranchQualifier());
-      
-      assertEquals(xid1.getFormatId(), xid2.getFormatId());
-      
-      assertByteArraysEquivalent(xid1.getGlobalTransactionId(), xid2.getGlobalTransactionId());
-   }
-   
-   // Inner classes ---------------------------------------------------------------------------
-   
-   class ForeignXid implements Xid
-   {
-      private byte[] branchQualifier;
-      
-      private int formatId;
-      
-      private byte[] globalTransactionId;
-      
-      public ForeignXid(byte[] branchQualifier, int formatId, byte[] globalTransactionId)
-      {
-         this.branchQualifier = branchQualifier;
-         this.formatId = formatId;
-         this.globalTransactionId = globalTransactionId;          
-      }
-           
-      public byte[] getBranchQualifier()
-      {
-         return this.branchQualifier;
-      }
-
-      public int getFormatId()
-      {
-         return this.formatId;
-      }
-
-      public byte[] getGlobalTransactionId()
-      {
-         return this.globalTransactionId;
-      }
-      
-   }
-   
-   
-}

Deleted: trunk/tests/src/org/jboss/messaging/deployers/queue/tests/unit/QueueSettingsDeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/deployers/queue/tests/unit/QueueSettingsDeployerTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/deployers/queue/tests/unit/QueueSettingsDeployerTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,79 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005, JBoss Inc., and individual contributors as indicated
-   * 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.deployers.queue.tests.unit;
-
-import junit.framework.TestCase;
-import org.easymock.EasyMock;
-import org.jboss.messaging.core.deployers.impl.QueueSettingsDeployer;
-import org.jboss.messaging.core.server.impl.QueueSettings;
-import org.jboss.messaging.core.settings.HierarchicalRepository;
-import org.jboss.messaging.util.XMLUtil;
-
-/**
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class QueueSettingsDeployerTest extends TestCase
-{
-   private String conf = "<queue-settings match=\"queues.*\">\n" +
-           "      <clustered>false</clustered>\n" +
-           "      <dlq>DLQtest</dlq>\n" +
-           "      <expiry-queue>ExpiryQueueTest</expiry-queue>\n" +
-           "      <redelivery-delay>100</redelivery-delay>\n" +
-           "      <max-size>-100</max-size>\n" +
-           "      <distribution-policy-class>org.jboss.messaging.core.impl.RoundRobinDistributionPolicy</distribution-policy-class>\n" +
-           "      <message-counter-history-day-limit>1000</message-counter-history-day-limit>\n" +
-           "   </queue-settings>";
-
-   QueueSettingsDeployer queueSettingsDeployer;
-
-
-   protected void setUp() throws Exception
-   {
-      queueSettingsDeployer = new QueueSettingsDeployer();
-   }
-
-   public void testDeploy() throws Exception
-   {
-      HierarchicalRepository<QueueSettings> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
-      queueSettingsDeployer.setQueueSettingsRepository(repository);
-      QueueSettings queueSettings = new QueueSettings();
-      queueSettings.setClustered(false);
-      //queueSettings.setDLQ("DLQtest");
-      //queueSettings.setExpiryQueue("ExpiryQueueTest");
-      queueSettings.setRedeliveryDelay((long)100);
-      queueSettings.setMaxSize(-100);
-      queueSettings.setDistributionPolicyClass("org.jboss.messaging.core.impl.RoundRobinDistributionPolicy");
-      queueSettings.setMessageCounterHistoryDayLimit(1000);
-      repository.addMatch("queues.*", queueSettings);
-      EasyMock.replay(repository);
-      queueSettingsDeployer.deploy(XMLUtil.stringToElement(conf));
-   }
-
-   public void testUndeploy()
-   {
-      HierarchicalRepository<QueueSettings> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
-      queueSettingsDeployer.setQueueSettingsRepository(repository);
-      repository.removeMatch(conf);
-      EasyMock.replay(repository);
-
-   }
-}

Deleted: trunk/tests/src/org/jboss/messaging/util/test/unit/RepositoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/util/test/unit/RepositoryTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/messaging/util/test/unit/RepositoryTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,213 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005, JBoss Inc., and individual contributors as indicated
-   * 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.util.test.unit;
-
-import junit.framework.TestCase;
-import org.jboss.messaging.core.security.Role;
-import org.jboss.messaging.core.settings.HierarchicalRepository;
-import org.jboss.messaging.core.settings.Mergeable;
-import org.jboss.messaging.core.settings.impl.HierarchicalObjectRepository;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public class RepositoryTest extends TestCase
-{
-   HierarchicalRepository<HashSet<Role>> securityRepository;
-
-
-   protected void setUp() throws Exception
-   {
-      securityRepository = new HierarchicalObjectRepository<HashSet<Role>>();
-   }
-
-   public void testDefault()
-   {
-      securityRepository.setDefault(new HashSet<Role>());
-      HashSet<Role> roles = securityRepository.getMatch("queues.something");
-
-      assertEquals(roles.size(), 0);
-   }
-
-   public void testSingleMatch()
-   {
-      securityRepository.addMatch("queues.*", new HashSet<Role>());
-      HashSet<Role> hashSet = securityRepository.getMatch("queues.something");
-      assertEquals(hashSet.size(), 0);
-   }
-
-   public void testSingletwo()
-   {
-      securityRepository.addMatch("queues.another.aq.*", new HashSet<Role>());
-      HashSet<Role> roles = new HashSet<Role>(2);
-      roles.add(new Role("test1"));
-      roles.add(new Role("test2"));
-      securityRepository.addMatch("queues.aq", roles);
-      HashSet<Role> roles2 = new HashSet<Role>(2);
-      roles2.add(new Role("test1"));
-      roles2.add(new Role("test2"));
-      roles2.add(new Role("test3"));
-      securityRepository.addMatch("queues.another.andanother", roles2);
-      
-      HashSet<Role> hashSet = securityRepository.getMatch("queues.another.andanother");
-      assertEquals(hashSet.size(), 3);
-   }
-
-   public void testWithoutWildcard()
-   {
-      securityRepository.addMatch("queues.1.*", new HashSet<Role>());
-      HashSet<Role> roles = new HashSet<Role>(2);
-      roles.add(new Role("test1"));
-      roles.add(new Role("test2"));
-      securityRepository.addMatch("queues.2.aq", roles);
-      HashSet<Role> hashSet = securityRepository.getMatch("queues.2.aq");
-      assertEquals(hashSet.size(), 2);
-   }
-
-   public void testMultipleWildcards()
-   {
-      HierarchicalRepository<String> repository = new HierarchicalObjectRepository<String>();
-      repository.addMatch("*", "*");
-      repository.addMatch("a", "a");
-      repository.addMatch("a.*", "a.*");
-      repository.addMatch("a.^", "a.^");
-      repository.addMatch("a.b.c", "a.b.c");
-      repository.addMatch("a.^.c", "a.^.c");
-      repository.addMatch("a.d.c", "a.d.c");
-      repository.addMatch("a.b.*", "a.b.*");
-      repository.addMatch("a.b", "a.b");
-      repository.addMatch("a.b.c.*", "a.b.c.*");
-      repository.addMatch("a.b.c.d", "a.b.c.d");
-      repository.addMatch("a.^.^.d", "a.^.^.d");
-      repository.addMatch("a.^.d.*", "a.^.d.*");
-      String val = repository.getMatch("a");
-      assertEquals("a", val);
-      val = repository.getMatch("a.b");
-      assertEquals("a.b", val);
-      val = repository.getMatch("a.x");
-      assertEquals("a.^", val);
-      val = repository.getMatch("a.b.x");
-      assertEquals("a.b.*", val);
-      val = repository.getMatch("a.b.c");
-      assertEquals("a.b.c", val);
-      val = repository.getMatch("a.d.c");
-      assertEquals("a.d.c", val);
-      val = repository.getMatch("a.x.c");
-      assertEquals("a.^.c", val);
-      val = repository.getMatch("a.b.c.d");
-      assertEquals("a.b.c.d", val);
-      val = repository.getMatch("a.x.c.d");
-      assertEquals("a.^.^.d", val);
-      val = repository.getMatch("a.b.x.d");
-      assertEquals("a.^.^.d", val);
-      val = repository.getMatch("a.d.x.d");
-      assertEquals("a.^.^.d", val);
-      val = repository.getMatch("a.d.d.g");
-      assertEquals("a.^.d.*", val);
-      val = repository.getMatch("zzzz.z.z.z.d.r.g.f.sd.s.fsdfd.fsdfs");
-      assertEquals("*", val);
-   }
-
-   public void testRepositoryMerge()
-   {
-      HierarchicalRepository<DummyMergeable> repository = new HierarchicalObjectRepository<DummyMergeable>();
-      repository.addMatch("*", new DummyMergeable(1));
-      repository.addMatch("a.*", new DummyMergeable(2));
-      repository.addMatch("b.*", new DummyMergeable(3));
-      repository.addMatch("a.b.*", new DummyMergeable(4));
-      repository.addMatch("b.c.*", new DummyMergeable(5));
-      repository.addMatch("a.b.c.*", new DummyMergeable(6));
-      repository.addMatch("a.b.^.d", new DummyMergeable(7));
-      repository.addMatch("a.b.c.^", new DummyMergeable(8));
-      repository.getMatch("a.b.c.d");
-      assertEquals(5, DummyMergeable.timesMerged);
-      assertTrue(DummyMergeable.contains(1));
-      assertTrue(DummyMergeable.contains(2));
-      assertTrue(DummyMergeable.contains(4));
-      assertTrue(DummyMergeable.contains(7));
-      assertTrue(DummyMergeable.contains(8));
-      DummyMergeable.reset();
-      repository.getMatch("a.b.c");
-      assertEquals(2, DummyMergeable.timesMerged);
-      assertTrue(DummyMergeable.contains(1));
-      assertTrue(DummyMergeable.contains(2));
-      assertTrue(DummyMergeable.contains(4));
-      DummyMergeable.reset();
-      repository.getMatch("a");
-      assertEquals(0, DummyMergeable.timesMerged);
-      DummyMergeable.reset();
-   }
-
-   public void testIllegalMatches()
-   {
-      HierarchicalRepository<String> repository = new HierarchicalObjectRepository<String>();
-      try
-      {
-         repository.addMatch("hjhjhjhjh.*.hhh", "test");
-      }
-      catch (IllegalArgumentException e)
-      {
-         //pass
-      }
-      try
-      {
-         repository.addMatch(null, "test");
-      }
-      catch (IllegalArgumentException e)
-      {
-         //pass
-      }
-   }
-
-   static class DummyMergeable implements Mergeable
-   {
-      static int timesMerged = 0;
-      static ArrayList<Integer> merged = new ArrayList<Integer>();
-      private Integer id;
-
-      static void reset()
-      {
-          timesMerged = 0;
-         DummyMergeable.merged = new ArrayList<Integer>();
-      }
-
-      static boolean contains(Integer i)
-      {
-         return DummyMergeable.merged.contains(i);
-      }
-      public DummyMergeable(Integer id)
-      {
-         this.id = id;
-      }
-
-      public void merge(Object merged)
-      {
-         timesMerged++;
-         DummyMergeable.merged.add(id);
-         DummyMergeable.merged.add(((DummyMergeable)merged).id);
-      }
-   }
-}

Deleted: trunk/tests/src/org/jboss/test/messaging/DropTablesTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/DropTablesTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/test/messaging/DropTablesTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -1,28 +0,0 @@
-package org.jboss.test.messaging;
-
-/**
- * 
- * This test only exists so we have a way of dropping the tables on Hudson for QA runs
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: $</tt>10 Aug 2007
- *
- * $Id: $
- *
- */
-public class DropTablesTest extends JBMServerTestCase
-{
-
-	public DropTablesTest(String name)
-	{
-		super(name);
-	}
-	
-	public void testDropTables() throws Exception
-	{
-	
-			dropTables();
-
-	}
-
-}

Modified: trunk/tests/src/org/jboss/test/messaging/jms/ManifestTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ManifestTest.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ManifestTest.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -22,7 +22,6 @@
 package org.jboss.test.messaging.jms;
 
 import java.io.File;
-import java.util.Iterator;
 import java.util.Properties;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
@@ -83,23 +82,8 @@
 	      // Compare the value from ConnectionMetaData and MANIFEST.MF
 	      Attributes attrs = manifest.getMainAttributes();
 	      
-	      log.info("META--> " + meta.getJMSMajorVersion());
-	      log.info("META--> " + meta.getJMSMinorVersion());
-	      log.info("META--> " + meta.getJMSProviderName());
-	      log.info("META--> " + meta.getJMSVersion());
-	      log.info("META--> " + meta.getProviderMajorVersion());
-	      log.info("META--> " + meta.getProviderMinorVersion());
-	      log.info("META--> " + meta.getProviderVersion());
-	      
-	      Iterator itr = attrs.entrySet().iterator();
-	      while (itr.hasNext()) {
-	         Object item = itr.next();
-	         log.trace("MANIFEST--> " + item + " : " + attrs.get(item));
-	      }
-	      
-	      assertEquals(attrs.getValue("Implementation-Title"), meta.getJMSProviderName());
-	      String ver = attrs.getValue("Implementation-Version");
-	      assertTrue(-1 != ver.indexOf(meta.getProviderVersion()));
+	      assertEquals(meta.getProviderVersion(), attrs.getValue("JBossMessaging-Version"));
+	      assertEquals("https://svn.jboss.org/repos/messaging/trunk", attrs.getValue("JBossMessaging-SVN-URL"));
       }
       finally
       {

Modified: trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java	2008-02-26 10:20:51 UTC (rev 3799)
+++ trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java	2008-02-26 16:57:25 UTC (rev 3800)
@@ -47,7 +47,7 @@
 import org.jboss.messaging.core.security.Role;
 import org.jboss.messaging.core.server.Binding;
 import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.core.server.impl.QueueSettings;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
 import org.jboss.messaging.jms.server.JMSServerManager;
 import org.jboss.messaging.microcontainer.JBMBootstrapServer;
 import org.jboss.messaging.util.JNDIUtil;




More information about the jboss-cvs-commits mailing list