Search in sources :

Example 21 with AddressInfo

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

the class ActiveMQServerControlTest method testListSessionsAsJSON.

@Test
public void testListSessionsAsJSON() throws Exception {
    SimpleString queueName = new SimpleString(UUID.randomUUID().toString());
    server.addAddressInfo(new AddressInfo(queueName, RoutingType.ANYCAST));
    server.createQueue(queueName, RoutingType.ANYCAST, queueName, null, false, false);
    ActiveMQServerControl serverControl = createManagementControl();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = createSessionFactory(locator);
    ClientSession session1 = addClientSession(factory.createSession());
    ClientSession session2 = addClientSession(factory.createSession("myUser", "myPass", false, false, false, false, 0));
    session2.createConsumer(queueName);
    String jsonString = serverControl.listSessionsAsJSON(factory.getConnection().getID().toString());
    IntegrationTestLogger.LOGGER.info(jsonString);
    Assert.assertNotNull(jsonString);
    JsonArray array = JsonUtil.readJsonArray(jsonString);
    Assert.assertEquals(2, array.size());
    JsonObject first = lookupSession(array, session1);
    JsonObject second = lookupSession(array, session2);
    Assert.assertTrue(first.getString("sessionID").length() > 0);
    Assert.assertEquals(((ClientSessionImpl) session1).getName(), first.getString("sessionID"));
    Assert.assertTrue(first.getString("principal").length() > 0);
    Assert.assertEquals("guest", first.getString("principal"));
    Assert.assertTrue(first.getJsonNumber("creationTime").longValue() > 0);
    Assert.assertEquals(0, first.getJsonNumber("consumerCount").longValue());
    Assert.assertTrue(second.getString("sessionID").length() > 0);
    Assert.assertEquals(((ClientSessionImpl) session2).getName(), second.getString("sessionID"));
    Assert.assertTrue(second.getString("principal").length() > 0);
    Assert.assertEquals("myUser", second.getString("principal"));
    Assert.assertTrue(second.getJsonNumber("creationTime").longValue() > 0);
    Assert.assertEquals(1, second.getJsonNumber("consumerCount").longValue());
}
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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 22 with AddressInfo

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

the class ActiveMQServerControlTest method testListConsumers.

@Test
public void testListConsumers() throws Exception {
    SimpleString queueName1 = new SimpleString("my_queue_one");
    SimpleString queueName2 = new SimpleString("my_queue_two");
    SimpleString queueName3 = new SimpleString("other_queue_three");
    SimpleString addressName1 = new SimpleString("my_address_one");
    SimpleString addressName2 = new SimpleString("my_address_two");
    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.createQueue(addressName2, RoutingType.ANYCAST, queueName3, null, false, false);
    // create some consumers
    try (ServerLocator locator = createInVMNonHALocator();
        ClientSessionFactory csf = createSessionFactory(locator);
        ClientSession session = csf.createSession()) {
        ClientConsumer consumer1_q1 = session.createConsumer(queueName1);
        ClientConsumer consumer2_q1 = session.createConsumer(queueName1);
        ClientConsumer consumer1_q2 = session.createConsumer(queueName2);
        ClientConsumer consumer1_q3 = session.createConsumer(queueName3);
        // test with filter  EQUALS
        String filterString = createJsonFilter("queue", "EQUALS", queueName1.toString());
        String consumersAsJsonString = serverControl.listConsumers(filterString, 1, 50);
        JsonObject consumersAsJsonObject = JsonUtil.readJsonObject(consumersAsJsonString);
        JsonArray array = (JsonArray) consumersAsJsonObject.get("data");
        Assert.assertEquals("number of consumers returned from query", 2, array.size());
        Assert.assertEquals("check consumer's queue", queueName1.toString(), array.getJsonObject(0).getString("queue"));
        Assert.assertEquals("check consumer's queue", queueName1.toString(), array.getJsonObject(0).getString("queue"));
        // test with a CONTAINS operation
        filterString = createJsonFilter("queue", "CONTAINS", "my_queue");
        consumersAsJsonString = serverControl.listConsumers(filterString, 1, 50);
        consumersAsJsonObject = JsonUtil.readJsonObject(consumersAsJsonString);
        array = (JsonArray) consumersAsJsonObject.get("data");
        Assert.assertEquals("number of consumers returned from query", 3, array.size());
        // filter by address
        filterString = createJsonFilter("address", "EQUALS", addressName1.toString());
        consumersAsJsonString = serverControl.listConsumers(filterString, 1, 50);
        consumersAsJsonObject = JsonUtil.readJsonObject(consumersAsJsonString);
        array = (JsonArray) consumersAsJsonObject.get("data");
        Assert.assertEquals("number of consumers returned from query", 2, array.size());
        Assert.assertEquals("check consumers address", addressName1.toString(), array.getJsonObject(0).getString("address"));
        Assert.assertEquals("check consumers address", addressName1.toString(), array.getJsonObject(1).getString("address"));
        // test with empty filter - all consumers should be returned
        filterString = createJsonFilter("", "", "");
        consumersAsJsonString = serverControl.listConsumers(filterString, 1, 50);
        consumersAsJsonObject = JsonUtil.readJsonObject(consumersAsJsonString);
        array = (JsonArray) consumersAsJsonObject.get("data");
        Assert.assertTrue("at least 4 consumers returned from query", 4 <= array.size());
        // test with small page size
        consumersAsJsonString = serverControl.listConsumers(filterString, 1, 1);
        consumersAsJsonObject = JsonUtil.readJsonObject(consumersAsJsonString);
        array = (JsonArray) consumersAsJsonObject.get("data");
        Assert.assertEquals("number of consumers returned from query", 1, array.size());
        // test contents of returned consumer
        filterString = createJsonFilter("queue", "EQUALS", queueName3.toString());
        consumersAsJsonString = serverControl.listConsumers(filterString, 1, 50);
        consumersAsJsonObject = JsonUtil.readJsonObject(consumersAsJsonString);
        array = (JsonArray) consumersAsJsonObject.get("data");
        Assert.assertEquals("number of consumers returned from query", 1, array.size());
        JsonObject jsonConsumer = array.getJsonObject(0);
        Assert.assertEquals("queue name in consumer", queueName3.toString(), jsonConsumer.getString("queue"));
        Assert.assertEquals("address name in consumer", addressName2.toString(), jsonConsumer.getString("address"));
        Assert.assertEquals("consumer protocol ", "CORE", jsonConsumer.getString("protocol"));
        Assert.assertEquals("queue type", "anycast", jsonConsumer.getString("queueType"));
        Assert.assertNotEquals("id", "", jsonConsumer.getString("id"));
        Assert.assertNotEquals("session", "", jsonConsumer.getString("session"));
        Assert.assertEquals("clientID", "", jsonConsumer.getString("clientID"));
        Assert.assertEquals("user", "", jsonConsumer.getString("user"));
        Assert.assertNotEquals("localAddress", "", jsonConsumer.getString("localAddress"));
        Assert.assertNotEquals("remoteAddress", "", jsonConsumer.getString("remoteAddress"));
        Assert.assertNotEquals("creationTime", "", jsonConsumer.getString("creationTime"));
    }
}
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 23 with AddressInfo

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

