qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kgiu...@apache.org
Subject svn commit: r1172657 [11/21] - in /qpid/branches/qpid-3346/qpid: ./ cpp/ cpp/bindings/ cpp/bindings/qmf2/examples/cpp/ cpp/bindings/qpid/dotnet/ cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/Properties/ cpp/bindings/qpid/dotnet/examples/csha...
Date Mon, 19 Sep 2011 15:13:38 GMT
Modified: qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java Mon Sep 19 15:13:18 2011
@@ -25,31 +25,34 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Map;
 
+import org.apache.log4j.Logger;
 import org.apache.qpid.AMQException;
 import org.apache.qpid.AMQUnknownExchangeType;
-import org.apache.qpid.common.AMQPFilterTypes;
 import org.apache.qpid.framing.AMQShortString;
 import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.server.exchange.*;
+import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.exchange.ExchangeFactory;
+import org.apache.qpid.server.exchange.ExchangeInUseException;
+import org.apache.qpid.server.exchange.ExchangeRegistry;
+import org.apache.qpid.server.exchange.ExchangeType;
+import org.apache.qpid.server.exchange.HeadersExchange;
 import org.apache.qpid.server.filter.FilterManager;
 import org.apache.qpid.server.filter.FilterManagerFactory;
 import org.apache.qpid.server.flow.FlowCreditManager_0_10;
 import org.apache.qpid.server.flow.WindowCreditManager;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.GenericActor;
+import org.apache.qpid.server.logging.messages.ExchangeMessages;
 import org.apache.qpid.server.message.MessageMetaData_0_10;
 import org.apache.qpid.server.message.MessageTransferMessage;
-import org.apache.qpid.server.protocol.AMQSessionModel;
 import org.apache.qpid.server.queue.AMQQueue;
 import org.apache.qpid.server.queue.AMQQueueFactory;
 import org.apache.qpid.server.queue.BaseQueue;
 import org.apache.qpid.server.queue.QueueRegistry;
 import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
 import org.apache.qpid.server.security.SecurityManager;
 import org.apache.qpid.server.store.DurableConfigurationStore;
 import org.apache.qpid.server.store.MessageStore;
 import org.apache.qpid.server.store.StoredMessage;
+import org.apache.qpid.server.subscription.SubscriptionFactoryImpl;
 import org.apache.qpid.server.subscription.Subscription_0_10;
 import org.apache.qpid.server.virtualhost.VirtualHost;
 import org.apache.qpid.transport.Acquired;
@@ -95,26 +98,34 @@ import org.apache.qpid.transport.TxSelec
 
 public class ServerSessionDelegate extends SessionDelegate
 {
-    private final IApplicationRegistry _appRegistry;
+    private static final Logger LOGGER = Logger.getLogger(ServerSessionDelegate.class);
 
-    public ServerSessionDelegate(IApplicationRegistry appRegistry)
+    public ServerSessionDelegate()
     {
-        _appRegistry = appRegistry;
+
     }
 
     @Override
     public void command(Session session, Method method)
     {
-        SecurityManager.setThreadPrincipal(session.getConnection().getAuthorizationID());
-
-        if(!session.isClosing())
+        try
         {
-            super.command(session, method);
-            if (method.isSync())
+            setThreadSubject(session);
+
+            if(!session.isClosing())
             {
-                session.flushProcessed();
+                super.command(session, method);
+                if (method.isSync())
+                {
+                    session.flushProcessed();
+                }
             }
         }
+        catch(RuntimeException e)
+        {
+            LOGGER.error("Exception processing command", e);
+            exception(session, method, ExecutionErrorCode.INTERNAL_ERROR, "Exception processing command: " + e);
+        }
     }
 
     @Override
@@ -123,8 +134,6 @@ public class ServerSessionDelegate exten
         ((ServerSession)session).accept(method.getTransfers());
     }
 
