Search in sources :

Example 26 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class ActiveMQServerControlTest method testListQueuesNumericFilter.

@Test
public void testListQueuesNumericFilter() throws Exception {
    SimpleString queueName1 = new SimpleString("my_queue_one");
    SimpleString queueName2 = new SimpleString("my_queue_two");
    SimpleString queueName3 = new SimpleString("one_consumer_queue_three");
    SimpleString queueName4 = new SimpleString("my_queue_four");
    ActiveMQServerControl serverControl = createManagementControl();
    server.addAddressInfo(new AddressInfo(queueName1, RoutingType.ANYCAST));
    server.createQueue(queueName1, RoutingType.ANYCAST, queueName1, null, false, false);
    server.addAddressInfo(new AddressInfo(queueName2, RoutingType.ANYCAST));
    server.createQueue(queueName2, RoutingType.ANYCAST, queueName2, null, false, false);
    server.addAddressInfo(new AddressInfo(queueName3, RoutingType.ANYCAST));
    server.createQueue(queueName3, RoutingType.ANYCAST, queueName3, null, false, false, 10, false, false);
    server.addAddressInfo(new AddressInfo(queueName4, RoutingType.ANYCAST));
    server.createQueue(queueName4, RoutingType.ANYCAST, queueName4, null, false, false);
    // create some consumers
    try (ServerLocator locator = createInVMNonHALocator();
        ClientSessionFactory csf = createSessionFactory(locator);
        ClientSession session = csf.createSession()) {
        session.start();
        ClientConsumer consumer1_q1 = session.createConsumer(queueName1);
        ClientConsumer consumer2_q1 = session.createConsumer(queueName1);
        ClientConsumer consumer1_q2 = session.createConsumer(queueName2);
        ClientConsumer consumer2_q2 = session.createConsumer(queueName2);
        ClientConsumer consumer3_q2 = session.createConsumer(queueName2);
        ClientConsumer consumer1_q3 = session.createConsumer(queueName3);
        ClientProducer clientProducer = session.createProducer(queueName1);
        ClientMessage message = session.createMessage(false);
        for (int i = 0; i < 10; i++) {
            clientProducer.send(message);
        }
        // consume one message
        ClientMessage messageReceived = consumer1_q1.receive(100);
        if (messageReceived == null) {
            fail("should have received a message");
        }
        messageReceived.acknowledge();
        session.commit();
        // test with CONTAINS returns nothing for numeric field
        String filterString = createJsonFilter("CONSUMER_COUNT", "CONTAINS", "0");
        String queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        JsonObject queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        JsonArray array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from query", 0, array.size());
        // test with LESS_THAN returns 1 queue
        filterString = createJsonFilter("CONSUMER_COUNT", "LESS_THAN", "1");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from LESS_THAN query", 1, array.size());
        Assert.assertEquals("correct queue returned from query", queueName4.toString(), array.getJsonObject(0).getString("name"));
        // test with GREATER_THAN returns 2 queue
        filterString = createJsonFilter("CONSUMER_COUNT", "GREATER_THAN", "2");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from GREATER_THAN query", 1, array.size());
        Assert.assertEquals("correct queue returned from query", queueName2.toString(), array.getJsonObject(0).getString("name"));
        // test with GREATER_THAN returns 2 queue
        filterString = createJsonFilter("CONSUMER_COUNT", "EQUALS", "3");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from EQUALS query", 1, array.size());
        Assert.assertEquals("correct queue returned from query", queueName2.toString(), array.getJsonObject(0).getString("name"));
        // test with MESSAGE_COUNT returns 2 queue
        filterString = createJsonFilter("MESSAGE_COUNT", "GREATER_THAN", "5");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from MESSAGE_COUNT query", 1, array.size());
        Assert.assertEquals("correct queue returned from query", queueName1.toString(), array.getJsonObject(0).getString("name"));
        // test with MESSAGE_ADDED returns 1 queue
        filterString = createJsonFilter("MESSAGES_ADDED", "GREATER_THAN", "5");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from MESSAGE_COUNT query", 1, array.size());
        Assert.assertEquals("correct queue returned from query", queueName1.toString(), array.getJsonObject(0).getString("name"));
        // test with DELIVERING_COUNT returns 1 queue
        filterString = createJsonFilter("DELIVERING_COUNT", "GREATER_THAN", "5");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from DELIVERING_COUNT query", 1, array.size());
        Assert.assertEquals("correct queue returned from query", queueName1.toString(), array.getJsonObject(0).getString("name"));
        // test with MESSAGE_ACKED returns 1 queue
        filterString = createJsonFilter("MESSAGES_ACKED", "GREATER_THAN", "0");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from MESSAGES_ACKED query", 1, array.size());
        Assert.assertEquals("correct queue returned from query", queueName1.toString(), array.getJsonObject(0).getString("name"));
        // test with MAX_CONSUMERS returns 1 queue
        filterString = createJsonFilter("MAX_CONSUMERS", "GREATER_THAN", "9");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from MAX_CONSUMERS query", 1, array.size());
        Assert.assertEquals("correct queue returned from query", queueName3.toString(), array.getJsonObject(0).getString("name"));
        // test with MESSAGES_KILLED returns 0 queue
        filterString = createJsonFilter("MESSAGES_KILLED", "GREATER_THAN", "0");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from MESSAGES_KILLED query", 0, array.size());
    }
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JsonObject(javax.json.JsonObject) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) JsonArray(javax.json.JsonArray) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 27 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class JmsConsumerTest method testConsumerAfterWildcardAddressRemoval.