the class ActiveMQServerControlTest method testListAllSessionsAsJSON.

@Test
public void testListAllSessionsAsJSON() throws Exception {
    SimpleString queueName = new SimpleString(UUID.randomUUID().toString());
    server.addAddressInfo(new AddressInfo(queueName, RoutingType.ANYCAST));
    server.createQueue(queueName, RoutingType.ANYCAST, queueName, null, false, false);
    ActiveMQServerControl serverControl = createManagementControl();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = createSessionFactory(locator);
    ServerLocator locator2 = createInVMNonHALocator();
    ClientSessionFactory factory2 = createSessionFactory(locator2);
    ClientSession session1 = addClientSession(factory.createSession());
    Thread.sleep(5);
    ClientSession session2 = addClientSession(factory2.createSession("myUser", "myPass", false, false, false, false, 0));
    session2.createConsumer(queueName);
    String jsonString = serverControl.listAllSessionsAsJSON();
    IntegrationTestLogger.LOGGER.info(jsonString);
    Assert.assertNotNull(jsonString);
    JsonArray array = JsonUtil.readJsonArray(jsonString);
    Assert.assertEquals(2 + (usingCore() ? 1 : 0), array.size());
    JsonObject first = lookupSession(array, session1);
    JsonObject second = lookupSession(array, session2);
    Assert.assertTrue(first.getString("sessionID").length() > 0);
    Assert.assertEquals(((ClientSessionImpl) session1).getName(), first.getString("sessionID"));
    Assert.assertTrue(first.getString("principal").length() > 0);
    Assert.assertEquals("guest", first.getString("principal"));
    Assert.assertTrue(first.getJsonNumber("creationTime").longValue() > 0);
    Assert.assertEquals(0, first.getJsonNumber("consumerCount").longValue());
    Assert.assertTrue(second.getString("sessionID").length() > 0);
    Assert.assertEquals(((ClientSessionImpl) session2).getName(), second.getString("sessionID"));
    Assert.assertTrue(second.getString("principal").length() > 0);
    Assert.assertEquals("myUser", second.getString("principal"));
    Assert.assertTrue(second.getJsonNumber("creationTime").longValue() > 0);
    Assert.assertEquals(1, second.getJsonNumber("consumerCount").longValue());
}
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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 24 with AddressInfo

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

the class ActiveMQServerControlTest method scaleDown.