-
-
     @Override
     public void messageReject(Session session, MessageReject method)
     {
@@ -159,7 +168,6 @@ public class ServerSessionDelegate exten
     @Override
     public void messageSubscribe(Session session, MessageSubscribe method)
     {
-
         //TODO - work around broken Python tests
         if(!method.hasAcceptMode())
         {
@@ -203,7 +211,7 @@ public class ServerSessionDelegate exten
                 {
                     exception(session,method,ExecutionErrorCode.NOT_FOUND, "Queue: " + queueName + " not found");
                 }
-                else if(queue.getPrincipalHolder() != null && queue.getPrincipalHolder() != session)
+                else if(queue.getAuthorizationHolder() != null && queue.getAuthorizationHolder() != session)
                 {
                     exception(session,method,ExecutionErrorCode.RESOURCE_LOCKED, "Exclusive Queue: " + queueName + " owned exclusively by another session");
                 }
@@ -213,17 +221,17 @@ public class ServerSessionDelegate exten
                     {
                         ServerSession s = (ServerSession) session;
                         queue.setExclusiveOwningSession(s);
-                        if(queue.getPrincipalHolder() == null)
+                        if(queue.getAuthorizationHolder() == null)
                         {
-                            queue.setPrincipalHolder(s);
+                            queue.setAuthorizationHolder(s);
                             queue.setExclusiveOwningSession(s);
                             ((ServerSession) session).addSessionCloseTask(new ServerSession.Task()
                             {
                                 public void doTask(ServerSession session)
                                 {
-                                    if(queue.getPrincipalHolder() == session)
+                                    if(queue.getAuthorizationHolder() == session)
                                     {
-                                        queue.setPrincipalHolder(null);
+                                        queue.setAuthorizationHolder(null);
                                         queue.setExclusiveOwningSession(null);
                                     }
                                 }
@@ -245,7 +253,7 @@ public class ServerSessionDelegate exten
                         return;
                     }
 
-                    Subscription_0_10 sub = new Subscription_0_10((ServerSession)session,
+                    Subscription_0_10 sub = SubscriptionFactoryImpl.INSTANCE.createSubscription((ServerSession)session,
                                                                   destination,
                                                                   method.getAcceptMode(),
                                                                   method.getAcquireMode(),
@@ -276,25 +284,10 @@ public class ServerSessionDelegate exten
         }
     }
 
-
     @Override
     public void messageTransfer(Session ssn, MessageTransfer xfr)
     {
-        ExchangeRegistry exchangeRegistry = getExchangeRegistry(ssn);
-        Exchange exchange;
-        if(xfr.hasDestination())
-        {
-            exchange = exchangeRegistry.getExchange(xfr.getDestination());
-            if(exchange == null)
-            {
-                exchange = exchangeRegistry.getDefaultExchange();
-            }
-        }
-        else
-        {
-            exchange = exchangeRegistry.getDefaultExchange();
-        }
-        
+        final Exchange exchange = getExchangeForMessage(ssn, xfr);
 
         DeliveryProperties delvProps = null;
         if(xfr.getHeader() != null && (delvProps = xfr.getHeader().get(DeliveryProperties.class)) != null && delvProps.hasTtl() && !delvProps.hasExpiration())
@@ -302,7 +295,7 @@ public class ServerSessionDelegate exten
             delvProps.setExpiration(System.currentTimeMillis() + delvProps.getTtl());
         }
 
-        MessageMetaData_0_10 messageMetaData = new MessageMetaData_0_10(xfr);
+        final MessageMetaData_0_10 messageMetaData = new MessageMetaData_0_10(xfr);
         
         if (!getVirtualHost(ssn).getSecurityManager().authorisePublish(messageMetaData.isImmediate(), messageMetaData.getRoutingKey(), exchange.getName()))
         {
@@ -312,66 +305,65 @@ public class ServerSessionDelegate exten
             
             return;
         }
-        
-        final MessageStore store = getVirtualHost(ssn).getMessageStore();
-        StoredMessage<MessageMetaData_0_10> storeMessage = store.addMessage(messageMetaData);
-        ByteBuffer body = xfr.getBody();
-        if(body != null)
+
+        final Exchange exchangeInUse;
+        ArrayList<? extends BaseQueue> queues = exchange.route(messageMetaData);
+        if(queues.isEmpty() && exchange.getAlternateExchange() != null)
+        {
+            final Exchange alternateExchange = exchange.getAlternateExchange();
+            queues = alternateExchange.route(messageMetaData);
+            if (!queues.isEmpty())
+            {
+                exchangeInUse = alternateExchange;
+            }
+            else
+            {
+                exchangeInUse = exchange;
+            }
+        }
+        else
         {
-            storeMessage.addContent(0, body);
+            exchangeInUse = exchange;
         }
-        storeMessage.flushToStore();
-        MessageTransferMessage message = new MessageTransferMessage(storeMessage, ((ServerSession)ssn).getReference());
-
-        ArrayList<? extends BaseQueue> queues = exchange.route(message);
 
-
-
-        if(queues != null && queues.size() != 0)
+        if(!queues.isEmpty())
         {
+            final MessageStore store = getVirtualHost(ssn).getMessageStore();
+            final StoredMessage<MessageMetaData_0_10> storeMessage = createAndFlushStoreMessage(xfr, messageMetaData, store);
+            MessageTransferMessage message = new MessageTransferMessage(storeMessage, ((ServerSession)ssn).getReference());
             ((ServerSession) ssn).enqueue(message, queues);
         }
         else
         {
-            if(delvProps == null || !delvProps.hasDiscardUnroutable() || !delvProps.getDiscardUnroutable())
+            if((delvProps == null || !delvProps.getDiscardUnroutable()) && xfr.getAcceptMode() == MessageAcceptMode.EXPLICIT)
             {
-                if(xfr.getAcceptMode() == MessageAcceptMode.EXPLICIT)
-                {
-                    RangeSet rejects = new RangeSet();
-                    rejects.add(xfr.getId());
-                    MessageReject reject = new MessageReject(rejects, MessageRejectCode.UNROUTABLE, "Unroutable");
-                    ssn.invoke(reject);
-                }
-                else
-                {
-                    Exchange alternate = exchange.getAlternateExchange();
-                    if(alternate != null)
-                    {
-                        queues = alternate.route(message);
-                        if(queues != null && queues.size() != 0)
-                        {
-                            ((ServerSession) ssn).enqueue(message, queues);
-                        }
-                        else
-                        {
-                            //TODO - log the message discard
-                        }
-                    }
-                    else
-                    {
-                        //TODO - log the message discard
-                    }
-
-
-                }
+                RangeSet rejects = new RangeSet();
+                rejects.add(xfr.getId());
+                MessageReject reject = new MessageReject(rejects, MessageRejectCode.UNROUTABLE, "Unroutable");
+                ssn.invoke(reject);
+            }
+            else
+            {
+                ((ServerSession) ssn).getLogActor().message(ExchangeMessages.DISCARDMSG(exchangeInUse.getName(), messageMetaData.getRoutingKey()));
             }
-
-
         }
 
         ssn.processed(xfr);
     }
 
+    private StoredMessage<MessageMetaData_0_10> createAndFlushStoreMessage(final MessageTransfer xfr,
+            final MessageMetaData_0_10 messageMetaData, final MessageStore store)
+    {
+        final StoredMessage<MessageMetaData_0_10> storeMessage = store.addMessage(messageMetaData);
+        ByteBuffer body = xfr.getBody();
+        if(body != null)
+        {
+            storeMessage.addContent(0, body);
+        }
+        storeMessage.flushToStore();
+        return storeMessage;
+    }
+
     @Override
     public void messageCancel(Session session, MessageCancel method)
     {
@@ -389,7 +381,7 @@ public class ServerSessionDelegate exten
             ((ServerSession)session).unregister(sub);
             if(!queue.isDeleted() && queue.isExclusive() && queue.getConsumerCount() == 0)
             {
-                queue.setPrincipalHolder(null);
+                queue.setAuthorizationHolder(null);
             }
         }
     }
@@ -448,6 +440,19 @@ public class ServerSessionDelegate exten
         VirtualHost virtualHost = getVirtualHost(session);
         Exchange exchange = getExchange(session, exchangeName);
 
+        //we must check for any unsupported arguments present and throw not-implemented
+        if(method.hasArguments())
+        {
+            Map<String,Object> args = method.getArguments();
+
+            //QPID-3392: currently we don't support any!
+            if(!args.isEmpty())
+            {
+                exception(session, method, ExecutionErrorCode.NOT_IMPLEMENTED, "Unsupported exchange argument(s) found " + args.keySet().toString());
+                return;
+            }
+        }
+
         if(method.getPassive())
         {
             if(exchange == null)
@@ -457,7 +462,6 @@ public class ServerSessionDelegate exten
             }
             else
             {
-                // TODO - check exchange has same properties
                 if(!exchange.getTypeShortString().toString().equals(method.getType()))
                 {
                     exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Cannot redeclare with a different exchange type");
@@ -562,6 +566,25 @@ public class ServerSessionDelegate exten
 
     }
 
+    private Exchange getExchangeForMessage(Session ssn, MessageTransfer xfr)
+    {
+        final ExchangeRegistry exchangeRegistry = getExchangeRegistry(ssn);
+        Exchange exchange;
+        if(xfr.hasDestination())
+        {
+            exchange = exchangeRegistry.getExchange(xfr.getDestination());
+            if(exchange == null)
+            {
+                exchange = exchangeRegistry.getDefaultExchange();
+            }
+        }
+        else
+        {
+            exchange = exchangeRegistry.getDefaultExchange();
+        }
+        return exchange;
+    }
+
     private VirtualHost getVirtualHost(Session session)
     {
         ServerConnection conn = getServerConnection(session);
@@ -1007,7 +1030,7 @@ public class ServerSessionDelegate exten
                             {
                                 public void doTask(ServerSession session)
                                 {
-                                    q.setPrincipalHolder(null);
+                                    q.setAuthorizationHolder(null);
                                     q.setExclusiveOwningSession(null);
                                 }
                             };
@@ -1077,7 +1100,7 @@ public class ServerSessionDelegate exten
             }
             else
             {
-                if(queue.getPrincipalHolder() != null && queue.getPrincipalHolder() != session)
+                if(queue.getAuthorizationHolder() != null && queue.getAuthorizationHolder() != session)
                 {
                     exception(session,method,ExecutionErrorCode.RESOURCE_LOCKED, "Exclusive Queue: " + queueName + " owned exclusively by another session");
                 }
@@ -1223,6 +1246,8 @@ public class ServerSessionDelegate exten
     @Override
     public void closed(Session session)
     {
+        setThreadSubject(session);
+
         for(Subscription_0_10 sub : getSubscriptions(session))
         {
             ((ServerSession)session).unregister(sub);
@@ -1241,4 +1266,9 @@ public class ServerSessionDelegate exten
         return ((ServerSession)session).getSubscriptions();
     }
 
+    private void setThreadSubject(Session session)
+    {
+        final ServerConnection scon = (ServerConnection) session.getConnection();
+        SecurityManager.setThreadSubject(scon.getAuthorizedSubject());
+    }
 }

Propchange: qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep 19 15:13:18 2011
@@ -1,3 +1,3 @@
 /qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost:930288
 /qpid/branches/qpid-2935/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost:1061302-1072333
-/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost:1156188
+/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost:1144319-1172654

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java Mon Sep 19 15:13:18 2011
@@ -43,7 +43,10 @@ import org.apache.qpid.framing.FieldTabl
 import org.apache.qpid.AMQException;
 
 import org.apache.log4j.Logger;
+import org.apache.qpid.server.util.ByteBufferInputStream;
 
+import java.io.DataInputStream;
+import java.io.IOException;
 import java.nio.ByteBuffer;
 
 import java.util.List;
@@ -236,7 +239,14 @@ public class VirtualHostConfigRecoveryHa
                 FieldTable argumentsFT = null;
                 if(buf != null)
                 {
-                    argumentsFT = new FieldTable(org.apache.mina.common.ByteBuffer.wrap(buf),buf.limit());
+                    try
+                    {
+                        argumentsFT = new FieldTable(new DataInputStream(new ByteBufferInputStream(buf)),buf.limit());
+                    }
+                    catch (IOException e)
+                    {
+                        throw new RuntimeException("IOException should not be thrown here", e);
+                    }
                 }
 
                 BindingFactory bf = _virtualHost.getBindingFactory();

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java Mon Sep 19 15:13:18 2011
@@ -20,7 +20,6 @@
  */
 package org.apache.qpid.server.virtualhost;
 
-import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -72,7 +71,6 @@ import org.apache.qpid.server.registry.A
 import org.apache.qpid.server.registry.IApplicationRegistry;
 import org.apache.qpid.server.security.SecurityManager;
 import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
 import org.apache.qpid.server.stats.StatisticsCounter;
 import org.apache.qpid.server.store.ConfigurationRecoveryHandler;
 import org.apache.qpid.server.store.DurableConfigurationStore;
@@ -179,22 +177,11 @@ public class VirtualHostImpl implements 
         }
     }
 
-    public VirtualHostImpl(IApplicationRegistry appRegistry, VirtualHostConfiguration hostConfig) throws Exception
-    {
-        this(appRegistry, hostConfig, null);
-    }
-
-
-    public VirtualHostImpl(VirtualHostConfiguration hostConfig, MessageStore store) throws Exception
-    {
-        this(ApplicationRegistry.getInstance(),hostConfig,store);
-    }
-
-    private VirtualHostImpl(IApplicationRegistry appRegistry, VirtualHostConfiguration hostConfig, MessageStore store) throws Exception
+    public VirtualHostImpl(IApplicationRegistry appRegistry, VirtualHostConfiguration hostConfig, MessageStore store) throws Exception
     {
 		if (hostConfig == null)
 		{
-			throw new IllegalAccessException("HostConfig and MessageStore cannot be null");
+			throw new IllegalArgumentException("HostConfig cannot be null");
 		}
 		
         _appRegistry = appRegistry;
@@ -252,19 +239,24 @@ public class VirtualHostImpl implements 
 
         _brokerMBean = new AMQBrokerManagerMBean(_virtualHostMBean);
         _brokerMBean.register();
-        initialiseHouseKeeping(hostConfig.getHousekeepingExpiredMessageCheckPeriod());
+        initialiseHouseKeeping(hostConfig.getHousekeepingCheckPeriod());
         
         initialiseStatistics();
     }
 
+    /**
+     * Initialise a housekeeping task to iterate over queues cleaning expired messages with no consumers
+     * and checking for idle or open transactions that have exceeded the permitted thresholds.
+     *
+     * @param period
+     */
 	private void initialiseHouseKeeping(long period)
     {
-        /* add a timer task to iterate over queues, cleaning expired messages from queues with no consumers */
         if (period != 0L)
         {
-            class ExpiredMessagesTask extends HouseKeepingTask
+            class VirtualHostHouseKeepingTask extends HouseKeepingTask
             {
-                public ExpiredMessagesTask(VirtualHost vhost)
+                public VirtualHostHouseKeepingTask(VirtualHost vhost)
                 {
                     super(vhost);
                 }
@@ -309,7 +301,7 @@ public class VirtualHostImpl implements 
                 }
             }
 
-            scheduleHouseKeepingTask(period, new ExpiredMessagesTask(this));
+            scheduleHouseKeepingTask(period, new VirtualHostHouseKeepingTask(this));
 
             Map<String, VirtualHostPluginFactory> plugins =
                 ApplicationRegistry.getInstance().getPluginManager().getVirtualHostPlugins();
@@ -463,46 +455,57 @@ public class VirtualHostImpl implements 
     private void configureQueue(QueueConfiguration queueConfiguration) throws AMQException, ConfigurationException
     {
     	AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(queueConfiguration, this);
+        String queueName = queue.getName();
 
     	if (queue.isDurable())
     	{
     		getDurableConfigurationStore().createQueue(queue);
     	}
 
+        //get the exchange name (returns default exchange name if none was specified)
     	String exchangeName = queueConfiguration.getExchange();
 
-    	Exchange exchange = _exchangeRegistry.getExchange(exchangeName == null ? null : new AMQShortString(exchangeName));
-
-        if (exchange == null)
-        {
-            exchange = _exchangeRegistry.getDefaultExchange();
-        }
-
+        Exchange exchange = _exchangeRegistry.getExchange(exchangeName);
     	if (exchange == null)
     	{
-    		throw new ConfigurationException("Attempt to bind queue to unknown exchange:" + exchangeName);
+            throw new ConfigurationException("Attempt to bind queue '" + queueName + "' to unknown exchange:" + exchangeName);
     	}
 
-        List routingKeys = queueConfiguration.getRoutingKeys();
-        if (routingKeys == null || routingKeys.isEmpty())
-        {
-            routingKeys = Collections.singletonList(queue.getNameShortString());
-        }
+        Exchange defaultExchange = _exchangeRegistry.getDefaultExchange();
+
+        //get routing keys in configuration (returns empty list if none are defined)
+        List<?> routingKeys = queueConfiguration.getRoutingKeys();
 
         for (Object routingKeyNameObj : routingKeys)
         {
-            AMQShortString routingKey = new AMQShortString(String.valueOf(routingKeyNameObj));
-            if (_logger.isInfoEnabled())
+            String routingKey = String.valueOf(routingKeyNameObj);
+
+            if (exchange.equals(defaultExchange) && !queueName.equals(routingKey))
             {
-                _logger.info("Binding queue:" + queue + " with routing key '" + routingKey + "' to exchange:" + this);
+                throw new ConfigurationException("Illegal attempt to bind queue '" + queueName +
+                        "' to the default exchange with a key other than the queue name: " + routingKey);
             }
-            _bindingFactory.addBinding(routingKey.toString(), queue, exchange, null);
+
+            configureBinding(queue, exchange, routingKey);
         }
 
-        if (exchange != _exchangeRegistry.getDefaultExchange())
+        if (!exchange.equals(defaultExchange))
+        {
+            //bind the queue to the named exchange using its name
+            configureBinding(queue, exchange, queueName);
+        }
+
+        //ensure the queue is bound to the default exchange using its name
+        configureBinding(queue, defaultExchange, queueName);
+    }
+
+    private void configureBinding(AMQQueue queue, Exchange exchange, String routingKey) throws AMQException
+    {
+        if (_logger.isInfoEnabled())
         {
-            _bindingFactory.addBinding(queue.getNameShortString().toString(), queue, exchange, null);
+            _logger.info("Binding queue:" + queue + " with routing key '" + routingKey + "' to exchange:" + exchange.getName());
         }
+        _bindingFactory.addBinding(routingKey, queue, exchange, null);
     }
 
     public String getName()

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java Mon Sep 19 15:13:18 2011
@@ -20,16 +20,11 @@
  */
 package org.apache.qpid.server;
 
-import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS;
-import static org.apache.qpid.server.configuration.ServerConfiguration.DEFAULT_PORT;
-import static org.apache.qpid.server.configuration.ServerConfiguration.DEFAULT_JMXPORT;
-
-import java.util.Collections;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
-
 import org.apache.qpid.test.utils.QpidTestCase;
 
 
@@ -126,15 +121,26 @@ public class BrokerOptionsTest extends Q
         assertEquals(testLogConfigFile, _options.getLogConfigFile());
     }
 
-    public void testDefaultJmxPort()
+    public void testDefaultJmxPortRegistryServer()
+    {
+        assertNull(_options.getJmxPortRegistryServer());
+    }
+
+    public void testJmxPortRegistryServer()
+    {
+        _options.setJmxPortRegistryServer(TEST_PORT1);
+        assertEquals(Integer.valueOf(TEST_PORT1), _options.getJmxPortRegistryServer());
+    }
+
+    public void testDefaultJmxPortConnectorServer()
     {
-        assertNull(_options.getJmxPort());
+        assertNull(_options.getJmxPortConnectorServer());
     }
 
-    public void testJmxPort()
+    public void testJmxPortConnectorServer()
     {
-        _options.setJmxPort(TEST_PORT1);
-        assertEquals(Integer.valueOf(TEST_PORT1), _options.getJmxPort());
+        _options.setJmxPortConnectorServer(TEST_PORT1);
+        assertEquals(Integer.valueOf(TEST_PORT1), _options.getJmxPortConnectorServer());
     }
 
     public void testQpidHomeExposesSysProperty()

Copied: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java (from r1156187, qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java)
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java?p2=qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java&p1=qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java&r1=1156187&r2=1172657&rev=1172657&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java Mon Sep 19 15:13:18 2011
@@ -17,7 +17,7 @@ public class MainTest extends QpidTestCa
 
         assertTrue(options.getPorts().isEmpty());
         assertTrue(options.getSSLPorts().isEmpty());
-        assertEquals(null, options.getJmxPort());
+        assertEquals(null, options.getJmxPortRegistryServer());
         assertEquals(null, options.getConfigFile());
         assertEquals(null, options.getLogConfigFile());
         assertEquals(null, options.getBind());
@@ -76,11 +76,21 @@ public class MainTest extends QpidTestCa
         assertEquals(1, options.getSSLPorts().size());
     }
 
-    public void testJMXportOverridden()
+    public void testJmxPortRegistryServerOverridden()
     {
-        BrokerOptions options = startDummyMain("-m 3456");
+        BrokerOptions options = startDummyMain("--jmxregistryport 3456");
 
-        assertEquals(Integer.valueOf(3456), options.getJmxPort());
+        assertEquals(Integer.valueOf(3456), options.getJmxPortRegistryServer());
+
+         options = startDummyMain("-m 3457");
+         assertEquals(Integer.valueOf(3457), options.getJmxPortRegistryServer());
+    }
+
+    public void testJmxPortConnectorServerOverridden()
+    {
+        BrokerOptions options = startDummyMain("--jmxconnectorport 3456");
+
+        assertEquals(Integer.valueOf(3456), options.getJmxPortConnectorServer());
     }
 
     public void testExclude0_10()

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java Mon Sep 19 15:13:18 2011
@@ -25,7 +25,6 @@ import static org.apache.qpid.transport.
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.util.List;
 import java.util.Locale;
 
 import org.apache.commons.configuration.ConfigurationException;
@@ -59,128 +58,85 @@ public class ServerConfigurationTest ext
         ApplicationRegistry.remove();
     }
 
-    public void testSetJMXManagementPort() throws ConfigurationException
+    public void testSetJMXPortRegistryServer() throws ConfigurationException
     {
         _serverConfig.initialise();
-        _serverConfig.setJMXManagementPort(23);
-        assertEquals(23, _serverConfig.getJMXManagementPort());
+        _serverConfig.setJMXPortRegistryServer(23);
+        assertEquals(23, _serverConfig.getJMXPortRegistryServer());
     }
 
-    public void testGetJMXManagementPort() throws ConfigurationException
+    public void testGetJMXPortRegistryServer() throws ConfigurationException
     {
-        _config.setProperty("management.jmxport", 42);
+        _config.setProperty(ServerConfiguration.MGMT_JMXPORT_REGISTRYSERVER, 42);
         _serverConfig.initialise();
-        assertEquals(42, _serverConfig.getJMXManagementPort());
+        assertEquals(42, _serverConfig.getJMXPortRegistryServer());
     }
 
-    public void testGetPlatformMbeanserver() throws ConfigurationException
+    public void testDefaultJMXPortRegistryServer() throws ConfigurationException
     {
         _serverConfig.initialise();
-        assertEquals(true, _serverConfig.getPlatformMbeanserver());
-
-        // Check value we set
-        _config.setProperty("management.platform-mbeanserver", false);
-        _serverConfig = new ServerConfiguration(_config);
-        _serverConfig.initialise();
-        assertEquals(false, _serverConfig.getPlatformMbeanserver());
+        assertEquals(8999, _serverConfig.getJMXPortRegistryServer());
     }
 
-    public void testGetPluginDirectory() throws ConfigurationException
+    public void testSetJMXPortConnectorServer() throws ConfigurationException
     {
-        // Check default
-        _serverConfig.initialise();
-        assertEquals(null, _serverConfig.getPluginDirectory());
-
-        // Check value we set
-        _config.setProperty("plugin-directory", "/path/to/plugins");
-        _serverConfig = new ServerConfiguration(_config);
-        _serverConfig.initialise();
-        assertEquals("/path/to/plugins", _serverConfig.getPluginDirectory());
+        ServerConfiguration serverConfig = new ServerConfiguration(_config);
+        serverConfig.setJMXPortConnectorServer(67);
+        assertEquals(67, serverConfig.getJMXConnectorServerPort());
     }
 
-    public void testGetCacheDirectory() throws ConfigurationException
+    public void testGetJMXPortConnectorServer() throws ConfigurationException
     {
-        // Check default
-        _serverConfig.initialise();
-        assertEquals(null, _serverConfig.getCacheDirectory());
-
-        // Check value we set
-        _config.setProperty("cache-directory", "/path/to/cache");
-        _serverConfig = new ServerConfiguration(_config);
-        _serverConfig.initialise();
-        assertEquals("/path/to/cache", _serverConfig.getCacheDirectory());
+        _config.setProperty(ServerConfiguration.MGMT_JMXPORT_CONNECTORSERVER, 67);
+        ServerConfiguration serverConfig = new ServerConfiguration(_config);
+        assertEquals(67, serverConfig.getJMXConnectorServerPort());
     }
 
-    public void testGetPrincipalDatabaseNames() throws ConfigurationException
+    public void testDefaultJMXPortConnectorServer() throws ConfigurationException
     {
-        // Check default
-        _serverConfig.initialise();
-        assertEquals(0, _serverConfig.getPrincipalDatabaseNames().size());
-
-        // Check value we set
-        _config.setProperty("security.principal-databases.principal-database(0).name", "a");
-        _config.setProperty("security.principal-databases.principal-database(1).name", "b");
-        _serverConfig = new ServerConfiguration(_config);
-        _serverConfig.initialise();
-        List<String> dbs = _serverConfig.getPrincipalDatabaseNames();
-        assertEquals(2, dbs.size());
-        assertEquals("a", dbs.get(0));
-        assertEquals("b", dbs.get(1));
+        ServerConfiguration serverConfig = new ServerConfiguration(_config);
+        assertEquals(ServerConfiguration.DEFAULT_JMXPORT_REGISTRYSERVER + ServerConfiguration.JMXPORT_CONNECTORSERVER_OFFSET,
+                        serverConfig.getJMXConnectorServerPort());
     }
 
-    public void testGetPrincipalDatabaseClass() throws ConfigurationException
+    public void testGetPlatformMbeanserver() throws ConfigurationException
     {
-        // Check default
         _serverConfig.initialise();
-        assertEquals(0, _serverConfig.getPrincipalDatabaseClass().size());
+        assertEquals(true, _serverConfig.getPlatformMbeanserver());
 
         // Check value we set
-        _config.setProperty("security.principal-databases.principal-database(0).class", "a");
-        _config.setProperty("security.principal-databases.principal-database(1).class", "b");
+        _config.setProperty("management.platform-mbeanserver", false);
         _serverConfig = new ServerConfiguration(_config);
         _serverConfig.initialise();
-        List<String> dbs = _serverConfig.getPrincipalDatabaseClass();
-        assertEquals(2, dbs.size());
-        assertEquals("a", dbs.get(0));
-        assertEquals("b", dbs.get(1));
+        assertEquals(false, _serverConfig.getPlatformMbeanserver());
     }
 
-    public void testGetPrincipalDatabaseAttributeNames() throws ConfigurationException
+    public void testGetPluginDirectory() throws ConfigurationException
     {
         // Check default
         _serverConfig.initialise();
-        assertEquals(0, _serverConfig.getPrincipalDatabaseAttributeNames(1).size());
+        assertEquals(null, _serverConfig.getPluginDirectory());
 
         // Check value we set
-        _config.setProperty("security.principal-databases.principal-database(0).attributes(0).attribute.name", "a");
-        _config.setProperty("security.principal-databases.principal-database(0).attributes(1).attribute.name", "b");
+        _config.setProperty("plugin-directory", "/path/to/plugins");
         _serverConfig = new ServerConfiguration(_config);
         _serverConfig.initialise();
-        List<String> dbs = _serverConfig.getPrincipalDatabaseAttributeNames(0);
-        assertEquals(2, dbs.size());
-        assertEquals("a", dbs.get(0));
-        assertEquals("b", dbs.get(1));
+        assertEquals("/path/to/plugins", _serverConfig.getPluginDirectory());
     }
 
-    public void testGetPrincipalDatabaseAttributeValues() throws ConfigurationException
+    public void testGetCacheDirectory() throws ConfigurationException
     {
         // Check default
         _serverConfig.initialise();
-        assertEquals(0, _serverConfig.getPrincipalDatabaseAttributeValues(1).size());
+        assertEquals(null, _serverConfig.getCacheDirectory());
 
         // Check value we set
-        _config.setProperty("security.principal-databases.principal-database(0).attributes(0).attribute.value", "a");
-        _config.setProperty("security.principal-databases.principal-database(0).attributes(1).attribute.value", "b");
+        _config.setProperty("cache-directory", "/path/to/cache");
         _serverConfig = new ServerConfiguration(_config);
         _serverConfig.initialise();
-        List<String> dbs = _serverConfig.getPrincipalDatabaseAttributeValues(0);
-        assertEquals(2, dbs.size());
-        assertEquals("a", dbs.get(0));
-        assertEquals("b", dbs.get(1));
+        assertEquals("/path/to/cache", _serverConfig.getCacheDirectory());
     }
 
-
-
     public void testGetFrameSize() throws ConfigurationException
     {
         // Check default
@@ -582,7 +538,7 @@ public class ServerConfigurationTest ext
     {
         // Check default
         _serverConfig.initialise();
-        assertEquals("none", _serverConfig.getKeystorePath());
+        assertNull(_serverConfig.getKeystorePath());
 
         // Check value we set
         _config.setProperty("connector.ssl.keystorePath", "a");
@@ -595,7 +551,7 @@ public class ServerConfigurationTest ext
     {
         // Check default
         _serverConfig.initialise();
-        assertEquals("none", _serverConfig.getKeystorePassword());
+        assertNull(_serverConfig.getKeystorePassword());
 
         // Check value we set
         _config.setProperty("connector.ssl.keystorePassword", "a");
@@ -630,18 +586,17 @@ public class ServerConfigurationTest ext
         assertEquals(true, _serverConfig.getUseBiasedWrites());
     }
 
-    public void testGetHousekeepingExpiredMessageCheckPeriod() throws ConfigurationException
+    public void testGetHousekeepingCheckPeriod() throws ConfigurationException
     {
         // Check default
         _serverConfig.initialise();
         assertEquals(30000, _serverConfig.getHousekeepingCheckPeriod());
 
         // Check value we set
-        _config.setProperty("housekeeping.expiredMessageCheckPeriod", 23L);
+        _config.setProperty("housekeeping.checkPeriod", 23L);
         _serverConfig = new ServerConfiguration(_config);
         _serverConfig.initialise();
-        assertEquals(23, _serverConfig.getHousekeepingCheckPeriod());
-        _serverConfig.setHousekeepingExpiredMessageCheckPeriod(42L);
+        _serverConfig.setHousekeepingCheckPeriod(42L);
         assertEquals(42, _serverConfig.getHousekeepingCheckPeriod());
     }
 
@@ -720,9 +675,8 @@ public class ServerConfigurationTest ext
         out.write("<broker>\n");
         out.write("\t<management><enabled>false</enabled></management>\n");
         out.write("\t<security>\n");
-        out.write("\t\t<principal-databases>\n");
+        out.write("\t\t<pd-auth-manager>\n");
         out.write("\t\t\t<principal-database>\n");
-        out.write("\t\t\t\t<name>passwordfile</name>\n");
         out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
         out.write("\t\t\t\t<attributes>\n");
         out.write("\t\t\t\t\t<attribute>\n");
@@ -731,7 +685,7 @@ public class ServerConfigurationTest ext
         out.write("\t\t\t\t\t</attribute>\n");
         out.write("\t\t\t\t</attributes>\n");
         out.write("\t\t\t</principal-database>\n");
-        out.write("\t\t</principal-databases>\n");
+        out.write("\t\t</pd-auth-manager>\n");
         out.write("\t\t<firewall>\n");
         out.write("\t\t\t<rule access=\""+ ((allow) ? "allow" : "deny") +"\" network=\"127.0.0.1\"/>");
         out.write("\t\t</firewall>\n");
@@ -767,9 +721,8 @@ public class ServerConfigurationTest ext
         out.write("<broker>\n");
         out.write("\t<management><enabled>false</enabled></management>\n");
         out.write("\t<security>\n");
-        out.write("\t\t<principal-databases>\n");
+        out.write("\t\t<pd-auth-manager>\n");
         out.write("\t\t\t<principal-database>\n");
-        out.write("\t\t\t\t<name>passwordfile</name>\n");
         out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
         out.write("\t\t\t\t<attributes>\n");
         out.write("\t\t\t\t\t<attribute>\n");
@@ -778,7 +731,7 @@ public class ServerConfigurationTest ext
         out.write("\t\t\t\t\t</attribute>\n");
         out.write("\t\t\t\t</attributes>\n");
         out.write("\t\t\t</principal-database>\n");
-        out.write("\t\t</principal-databases>\n");
+        out.write("\t\t</pd-auth-manager>\n");
         out.write("\t\t<firewall>\n");
         out.write("\t\t\t<rule access=\"allow\" network=\"127.0.0.1\"/>");
         out.write("\t\t</firewall>\n");
@@ -869,9 +822,8 @@ public class ServerConfigurationTest ext
         out.write("<broker>\n");
         out.write("\t<management><enabled>false</enabled></management>\n");
         out.write("\t<security>\n");
-        out.write("\t\t<principal-databases>\n");
+        out.write("\t\t<pd-auth-manager>\n");
         out.write("\t\t\t<principal-database>\n");
-        out.write("\t\t\t\t<name>passwordfile</name>\n");
         out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
         out.write("\t\t\t\t<attributes>\n");
         out.write("\t\t\t\t\t<attribute>\n");
@@ -880,7 +832,7 @@ public class ServerConfigurationTest ext
         out.write("\t\t\t\t\t</attribute>\n");
         out.write("\t\t\t\t</attributes>\n");
         out.write("\t\t\t</principal-database>\n");
-        out.write("\t\t</principal-databases>\n");
+        out.write("\t\t</pd-auth-manager>\n");
         out.write("\t\t<firewall>\n");
         out.write("\t\t\t<rule access=\"allow\" network=\"127.0.0.1\"/>");
         out.write("\t\t</firewall>\n");
@@ -1387,7 +1339,7 @@ public class ServerConfigurationTest ext
     }
 
     /*
-     * Tests that the old element security.jmx.principal-databases (that used to define the
+     * Tests that the old element security.jmx.principal-database (that used to define the
      * principal database used for JMX authentication) is rejected.
      */
     public void testManagementPrincipalDatabaseRejected() throws ConfigurationException
@@ -1411,4 +1363,54 @@ public class ServerConfigurationTest ext
                     ce.getMessage());
         }
     }