/**
 * Test for ARTEMIS-1610
 * @throws Exception
 */
@Test
public void testConsumerAfterWildcardAddressRemoval() throws Exception {
    String queue1 = "queue.#";
    String topic1 = "durable.#";
    String topic2 = "durable.test";
    // Create a new address along with 1 queue for it (this cases a wildcard address to get registered
    // inside the WildcardAddressManager manager when the binding is created)
    server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(queue1), RoutingType.ANYCAST));
    server.createQueue(SimpleString.toSimpleString(queue1), RoutingType.ANYCAST, SimpleString.toSimpleString(queue1), null, false, false);
    // create addresses for both topics
    server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(topic1), RoutingType.MULTICAST));
    server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(topic2), RoutingType.MULTICAST));
    // Remove the wildcard address associated with topic2
    server.removeAddressInfo(SimpleString.toSimpleString(topic1), null);
    conn = cf.createConnection();
    conn.setClientID("clientId");
    conn.start();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Verify consumer can be created without issue - this caused a NPE
    // before ARTEMIS-1610
    sess.createConsumer(sess.createTopic(topic2));
    sess.close();
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Session(javax.jms.Session) Test(org.junit.Test)

Example 28 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class ActiveMQServerControlTest method testListConnections.

@Test
public void testListConnections() throws Exception {
    SimpleString queueName1 = new SimpleString("my_queue_one");
    SimpleString addressName1 = new SimpleString("my_address_one");
    ActiveMQServerControl serverControl = createManagementControl();
    server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST));
    server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false);
    ClientSessionFactoryImpl csf = null;
    ClientSessionFactoryImpl csf2 = null;
    ClientSessionFactoryImpl csf3 = null;
    // create some consumers
    try (ServerLocator locator = createInVMNonHALocator()) {
        // sleep as test compares creationTime
        csf = (ClientSessionFactoryImpl) createSessionFactory(locator);
        Thread.sleep(500);
        csf2 = (ClientSessionFactoryImpl) createSessionFactory(locator);
        Thread.sleep(500);
        csf3 = (ClientSessionFactoryImpl) createSessionFactory(locator);
        ClientSession session1_c1 = csf.createSession();
        ClientSession session2_c1 = csf.createSession();
        ClientSession session1_c2 = csf2.createSession();
        ClientSession session2_c2 = csf2.createSession();
        ClientSession session3_c2 = csf2.createSession();
        ClientSession session4_c2 = csf2.createSession();
        ClientSession session1_c4 = csf3.createSession();
        ClientSession session2_c4 = csf3.createSession();
        ClientSession session3_c4 = csf3.createSession();
        String filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1");
        String connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
        JsonObject connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
        JsonArray array = (JsonArray) connectionsAsJsonObject.get("data");
        Assert.assertEquals("number of connections returned from query", 3, array.size());
        JsonObject jsonConnection = array.getJsonObject(0);
        // check all fields
        Assert.assertNotEquals("connectionID", "", jsonConnection.getString("connectionID"));
        Assert.assertNotEquals("remoteAddress", "", jsonConnection.getString("remoteAddress"));
        Assert.assertEquals("users", "", jsonConnection.getString("users"));
        Assert.assertNotEquals("creationTime", "", jsonConnection.getString("creationTime"));
        Assert.assertNotEquals("implementation", "", jsonConnection.getString("implementation"));
        Assert.assertNotEquals("protocol", "", jsonConnection.getString("protocol"));
        Assert.assertEquals("clientID", "", jsonConnection.getString("clientID"));
        Assert.assertNotEquals("localAddress", "", jsonConnection.getString("localAddress"));
        Assert.assertEquals("sessionCount", 2, jsonConnection.getInt("sessionCount"));
        // check default order
        Assert.assertEquals("connection1 default Order", csf.getConnection().getID(), array.getJsonObject(0).getString("connectionID"));
        Assert.assertEquals("connection2 default Order", csf2.getConnection().getID(), array.getJsonObject(1).getString("connectionID"));
        Assert.assertEquals("connection3 session Order", csf3.getConnection().getID(), array.getJsonObject(2).getString("connectionID"));
        // check order by session count desc
        filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1", "sessionCount", "desc");
        connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
        connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
        array = (JsonArray) connectionsAsJsonObject.get("data");
        Assert.assertEquals("number of connections returned from query", 3, array.size());
        Assert.assertEquals("connection2 session Order", csf2.getConnection().getID(), array.getJsonObject(0).getString("connectionID"));
        Assert.assertEquals("connection3 session Order", csf3.getConnection().getID(), array.getJsonObject(1).getString("connectionID"));
        Assert.assertEquals("connection1 session Order", csf.getConnection().getID(), array.getJsonObject(2).getString("connectionID"));
        // check order by creationTime desc
        filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1", "creationTime", "desc");
        connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
        connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
        array = (JsonArray) connectionsAsJsonObject.get("data");
        Assert.assertEquals("number of connections returned from query", 3, array.size());
        Assert.assertEquals("connection3 creationTime Order", csf3.getConnection().getID(), array.getJsonObject(0).getString("connectionID"));
        Assert.assertEquals("connection2 creationTime Order", csf2.getConnection().getID(), array.getJsonObject(1).getString("connectionID"));
        Assert.assertEquals("connection1 creationTime Order", csf.getConnection().getID(), array.getJsonObject(2).getString("connectionID"));
    } finally {
        if (csf != null) {
            csf.close();
        }
        if (csf2 != null) {
            csf.close();
        }
        if (csf3 != null) {
            csf.close();
        }
    }
}
Also used : JsonArray(javax.json.JsonArray) ClientSessionFactoryImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JsonObject(javax.json.JsonObject) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 29 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class ActiveMQServerControlTest method testListQueuesNumericFilterInvalid.