protected void scaleDown(ScaleDownHandler handler) throws Exception {
    SimpleString address = new SimpleString("testQueue");
    HashMap<String, Object> params = new HashMap<>();
    params.put(TransportConstants.SERVER_ID_PROP_NAME, "2");
    Configuration config = createDefaultInVMConfig(2).clearAcceptorConfigurations().addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName(), params)).setSecurityEnabled(false);
    ActiveMQServer server2 = addServer(ActiveMQServers.newActiveMQServer(config, null, true));
    this.conf.clearConnectorConfigurations().addConnectorConfiguration("server2-connector", new TransportConfiguration(INVM_CONNECTOR_FACTORY, params));
    server2.start();
    server.addAddressInfo(new AddressInfo(address, RoutingType.ANYCAST));
    server.createQueue(address, RoutingType.ANYCAST, address, null, true, false, -1, false, false);
    server2.addAddressInfo(new AddressInfo(address, RoutingType.ANYCAST));
    server2.createQueue(address, RoutingType.ANYCAST, address, null, true, false, -1, false, false);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession session = csf.createSession();
    ClientProducer producer = session.createProducer(address);
    for (int i = 0; i < 100; i++) {
        ClientMessage message = session.createMessage(true);
        message.getBodyBuffer().writeString("m" + i);
        producer.send(message);
    }
    ActiveMQServerControl managementControl = createManagementControl();
    handler.scaleDown(managementControl);
    locator.close();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(INVM_CONNECTOR_FACTORY, params)));
    csf = createSessionFactory(locator);
    session = csf.createSession();
    session.start();
    ClientConsumer consumer = session.createConsumer(address);
    for (int i = 0; i < 100; i++) {
        ClientMessage m = consumer.receive(5000);
        assertNotNull(m);
    }
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) HashMap(java.util.HashMap) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) JsonObject(javax.json.JsonObject) 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) InVMAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Example 25 with AddressInfo

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

the class ActiveMQServerControlTest method testListQueues.

@Test
public void testListQueues() throws Exception {
    SimpleString queueName1 = new SimpleString("my_queue_one");
    SimpleString queueName2 = new SimpleString("my_queue_two");
    SimpleString queueName3 = new SimpleString("other_queue_three");
    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);
    // test with filter that matches 2 queues
    String filterString = createJsonFilter("name", "CONTAINS", "my_queue");
    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", 2, array.size());
    Assert.assertTrue(array.getJsonObject(0).getString("name").contains("my_queue"));
    Assert.assertTrue(array.getJsonObject(1).getString("name").contains("my_queue"));
    // test with an empty filter
    filterString = createJsonFilter("", "", "");
    queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
    queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
    array = (JsonArray) queuesAsJsonObject.get("data");
    // at least 3 queues or more
    Assert.assertTrue("number of queues returned from query", 3 <= array.size());
    // test with small page size
    queuesAsJsonString = serverControl.listQueues(filterString, 1, 1);
    queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
    array = (JsonArray) queuesAsJsonObject.get("data");
    Assert.assertEquals("number of queues returned from query", 1, array.size());
    // check all field names are available
    Assert.assertNotEquals("name", "", array.getJsonObject(0).getString("name"));
    Assert.assertNotEquals("id", "", array.getJsonObject(0).getString("id"));
    Assert.assertNotEquals("address", "", array.getJsonObject(0).getString("address"));
    Assert.assertEquals("filter", "", array.getJsonObject(0).getString("filter"));
    Assert.assertNotEquals("rate", "", array.getJsonObject(0).getString("rate"));
    Assert.assertEquals("durable", "false", array.getJsonObject(0).getString("durable"));
    Assert.assertEquals("paused", "false", array.getJsonObject(0).getString("paused"));
    Assert.assertNotEquals("temporary", "", array.getJsonObject(0).getString("temporary"));
    Assert.assertEquals("purgeOnNoConsumers", "false", array.getJsonObject(0).getString("purgeOnNoConsumers"));
    Assert.assertNotEquals("consumerCount", "", array.getJsonObject(0).getString("consumerCount"));
    Assert.assertEquals("maxConsumers", "-1", array.getJsonObject(0).getString("maxConsumers"));
    Assert.assertEquals("autoCreated", "false", array.getJsonObject(0).getString("autoCreated"));
    Assert.assertEquals("user", "", array.getJsonObject(0).getString("user"));
    Assert.assertNotEquals("routingType", "", array.getJsonObject(0).getString("routingType"));
    Assert.assertEquals("messagesAdded", "0", array.getJsonObject(0).getString("messagesAdded"));
    Assert.assertEquals("messageCount", "0", array.getJsonObject(0).getString("messageCount"));
    Assert.assertEquals("messagesAcked", "0", array.getJsonObject(0).getString("messagesAcked"));
    Assert.assertEquals("deliveringCount", "0", array.getJsonObject(0).getString("deliveringCount"));
    Assert.assertEquals("messagesKilled", "0", array.getJsonObject(0).getString("messagesKilled"));
    Assert.assertEquals("deliverDeliver", "true", array.getJsonObject(0).getString("deliverDeliver"));
}
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