use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class ActiveMQDestinationTest method testEquals.
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testEquals() throws Exception {
String destinationName = RandomUtil.randomString();
String address = QUEUE_QUALIFIED_PREFIX + destinationName;
ActiveMQDestination destination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address);
ActiveMQDestination sameDestination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address);
ActiveMQDestination differentDestination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address + RandomUtil.randomString());
Assert.assertFalse(destination.equals(null));
Assert.assertTrue(destination.equals(destination));
Assert.assertTrue(destination.equals(sameDestination));
Assert.assertFalse(destination.equals(differentDestination));
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class ReferenceableTest method testReferenceQueue.
@Test
public void testReferenceQueue() throws Exception {
Reference queueRef = ((Referenceable) queue1).getReference();
String factoryName = queueRef.getFactoryClassName();
Class<?> factoryClass = Class.forName(factoryName);
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
Object instance = factory.getObjectInstance(queueRef, null, null, null);
ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
ActiveMQQueue queue2 = (ActiveMQQueue) instance;
ProxyAssertSupport.assertEquals(queue1.getQueueName(), queue2.getQueueName());
simpleSendReceive(cf, queue2);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class ReferenceableTest method testReferenceTopic.
@Test
public void testReferenceTopic() throws Exception {
Reference topicRef = ((Referenceable) ActiveMQServerTestCase.topic1).getReference();
String factoryName = topicRef.getFactoryClassName();
Class factoryClass = Class.forName(factoryName);
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
Object instance = factory.getObjectInstance(topicRef, null, null, null);
ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
ActiveMQTopic topic2 = (ActiveMQTopic) instance;
ProxyAssertSupport.assertEquals(ActiveMQServerTestCase.topic1.getTopicName(), topic2.getTopicName());
simpleSendReceive(cf, topic2);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class ResourceAdapterTest method testStartStopActivationManyTimes.
@Test
public void testStartStopActivationManyTimes() throws Exception {
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(false, false, false);
ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue("test");
session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), true);
session.close();
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
ra.setUserName("userGlobal");
ra.setPassword("passwordGlobal");
ra.start(new BootstrapContext());
Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection();
conn.close();
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setResourceAdapter(ra);
spec.setUseJNDI(false);
spec.setUser("user");
spec.setPassword("password");
spec.setDestinationType("javax.jms.Topic");
spec.setDestination("test");
spec.setMinSession(1);
spec.setMaxSession(15);
ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
ServerLocatorImpl serverLocator = (ServerLocatorImpl) ra.getDefaultActiveMQConnectionFactory().getServerLocator();
Set<XARecoveryConfig> resources = ra.getRecoveryManager().getResources();
for (int i = 0; i < 10; i++) {
System.out.println(i);
activation.start();
assertEquals(1, resources.size());
activation.stop();
}
ra.stop();
assertEquals(0, resources.size());
locator.close();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class EmbeddedJMSResource method getMessageCount.
/**
* Get the number of messages in a specific JMS Destination.
* <p>
* The full name of the JMS destination including the prefix should be provided - i.e. queue://myQueue
* or topic://myTopic. If the destination type prefix is not included in the destination name, a prefix
* of "queue://" is assumed.
*
* NOTE: For JMS Topics, this returned count will be the total number of messages for all subscribers. For
* example, if there are two subscribers on the topic and a single message is published, the returned count will
* be two (one message for each subscriber).
*
* @param destinationName the full name of the JMS Destination
* @return the number of messages in the JMS Destination
*/
public long getMessageCount(String destinationName) {
long count = 0;
ActiveMQDestination destination = ActiveMQDestination.createDestination(destinationName, ActiveMQDestination.TYPE.QUEUE);
if (destination.isQueue()) {
Queue queue = getDestinationQueue(destinationName);
if (queue == null) {
log.warn("getMessageCount(destinationName) - destination {} not found; returning -1", destinationName);
count = -1;
} else {
count = queue.getMessageCount();
}
} else {
for (Queue topicQueue : getTopicQueues(destinationName)) {
count += topicQueue.getMessageCount();
}
}
return count;
}
Aggregations