ARTEMIS-3800 allow CLI to delete address with queues
This commit is contained in:
parent
49102443f6
commit
bcfff61e17
|
@ -18,6 +18,7 @@
|
|||
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;
|
||||
|
@ -25,6 +26,9 @@ 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 @@ public class DeleteAddress extends AddressAbstract {
|
|||
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 class DeleteAddress extends AddressAbstract {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setForce(Boolean force) {
|
||||
this.force = force;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,11 @@ import java.util.EnumSet;
|
|||
|
||||
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.ShowAddress;
|
|||
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 class AddressCommandTest extends JMSTestBase {
|
|||
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";
|
||||
|
|
Loading…
Reference in New Issue