+
+    /*
+     * Tests that the old element security.principal-databases. ... (that used to define 
+     * principal databases) is rejected.
+     */
+    public void testPrincipalDatabasesRejected() throws ConfigurationException
+    {
+        _serverConfig.initialise();
+
+        // Check value we set
+        _config.setProperty("security.principal-databases.principal-database.class", "myclass");
+        _serverConfig = new ServerConfiguration(_config);
+
+        try
+        {
+            _serverConfig.initialise();
+            fail("Exception not thrown");
+        }
+        catch (ConfigurationException ce)
+        {
+            assertEquals("Incorrect error message",
+                    "Validation error : security/principal-databases is no longer supported within the configuration xml.",
+                    ce.getMessage());
+        }
+    }
+
+    /*
+     * Tests that the old element housekeeping.expiredMessageCheckPeriod. ... (that was
+     * replaced by housekeeping.checkPeriod) is rejected.
+     */
+    public void testExpiredMessageCheckPeriodRejected() throws ConfigurationException
+    {
+        _serverConfig.initialise();
+
+        // Check value we set
+        _config.setProperty("housekeeping.expiredMessageCheckPeriod", 23L);
+        _serverConfig = new ServerConfiguration(_config);
+
+        try
+        {
+            _serverConfig.initialise();
+            fail("Exception not thrown");
+        }
+        catch (ConfigurationException ce)
+        {
+            assertEquals("Incorrect error message",
+                    "Validation error : housekeeping/expiredMessageCheckPeriod must be replaced by housekeeping/checkPeriod.",
+                    ce.getMessage());
+        }
+    }
 }

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java Mon Sep 19 15:13:18 2011
@@ -229,5 +229,26 @@ public class VirtualHostConfigurationTes
          }
      }
 
