Search in sources :

Example 6 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class AddressControlTest method testGetRoles.

@Test
public void testGetRoles() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    Role role = new Role(RandomUtil.randomString(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean());
    session.createQueue(address, queue, true);
    AddressControl addressControl = createManagementControl(address);
    Object[] roles = addressControl.getRoles();
    Assert.assertEquals(0, roles.length);
    Set<Role> newRoles = new HashSet<>();
    newRoles.add(role);
    server.getSecurityRepository().addMatch(address.toString(), newRoles);
    roles = addressControl.getRoles();
    Assert.assertEquals(1, roles.length);
    Object[] r = (Object[]) roles[0];
    Assert.assertEquals(role.getName(), r[0]);
    Assert.assertEquals(CheckType.SEND.hasRole(role), r[1]);
    Assert.assertEquals(CheckType.CONSUME.hasRole(role), r[2]);
    Assert.assertEquals(CheckType.CREATE_DURABLE_QUEUE.hasRole(role), r[3]);
    Assert.assertEquals(CheckType.DELETE_DURABLE_QUEUE.hasRole(role), r[4]);
    Assert.assertEquals(CheckType.CREATE_NON_DURABLE_QUEUE.hasRole(role), r[5]);
    Assert.assertEquals(CheckType.DELETE_NON_DURABLE_QUEUE.hasRole(role), r[6]);
    Assert.assertEquals(CheckType.MANAGE.hasRole(role), r[7]);
    session.deleteQueue(queue);
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class AddressControlTest method testGetAddress.

@Test
public void testGetAddress() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, false);
    AddressControl addressControl = createManagementControl(address);
    Assert.assertEquals(address.toString(), addressControl.getAddress());
    session.deleteQueue(queue);
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 8 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class ActiveMQServerControlTest method testCreateAndDestroyQueue_4.

@Test
public void testCreateAndDestroyQueue_4() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();
    boolean durable = RandomUtil.randomBoolean();
    boolean purgeOnNoConsumers = RandomUtil.randomBoolean();
    boolean autoCreateAddress = true;
    int maxConsumers = RandomUtil.randomInt();
    ActiveMQServerControl serverControl = createManagementControl();
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    serverControl.createQueue(address.toString(), RoutingType.ANYCAST.toString(), name.toString(), null, durable, maxConsumers, purgeOnNoConsumers, autoCreateAddress);
    checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, RoutingType.ANYCAST, mbeanServer);
    Assert.assertEquals(address.toString(), queueControl.getAddress());
    Assert.assertEquals(name.toString(), queueControl.getName());
    Assert.assertNull(queueControl.getFilter());
    Assert.assertEquals(durable, queueControl.isDurable());
    Assert.assertEquals(purgeOnNoConsumers, queueControl.isPurgeOnNoConsumers());
    Assert.assertEquals(maxConsumers, queueControl.getMaxConsumers());
    Assert.assertEquals(false, queueControl.isTemporary());
    checkResource(ObjectNameBuilder.DEFAULT.getAddressObjectName(address));
    AddressControl addressControl = ManagementControlHelper.createAddressControl(address, mbeanServer);
    Assert.assertEquals(address.toString(), addressControl.getAddress());
    serverControl.destroyQueue(name.toString(), true, true);
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    checkNoResource(ObjectNameBuilder.DEFAULT.getAddressObjectName(address));
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 9 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class TopicControlClusterTest method testClusteredSubscriptionCount.

@Test
public void testClusteredSubscriptionCount() throws Exception {
    final String topicName = "t1";
    final SimpleString simpleTopicName = SimpleString.toSimpleString(topicName);
    try (Connection conn1 = cf1.createConnection();
        Connection conn2 = cf2.createConnection()) {
        conn1.setClientID("someClient1");
        conn2.setClientID("someClient2");
        Topic topic1 = createTopic(topicName);
        Topic topic2 = (Topic) context2.lookup("/topic/" + topicName);
        Session session1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        session1.createDurableSubscriber(topic1, "sub1_1");
        session1.createDurableSubscriber(topic1, "sub1_2");
        Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        session2.createDurableSubscriber(topic2, "sub2");
        AddressControl topicControl1 = ManagementControlHelper.createAddressControl(simpleTopicName, mBeanServer1);
        AddressControl topicControl2 = ManagementControlHelper.createAddressControl(simpleTopicName, mBeanServer2);
        assertTrue("There should be 3 subscriptions on the topic, 2 local and 1 remote.", Wait.waitFor(() -> topicControl1.getQueueNames().length == 3, 2000));
        assertTrue("There should be 3 subscriptions on the topic, 1 local and 2 remote.", Wait.waitFor(() -> topicControl2.getQueueNames().length == 3, 2000));
    }
    jmsServer1.destroyTopic("t1");
    jmsServer2.destroyTopic("t1");
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Topic(javax.jms.Topic) Session(javax.jms.Session) Test(org.junit.Test)

Example 10 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class BridgeTestBase method checkNoSubscriptions.

protected void checkNoSubscriptions(final Topic topic, final int index) throws Exception {
    ManagementService managementService = server0.getManagementService();
    if (index == 1) {
        managementService = server1.getManagementService();
    }
    AddressControl topicControl = (AddressControl) managementService.getResource(ResourceNames.ADDRESS + topic.getTopicName());
    if (topicControl != null) {
        Assert.assertEquals(0, topicControl.getQueueNames().length);
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService)

Aggregations

AddressControl (org.apache.activemq.artemis.api.core.management.AddressControl)29 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)21 Test (org.junit.Test)18 HashSet (java.util.HashSet)5 Connection (javax.jms.Connection)5 Session (javax.jms.Session)5 JsonString (javax.json.JsonString)5 RandomUtil.randomString (org.apache.activemq.artemis.tests.util.RandomUtil.randomString)5 OperationFailedException (org.jboss.as.controller.OperationFailedException)5 ManagementService (org.apache.activemq.artemis.core.server.management.ManagementService)4 PathAddress (org.jboss.as.controller.PathAddress)4 TextMessage (javax.jms.TextMessage)3 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)3 ModelNode (org.jboss.dmr.ModelNode)3 ServiceName (org.jboss.msc.service.ServiceName)3 BytesMessage (javax.jms.BytesMessage)2 MapMessage (javax.jms.MapMessage)2 Message (javax.jms.Message)2 MessageConsumer (javax.jms.MessageConsumer)2 ObjectMessage (javax.jms.ObjectMessage)2