use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class VerySimpleOenwireTest method testOpenWireExample.
/**
* This is the example shipped with the distribution
*
* @throws Exception
*/
@Test
public void testOpenWireExample() throws Exception {
Connection exConn = null;
SimpleString durableQueue = new SimpleString("exampleQueue");
this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
try {
ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
Queue queue = new ActiveMQQueue("exampleQueue");
exConn = exFact.createConnection();
exConn.start();
Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage("This is a text message");
producer.send(message);
MessageConsumer messageConsumer = session.createConsumer(queue);
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
assertEquals("This is a text message", messageReceived.getText());
} finally {
if (exConn != null) {
exConn.close();
}
}
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class JmsQueueBrowserTest method testReceiveBrowseReceive.
/**
* Tests the queue browser. Browses the messages then the consumer tries to
* receive them. The messages should still be in the queue even when it was
* browsed.
*
* @throws Exception
*/
@Test
public void testReceiveBrowseReceive() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue destination = (ActiveMQQueue) this.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
MessageProducer producer = session.createProducer(destination);
MessageConsumer consumer = session.createConsumer(destination);
connection.start();
Message[] outbound = new Message[] { session.createTextMessage("First Message"), session.createTextMessage("Second Message"), session.createTextMessage("Third Message") };
// lets consume any outstanding messages from previous test runs
while (consumer.receive(1000) != null) {
}
producer.send(outbound[0]);
producer.send(outbound[1]);
producer.send(outbound[2]);
// Get the first.
assertEquals(outbound[0], consumer.receive(1000));
consumer.close();
System.out.println("creating browser...");
QueueBrowser browser = session.createBrowser(destination);
System.out.println("browser created");
Enumeration<?> enumeration = browser.getEnumeration();
// browse the second
assertTrue("should have received the second message", enumeration.hasMoreElements());
assertEquals(outbound[1], enumeration.nextElement());
// browse the third.
assertTrue("Should have received the third message", enumeration.hasMoreElements());
assertEquals(outbound[2], enumeration.nextElement());
// There should be no more.
boolean tooMany = false;
while (enumeration.hasMoreElements()) {
System.out.println("Got extra message: " + ((TextMessage) enumeration.nextElement()).getText());
tooMany = true;
}
assertFalse(tooMany);
browser.close();
// Re-open the consumer.
consumer = session.createConsumer(destination);
// Receive the second.
assertEquals(outbound[1], consumer.receive(1000));
// Receive the third.
assertEquals(outbound[2], consumer.receive(1000));
consumer.close();
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class JmsQueueBrowserTest method testBatchSendBrowseReceive.
@Test
public void testBatchSendBrowseReceive() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue destination = (ActiveMQQueue) this.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
MessageProducer producer = session.createProducer(destination);
MessageConsumer consumer = session.createConsumer(destination);
connection.start();
TextMessage[] outbound = new TextMessage[10];
for (int i = 0; i < 10; i++) {
outbound[i] = session.createTextMessage(i + " Message");
}
// lets consume any outstanding messages from previous test runs
while (consumer.receive(1000) != null) {
}
consumer.close();
for (int i = 0; i < outbound.length; i++) {
producer.send(outbound[i]);
}
QueueBrowser browser = session.createBrowser(destination);
Enumeration<?> enumeration = browser.getEnumeration();
for (int i = 0; i < outbound.length; i++) {
assertTrue("should have a", enumeration.hasMoreElements());
assertEquals(outbound[i], enumeration.nextElement());
}
browser.close();
for (int i = 0; i < outbound.length; i++) {
producer.send(outbound[i]);
}
// verify second batch is visible to browse
browser = session.createBrowser(destination);
enumeration = browser.getEnumeration();
for (int j = 0; j < 2; j++) {
for (int i = 0; i < outbound.length; i++) {
assertTrue("should have a", enumeration.hasMoreElements());
assertEquals("j=" + j + ", i=" + i, outbound[i].getText(), ((TextMessage) enumeration.nextElement()).getText());
}
}
browser.close();
consumer = session.createConsumer(destination);
for (int i = 0; i < outbound.length * 2; i++) {
assertNotNull("Got message: " + i, consumer.receive(2000));
}
consumer.close();
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class AbstractCachedLDAPAuthorizationMapLegacyTest method testSynchronousUpdate.
@Test
public void testSynchronousUpdate() throws Exception {
map.setRefreshInterval(1);
map.query();
Set<?> readACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
assertEquals("set size: " + readACLs, 2, readACLs.size());
assertTrue("Contains admin group", readACLs.contains(ADMINS));
assertTrue("Contains users group", readACLs.contains(USERS));
Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
assertEquals("set size: " + failedACLs, 0, failedACLs.size());
LdifReader reader = new LdifReader(getRemoveLdif());
for (LdifEntry entry : reader) {
connection.delete(entry.getDn());
}
reader.close();
assertTrue("did not get expected size. ", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return map.getReadACLs(new ActiveMQQueue("TEST.FOO")).size() == 0;
}
}));
assertNull(map.getTempDestinationReadACLs());
assertNull(map.getTempDestinationWriteACLs());
assertNull(map.getTempDestinationAdminACLs());
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class AbstractCachedLDAPAuthorizationMapLegacyTest method testAdd.
@Test
public void testAdd() throws Exception {
map.query();
Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
assertEquals("set size: " + failedACLs, 0, failedACLs.size());
LdifReader reader = new LdifReader(getAddLdif());
for (LdifEntry entry : reader) {
connection.add(entry.getEntry());
}
reader.close();
Thread.sleep(2000);
failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
assertEquals("set size: " + failedACLs, 2, failedACLs.size());
}
Aggregations