+     /*
+      * Tests that the old element housekeeping.expiredMessageCheckPeriod. ... (that was
+      * replaced by housekeeping.checkPeriod) is rejected.
+      */
+     public void testExpiredMessageCheckPeriodRejected() throws Exception
+     {
+         getConfigXml().addProperty("virtualhosts.virtualhost.testExpiredMessageCheckPeriodRejected.housekeeping.expiredMessageCheckPeriod",
+                 5);
 
+         try
+         {
+             super.createBroker();
+             fail("Exception not thrown");
+         }
+         catch (ConfigurationException ce)
+         {
+             assertEquals("Incorrect error message",
+                     "Validation error : housekeeping/expiredMessageCheckPeriod must be replaced by housekeeping/checkPeriod." +
+                     " It appears in virtual host definition : " + getName(),
+                     ce.getMessage());
+         }
+     }
 }

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java Mon Sep 19 15:13:18 2011
@@ -52,6 +52,7 @@ import org.apache.qpid.server.store.Stor
 import org.apache.qpid.server.subscription.Subscription;
 import org.apache.qpid.server.util.InternalBrokerBaseCase;
 
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -428,21 +429,11 @@ public class AbstractHeadersExchangeTest
                     //To change body of implemented methods use File | Settings | File Templates.
                 }
 
