use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class JMSBridgeImplTest method doTestAutoAckOnSource.
public void doTestAutoAckOnSource(int maxBatchSize) throws Exception {
final int numMessages = maxBatchSize;
ConnectionFactoryFactory sourceCFF = JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
ConnectionFactoryFactory targetCFF = JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
DestinationFactory sourceDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.SOURCE));
DestinationFactory targetDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.TARGET));
TransactionManager tm = JMSBridgeImplTest.newTransactionManager();
JMSBridgeImpl bridge = new JMSBridgeImpl();
Assert.assertNotNull(bridge);
bridge.setSourceConnectionFactoryFactory(sourceCFF);
bridge.setSourceDestinationFactory(sourceDF);
bridge.setTargetConnectionFactoryFactory(targetCFF);
bridge.setTargetDestinationFactory(targetDF);
bridge.setFailureRetryInterval(10);
bridge.setMaxRetries(1);
bridge.setMaxBatchSize(maxBatchSize);
bridge.setMaxBatchTime(-1);
bridge.setTransactionManager(tm);
bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);
Assert.assertFalse(bridge.isStarted());
bridge.start();
Assert.assertTrue(bridge.isStarted());
Connection sourceConn = JMSBridgeImplTest.createConnectionFactory().createConnection();
Session sourceSess = sourceConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = sourceSess.createProducer(sourceDF.createDestination());
for (int i = 0; i < numMessages; i++) {
TextMessage msg = sourceSess.createTextMessage();
producer.send(msg);
JMSBridgeImplTest.log.info("sent message " + i);
}
sourceConn.close();
SimpleString add = new SimpleString(JMSBridgeImplTest.SOURCE);
QueueControl jmsQueueControl = MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(), ObjectNameBuilder.DEFAULT.getQueueObjectName(add, add, RoutingType.ANYCAST), QueueControl.class, false);
assertNotEquals(jmsQueueControl.getDeliveringCount(), numMessages);
bridge.stop();
Assert.assertFalse(bridge.isStarted());
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testCreateAndDestroyQueue.
@Test
public void testCreateAndDestroyQueue() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString name = RandomUtil.randomSimpleString();
ActiveMQServerControl serverControl = createManagementControl();
checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
serverControl.createAddress(address.toString(), "ANYCAST");
serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), null, true, -1, false, false);
checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, RoutingType.ANYCAST, mbeanServer);
Assert.assertEquals(address.toString(), queueControl.getAddress());
Assert.assertEquals(name.toString(), queueControl.getName());
Assert.assertNull(queueControl.getFilter());
Assert.assertEquals(true, queueControl.isDurable());
Assert.assertEquals(false, queueControl.isTemporary());
serverControl.destroyQueue(name.toString());
checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testCreateAndDestroyQueueWithNullFilter.
@Test
public void testCreateAndDestroyQueueWithNullFilter() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString name = RandomUtil.randomSimpleString();
String filter = null;
boolean durable = true;
ActiveMQServerControl serverControl = createManagementControl();
checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
serverControl.createAddress(address.toString(), "ANYCAST");
serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), filter, durable, -1, false, false);
checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, RoutingType.ANYCAST, mbeanServer);
Assert.assertEquals(address.toString(), queueControl.getAddress());
Assert.assertEquals(name.toString(), queueControl.getName());
Assert.assertNull(queueControl.getFilter());
Assert.assertEquals(durable, queueControl.isDurable());
Assert.assertEquals(false, queueControl.isTemporary());
serverControl.destroyQueue(name.toString());
checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class ManagementWithPagingServerTest method testListMessagesAsJSON.
@Test
public void testListMessagesAsJSON() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session1.createQueue(address, queue, null, true);
QueueControl queueControl = createManagementControl(address, queue);
int num = 1000;
SenderThread sender = new SenderThread(address, num, 0);
ReceiverThread receiver = new ReceiverThread(queue, num, 0);
// kick off sender
sender.start();
// wait for all messages sent
sender.join();
assertNull(sender.getError());
long count = queueControl.countMessages(null);
assertEquals(num, count);
String result = queueControl.listMessagesAsJSON(null);
JsonArray array = JsonUtil.readJsonArray(result);
List<Long> longs = new ArrayList<>();
for (JsonValue jsonValue : array) {
JsonValue val = ((JsonObject) jsonValue).get("messageID");
Long l = ((JsonLongImpl) val).longValue();
if (longs.contains(l)) {
System.out.println("ManagementWithPagingServerTest.testListMessagesAsJSON");
}
longs.add(l);
System.out.println("jsonValue = " + jsonValue);
}
assertEquals(num, array.size());
// kick off receiver
receiver.start();
receiver.join();
assertNull(receiver.getError());
result = queueControl.listMessagesAsJSON(null);
array = JsonUtil.readJsonArray(result);
assertEquals(0, array.size());
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class ManagementWithPagingServerTest method testListMessagesAsJSONWithFilter.
@Test
public void testListMessagesAsJSONWithFilter() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session1.createQueue(address, queue, null, true);
QueueControl queueControl = createManagementControl(address, queue);
int num = 1000;
SimpleString key = new SimpleString("key");
long matchingValue = RandomUtil.randomLong();
long unmatchingValue = matchingValue + 1;
String filter = key + " =" + matchingValue;
byte[] body = new byte[64];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= 64; j++) {
bb.put(getSamplebyte(j));
}
ClientProducer producer = session1.createProducer(address);
for (int i = 0; i < num; i++) {
ClientMessage message = session1.createMessage(true);
if (i % 2 == 0) {
message.putLongProperty(key, matchingValue);
} else {
message.putLongProperty(key, unmatchingValue);
}
producer.send(message);
}
String jsonString = queueControl.listMessagesAsJSON(filter);
Assert.assertNotNull(jsonString);
JsonArray array = JsonUtil.readJsonArray(jsonString);
Assert.assertEquals(num / 2, array.size());
long l = Long.parseLong(array.getJsonObject(0).get("key").toString().replaceAll("\"", ""));
Assert.assertEquals(matchingValue, l);
long n = queueControl.countMessages(filter);
assertEquals(num / 2, n);
// drain out messages
ReceiverThread receiver = new ReceiverThread(queue, num, 1);
receiver.start();
receiver.join();
}
Aggregations