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();
}
}
}
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());
}
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);
}
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());
}
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());
}
Aggregations