-                public void reject(Subscription subscription)
-                {
-                    //To change body of implemented methods use File | Settings | File Templates.
-                }
-
-                public boolean isRejectedBy(Subscription subscription)
+                public boolean isRejectedBy(long subscriptionId)
                 {
                     return false;  //To change body of implemented methods use File | Settings | File Templates.
                 }
 
-                public void requeue(Subscription subscription) 
-                {
-                    //To change body of implemented methods use File | Settings | File Templates.
-                }
-
                 public void dequeue()
                 {
                     //To change body of implemented methods use File | Settings | File Templates.
@@ -575,8 +566,8 @@ public class AbstractHeadersExchangeTest
             int pos = 0;
             for(ContentBody body : bodies)
             {
-                storedMessage.addContent(pos, body.payload.duplicate().buf());
-                pos += body.payload.limit();
+                storedMessage.addContent(pos, ByteBuffer.wrap(body._payload));
+                pos += body._payload.length;
             }
 
             _incoming = new TestIncomingMessage(getMessageId(),publish, protocolsession);

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java Mon Sep 19 15:13:18 2011
@@ -28,11 +28,7 @@ import org.apache.qpid.server.logging.Ab
 
 public class UnitTestMessageLogger extends AbstractRootMessageLogger
 {
-    List<Object> _log;
-    
-    {
-        _log = new LinkedList<Object>();
-    }
+    private final List<Object> _log = new LinkedList<Object>();
     
     public UnitTestMessageLogger()
     {
@@ -69,4 +65,14 @@ public class UnitTestMessageLogger exten
     {
         _log.clear();
     }
+    
+    public boolean messageContains(final int index, final String contains)
+    {
+        if (index + 1 > _log.size())
+        {
+            throw new IllegalArgumentException("Message with index " + index + " has not been logged");
+        }
+        final String message = _log.get(index).toString();
+        return message.contains(contains);
+    }
 }

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java Mon Sep 19 15:13:18 2011
@@ -20,13 +20,13 @@
  */
 package org.apache.qpid.server.logging.actors;
 
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.logging.LogMessage;
-import org.apache.qpid.server.logging.LogSubject;
-import org.apache.qpid.AMQException;
-
+import java.security.PrivilegedAction;
+import java.util.Collections;
 import java.util.List;
 
+import javax.management.remote.JMXPrincipal;
+import javax.security.auth.Subject;
+
 /**
  * Test : AMQPManagementActorTest
  * Validate the AMQPManagementActor class.
@@ -96,8 +96,40 @@ public class ManagementActorTest extends
 
         // Verify that the message has the right values
         assertTrue("Message contains the [mng: prefix",
-                   logs.get(0).toString().contains("[mng:" + CONNECTION_ID + "(" + IP + ")"));
+                   logs.get(0).toString().contains("[mng:N/A(" + IP + ")"));
+    }
+
+    /**
+     * Tests appearance of principal name in log message
+     */
+    public void testSubjectPrincipalNameAppearance()
+    {
+        Subject subject = new Subject(true, Collections.singleton(new JMXPrincipal("guest")), Collections.EMPTY_SET,
+                Collections.EMPTY_SET);
+
+        final String message = Subject.doAs(subject, new PrivilegedAction<String>()
+        {
+            public String run()
+            {
+                return sendTestLogMessage(_amqpActor);
+            }
+        });
+
+        // Verify that the log message was created
+        assertNotNull("Test log message is not created!", message);
+
+        List<Object> logs = _rawLogger.getLogMessages();
+
+        // Verify that at least one log message was added to log
+        assertEquals("Message log size not as expected.", 1, logs.size());
+
+        String logMessage = logs.get(0).toString();
+
+        // Verify that the logged message is present in the output
+        assertTrue("Message was not found in log message", logMessage.contains(message));
 
+        // Verify that the message has the right principal value
+        assertTrue("Message contains the [mng: prefix", logMessage.contains("[mng:guest(" + IP + ")"));
     }
 
 }

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java Mon Sep 19 15:13:18 2011
@@ -66,7 +66,6 @@ public class ExchangeMessagesTest extend
         validateLogMessage(log, "EXH-1001", expected);
     }
 
