Skip to content
Permalink
Browse files
ARTEMIS-3800 allow CLI to delete address with queues
  • Loading branch information
jbertram authored and clebertsuconic committed Apr 25, 2022
1 parent 4910244 commit bcfff61e1754f00f555c18d6085b4777ccc7015a
Showing 2 changed files with 39 additions and 1 deletion.
@@ -18,13 +18,17 @@
package org.apache.activemq.artemis.cli.commands.address;

import io.airlift.airline.Command;
import io.airlift.airline.Option;
import org.apache.activemq.artemis.api.core.client.ClientMessage;
import org.apache.activemq.artemis.api.core.management.ManagementHelper;
import org.apache.activemq.artemis.cli.commands.ActionContext;

@Command(name = "delete", description = "delete an address")
public class DeleteAddress extends AddressAbstract {

@Option(name = "--force", description = "delete the address even if it has queues - all messages in those queues will be deleted! (default false)")
private Boolean force = false;

@Override
public Object execute(ActionContext context) throws Exception {
super.execute(context);
@@ -36,7 +40,7 @@ private void deleteAddress(final ActionContext context) throws Exception {
performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
ManagementHelper.putOperationInvocation(message, "broker", "deleteAddress", getName(true));
ManagementHelper.putOperationInvocation(message, "broker", "deleteAddress", getName(true), force);
}

@Override
@@ -51,4 +55,8 @@ public void requestFailed(ClientMessage reply) throws Exception {
}
});
}

public void setForce(Boolean force) {
this.force = force;
}
}
@@ -23,6 +23,11 @@

import org.apache.activemq.artemis.api.core.QueueConfiguration;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.client.ClientProducer;
import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.cli.commands.AbstractAction;
import org.apache.activemq.artemis.cli.commands.ActionContext;
import org.apache.activemq.artemis.cli.commands.address.CreateAddress;
@@ -31,8 +36,10 @@
import org.apache.activemq.artemis.cli.commands.address.UpdateAddress;
import org.apache.activemq.artemis.core.config.DivertConfiguration;
import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
import org.apache.activemq.artemis.tests.util.JMSTestBase;
import org.apache.activemq.artemis.utils.Wait;
import org.junit.Before;
import org.junit.Test;

@@ -116,6 +123,29 @@ public void testFailDeleteAddressWhenExistsQueues() throws Exception {
checkExecutionFailure(deleteAddress, "Address " + addressName + " has bindings");
}

@Test
public void testForceDeleteAddressWhenExistsQueues() throws Exception {
final String addressName = "address";
final SimpleString addressSimpleString = new SimpleString(addressName);
final String queueName = "queue1";
final AddressInfo addressInfo = new AddressInfo(addressSimpleString, EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST));
server.addAddressInfo(addressInfo);
Queue queue = server.createQueue(new QueueConfiguration(new SimpleString(queueName)).setAddress(addressSimpleString).setRoutingType(RoutingType.MULTICAST));
ServerLocator locator = ActiveMQClient.createServerLocator("tcp://127.0.0.1:61616");
ClientSessionFactory csf = locator.createSessionFactory();
ClientSession session = csf.createSession();
ClientProducer producer = session.createProducer(addressName);
producer.send(session.createMessage(true));
Wait.assertEquals(1L, () -> queue.getMessageCount());

final DeleteAddress deleteAddress = new DeleteAddress();
deleteAddress.setName(addressName);
deleteAddress.setForce(true);
deleteAddress.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));
checkExecutionPassed(deleteAddress);
Wait.assertEquals(null, () -> server.locateQueue(queueName));
}

@Test
public void testShowAddress() throws Exception {
String address = "address";

0 comments on commit bcfff61

Please sign in to comment.