@Test
public void testListQueuesNumericFilterInvalid() throws Exception {
    SimpleString queueName1 = new SimpleString("my_queue_one");
    SimpleString queueName2 = new SimpleString("one_consumer_queue_two");
    SimpleString queueName3 = new SimpleString("one_consumer_queue_three");
    SimpleString queueName4 = new SimpleString("my_queue_four");
    ActiveMQServerControl serverControl = createManagementControl();
    server.addAddressInfo(new AddressInfo(queueName1, RoutingType.ANYCAST));
    server.createQueue(queueName1, RoutingType.ANYCAST, queueName1, null, false, false);
    server.addAddressInfo(new AddressInfo(queueName2, RoutingType.ANYCAST));
    server.createQueue(queueName2, RoutingType.ANYCAST, queueName2, null, false, false);
    server.addAddressInfo(new AddressInfo(queueName3, RoutingType.ANYCAST));
    server.createQueue(queueName3, RoutingType.ANYCAST, queueName3, null, false, false, 10, false, false);
    server.addAddressInfo(new AddressInfo(queueName4, RoutingType.ANYCAST));
    server.createQueue(queueName4, RoutingType.ANYCAST, queueName4, null, false, false);
    // create some consumers
    try (ServerLocator locator = createInVMNonHALocator();
        ClientSessionFactory csf = createSessionFactory(locator);
        ClientSession session = csf.createSession()) {
        session.start();
        ClientConsumer consumer1_q1 = session.createConsumer(queueName1);
        ClientConsumer consumer2_q1 = session.createConsumer(queueName1);
        // test with CONTAINS returns nothing for numeric field
        String filterString = createJsonFilter("CONSUMER_COUNT", "CONTAINS", "NOT_NUMBER");
        String queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        JsonObject queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        JsonArray array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from query", 0, array.size());
        // test with LESS_THAN and not a number
        filterString = createJsonFilter("CONSUMER_COUNT", "LESS_THAN", "NOT_NUMBER");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from LESS_THAN query", 0, array.size());
        // test with GREATER_THAN and not a number
        filterString = createJsonFilter("CONSUMER_COUNT", "GREATER_THAN", "NOT_NUMBER");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from GREATER_THAN query", 0, array.size());
        // test with EQUALS and not number
        filterString = createJsonFilter("CONSUMER_COUNT", "EQUALS", "NOT_NUMBER");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from EQUALS query", 0, array.size());
        // test with LESS_THAN on string value returns no queue
        filterString = createJsonFilter("name", "LESS_THAN", "my_queue");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from LESS_THAN on non numeric field", 0, array.size());
        // test with GREATER_THAN on string value returns no queue
        filterString = createJsonFilter("name", "GREATER_THAN", "my_queue");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from GREATER_THAN on non numeric field", 0, array.size());
        // test with GREATER_THAN and empty string
        filterString = createJsonFilter("CONSUMER_COUNT", "GREATER_THAN", " ");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from GREATER_THAN query", 0, array.size());
        // test with CONSUMER_COUNT against a float value
        filterString = createJsonFilter("CONSUMER_COUNT", "GREATER_THAN", "0.12");
        queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
        queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
        array = (JsonArray) queuesAsJsonObject.get("data");
        Assert.assertEquals("number of queues returned from GREATER_THAN query", 0, array.size());
    }
}
Also used : JsonArray(javax.json.JsonArray) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JsonObject(javax.json.JsonObject) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 30 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class ActiveMQServerControlTest method testListAddresses.