-
     public void testExchangeDeleted()
     {
         _logMessage = ExchangeMessages.DELETED();
@@ -77,4 +76,21 @@ public class ExchangeMessagesTest extend
         validateLogMessage(log, "EXH-1002", expected);
     }
 
+    public void testExchangeDiscardedMessage()
+    {
+        // Get the Default Exchange on the Test Vhost for testing
+        final Exchange exchange = ApplicationRegistry.getInstance().
+                getVirtualHostRegistry().getVirtualHost("test").
+                getExchangeRegistry().getDefaultExchange();
+
+        final String name = exchange.getNameShortString().toString();
+        final String routingKey = "routingKey";
+
+        _logMessage = ExchangeMessages.DISCARDMSG(name, routingKey);
+        List<Object> log = performLog();
+
+        String[] expected = {"Discarded Message :","Name:", name, "Routing Key:", routingKey};
+
+        validateLogMessage(log, "EXH-1003", expected);
+    }
 }

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java Mon Sep 19 15:13:18 2011
@@ -102,13 +102,6 @@ public class AMQUserManagementMBeanTest 
         assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size());
     }
 
-    public void testFiveArgCreateUserWithNegativeRightsRemainsSupported()
-    {
-        assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size());
-        assertTrue("Create should return true to flag successful create", _amqumMBean.createUser("newuser", "mypass".toCharArray(), false, false, false));
-        assertEquals("Unexpected number of users before test", 2,_amqumMBean.viewUsers().size());
-    }
-
     public void testSetPassword()
     {
         assertTrue("Set password should return true to flag successful change", _amqumMBean.setPassword(TEST_USERNAME, "newpassword"));
@@ -137,33 +130,6 @@ public class AMQUserManagementMBeanTest 
         assertEquals(false, userRec.get(UserManagement.RIGHTS_ADMIN));
     }
 
-    // TEST DEPRECATED METHODS
-    public void testFiveArgCreateUserWithPositiveRightsThrowsUnsupportedOperation()
-    {
-        try 
-        {
-            _amqumMBean.createUser(TEST_USERNAME, "mypass", true, false, false);
-            fail("Exception not thrown");
-        }
-        catch (UnsupportedOperationException uoe)
-        {
-            // PASS
-        }
-    }
-
-    public void testSetRightsThrowsUnsupportedOperation()
-    {
-        try 
-        {
-            _amqumMBean.setRights("", false, false, false);
-            fail("Exception not thrown");
-        }
-        catch(UnsupportedOperationException nie)
-        {
-            // PASS
-        }
-    }
-
     // ============================ Utility methods =========================
 
     private void loadFreshTestPasswordFile()

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java Mon Sep 19 15:13:18 2011
@@ -49,7 +49,7 @@ public class PluginTest extends Internal
     
     public void testNoExchanges() throws Exception
     {
-        PluginManager manager = new PluginManager("/path/to/nowhere", "/tmp");
+        PluginManager manager = new PluginManager("/path/to/nowhere", "/tmp", null);
         Map<String, ExchangeType<?>> exchanges = manager.getExchanges();
         assertTrue("Exchanges found", exchanges.isEmpty());
     }

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java Mon Sep 19 15:13:18 2011
@@ -20,13 +20,16 @@
  */
 package org.apache.qpid.server.protocol;
 
-import java.security.Principal;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.security.auth.Subject;
 
 import org.apache.qpid.AMQException;
 import org.apache.qpid.framing.AMQShortString;
@@ -39,6 +42,7 @@ import org.apache.qpid.server.message.Me
 import org.apache.qpid.server.output.ProtocolOutputConverter;
 import org.apache.qpid.server.queue.QueueEntry;
 import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
 import org.apache.qpid.server.virtualhost.VirtualHost;
 import org.apache.qpid.transport.TestNetworkConnection;
 
@@ -47,21 +51,17 @@ public class InternalTestProtocolSession
     // ChannelID(LIST)  -> LinkedList<Pair>
     final Map<Integer, Map<AMQShortString, LinkedList<DeliveryPair>>> _channelDelivers;
     private AtomicInteger _deliveryCount = new AtomicInteger(0);
