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