Search in sources :

Example 21 with AddressControl

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

the class AddressControlTest method testGetRolesAsJSON.

@Test
public void testGetRolesAsJSON() 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);
    String jsonString = addressControl.getRolesAsJSON();
    Assert.assertNotNull(jsonString);
    RoleInfo[] roles = RoleInfo.from(jsonString);
    Assert.assertEquals(0, roles.length);
    Set<Role> newRoles = new HashSet<>();
    newRoles.add(role);
    server.getSecurityRepository().addMatch(address.toString(), newRoles);
    jsonString = addressControl.getRolesAsJSON();
    Assert.assertNotNull(jsonString);
    roles = RoleInfo.from(jsonString);
    Assert.assertEquals(1, roles.length);
    RoleInfo r = roles[0];
    Assert.assertEquals(role.getName(), roles[0].getName());
    Assert.assertEquals(role.isSend(), r.isSend());
    Assert.assertEquals(role.isConsume(), r.isConsume());
    Assert.assertEquals(role.isCreateDurableQueue(), r.isCreateDurableQueue());
    Assert.assertEquals(role.isDeleteDurableQueue(), r.isDeleteDurableQueue());
    Assert.assertEquals(role.isCreateNonDurableQueue(), r.isCreateNonDurableQueue());
    Assert.assertEquals(role.isDeleteNonDurableQueue(), r.isDeleteNonDurableQueue());
    Assert.assertEquals(role.isManage(), r.isManage());
    session.deleteQueue(queue);
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) RoleInfo(org.apache.activemq.artemis.api.core.management.RoleInfo) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RandomUtil.randomString(org.apache.activemq.artemis.tests.util.RandomUtil.randomString) JsonString(javax.json.JsonString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with AddressControl

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

the class AddressControlTest method testGetRoutingTypes.

@Test
public void testGetRoutingTypes() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    session.createAddress(address, RoutingType.ANYCAST, false);
    AddressControl addressControl = createManagementControl(address);
    String[] routingTypes = addressControl.getRoutingTypes();
    Assert.assertEquals(1, routingTypes.length);
    Assert.assertEquals(RoutingType.ANYCAST.toString(), routingTypes[0]);
    address = RandomUtil.randomSimpleString();
    EnumSet<RoutingType> types = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
    session.createAddress(address, types, false);
    addressControl = createManagementControl(address);
    routingTypes = addressControl.getRoutingTypes();
    Set<String> strings = new HashSet<>(Arrays.asList(routingTypes));
    Assert.assertEquals(2, strings.size());
    Assert.assertTrue(strings.contains(RoutingType.ANYCAST.toString()));
    Assert.assertTrue(strings.contains(RoutingType.MULTICAST.toString()));
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RandomUtil.randomString(org.apache.activemq.artemis.tests.util.RandomUtil.randomString) JsonString(javax.json.JsonString) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with AddressControl

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

the class AddressControlTest method testGetBindingNames.

@Test
public void testGetBindingNames() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    String divertName = RandomUtil.randomString();
    session.createQueue(address, queue, false);
    AddressControl addressControl = createManagementControl(address);
    String[] bindingNames = addressControl.getBindingNames();
    assertEquals(1, bindingNames.length);
    assertEquals(queue.toString(), bindingNames[0]);
    server.getActiveMQServerControl().createDivert(divertName, randomString(), address.toString(), RandomUtil.randomString(), false, null, null);
    bindingNames = addressControl.getBindingNames();
    Assert.assertEquals(2, bindingNames.length);
    session.deleteQueue(queue);
    bindingNames = addressControl.getBindingNames();
    assertEquals(1, bindingNames.length);
    assertEquals(divertName.toString(), bindingNames[0]);
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RandomUtil.randomString(org.apache.activemq.artemis.tests.util.RandomUtil.randomString) JsonString(javax.json.JsonString) Test(org.junit.Test)

Example 24 with AddressControl

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

the class AdvisoryOpenWireTest method testTempQueueLeakManyConnections.

@Test
public void testTempQueueLeakManyConnections() throws Exception {
    final Connection[] connections = new Connection[20];
    try {
        for (int i = 0; i < connections.length; i++) {
            connections[i] = factory.createConnection();
            connections[i].start();
        }
        Session session = connections[0].createSession(false, Session.AUTO_ACKNOWLEDGE);
        for (int i = 0; i < connections.length; i++) {
            TemporaryQueue temporaryQueue = session.createTemporaryQueue();
            temporaryQueue.delete();
        }
        Object[] addressResources = server.getManagementService().getResources(AddressControl.class);
        for (Object addressResource : addressResources) {
            if (((AddressControl) addressResource).getAddress().equals("ActiveMQ.Advisory.TempQueue")) {
                AddressControl addressControl = (AddressControl) addressResource;
                Wait.waitFor(() -> addressControl.getMessageCount() == 0);
                assertNotNull("addressControl for temp advisory", addressControl);
                Wait.assertEquals(0, addressControl::getMessageCount);
            }
        }
    // sleep a bit to allow message count to go down.
    } finally {
        for (Connection conn : connections) {
            if (conn != null) {
                conn.close();
            }
        }
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) Session(javax.jms.Session) Test(org.junit.Test)

Example 25 with AddressControl

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

the class ExpiryMessageTest method testSendTopicNoSubscription.

@Test
public void testSendTopicNoSubscription() throws Exception {
    Topic topic = createTopic("test-topic");
    AddressControl control = ManagementControlHelper.createAddressControl(new SimpleString(topic.getTopicName()), mbeanServer);
    Connection conn2 = cf.createConnection();
    conn2.setClientID("client1");
    Session sess2 = conn2.createSession(true, Session.SESSION_TRANSACTED);
    sess2.createDurableSubscriber(topic, "client-sub1");
    sess2.createDurableSubscriber(topic, "client-sub2");
    conn2.close();
    conn = cf.createConnection();
    Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
    MessageProducer prod = sess.createProducer(topic);
    prod.setTimeToLive(1000);
    for (int i = 0; i < 100; i++) {
        TextMessage txt = sess.createTextMessage("txt");
        prod.send(txt);
    }
    sess.commit();
    conn.close();
    // minimal time needed
    Thread.sleep(2000);
    long timeout = System.currentTimeMillis() + 10000;
    // We will wait some time, but we will wait as minimal as possible
    while (control.getMessageCount() != 0 && System.currentTimeMillis() > timeout) {
        Thread.sleep(100);
    }
    assertEquals(0, control.getMessageCount());
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

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