+    private static final AtomicLong ID_GENERATOR = new AtomicLong(0);
 
     public InternalTestProtocolSession(VirtualHost virtualHost) throws AMQException
     {
-        super(ApplicationRegistry.getInstance().getVirtualHostRegistry(), new TestNetworkConnection());
+        super(ApplicationRegistry.getInstance().getVirtualHostRegistry(), new TestNetworkConnection(), ID_GENERATOR.getAndIncrement());
 
         _channelDelivers = new HashMap<Integer, Map<AMQShortString, LinkedList<DeliveryPair>>>();
 
         // Need to authenticate session for it to be representative testing.
-        setAuthorizedID(new Principal()
-        {
-            public String getName()
-            {
-                return "InternalTestProtocolSession";
-            }
-        });
+        setAuthorizedSubject(new Subject(true, Collections.singleton(new UsernamePrincipal("InternalTestProtocolSession")),
+                Collections.EMPTY_SET, Collections.EMPTY_SET));
 
         setVirtualHost(virtualHost);
     }
@@ -196,7 +196,7 @@ public class InternalTestProtocolSession
         return _closed;
     }
 
-    public void closeProtocolSession(boolean waitLast)
+    public void closeProtocolSession()
     {
         // Override as we don't have a real IOSession to close.
         //  The alternative is to fully implement the TestIOSession to return a CloseFuture from close();

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java Mon Sep 19 15:13:18 2011
@@ -20,7 +20,6 @@
  */
 package org.apache.qpid.server.queue;
 
-import org.apache.mina.common.ByteBuffer;
 import org.apache.qpid.AMQException;
 import org.apache.qpid.framing.AMQShortString;
 import org.apache.qpid.framing.ContentHeaderBody;
@@ -289,7 +288,7 @@ public class AMQQueueAlertTest extends I
     protected void configure()
     {
         // Increase Alert Check period
-        getConfiguration().setHousekeepingExpiredMessageCheckPeriod(200);
+        getConfiguration().setHousekeepingCheckPeriod(200);
     }
 
     private void sendMessages(AMQChannel channel, long messageCount, final long size) throws AMQException
@@ -312,18 +311,14 @@ public class AMQQueueAlertTest extends I
         {
             messages[i].addContentBodyFrame(new ContentChunk(){
 
-                ByteBuffer _data = ByteBuffer.allocate((int)size);
-
-                {
-                    _data.limit((int)size);
-                }
+                byte[] _data = new byte[(int)size];
 
                 public int getSize()
                 {
                     return (int) size;
                 }
 
-                public ByteBuffer getData()
+                public byte[] getData()
                 {
                     return _data;
                 }

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java Mon Sep 19 15:13:18 2011
@@ -37,7 +37,6 @@ import org.apache.qpid.server.subscripti
 import org.apache.qpid.server.protocol.InternalTestProtocolSession;
 import org.apache.qpid.server.registry.ApplicationRegistry;
 import org.apache.qpid.server.store.TestableMemoryMessageStore;
-import org.apache.mina.common.ByteBuffer;
 
 import javax.management.JMException;
 
@@ -275,18 +274,14 @@ public class AMQQueueMBeanTest extends I
 
         msg.addContentBodyFrame(new ContentChunk()
         {
-            ByteBuffer _data = ByteBuffer.allocate((int)MESSAGE_SIZE);
-
-            {
-                _data.limit((int)MESSAGE_SIZE);
-            }
+            byte[] _data = new byte[((int)MESSAGE_SIZE)];
 
             public int getSize()
             {
                 return (int) MESSAGE_SIZE;
             }
 
-            public ByteBuffer getData()
+            public byte[] getData()
             {
                 return _data;
             }
@@ -441,8 +436,7 @@ public class AMQQueueMBeanTest extends I
                     getSession().getMethodRegistry()
                                                        .getProtocolVersionMethodConverter()
                                                        .convertToContentChunk(
-                                                       new ContentBody(ByteBuffer.allocate((int) MESSAGE_SIZE),
-                                                                       MESSAGE_SIZE)));
+                                                       new ContentBody(new byte[(int) MESSAGE_SIZE])));
 
             AMQMessage m = new AMQMessage(currentMessage.getStoredMessage());
             for(BaseQueue q : currentMessage.getDestinationQueues())

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java Mon Sep 19 15:13:18 2011
@@ -29,7 +29,7 @@ import org.apache.qpid.server.subscripti
 import org.apache.qpid.server.virtualhost.VirtualHost;
 import org.apache.qpid.server.management.ManagedObject;
 import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.security.PrincipalHolder;
+import org.apache.qpid.server.security.AuthorizationHolder;
 import org.apache.qpid.server.AMQChannel;
 import org.apache.qpid.server.protocol.AMQSessionModel;
 import org.apache.qpid.server.binding.Binding;
@@ -48,7 +48,7 @@ public class MockAMQQueue implements AMQ
     private AMQShortString _name;
     private VirtualHost _virtualhost;
 
-    private PrincipalHolder _principalHolder;
+    private AuthorizationHolder _authorizationHolder;
 
     private AMQSessionModel _exclusiveOwner;
     private AMQShortString _owner;
@@ -536,14 +536,14 @@ public class MockAMQQueue implements AMQ
         return null;  //To change body of implemented methods use File | Settings | File Templates.
     }
 
-    public PrincipalHolder getPrincipalHolder()
+    public AuthorizationHolder getAuthorizationHolder()
     {
-        return _principalHolder;
+        return _authorizationHolder;
     }
 
-    public void setPrincipalHolder(PrincipalHolder principalHolder)
+    public void setAuthorizationHolder(final AuthorizationHolder authorizationHolder)
     {
-        _principalHolder = principalHolder;
+        _authorizationHolder = authorizationHolder;
     }
 
     public AMQSessionModel getExclusiveOwningSession()

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java Mon Sep 19 15:13:18 2011
@@ -139,7 +139,7 @@ public class MockQueueEntry implements Q
     }
 
 
-    public boolean isRejectedBy(Subscription subscription)
+    public boolean isRejectedBy(long subscriptionId)
     {
 
         return false;
@@ -153,13 +153,6 @@ public class MockQueueEntry implements Q
     }
 
 
-    public void reject(Subscription subscription)
-    {
-
-
-    }
-
-
     public void release()
     {
 

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java Mon Sep 19 15:13:18 2011
@@ -26,6 +26,7 @@ import org.apache.qpid.AMQException;
 import org.apache.qpid.server.message.AMQMessage;
 import org.apache.qpid.server.queue.QueueEntry.EntryState;
 import org.apache.qpid.server.subscription.MockSubscription;
+import org.apache.qpid.server.subscription.Subscription;
 
 /**
  * Tests for {@link QueueEntryImpl}
@@ -210,4 +211,37 @@ public class QueueEntryImplTest extends 
         }
         return state;
     }
+
+    /**
+     * Tests rejecting a queue entry records the Subscription ID
+     * for later verification by isRejectedBy(subscriptionId).
+     */
+    public void testRejectAndRejectedBy()
+    {
+        Subscription sub = new MockSubscription();
+        long subId = sub.getSubscriptionID();
+
+        assertFalse("Queue entry should not yet have been rejected by the subscription", _queueEntry.isRejectedBy(subId));
+        assertFalse("Queue entry should not yet have been acquired by a subscription", _queueEntry.isAcquired());
+
+        //acquire, reject, and release the message using the subscription
+        assertTrue("Queue entry should have been able to be acquired", _queueEntry.acquire(sub));
+        _queueEntry.reject();
+        _queueEntry.release();
+
+        //verify the rejection is recorded
+        assertTrue("Queue entry should have been rejected by the subscription", _queueEntry.isRejectedBy(subId));
+
+        //repeat rejection using a second subscription
+        Subscription sub2 = new MockSubscription();
+        long sub2Id = sub2.getSubscriptionID();
+
+        assertFalse("Queue entry should not yet have been rejected by the subscription", _queueEntry.isRejectedBy(sub2Id));
+        assertTrue("Queue entry should have been able to be acquired", _queueEntry.acquire(sub2));
+        _queueEntry.reject();
+
+        //verify it still records being rejected by both subscriptions
+        assertTrue("Queue entry should have been rejected by the subscription", _queueEntry.isRejectedBy(subId));
+        assertTrue("Queue entry should have been rejected by the subscription", _queueEntry.isRejectedBy(sub2Id));
+    }
 }

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java Mon Sep 19 15:13:18 2011
@@ -107,7 +107,7 @@ public class SimpleAMQQueueTest extends 
         ApplicationRegistry applicationRegistry = (ApplicationRegistry)ApplicationRegistry.getInstance();
 
         PropertiesConfiguration env = new PropertiesConfiguration();
-        _virtualHost = new VirtualHostImpl(new VirtualHostConfiguration(getClass().getName(), env), _store);
+        _virtualHost = new VirtualHostImpl(ApplicationRegistry.getInstance(), new VirtualHostConfiguration(getClass().getName(), env), _store);
         applicationRegistry.getVirtualHostRegistry().registerVirtualHost(_virtualHost);
 
         _queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(_qname, false, _owner, false, false, _virtualHost, _arguments);

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java Mon Sep 19 15:13:18 2011
@@ -20,6 +20,10 @@
  */
 package org.apache.qpid.server.security.auth.manager;
 
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
 import java.security.Provider;
 import java.security.Security;
 
@@ -27,8 +31,13 @@ import javax.security.auth.Subject;
 import javax.security.sasl.SaslException;
 import javax.security.sasl.SaslServer;
 
+import org.apache.commons.configuration.CompositeConfiguration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
 import org.apache.qpid.server.security.auth.AuthenticationResult;
 import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
+import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
 import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
 import org.apache.qpid.server.util.InternalBrokerBaseCase;
 
@@ -39,8 +48,10 @@ import org.apache.qpid.server.util.Inter
  */
 public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBaseCase
 {
-    private PrincipalDatabaseAuthenticationManager _manager = null;
-    
+    private AuthenticationManager _manager = null; // Class under test
+    private String TEST_USERNAME = "guest";
+    private String TEST_PASSWORD = "guest";
+
     /**
      * @see org.apache.qpid.server.util.InternalBrokerBaseCase#tearDown()
      */
@@ -62,7 +73,79 @@ public class PrincipalDatabaseAuthentica
     {
         super.setUp();
         
-        _manager = new PrincipalDatabaseAuthenticationManager();
+        final String passwdFilename = createPasswordFile().getCanonicalPath();
+        final ConfigurationPlugin config = getConfig(PlainPasswordFilePrincipalDatabase.class.getName(),
+                "passwordFile", passwdFilename);
+
+        _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(config);
+    }
+
+    /**
+     * Tests where the case where the config specifies a PD implementation
+     * that is not found.
+     */
+    public void testPrincipalDatabaseImplementationNotFound() throws Exception
+    {
+        try
+        {
+            _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig("not.Found", null, null));
+            fail("Exception not thrown");
+        }
+        catch (ConfigurationException ce)
+        {
+            // PASS
+        }
+    }
+
+    /**
+     * Tests where the case where the config specifies a PD implementation
+     * of the wrong type.
+     */
+    public void testPrincipalDatabaseImplementationWrongType() throws Exception
+    {
+        try
+        {
+            _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(String.class.getName(), null, null)); // Not a PrincipalDatabase implementation
+            fail("Exception not thrown");
+        }
+        catch (ConfigurationException ce)
+        {
+            // PASS
+        }
+    }
+
+    /**
+     * Tests the case where a setter with the desired name cannot be found.
+     */
+    public void testPrincipalDatabaseSetterNotFound() throws Exception
+    {
+        try
+        {
+            _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "noMethod", "test")); 
+            fail("Exception not thrown");
+        }
+        catch (ConfigurationException ce)
+        {
+            // PASS
+        }
+    }
+
+    /**
+     * QPID-1347. Make sure the exception message and stack trace is reasonable for an absent password file.
+     */
+    public void testPrincipalDatabaseThrowsSetterFileNotFound() throws Exception
+    {
+        try
+        {
+            _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "passwordFile", "/not/found")); 
+            fail("Exception not thrown");
+        }
+        catch (ConfigurationException ce)
+        {
+            // PASS
+            assertNotNull("Expected an underlying cause", ce.getCause());
+            assertEquals(FileNotFoundException.class, ce.getCause().getClass());
+        }
     }
 
     /**
@@ -72,8 +155,8 @@ public class PrincipalDatabaseAuthentica
     {
         assertNotNull(_manager.getMechanisms());
         // relies on those mechanisms attached to PropertiesPrincipalDatabaseManager
-        assertEquals("PLAIN CRAM-MD5", _manager.getMechanisms());
-    
+        assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms());
+
         Provider qpidProvider = Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME);
         assertNotNull(qpidProvider);
     }
@@ -166,11 +249,11 @@ public class PrincipalDatabaseAuthentica
      */
     public void testClose() throws Exception
     {
-        assertEquals("PLAIN CRAM-MD5", _manager.getMechanisms());
+        assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms());
         assertNotNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME));