@Test
public void testListAddresses() throws Exception {
    SimpleString queueName1 = new SimpleString("my_queue_one");
    SimpleString queueName2 = new SimpleString("my_queue_two");
    SimpleString queueName3 = new SimpleString("other_queue_three");
    SimpleString queueName4 = new SimpleString("other_queue_four");
    SimpleString addressName1 = new SimpleString("my_address_one");
    SimpleString addressName2 = new SimpleString("my_address_two");
    SimpleString addressName3 = new SimpleString("other_address_three");
    ActiveMQServerControl serverControl = createManagementControl();
    server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST));
    server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false);
    server.addAddressInfo(new AddressInfo(addressName2, RoutingType.ANYCAST));
    server.createQueue(addressName2, RoutingType.ANYCAST, queueName2, null, false, false);
    server.addAddressInfo(new AddressInfo(addressName3, RoutingType.ANYCAST));
    server.createQueue(addressName3, RoutingType.ANYCAST, queueName3, null, false, false);
    server.createQueue(addressName3, RoutingType.ANYCAST, queueName4, null, false, false);
    // test with CONTAINS filter
    String filterString = createJsonFilter("name", "CONTAINS", "my_address");
    String addressesAsJsonString = serverControl.listAddresses(filterString, 1, 50);
    JsonObject addressesAsJsonObject = JsonUtil.readJsonObject(addressesAsJsonString);
    JsonArray array = (JsonArray) addressesAsJsonObject.get("data");
    Assert.assertEquals("number of addresses returned from query", 2, array.size());
    Assert.assertTrue("address name check", array.getJsonObject(0).getString("name").contains("my_address"));
    Assert.assertTrue("address name check", array.getJsonObject(1).getString("name").contains("my_address"));
    // test with EQUALS filter
    filterString = createJsonFilter("name", "EQUALS", addressName1.toString());
    addressesAsJsonString = serverControl.listAddresses(filterString, 1, 50);
    addressesAsJsonObject = JsonUtil.readJsonObject(addressesAsJsonString);
    array = (JsonArray) addressesAsJsonObject.get("data");
    Assert.assertEquals("number of addresses returned from query", 1, array.size());
    // check all field names
    Assert.assertEquals("address name check", addressName1.toString(), array.getJsonObject(0).getString("name"));
    Assert.assertNotEquals("id", "", array.getJsonObject(0).getString("id"));
    Assert.assertTrue("routingTypes", array.getJsonObject(0).getString("routingTypes").contains(RoutingType.ANYCAST.name()));
    Assert.assertEquals("queueCount", "1", array.getJsonObject(0).getString("queueCount"));
    // test with empty filter - all addresses should be returned
    filterString = createJsonFilter("", "", "");
    addressesAsJsonString = serverControl.listAddresses(filterString, 1, 50);
    addressesAsJsonObject = JsonUtil.readJsonObject(addressesAsJsonString);
    array = (JsonArray) addressesAsJsonObject.get("data");
    Assert.assertTrue("number of addresses returned from query", 3 <= array.size());
    // test with small page size
    addressesAsJsonString = serverControl.listAddresses(filterString, 1, 1);
    addressesAsJsonObject = JsonUtil.readJsonObject(addressesAsJsonString);
    array = (JsonArray) addressesAsJsonObject.get("data");
    Assert.assertEquals("number of queues returned from query", 1, array.size());
    // test with QUEUE_COUNT with GREATER_THAN filter
    filterString = createJsonFilter("QUEUE_COUNT", "GREATER_THAN", "1");
    addressesAsJsonString = serverControl.listAddresses(filterString, 1, 50);
    addressesAsJsonObject = JsonUtil.readJsonObject(addressesAsJsonString);
    array = (JsonArray) addressesAsJsonObject.get("data");
    Assert.assertEquals("number of addresses returned from query", 1, array.size());
    Assert.assertEquals("address name check", addressName3.toString(), array.getJsonObject(0).getString("name"));
    // test with QUEUE_COUNT with LESS_THAN filter
    filterString = createJsonFilter("QUEUE_COUNT", "LESS_THAN", "0");
    addressesAsJsonString = serverControl.listAddresses(filterString, 1, 50);
    addressesAsJsonObject = JsonUtil.readJsonObject(addressesAsJsonString);
    array = (JsonArray) addressesAsJsonObject.get("data");
    Assert.assertEquals("number of addresses returned from query", 0, array.size());
}
Also used : JsonArray(javax.json.JsonArray) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JsonObject(javax.json.JsonObject) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Aggregations

AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)116 Test (org.junit.Test)89 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)73 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)32 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)24 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)23 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)23 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)22 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)21 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)19 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)18 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)17 JsonObject (javax.json.JsonObject)16 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)16 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)16 JsonArray (javax.json.JsonArray)15 Queue (org.apache.activemq.artemis.core.server.Queue)15 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)13 Configuration (org.apache.activemq.artemis.core.config.Configuration)12 Session (javax.jms.Session)11