Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 11336 invoked from network); 15 Jun 2010 14:07:30 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Jun 2010 14:07:30 -0000 Received: (qmail 24340 invoked by uid 500); 15 Jun 2010 14:07:30 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 24268 invoked by uid 500); 15 Jun 2010 14:07:30 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 24259 invoked by uid 99); 15 Jun 2010 14:07:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jun 2010 14:07:29 +0000 X-ASF-Spam-Status: No, hits=-1517.5 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jun 2010 14:07:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 85A4823888E8; Tue, 15 Jun 2010 14:06:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r954893 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/jmx/DurableSubscriptionView.java test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.java Date: Tue, 15 Jun 2010 14:06:43 -0000 To: commits@activemq.apache.org From: dejanb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100615140643.85A4823888E8@eris.apache.org> Author: dejanb Date: Tue Jun 15 14:06:43 2010 New Revision: 954893 URL: http://svn.apache.org/viewvc?rev=954893&view=rev Log: https://issues.apache.org/activemq/browse/AMQ-2770 - durable subscription mbean Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.java Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DurableSubscriptionView.java Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DurableSubscriptionView.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DurableSubscriptionView.java?rev=954893&r1=954892&r2=954893&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DurableSubscriptionView.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DurableSubscriptionView.java Tue Jun 15 14:06:43 2010 @@ -142,4 +142,11 @@ public class DurableSubscriptionView ext } return false; } + + @Override + public boolean isActive() { + return durableSub.isActive(); + } + + } Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.java?rev=954893&view=auto ============================================================================== --- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.java (added) +++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.java Tue Jun 15 14:06:43 2010 @@ -0,0 +1,119 @@ +/** + * 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.activemq.usecases; + +import java.io.File; +import java.lang.management.ManagementFactory; + +import javax.jms.Connection; +import javax.jms.Session; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.command.ActiveMQTopic; +import org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter; + +public class ManagedDurableSubscriptionTest extends org.apache.activemq.TestSupport { + + BrokerService broker = null; + Connection connection = null; + ActiveMQTopic topic; + + public void testJMXSubscriptions() throws Exception { + // create durable subscription + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + session.createDurableSubscriber(topic, "SubsId"); + session.close(); + + // restart the broker + stopBroker(); + startBroker(); + + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + ObjectName subscriptionObjectName = broker.getAdminView().getDurableTopicSubscribers()[0]; + + Object active = mbs.getAttribute(subscriptionObjectName, "Active"); + assertTrue("Subscription is active.", Boolean.FALSE.equals(active)); + + // activate + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + session.createDurableSubscriber(topic, "SubsId"); + + active = mbs.getAttribute(subscriptionObjectName, "Active"); + assertTrue("Subscription is INactive.", Boolean.TRUE.equals(active)); + + // deactivate + connection.close(); + connection = null; + + active = mbs.getAttribute(subscriptionObjectName, "Active"); + assertTrue("Subscription is active.", Boolean.FALSE.equals(active)); + + } + + private void startBroker() throws Exception { + broker = BrokerFactory.createBroker("broker:(vm://localhost)"); + broker.setKeepDurableSubsActive(false); + broker.setPersistent(true); + KahaPersistenceAdapter persistenceAdapter = new KahaPersistenceAdapter(); + persistenceAdapter.setDirectory(new File("activemq-data/" + getName())); + broker.setPersistenceAdapter(persistenceAdapter); + broker.setUseJmx(true); + broker.setBrokerName(getName()); + broker.start(); + + connection = createConnection(); + } + + private void stopBroker() throws Exception { + if (connection != null) + connection.close(); + connection = null; + if (broker != null) + broker.stop(); + broker = null; + } + + protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { + return new ActiveMQConnectionFactory("vm://" + getName() + "?waitForStart=5000&create=false"); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + topic = (ActiveMQTopic) createDestination(); + startBroker(); + } + + @Override + protected void tearDown() throws Exception { + stopBroker(); + super.tearDown(); + } + + @Override + protected Connection createConnection() throws Exception { + Connection rc = super.createConnection(); + rc.setClientID(getName()); + rc.start(); + return rc; + } +}