You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2011/06/26 15:55:12 UTC

svn commit: r1139793 - in /qpid/trunk/qpid/java/broker/src: main/java/org/apache/qpid/server/virtualhost/ test/java/org/apache/qpid/server/virtualhost/

Author: robbie
Date: Sun Jun 26 13:55:11 2011
New Revision: 1139793

URL: http://svn.apache.org/viewvc?rev=1139793&view=rev
Log:
QPID-3318: ensure the abstract HouseKeepingTask class removes the LogActor it adds to the stack

Added:
    qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java
    qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java?rev=1139793&r1=1139792&r2=1139793&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java Sun Jun 26 13:55:11 2011
@@ -63,6 +63,10 @@ public abstract class HouseKeepingTask i
         {
             _logger.warn(this.getClass().getSimpleName() + " throw exception: " + e, e);
         }
+        finally
+        {
+            CurrentActor.remove();
+        }
     }
 
     public VirtualHost getVirtualHost()

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java?rev=1139793&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java Sun Jun 26 13:55:11 2011
@@ -0,0 +1,67 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.virtualhost;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.NullRootMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.TestLogActor;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class HouseKeepingTaskTest extends QpidTestCase
+{
+    /**
+     * Tests that the abstract HouseKeepingTask properly cleans up any LogActor
+     * it adds to the CurrentActor stack by verifying the CurrentActor set
+     * before task execution is the CurrentActor after execution.
+     */
+    public void testCurrentActorStackBalance() throws Exception
+    {
+        //create and set a test actor
+        LogActor testActor = new TestLogActor(new NullRootMessageLogger());
+        CurrentActor.set(testActor);
+
+        //verify it is returned correctly before executing a HouseKeepingTask
+        assertEquals("Expected LogActor was not returned", testActor, CurrentActor.get());
+
+        final CountDownLatch latch = new CountDownLatch(1);
+        HouseKeepingTask testTask = new HouseKeepingTask(new MockVirtualHost("HouseKeepingTaskTestVhost"))
+        {
+            @Override
+            public void execute()
+            {
+                latch.countDown();
+            }
+        };
+
+        //run the test HouseKeepingTask using the current Thread to influence its CurrentActor stack
+        testTask.run();
+
+        assertEquals("The expected LogActor was not returned, the CurrentActor stack has become unbalanced",
+                     testActor, CurrentActor.get());
+        assertEquals("HouseKeepingTask execute() method was not run", 0, latch.getCount());
+
+        //clean up the test actor
+        CurrentActor.remove();
+    }
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java?rev=1139793&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java Sun Jun 26 13:55:11 2011
@@ -0,0 +1,271 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.virtualhost;
+
+import java.util.UUID;
+
+import org.apache.qpid.server.binding.BindingFactory;
+import org.apache.qpid.server.configuration.BrokerConfig;
+import org.apache.qpid.server.configuration.ConfigStore;
+import org.apache.qpid.server.configuration.ConfiguredObject;
+import org.apache.qpid.server.configuration.VirtualHostConfig;
+import org.apache.qpid.server.configuration.VirtualHostConfigType;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.connection.IConnectionRegistry;
+import org.apache.qpid.server.exchange.ExchangeFactory;
+import org.apache.qpid.server.exchange.ExchangeRegistry;
+import org.apache.qpid.server.federation.BrokerLink;
+import org.apache.qpid.server.management.ManagedObject;
+import org.apache.qpid.server.queue.QueueRegistry;
+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.stats.StatisticsCounter;
+import org.apache.qpid.server.store.DurableConfigurationStore;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.TransactionLog;
+
+public class MockVirtualHost implements VirtualHost
+{
+    private String _name;
+
+    public MockVirtualHost(String name)
+    {
+        _name = name;
+    }
+
+    public void close()
+    {
+
+    }
+
+    public void createBrokerConnection(String transport, String host, int port,
+            String vhost, boolean durable, String authMechanism,
+            String username, String password)
+    {
+
+    }
+
+    public IApplicationRegistry getApplicationRegistry()
+    {
+        return null;
+    }
+
+    public AuthenticationManager getAuthenticationManager()
+    {
+        return null;
+    }
+
+    public BindingFactory getBindingFactory()
+    {
+        return null;
+    }
+
+    public UUID getBrokerId()
+    {
+        return null;
+    }
+
+    public ConfigStore getConfigStore()
+    {
+        return null;
+    }
+
+    public VirtualHostConfiguration getConfiguration()
+    {
+        return null;
+    }
+
+    public IConnectionRegistry getConnectionRegistry()
+    {
+        return null;
+    }
+
+    public DurableConfigurationStore getDurableConfigurationStore()
+    {
+        return null;
+    }
+
+    public ExchangeFactory getExchangeFactory()
+    {
+        return null;
+    }
+
+    public ExchangeRegistry getExchangeRegistry()
+    {
+        return null;
+    }
+
+    public int getHouseKeepingActiveCount()
+    {
+        return 0;
+    }
+
+    public long getHouseKeepingCompletedTaskCount()
+    {
+        return 0;
+    }
+
+    public int getHouseKeepingPoolSize()
+    {
+        return 0;
+    }
+
+    public long getHouseKeepingTaskCount()
+    {
+        return 0;
+    }
+
+    public ManagedObject getManagedObject()
+    {
+        return null;
+    }
+
+    public MessageStore getMessageStore()
+    {
+        return null;
+    }
+
+    public String getName()
+    {
+        return _name;
+    }
+
+    public QueueRegistry getQueueRegistry()
+    {
+        return null;
+    }
+
+    public SecurityManager getSecurityManager()
+    {
+        return null;
+    }
+
+    public TransactionLog getTransactionLog()
+    {
+        return null;
+    }
+
+    public void removeBrokerConnection(BrokerLink brokerLink)
+    {
+
+    }
+
+    public void scheduleHouseKeepingTask(long period, HouseKeepingTask task)
+    {
+
+    }
+
+    public void setHouseKeepingPoolSize(int newSize)
+    {
+
+    }
+
+    public BrokerConfig getBroker()
+    {
+        return null;
+    }
+
+    public String getFederationTag()
+    {
+        return null;
+    }
+
+    public void setBroker(BrokerConfig brokerConfig)
+    {
+
+    }
+
+    public VirtualHostConfigType getConfigType()
+    {
+        return null;
+    }
+
+    public long getCreateTime()
+    {
+        return 0;
+    }
+
+    public UUID getId()
+    {
+        return null;
+    }
+
+    public ConfiguredObject<VirtualHostConfigType, VirtualHostConfig> getParent()
+    {
+        return null;
+    }
+
+    public boolean isDurable()
+    {
+        return false;
+    }
+
+    public StatisticsCounter getDataDeliveryStatistics()
+    {
+        return null;
+    }
+
+    public StatisticsCounter getDataReceiptStatistics()
+    {
+        return null;
+    }
+
+    public StatisticsCounter getMessageDeliveryStatistics()
+    {
+        return null;
+    }
+
+    public StatisticsCounter getMessageReceiptStatistics()
+    {
+        return null;
+    }
+
+    public void initialiseStatistics()
+    {
+
+    }
+
+    public boolean isStatisticsEnabled()
+    {
+        return false;
+    }
+
+    public void registerMessageDelivered(long messageSize)
+    {
+
+    }
+
+    public void registerMessageReceived(long messageSize, long timestamp)
+    {
+
+    }
+
+    public void resetStatistics()
+    {
+
+    }
+
+    public void setStatisticsEnabled(boolean enabled)
+    {
+
+    }
+}
\ No newline at end of file



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