[ 
https://issues.apache.org/jira/browse/ARTEMIS-2124?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16676918#comment-16676918
 ] 

Justin Bertram commented on ARTEMIS-2124:
-----------------------------------------

[~johan1], yes it should.  I modified your test a bit to make it a bit more 
efficient and also to fit it with the way things are done in the Artemis 
test-suite.  Everything works as expected (including the removal of the queue 
on broker B after the consumer disconnects).  Here's my modified test:

{code:java}
/*
 * 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.artemis.tests.integration.client;

import javax.jms.JMSContext;
import java.util.Arrays;

import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
import org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration;
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.ActiveMQServers;
import org.apache.activemq.artemis.core.server.cluster.ClusterConnection;
import 
org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.junit.Wait;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.qpid.jms.JmsConnectionFactory;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Artemis2124_AutoDeleteTest extends ActiveMQTestBase {

   private ActiveMQServer brokerA;
   private final int brokerAPort = 5671;
   private ActiveMQServer brokerB;
   private final int brokerBPort = 5672;
   private final SimpleString queueName = new SimpleString("myQueue");

   private ActiveMQServer createClusterMember(final int port) throws Exception {
      final ActiveMQServer broker = 
addServer(ActiveMQServers.newActiveMQServer(new ConfigurationImpl()
                                                                                
   .setPersistenceEnabled(false)
                                                                                
   .setSecurityEnabled(false)
                                                                                
   .addAcceptorConfiguration("test", "tcp://localhost:" + port)

                                                                                
   /*
                                                                                
    * queue config
                                                                                
    */
                                                                                
   .addAddressesSetting(queueName.toString(), new AddressSettings()
                                                                                
      .setRedistributionDelay(0)
                                                                                
      .setDefaultMaxConsumers(-1)
                                                                                
      .setAutoCreateAddresses(true)
                                                                                
      .setAutoCreateQueues(true)
                                                                                
      .setAutoDeleteAddresses(true)
                                                                                
      .setAutoCreateQueues(true)
                                                                                
      .setDefaultPurgeOnNoConsumers(false)
                                                                                
      .setDefaultAddressRoutingType(RoutingType.ANYCAST)
                                                                                
      .setDefaultQueueRoutingType(RoutingType.ANYCAST))

                                                                                
   /*
                                                                                
    * cluster config
                                                                                
    */
                                                                                
   .addConnectorConfiguration("test", "tcp://localhost:" + port)
                                                                                
   .addBroadcastGroupConfiguration(new BroadcastGroupConfiguration()
                                                                                
                                      .setName("broadcast-group")
                                                                                
                                      .setBroadcastPeriod(2000)
                                                                                
                                      .setConnectorInfos(Arrays.asList("test"))
                                                                                
                                      .setEndpointFactory(new 
UDPBroadcastEndpointFactory()
                                                                                
                                                             
.setLocalBindAddress("127.0.0.1")
                                                                                
                                                             
.setLocalBindPort(port)
                                                                                
                                                             
.setGroupAddress("231.7.7.7")
                                                                                
                                                             
.setGroupPort(9876)))
                                                                                
   .addDiscoveryGroupConfiguration("discovery-group", new 
DiscoveryGroupConfiguration()
                                                                                
      .setName("discovery-group")
                                                                                
      .setDiscoveryInitialWaitTimeout(1000)
                                                                                
      .setRefreshTimeout(10000)
                                                                                
      .setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory()
                                                                                
                                      .setLocalBindAddress("127.0.0.1")
                                                                                
                                      .setLocalBindPort(port)
                                                                                
                                      .setGroupAddress("231.7.7.7")
                                                                                
                                      .setGroupPort(9876)))
                                                                                
   .setClusterUser("cluster")
                                                                                
   .setClusterPassword("secret")
                                                                                
   .addClusterConfiguration(new ClusterConnectionConfiguration()
                                                                                
                               .setName("cluster")
                                                                                
                               .setDiscoveryGroupName("discovery-group")
                                                                                
                               .setConnectorName("test")
                                                                                
                               .setCallTimeout(15000)
                                                                                
                               .setDuplicateDetection(true)
                                                                                
                               
.setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND)
                                                                                
                               .setMaxHops(1))));
      System.out.println("Starting broker with AMQP port " + port + "...");
      broker.start();
      return broker;
   }

   @Before
   public void setup() throws Exception {
      brokerA = createClusterMember(brokerAPort);
      brokerB = createClusterMember(brokerBPort);

      assertTrue(Wait.waitFor(() -> 
((ClusterConnection)brokerA.getClusterManager().getClusterConnections().toArray()[0]).getNodes().size()
 == 1, 3000, 100));
      assertTrue(Wait.waitFor(() -> 
((ClusterConnection)brokerB.getClusterManager().getClusterConnections().toArray()[0]).getNodes().size()
 == 1, 3000, 100));
   }

   private void sendAndReceive(final String senderURL,
                               final String receiverURL) throws Exception {
      assertNull(brokerA.locateQueue(queueName));
      assertNull(brokerB.locateQueue(queueName));

      try (JMSContext sender = new 
JmsConnectionFactory(senderURL).createContext();
           JMSContext receiver = new 
JmsConnectionFactory(receiverURL).createContext()) {

         System.out.println("Sending message to " + senderURL + "...");
         sender.createProducer().send(sender.createQueue(queueName.toString()), 
sender.createBytesMessage());
         receiver.start();
         System.out.println("Waiting for message to be received from " + 
receiverURL + "...");
         
assertNotNull(receiver.createConsumer(receiver.createQueue(queueName.toString())).receive(1000));
      }
   }

   @Test
   public void testAutoDelete_SingleServerMessaging() throws Exception {
      sendAndReceive("amqp://localhost:" + brokerAPort, "amqp://localhost:" + 
brokerAPort);
      assertTrue(Wait.waitFor(() -> brokerA.locateQueue(queueName) == null, 
2000, 100));
   }

   @Test
   public void testAutoDelete_ClusterMessaging() throws Exception {
      sendAndReceive("amqp://localhost:" + brokerAPort, "amqp://localhost:" + 
brokerBPort);
      assertTrue(Wait.waitFor(() -> brokerB.locateQueue(queueName) == null, 
2000, 100));
   }
}
{code}

> Addresses/Queues are not auto-deleted in clusters
> -------------------------------------------------
>
>                 Key: ARTEMIS-2124
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-2124
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>          Components: Broker
>    Affects Versions: 2.6.3
>            Reporter: Johan Stenberg
>            Priority: Major
>         Attachments: Artemis2124_AutoDeleteTest.java
>
>
> All addresses and queues in one of our production cluster environment are 
> configured as auto create/delete addresses and queues, however non of the 
> addresses and queues are never seem to get auto-deleted.
> I am attaching a test case that I believe reproduces the issue.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to