Search in sources :

Example 1 with AddressControl

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

the class JMSMessageTypesTest method testAddressControlSendMessageWithText.

@Test(timeout = 60000)
public void testAddressControlSendMessageWithText() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    server.createQueue(address, RoutingType.ANYCAST, address, null, true, false);
    AddressControl addressControl = ManagementControlHelper.createAddressControl(address, mBeanServer);
    Assert.assertEquals(1, addressControl.getQueueNames().length);
    addressControl.sendMessage(null, org.apache.activemq.artemis.api.core.Message.TEXT_TYPE, "test", false, fullUser, fullPass);
    Wait.assertEquals(1, addressControl::getMessageCount);
    Assert.assertEquals(1, addressControl.getMessageCount());
    Connection connection = createConnection("myClientId");
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        javax.jms.Queue queue = session.createQueue(address.toString());
        MessageConsumer consumer = session.createConsumer(queue);
        Message message = consumer.receive(500);
        assertNotNull(message);
        String text = ((TextMessage) message).getText();
        assertEquals("test", text);
        session.close();
        connection.close();
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) Queue(javax.jms.Queue) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) StreamMessage(javax.jms.StreamMessage) MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 2 with AddressControl

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

the class ManagementServiceImplTest method testGetResources.

@Test
public void testGetResources() throws Exception {
    Configuration config = createBasicConfig().setJMXManagementEnabled(false);
    ManagementServiceImpl managementService = new ManagementServiceImpl(null, config);
    managementService.setStorageManager(new NullStorageManager());
    SimpleString address = RandomUtil.randomSimpleString();
    managementService.registerAddress(new AddressInfo(address));
    Queue queue = new FakeQueue(RandomUtil.randomSimpleString());
    managementService.registerQueue(queue, RandomUtil.randomSimpleString(), new FakeStorageManager());
    Object[] addresses = managementService.getResources(AddressControl.class);
    Assert.assertEquals(1, addresses.length);
    Assert.assertTrue(addresses[0] instanceof AddressControl);
    AddressControl addressControl = (AddressControl) addresses[0];
    Assert.assertEquals(address.toString(), addressControl.getAddress());
    Object[] queues = managementService.getResources(QueueControl.class);
    Assert.assertEquals(1, queues.length);
    Assert.assertTrue(queues[0] instanceof QueueControl);
    QueueControl queueControl = (QueueControl) queues[0];
    Assert.assertEquals(queue.getName().toString(), queueControl.getName());
}
Also used : ManagementServiceImpl(org.apache.activemq.artemis.core.server.management.impl.ManagementServiceImpl) AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) FakeStorageManager(org.apache.activemq.artemis.tests.integration.server.FakeStorageManager) Configuration(org.apache.activemq.artemis.core.config.Configuration) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 3 with AddressControl

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

the class AddressControlTest method testGetQueueNames.

@Test
public void testGetQueueNames() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString anotherQueue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, true);
    AddressControl addressControl = createManagementControl(address);
    String[] queueNames = addressControl.getQueueNames();
    Assert.assertEquals(1, queueNames.length);
    Assert.assertEquals(queue.toString(), queueNames[0]);
    session.createQueue(address, anotherQueue, false);
    queueNames = addressControl.getQueueNames();
    Assert.assertEquals(2, queueNames.length);
    session.deleteQueue(queue);
    queueNames = addressControl.getQueueNames();
    Assert.assertEquals(1, queueNames.length);
    Assert.assertEquals(anotherQueue.toString(), queueNames[0]);
    session.deleteQueue(anotherQueue);
}
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 4 with AddressControl

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

the class AddressControlTest method testGetNumberOfPages.

@Test
public void testGetNumberOfPages() throws Exception {
    session.close();
    server.stop();
    server.getConfiguration().setPersistenceEnabled(true);
    SimpleString address = RandomUtil.randomSimpleString();
    AddressSettings addressSettings = new AddressSettings().setPageSizeBytes(1024).setMaxSizeBytes(10 * 1024);
    final int NUMBER_MESSAGES_BEFORE_PAGING = 7;
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    server.start();
    ServerLocator locator2 = createInVMNonHALocator();
    addServerLocator(locator2);
    ClientSessionFactory sf2 = createSessionFactory(locator2);
    session = sf2.createSession(false, true, false);
    session.start();
    session.createQueue(address, address, true);
    QueueImpl serverQueue = (QueueImpl) server.locateQueue(address);
    ClientProducer producer = session.createProducer(address);
    for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.getBodyBuffer().writeBytes(new byte[896]);
        producer.send(msg);
    }
    session.commit();
    AddressControl addressControl = createManagementControl(address);
    Assert.assertEquals(0, addressControl.getNumberOfPages());
    ClientMessage msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[896]);
    producer.send(msg);
    session.commit();
    Assert.assertEquals(1, addressControl.getNumberOfPages());
    msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[896]);
    producer.send(msg);
    session.commit();
    Assert.assertEquals(1, addressControl.getNumberOfPages());
    msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[896]);
    producer.send(msg);
    session.commit();
    Assert.assertEquals("# of pages is 2", 2, addressControl.getNumberOfPages());
    System.out.println("Address size=" + addressControl.getAddressSize());
    Assert.assertEquals(serverQueue.getPageSubscription().getPagingStore().getAddressSize(), addressControl.getAddressSize());
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 5 with AddressControl

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

the class AddressControlTest method testGetNumberOfBytesPerPage.

@Test
public void testGetNumberOfBytesPerPage() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    session.createQueue(address, address, true);
    AddressControl addressControl = createManagementControl(address);
    Assert.assertEquals(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), addressControl.getNumberOfBytesPerPage());
    session.close();
    server.stop();
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setPageSizeBytes(1024);
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    server.start();
    ServerLocator locator2 = createInVMNonHALocator();
    ClientSessionFactory sf2 = createSessionFactory(locator2);
    session = sf2.createSession(false, true, false);
    session.createQueue(address, address, true);
    Assert.assertEquals(1024, addressControl.getNumberOfBytesPerPage());
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) 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