-        
+
         _manager.close();
-        
+
         // Check provider has been removed.
         assertNull(_manager.getMechanisms());
         assertNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME));
@@ -228,4 +311,48 @@ public class PrincipalDatabaseAuthentica
             }
         };
     }
+
+    private ConfigurationPlugin getConfig(final String clazz, final String argName, final String argValue) throws Exception
+    {
+        final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
+
+        XMLConfiguration xmlconfig = new XMLConfiguration();
+        xmlconfig.addProperty("pd-auth-manager.principal-database.class", clazz);
+
+        if (argName != null)
+        {
+            xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.name", argName);
+            xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.value", argValue);
+        }
+
+        // Create a CompositeConfiguration as this is what the broker uses
+        CompositeConfiguration composite = new CompositeConfiguration();
+        composite.addConfiguration(xmlconfig);
+        config.setConfiguration("security", xmlconfig);
+        return config;
+    }
+
+    private File createPasswordFile() throws Exception
+    {
+        BufferedWriter writer = null;
+        try
+        {
+            File testFile = File.createTempFile(this.getClass().getName(),"tmp");
+            testFile.deleteOnExit();
+
+            writer = new BufferedWriter(new FileWriter(testFile));
+            writer.write(TEST_USERNAME + ":" + TEST_PASSWORD);
+            writer.newLine();
+ 
+            return testFile;
+
+        }
+        finally
+        {
+            if (writer != null)
+            {
+                writer.close();
+            }
+        }
+    }
 }

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java Mon Sep 19 15:13:18 2011
@@ -29,6 +29,7 @@ import javax.security.sasl.SaslServer;
 
 import junit.framework.TestCase;
 
+import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
 import org.apache.qpid.server.security.auth.AuthenticationResult;
 import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
 import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
@@ -210,6 +211,16 @@ public class RMIPasswordAuthenticatorTes
     {
         return new AuthenticationManager()
         {
+            public void configure(ConfigurationPlugin config)
+            {
+                throw new UnsupportedOperationException();
+            }
+
+            public void initialise()
+            {
+                throw new UnsupportedOperationException();
+            }
+
             public void close()
             {
                 throw new UnsupportedOperationException();
@@ -246,5 +257,4 @@ public class RMIPasswordAuthenticatorTes
             }
         };
     }
-
 }

Modified: qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java
URL: http://svn.apache.org/viewvc/qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java?rev=1172657&r1=1172656&r2=1172657&view=diff
==============================================================================
--- qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java (original)
+++ qpid/branches/qpid-3346/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java Mon Sep 19 15:13:18 2011
@@ -44,14 +44,13 @@ import org.apache.qpid.server.store.Mess
 import org.apache.qpid.server.store.TestableMemoryMessageStore;
 import org.apache.qpid.server.virtualhost.VirtualHost;
 import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.util.MockChannel;
 
 
 public class InternalBrokerBaseCase extends QpidTestCase
 {
     private IApplicationRegistry _registry;
     private MessageStore _messageStore;
-    private MockChannel _channel;
+    private AMQChannel _channel;
     private InternalTestProtocolSession _session;
     private VirtualHost _virtualHost;
     private AMQQueue _queue;
@@ -111,7 +110,7 @@ public class InternalBrokerBaseCase exte
         _session = new InternalTestProtocolSession(_virtualHost);
         CurrentActor.set(_session.getLogActor());
 
-        _channel = new MockChannel(_session, 1, _messageStore);
+        _channel = new AMQChannel(_session, 1, _messageStore);
 
         _session.addChannel(_channel);
     }
@@ -283,12 +282,12 @@ public class InternalBrokerBaseCase exte
         _messageStore = messageStore;
     }
 
-    public MockChannel getChannel()
+    public AMQChannel getChannel()
     {
         return _channel;
     }
 
-    public void setChannel(MockChannel channel)
+    public void setChannel(AMQChannel channel)
     {
         _channel = channel;
     }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message