@Override public long getTotalMessageCount() { long total = 0; for (Binding binding : postOffice.getAllBindings().values()) { if (binding.getType() == BindingType.LOCAL_QUEUE) { total += ((LocalQueueBinding) binding).getQueue().getMessageCount(); } } return total; }
@Override public long getTotalMessagesAdded() { long total = 0; for (Binding binding : postOffice.getAllBindings().values()) { if (binding.getType() == BindingType.LOCAL_QUEUE) { total += ((LocalQueueBinding) binding).getQueue().getMessagesAdded(); } } return total; }
@Override public long getTotalMessagesAcknowledged() { long total = 0; for (Binding binding : postOffice.getAllBindings().values()) { if (binding.getType() == BindingType.LOCAL_QUEUE) { total += ((LocalQueueBinding) binding).getQueue().getMessagesAcknowledged(); } } return total; }
@Override public long getTotalConsumerCount() { long total = 0; for (Binding binding : postOffice.getAllBindings().values()) { if (binding.getType() == BindingType.LOCAL_QUEUE) { total += ((LocalQueueBinding) binding).getQueue().getConsumerCount(); } } return total; }
public int getQueueCountForUser(String username) throws Exception { Map<SimpleString, Binding> bindings = postOffice.getAllBindings(); int queuesForUser = 0; for (Binding binding : bindings.values()) { if (binding instanceof LocalQueueBinding && ((LocalQueueBinding) binding).getQueue().getUser().equals(SimpleString.toSimpleString(username))) { queuesForUser++; } } return queuesForUser; }
protected List<Queue> getQueues(final String address) throws Exception { final List<Queue> queues = new ArrayList<>(); for (Binding binding : server.getPostOffice().getDirectBindings(SimpleString.toSimpleString(address)) .getBindings()) { if (binding.getType() == BindingType.LOCAL_QUEUE) { LocalQueueBinding queueBinding = (LocalQueueBinding) binding; queues.add(queueBinding.getQueue()); } } return queues; }
protected boolean assertRemainingMessages(final int expected) throws Exception { String queueName = "Queue1"; Binding binding = servers.get(0).getActiveMQServer().getPostOffice().getBinding(SimpleString.toSimpleString(queueName)); if (binding != null && binding instanceof LocalQueueBinding) { ((LocalQueueBinding) binding).getQueue().flushExecutor(); } Long messageCount = null; for (int i = 0; i < 10; i++) { messageCount = servers.get(0).getMessageCountForQueue(queueName); if (messageCount.longValue() == expected) { break; } else { Thread.sleep(100); } } ProxyAssertSupport.assertEquals(expected, messageCount.intValue()); return expected == messageCount.intValue(); }
private void checkQueueEmpty(String qName) { PostOffice po = server.getPostOffice(); LocalQueueBinding binding = (LocalQueueBinding) po.getBinding(SimpleString.toSimpleString(qName)); try { //waiting for last ack to finish Thread.sleep(1000); } catch (InterruptedException e) { } assertEquals(0L, binding.getQueue().getMessageCount()); }
for (Binding binding : bindings.getBindings()) { if (binding instanceof LocalQueueBinding) { Queue queue = ((LocalQueueBinding) binding).getQueue();
if (!key.toString().equals(topic.getAddress())) { foundStrayRoutingBinding = true; assertEquals(0, ((LocalQueueBinding) routingNames.get(key).get(0)).getQueue().getMessageCount());
for (Binding binding : postOffice.getMatchingBindings(SimpleString.toSimpleString(address)).getBindings()) { if (binding instanceof LocalQueueBinding) { Queue queue = ((LocalQueueBinding) binding).getQueue(); for (Consumer consumer : queue.getConsumers()) { if (consumer instanceof ServerConsumer) {
System.out.println("checking binidng " + b.getUniqueName() + " " + ((LocalQueueBinding)b).getQueue().getDeliveringMessages()); SimpleString qName = b.getUniqueName();
@Test public void testGetScheduledCountOnRemove() throws Exception { long delay = Integer.MAX_VALUE; SimpleString address = RandomUtil.randomSimpleString(); SimpleString queue = RandomUtil.randomSimpleString(); session.createQueue(address, RoutingType.MULTICAST, queue, null, durable); QueueControl queueControl = createManagementControl(address, queue); Assert.assertEquals(0, queueControl.getScheduledCount()); Field queueMemorySizeField = QueueImpl.class.getDeclaredField("queueMemorySize"); queueMemorySizeField.setAccessible(true); final LocalQueueBinding binding = (LocalQueueBinding) server.getPostOffice().getBinding(queue); Queue q = binding.getQueue(); AtomicInteger queueMemorySize1 = (AtomicInteger) queueMemorySizeField.get(q); assertEquals(0, queueMemorySize1.get()); ClientProducer producer = session.createProducer(address); ClientMessage message = session.createMessage(durable); message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, System.currentTimeMillis() + delay); producer.send(message); queueControl.removeAllMessages(); Assert.assertEquals(0, queueControl.getMessageCount()); //Verify that original queue has a memory size of 0 assertEquals(0, queueMemorySize1.get()); session.deleteQueue(queue); }
System.out.println("checking binidng " + b.getUniqueName() + " " + ((LocalQueueBinding)b).getQueue().getDeliveringMessages()); SimpleString qName = b.getUniqueName();
@Test public void testEndpointDeactivated() throws Exception { ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); CountDownLatch latch = new CountDownLatch(1); DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch); DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false); qResourceAdapter.endpointActivation(endpointFactory, spec); Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE); assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 15); qResourceAdapter.endpointDeactivation(endpointFactory, spec); assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 0); assertTrue(endpoint.released); qResourceAdapter.stop(); }
@Test public void testMaxSessions() throws Exception { ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setMaxSession(1); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); CountDownLatch latch = new CountDownLatch(1); DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch); DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false); qResourceAdapter.endpointActivation(endpointFactory, spec); Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE); assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 1); qResourceAdapter.endpointDeactivation(endpointFactory, spec); qResourceAdapter.stop(); }
qResourceAdapter.endpointActivation(endpointFactory, spec); Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE); assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 15); qResourceAdapter.endpointDeactivation(endpointFactory, spec); qResourceAdapter.stop();
@Test public void testSimpleMessageReceivedOnQueueWithSecurityFails() throws Exception { SecurityConfiguration emptyConfiguration = new SecurityConfiguration(); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).setConfiguration(emptyConfiguration); ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); spec.setUser("dodgyuser"); spec.setPassword("dodgypassword"); spec.setSetupAttempts(0); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); CountDownLatch latch = new CountDownLatch(1); DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch); DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false); qResourceAdapter.endpointActivation(endpointFactory, spec); Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE); assertEquals(0, ((LocalQueueBinding) binding).getQueue().getConsumerCount()); qResourceAdapter.endpointDeactivation(endpointFactory, spec); qResourceAdapter.stop(); }
locator.close(); Queue queue = ((LocalQueueBinding) server.getPostOffice().getBinding(new SimpleString(MY_QUEUE))).getQueue(); LinkedListIterator<MessageReference> totalIterator = queue.browserIterator();
@Test public void testSubscribeToNonExistentQueue() throws Exception { String nonExistentQueue = RandomUtil.randomString(); conn.connect(defUser, defPass); subscribe(conn, null, null, null, null, getQueuePrefix() + nonExistentQueue, true); sendJmsMessage(getName(), ActiveMQJMSClient.createQueue(nonExistentQueue)); ClientStompFrame frame = conn.receiveFrame(1000); Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand()); Assert.assertEquals(getQueuePrefix() + nonExistentQueue, frame.getHeader(Stomp.Headers.Send.DESTINATION)); Assert.assertEquals(getName(), frame.getBody()); assertNotNull(server.getPostOffice().getBinding(new SimpleString(nonExistentQueue))); final Queue subscription = ((LocalQueueBinding) server.getPostOffice().getBinding(new SimpleString(nonExistentQueue))).getQueue(); assertTrue(Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { if (subscription.getMessageCount() == 0) return true; else return false; } }, 1000, 50)); unsubscribe(conn, null, getQueuePrefix() + nonExistentQueue, true, false); assertNull(server.getPostOffice().getBinding(new SimpleString(nonExistentQueue))); sendJmsMessage(getName(), ActiveMQJMSClient.createQueue(nonExistentQueue)); frame = conn.receiveFrame(1000); log.info("Received frame: " + frame); Assert.assertNull("No message should have been received since subscription was removed", frame); conn.disconnect(); }