use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.
the class ScaleDownTest method testBasicScaleDown.
@Test
public void testBasicScaleDown() throws Exception {
final int TEST_SIZE = 2;
final String addressName = "testAddress";
final String queueName1 = "testQueue1";
final String queueName2 = "testQueue2";
// create 2 queues on each node mapped to the same address
createQueue(0, addressName, queueName1, null, true);
createQueue(0, addressName, queueName2, null, true);
createQueue(1, addressName, queueName1, null, true);
createQueue(1, addressName, queueName2, null, true);
// send messages to node 0
send(0, addressName, TEST_SIZE, true, null);
// consume a message from queue 2
addConsumer(1, 0, queueName2, null, false);
ClientMessage clientMessage = consumers[1].getConsumer().receive(250);
Assert.assertNotNull(clientMessage);
clientMessage.acknowledge();
consumers[1].getSession().commit();
// removeConsumer(1);
// at this point on node 0 there should be 2 messages in testQueue1 and 1 message in testQueue2
Assert.assertEquals(TEST_SIZE, getMessageCount(((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(queueName1))).getQueue()));
Assert.assertEquals(TEST_SIZE - 1, getMessageCount(((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(queueName2))).getQueue()));
// trigger scaleDown from node 0 to node 1
servers[0].stop();
// get the 2 messages from queue 1
addConsumer(0, 1, queueName1, null);
clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNotNull(clientMessage);
clientMessage.acknowledge();
clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNotNull(clientMessage);
clientMessage.acknowledge();
// ensure there are no more messages on queue 1
clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNull(clientMessage);
removeConsumer(0);
// get the 1 message from queue 2
addConsumer(0, 1, queueName2, null);
clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNotNull(clientMessage);
clientMessage.acknowledge();
// ensure there are no more messages on queue 1
clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNull(clientMessage);
removeConsumer(0);
}
use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.
the class ScaleDownTest method testStoreAndForward.
@Test
public void testStoreAndForward() throws Exception {
final int TEST_SIZE = 50;
final String addressName1 = "testAddress1";
final String addressName2 = "testAddress2";
final String queueName1 = "testQueue1";
final String queueName2 = "testQueue2";
// create queues on each node mapped to 2 addresses
createQueue(0, addressName1, queueName1, null, false);
createQueue(1, addressName1, queueName1, null, false);
createQueue(0, addressName2, queueName2, null, false);
createQueue(1, addressName2, queueName2, null, false);
// find and pause the sf queue so no messages actually move from node 0 to node 1
String sfQueueName = null;
for (Map.Entry<SimpleString, Binding> entry : servers[0].getPostOffice().getAllBindings().entrySet()) {
String temp = entry.getValue().getAddress().toString();
if (temp.startsWith(servers[1].getInternalNamingPrefix() + "sf.") && temp.endsWith(servers[1].getNodeID().toString())) {
// we found the sf queue for the other node
// need to pause the sfQueue here
((LocalQueueBinding) entry.getValue()).getQueue().pause();
sfQueueName = temp;
}
}
assertNotNull(sfQueueName);
// send messages to node 0
send(0, addressName1, TEST_SIZE, false, null);
send(0, addressName2, TEST_SIZE, false, null);
// add consumers to node 1 to force messages messages to redistribute to node 2 through the paused sf queue
addConsumer(0, 1, queueName1, null);
addConsumer(1, 1, queueName2, null);
LocalQueueBinding queue1Binding = ((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(queueName1)));
LocalQueueBinding queue2Binding = ((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(queueName2)));
LocalQueueBinding sfQueueBinding = ((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(sfQueueName)));
long timeout = 5000;
long start = System.currentTimeMillis();
while (getMessageCount(queue1Binding.getQueue()) > 0 && System.currentTimeMillis() - start <= timeout) {
Thread.sleep(50);
}
start = System.currentTimeMillis();
while (getMessageCount(queue2Binding.getQueue()) > 0 && System.currentTimeMillis() - start <= timeout) {
Thread.sleep(50);
}
start = System.currentTimeMillis();
while (getMessageCount(sfQueueBinding.getQueue()) < TEST_SIZE * 2 && System.currentTimeMillis() - start <= timeout) {
Thread.sleep(50);
}
// at this point on node 0 there should be 0 messages in test queues and TEST_SIZE * 2 messages in the sf queue
Assert.assertEquals(0, getMessageCount(queue1Binding.getQueue()));
Assert.assertEquals(0, getMessageCount(queue2Binding.getQueue()));
Assert.assertEquals(TEST_SIZE * 2, getMessageCount(sfQueueBinding.getQueue()));
removeConsumer(0);
removeConsumer(1);
// trigger scaleDown from node 0 to node 1
servers[0].stop();
// get the messages from node 1
addConsumer(0, 1, queueName1, null);
for (int i = 0; i < TEST_SIZE; i++) {
ClientMessage clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNotNull(clientMessage);
clientMessage.acknowledge();
}
ClientMessage clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNull(clientMessage);
removeConsumer(0);
addConsumer(0, 1, queueName2, null);
for (int i = 0; i < TEST_SIZE; i++) {
clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNotNull(clientMessage);
clientMessage.acknowledge();
}
clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNull(clientMessage);
removeConsumer(0);
}
use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.
the class QueueControlTest method testMoveMessages.
/**
* <ol>
* <li>send a message to queue</li>
* <li>move all messages from queue to otherQueue using management method</li>
* <li>check there is no message to consume from queue</li>
* <li>consume the message from otherQueue</li>
* </ol>
*/
@Test
public void testMoveMessages() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
SimpleString otherAddress = RandomUtil.randomSimpleString();
SimpleString otherQueue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
session.createQueue(otherAddress, RoutingType.MULTICAST, otherQueue, null, durable);
ClientProducer producer = session.createProducer(address);
// send on queue
ClientMessage message = session.createMessage(durable);
SimpleString key = RandomUtil.randomSimpleString();
long value = RandomUtil.randomLong();
message.putLongProperty(key, value);
producer.send(message);
final LocalQueueBinding binding = (LocalQueueBinding) server.getPostOffice().getBinding(queue);
Queue q = binding.getQueue();
Field queueMemorySizeField = QueueImpl.class.getDeclaredField("queueMemorySize");
queueMemorySizeField.setAccessible(true);
// Get memory size counters to verify
AtomicInteger queueMemorySize = (AtomicInteger) queueMemorySizeField.get(q);
QueueControl queueControl = createManagementControl(address, queue);
assertMessageMetrics(queueControl, 1, durable);
// verify memory usage is greater than 0
Assert.assertTrue(queueMemorySize.get() > 0);
// moved all messages to otherQueue
int movedMessagesCount = queueControl.moveMessages(null, otherQueue.toString());
Assert.assertEquals(1, movedMessagesCount);
assertMessageMetrics(queueControl, 0, durable);
// verify memory usage is 0 after move
Assert.assertEquals(0, queueMemorySize.get());
// check there is no message to consume from queue
consumeMessages(0, session, queue);
// consume the message from otherQueue
ClientConsumer otherConsumer = session.createConsumer(otherQueue);
ClientMessage m = otherConsumer.receive(500);
Assert.assertEquals(value, m.getObjectProperty(key));
m.acknowledge();
session.deleteQueue(queue);
otherConsumer.close();
session.deleteQueue(otherQueue);
}
use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.
the class FQQNOpenWireTest method testTopic.
@Test
public // however we can test query functionality
void testTopic() throws Exception {
Connection connection = factory.createConnection();
try {
connection.setClientID("FQQNconn");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(multicastAddress.toString());
MessageConsumer consumer1 = session.createConsumer(topic);
MessageConsumer consumer2 = session.createConsumer(topic);
MessageConsumer consumer3 = session.createConsumer(topic);
MessageProducer producer = session.createProducer(topic);
producer.send(session.createMessage());
// each consumer receives one
Message m = consumer1.receive(2000);
assertNotNull(m);
m = consumer2.receive(2000);
assertNotNull(m);
m = consumer3.receive(2000);
assertNotNull(m);
Bindings bindings = server.getPostOffice().getBindingsForAddress(multicastAddress);
for (Binding b : bindings.getBindings()) {
System.out.println("checking binidng " + b.getUniqueName() + " " + ((LocalQueueBinding) b).getQueue().getDeliveringMessages());
SimpleString qName = b.getUniqueName();
// do FQQN query
QueueQueryResult result = server.queueQuery(CompositeAddress.toFullQN(multicastAddress, qName));
assertTrue(result.isExists());
assertEquals(result.getName(), CompositeAddress.toFullQN(multicastAddress, qName));
// do qname query
result = server.queueQuery(qName);
assertTrue(result.isExists());
assertEquals(result.getName(), qName);
}
} finally {
connection.close();
}
}
use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.
the class PagingOrderTest method testPageCounter.
@Test
public void testPageCounter() throws Throwable {
boolean persistentMessages = true;
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
server.start();
final int messageSize = 1024;
final int numberOfMessages = 500;
ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(1024 * 1024);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
Queue q1 = server.createQueue(ADDRESS, RoutingType.MULTICAST, ADDRESS, null, true, false);
Queue q2 = server.createQueue(ADDRESS, RoutingType.MULTICAST, new SimpleString("inactive"), null, true, false);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
byte[] body = new byte[messageSize];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= messageSize; j++) {
bb.put(getSamplebyte(j));
}
final AtomicInteger errors = new AtomicInteger(0);
Thread t1 = new Thread() {
@Override
public void run() {
try {
ServerLocator sl = createInVMNonHALocator();
ClientSessionFactory sf = sl.createSessionFactory();
ClientSession sess = sf.createSession(true, true, 0);
sess.start();
ClientConsumer cons = sess.createConsumer(ADDRESS);
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage msg = cons.receive(5000);
assertNotNull(msg);
assertEquals(i, msg.getIntProperty("id").intValue());
msg.acknowledge();
}
assertNull(cons.receiveImmediate());
sess.close();
sl.close();
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
};
t1.start();
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage message = session.createMessage(persistentMessages);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
if (i % 20 == 0) {
session.commit();
}
}
session.commit();
t1.join();
assertEquals(0, errors.get());
assertEquals(numberOfMessages, getMessageCount(q2));
assertEquals(numberOfMessages, getMessagesAdded(q2));
assertEquals(0, getMessageCount(q1));
assertEquals(numberOfMessages, getMessagesAdded(q1));
session.close();
sf.close();
locator.close();
server.stop();
server.start();
Bindings bindings = server.getPostOffice().getBindingsForAddress(ADDRESS);
q1 = null;
q2 = null;
for (Binding bind : bindings.getBindings()) {
if (bind instanceof LocalQueueBinding) {
LocalQueueBinding qb = (LocalQueueBinding) bind;
if (qb.getQueue().getName().equals(ADDRESS)) {
q1 = qb.getQueue();
}
if (qb.getQueue().getName().equals(new SimpleString("inactive"))) {
q2 = qb.getQueue();
}
}
}
assertNotNull(q1);
assertNotNull(q2);
assertEquals("q2 msg count", numberOfMessages, getMessageCount(q2));
assertEquals("q2 msgs added", numberOfMessages, getMessagesAdded(q2));
assertEquals("q1 msg count", 0, getMessageCount(q1));
// 0, since nothing was sent to the queue after the server was restarted
assertEquals("q1 msgs added", 0, getMessagesAdded(q1));
}
Aggregations