Here are the examples of the java api class org.apache.activemq.broker.jmx.DestinationViewMBean taken from open source projects.
1. QueueProducerQoSTest#testInOnlyQueueProducerTTL()
Project: camel
File: QueueProducerQoSTest.java
File: QueueProducerQoSTest.java
@Test public void testInOnlyQueueProducerTTL() throws Exception { mockExpiredAdvisory.expectedMessageCount(1); String endpoint = String.format("sjms:queue:%s?ttl=1000", TEST_INONLY_DESTINATION_NAME); template.sendBody(endpoint, "test message"); assertMockEndpointsSatisfied(); DestinationViewMBean queue = getQueueMBean(TEST_INONLY_DESTINATION_NAME); assertEquals("There were unexpected messages left in the queue: " + TEST_INONLY_DESTINATION_NAME, 0, queue.getQueueSize()); }
2. QueueProducerQoSTest#testInOutQueueProducerTTL()
Project: camel
File: QueueProducerQoSTest.java
File: QueueProducerQoSTest.java
@Test public void testInOutQueueProducerTTL() throws Exception { mockExpiredAdvisory.expectedMessageCount(1); String endpoint = String.format("sjms:queue:%s?ttl=1000&exchangePattern=InOut&responseTimeOut=500", TEST_INOUT_DESTINATION_NAME); try { template.requestBody(endpoint, "test message"); fail("we aren't expecting any consumers, so should not succeed"); } catch (Exception e) { } assertMockEndpointsSatisfied(); DestinationViewMBean queue = getQueueMBean(TEST_INOUT_DESTINATION_NAME); assertEquals("There were unexpected messages left in the queue: " + TEST_INOUT_DESTINATION_NAME, 0, queue.getQueueSize()); }
3. TwoBrokerTempQueueAdvisoryTest#testTemporaryQueueAdvisory()
Project: activemq-artemis
File: TwoBrokerTempQueueAdvisoryTest.java
File: TwoBrokerTempQueueAdvisoryTest.java
public void testTemporaryQueueAdvisory() throws Exception { LOG.info("Running testTemporaryQueueAdvisory()"); bridgeBrokers("BrokerA", "BrokerB"); bridgeBrokers("BrokerB", "BrokerA"); startAllBrokers(); waitForBridgeFormation(); waitForMinTopicRegionConsumerCount("BrokerB", 1); waitForMinTopicRegionConsumerCount("BrokerA", 1); final int iterations = 30; for (int i = 0; i < iterations; i++) { sendReceiveTempQueueMessage("BrokerA"); } waitForMinTopicRegionConsumerCount("BrokerB", 1); waitForMinTopicRegionConsumerCount("BrokerA", 1); final DestinationViewMBean brokerAView = createView("BrokerA", "ActiveMQ.Advisory.TempQueue", ActiveMQDestination.TOPIC_TYPE); assertTrue("exact amount of advisories created on A, one each for creation/deletion", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { LOG.info("BrokerA temp advisory enque count: " + brokerAView.getEnqueueCount()); return iterations * 2 == brokerAView.getEnqueueCount(); } })); final DestinationViewMBean brokerBView = createView("BrokerB", "ActiveMQ.Advisory.TempQueue", ActiveMQDestination.TOPIC_TYPE); assertTrue("exact amount of advisories created on B, one each for creation/deletion", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { LOG.info("BrokerB temp advisory enque count: " + brokerBView.getEnqueueCount()); return iterations * 2 == brokerBView.getEnqueueCount(); } })); }
4. ExpiredMessagesWithNoConsumerTest#testExpireMessagesForDurableSubscriber()
Project: activemq-artemis
File: ExpiredMessagesWithNoConsumerTest.java
File: ExpiredMessagesWithNoConsumerTest.java
public void testExpireMessagesForDurableSubscriber() throws Exception { createBroker(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri); connection = factory.createConnection(); connection.setClientID("myConnection"); session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); connection.start(); Topic destination = session.createTopic("test"); producer = session.createProducer(destination); final int ttl = 1000; producer.setTimeToLive(ttl); final long sendCount = 10; TopicSubscriber sub = session.createDurableSubscriber(destination, "mySub"); sub.close(); for (int i = 0; i < sendCount; i++) { producer.send(session.createTextMessage("test")); } DestinationViewMBean view = createView((ActiveMQTopic) destination); LOG.info("messages sent"); LOG.info("expired=" + view.getExpiredCount() + " " + view.getEnqueueCount()); assertEquals(0, view.getExpiredCount()); assertEquals(10, view.getEnqueueCount()); Thread.sleep(5000); LOG.info("expired=" + view.getExpiredCount() + " " + view.getEnqueueCount()); assertEquals(10, view.getExpiredCount()); assertEquals(10, view.getEnqueueCount()); final AtomicLong received = new AtomicLong(); sub = session.createDurableSubscriber(destination, "mySub"); sub.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { received.incrementAndGet(); } }); LOG.info("Waiting for messages to arrive"); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return received.get() >= sendCount; } }, 1000); LOG.info("received=" + received.get()); LOG.info("expired=" + view.getExpiredCount() + " " + view.getEnqueueCount()); assertEquals(0, received.get()); assertEquals(10, view.getExpiredCount()); assertEquals(10, view.getEnqueueCount()); }
5. ExpiredMessagesWithNoConsumerTest#testExpiredMessagesWithVerySlowConsumerCanContinue()
Project: activemq-artemis
File: ExpiredMessagesWithNoConsumerTest.java
File: ExpiredMessagesWithNoConsumerTest.java
public void testExpiredMessagesWithVerySlowConsumerCanContinue() throws Exception { createBroker(); final long queuePrefetch = 600; ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri + "?jms.prefetchPolicy.queuePrefetch=" + queuePrefetch); connection = factory.createConnection(); session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); producer = session.createProducer(destination); final int ttl = 4000; producer.setTimeToLive(ttl); final long sendCount = 1500; final CountDownLatch receivedOneCondition = new CountDownLatch(1); final CountDownLatch waitCondition = new CountDownLatch(1); final AtomicLong received = new AtomicLong(); MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { if (LOG.isDebugEnabled()) { LOG.debug("Got my message: " + message); } receivedOneCondition.countDown(); received.incrementAndGet(); waitCondition.await(5, TimeUnit.MINUTES); if (LOG.isDebugEnabled()) { LOG.debug("acking message: " + message); } message.acknowledge(); } catch (Exception e) { e.printStackTrace(); fail(e.toString()); } } }); connection.start(); final Thread producingThread = new Thread("Producing Thread") { @Override public void run() { try { int i = 0; long tStamp = System.currentTimeMillis(); while (i++ < sendCount) { producer.send(session.createTextMessage("test")); if (i % 100 == 0) { LOG.info("sent: " + i + " @ " + ((System.currentTimeMillis() - tStamp) / 100) + "m/ms"); tStamp = System.currentTimeMillis(); } } } catch (Throwable ex) { ex.printStackTrace(); } } }; producingThread.start(); assertTrue("got one message", receivedOneCondition.await(20, TimeUnit.SECONDS)); assertTrue("producer failed to complete within allocated time", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { producingThread.join(1000); return !producingThread.isAlive(); } }, Wait.MAX_WAIT_MILLIS * 10)); final DestinationViewMBean view = createView(destination); assertTrue("Not all dispatched up to default prefetch ", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return queuePrefetch == view.getDispatchCount(); } })); assertTrue("all non inflight have expired ", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize()); return view.getExpiredCount() > 0 && (view.getEnqueueCount() - view.getInFlightCount()) == view.getExpiredCount(); } })); LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize()); // let the ack happen waitCondition.countDown(); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return 0 == view.getInFlightCount(); } }); LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize()); assertEquals("inflight didn't reduce to duck", 0, view.getInFlightCount()); assertEquals("size doesn't get back to 0 ", 0, view.getQueueSize()); assertEquals("dequeues don't match sent/expired ", sendCount, view.getDequeueCount()); // produce some more producer.setTimeToLive(0); long tStamp = System.currentTimeMillis(); for (int i = 0; i < sendCount; i++) { producer.send(session.createTextMessage("test-" + i)); if (i % 100 == 0) { LOG.info("sent: " + i + " @ " + ((System.currentTimeMillis() - tStamp) / 100) + "m/ms"); tStamp = System.currentTimeMillis(); } } Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return received.get() >= sendCount; } }); consumer.close(); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return 0 == view.getInFlightCount(); } }); assertEquals("inflight did not go to zero on close", 0, view.getInFlightCount()); LOG.info("done: " + getName()); }
6. ExpiredMessagesWithNoConsumerTest#testExpiredMessagesWithVerySlowConsumer()
Project: activemq-artemis
File: ExpiredMessagesWithNoConsumerTest.java
File: ExpiredMessagesWithNoConsumerTest.java
// first ack delivered after expiry public void testExpiredMessagesWithVerySlowConsumer() throws Exception { createBroker(); final long queuePrefetch = 5; ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri + "?jms.prefetchPolicy.queuePrefetch=" + queuePrefetch); connection = factory.createConnection(); session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); producer = session.createProducer(destination); final int ttl = 4000; producer.setTimeToLive(ttl); final long sendCount = 10; final CountDownLatch receivedOneCondition = new CountDownLatch(1); final CountDownLatch waitCondition = new CountDownLatch(1); MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { LOG.info("Got my message: " + message); receivedOneCondition.countDown(); waitCondition.await(6, TimeUnit.MINUTES); LOG.info("acking message: " + message); message.acknowledge(); } catch (Exception e) { e.printStackTrace(); fail(e.toString()); } } }); connection.start(); final Thread producingThread = new Thread("Producing Thread") { @Override public void run() { try { int i = 0; long tStamp = System.currentTimeMillis(); while (i++ < sendCount) { producer.send(session.createTextMessage("test")); if (i % 100 == 0) { LOG.info("sent: " + i + " @ " + ((System.currentTimeMillis() - tStamp) / 100) + "m/ms"); tStamp = System.currentTimeMillis(); } } } catch (Throwable ex) { ex.printStackTrace(); } } }; producingThread.start(); assertTrue("got one message", receivedOneCondition.await(20, TimeUnit.SECONDS)); assertTrue("producer failed to complete within allocated time", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { producingThread.join(1000); return !producingThread.isAlive(); } }, Wait.MAX_WAIT_MILLIS * 10)); final DestinationViewMBean view = createView(destination); assertTrue("all dispatched up to default prefetch ", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return queuePrefetch == view.getDispatchCount(); } })); assertTrue("all non inflight have expired ", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize()); return view.getExpiredCount() > 0 && (view.getEnqueueCount() - view.getInFlightCount()) == view.getExpiredCount(); } })); LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize()); // let the ack happen waitCondition.countDown(); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return 0 == view.getInFlightCount(); } }); LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize()); assertEquals("inflight reduced to duck", 0, view.getInFlightCount()); assertEquals("size didn't get back to 0 ", 0, view.getQueueSize()); assertEquals("dequeues didn't match sent/expired ", sendCount, view.getDequeueCount()); consumer.close(); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return 0 == view.getInFlightCount(); } }); assertEquals("inflight goes to zero on close", 0, view.getInFlightCount()); LOG.info("done: " + getName()); }
7. ExpiredMessagesWithNoConsumerTest#testExpiredMessagesWithNoConsumer()
Project: activemq-artemis
File: ExpiredMessagesWithNoConsumerTest.java
File: ExpiredMessagesWithNoConsumerTest.java
public void testExpiredMessagesWithNoConsumer() throws Exception { createBrokerWithMemoryLimit(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri); connection = factory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(destination); producer.setTimeToLive(1000); connection.start(); final long sendCount = 2000; final Thread producingThread = new Thread("Producing Thread") { @Override public void run() { try { int i = 0; long tStamp = System.currentTimeMillis(); while (i++ < sendCount) { producer.send(session.createTextMessage("test")); if (i % 100 == 0) { LOG.info("sent: " + i + " @ " + ((System.currentTimeMillis() - tStamp) / 100) + "m/ms"); tStamp = System.currentTimeMillis(); } } } catch (Throwable ex) { ex.printStackTrace(); } } }; producingThread.start(); assertTrue("producer failed to complete within allocated time", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { producingThread.join(TimeUnit.SECONDS.toMillis(3000)); return !producingThread.isAlive(); } })); final DestinationViewMBean view = createView(destination); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize()); return sendCount == view.getExpiredCount(); } }, Wait.MAX_WAIT_MILLIS * 10); LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize()); assertEquals("Not all sent messages have expired", sendCount, view.getExpiredCount()); assertEquals("memory usage doesn't go to duck egg", 0, view.getMemoryPercentUsage()); }
8. ExpiredMessagesWithNoConsumerTest#testExpiredNonPersistentMessagesWithNoConsumer()
Project: activemq-artemis
File: ExpiredMessagesWithNoConsumerTest.java
File: ExpiredMessagesWithNoConsumerTest.java
public void testExpiredNonPersistentMessagesWithNoConsumer() throws Exception { createBrokerWithMemoryLimit(2000); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri); connection = factory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(destination); producer.setTimeToLive(1000); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); connection.start(); final long sendCount = 2000; final Thread producingThread = new Thread("Producing Thread") { @Override public void run() { try { int i = 0; long tStamp = System.currentTimeMillis(); while (i++ < sendCount) { producer.send(session.createTextMessage("test")); if (i % 100 == 0) { LOG.info("sent: " + i + " @ " + ((System.currentTimeMillis() - tStamp) / 100) + "m/ms"); tStamp = System.currentTimeMillis(); } if (135 == i) { // allow pending messages to expire, before usage limit kicks in to flush them TimeUnit.SECONDS.sleep(5); } } } catch (Throwable ex) { ex.printStackTrace(); } } }; producingThread.start(); assertTrue("producer failed to complete within allocated time", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { producingThread.join(TimeUnit.SECONDS.toMillis(3000)); return !producingThread.isAlive(); } })); TimeUnit.SECONDS.sleep(5); final DestinationViewMBean view = createView(destination); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { try { LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize()); return view.getDequeueCount() != 0 && view.getDequeueCount() == view.getExpiredCount() && view.getDequeueCount() == view.getEnqueueCount() && view.getQueueSize() == 0; } catch (Exception ignored) { LOG.info(ignored.toString()); } return false; } }, Wait.MAX_WAIT_MILLIS * 10); LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize()); assertEquals("memory usage doesn't go to duck egg", 0, view.getMemoryPercentUsage()); assertEquals("0 queue", 0, view.getQueueSize()); }
9. XARecoveryBrokerTest#testQueuePersistentPreparedAcksNotLostOnRestart()
Project: activemq-artemis
File: XARecoveryBrokerTest.java
File: XARecoveryBrokerTest.java
public void testQueuePersistentPreparedAcksNotLostOnRestart() throws Exception { ActiveMQDestination destination = createDestination(); // Setup the producer and send the message. StubConnection connection = createConnection(); ConnectionInfo connectionInfo = createConnectionInfo(); SessionInfo sessionInfo = createSessionInfo(connectionInfo); ProducerInfo producerInfo = createProducerInfo(sessionInfo); connection.send(connectionInfo); connection.send(sessionInfo); connection.send(producerInfo); for (int i = 0; i < 4; i++) { Message message = createMessage(producerInfo, destination); message.setPersistent(true); connection.send(message); } // Begin the transaction. XATransactionId txid = createXATransaction(sessionInfo); connection.send(createBeginTransaction(connectionInfo, txid)); ConsumerInfo consumerInfo; Message m = null; for (ActiveMQDestination dest : destinationList(destination)) { // Setup the consumer and receive the message. consumerInfo = createConsumerInfo(sessionInfo, dest); connection.send(consumerInfo); for (int i = 0; i < 4; i++) { m = receiveMessage(connection); assertNotNull(m); } // one ack with last received, mimic a beforeEnd synchronization MessageAck ack = createAck(consumerInfo, m, 4, MessageAck.STANDARD_ACK_TYPE); ack.setTransactionId(txid); connection.send(ack); } connection.request(createPrepareTransaction(connectionInfo, txid)); // restart the broker. restartBroker(); connection = createConnection(); connectionInfo = createConnectionInfo(); connection.send(connectionInfo); // validate recovery TransactionInfo recoverInfo = new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER); DataArrayResponse dataArrayResponse = (DataArrayResponse) connection.request(recoverInfo); assertEquals("there is a prepared tx", 1, dataArrayResponse.getData().length); assertEquals("it matches", txid, dataArrayResponse.getData()[0]); sessionInfo = createSessionInfo(connectionInfo); connection.send(sessionInfo); consumerInfo = createConsumerInfo(sessionInfo, destination); connection.send(consumerInfo); // no redelivery, exactly once semantics unless there is rollback m = receiveMessage(connection); assertNull(m); assertNoMessagesLeft(connection); // validate destination depth via jmx DestinationViewMBean destinationView = getProxyToDestination(destinationList(destination)[0]); assertEquals("enqueue count does not see prepared acks", 4, destinationView.getQueueSize()); assertEquals("enqueue count does not see prepared acks", 0, destinationView.getDequeueCount()); connection.request(createCommitTransaction2Phase(connectionInfo, txid)); // validate recovery complete dataArrayResponse = (DataArrayResponse) connection.request(recoverInfo); assertEquals("there are no prepared tx", 0, dataArrayResponse.getData().length); assertEquals("enqueue count does not see committed acks", 0, destinationView.getQueueSize()); assertEquals("enqueue count does not see committed acks", 4, destinationView.getDequeueCount()); }
10. XARecoveryBrokerTest#getProxyToDestination()
Project: activemq-artemis
File: XARecoveryBrokerTest.java
File: XARecoveryBrokerTest.java
private DestinationViewMBean getProxyToDestination(ActiveMQDestination destination) throws MalformedObjectNameException, JMSException { final ObjectName objectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + broker.getBrokerName() + ",destinationType=" + JMXSupport.encodeObjectNamePart(destination.getDestinationTypeAsString()) + ",destinationName=" + JMXSupport.encodeObjectNamePart(destination.getPhysicalName())); DestinationViewMBean proxy = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(objectName, DestinationViewMBean.class, true); return proxy; }
11. XARecoveryBrokerTest#testPreparedJmxView()
Project: activemq-artemis
File: XARecoveryBrokerTest.java
File: XARecoveryBrokerTest.java
public void testPreparedJmxView() throws Exception { ActiveMQDestination destination = createDestination(); // Setup the producer and send the message. StubConnection connection = createConnection(); ConnectionInfo connectionInfo = createConnectionInfo(); SessionInfo sessionInfo = createSessionInfo(connectionInfo); ProducerInfo producerInfo = createProducerInfo(sessionInfo); connection.send(connectionInfo); connection.send(sessionInfo); connection.send(producerInfo); ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination); connection.send(consumerInfo); // Prepare 4 message sends. for (int i = 0; i < 4; i++) { // Begin the transaction. XATransactionId txid = createXATransaction(sessionInfo); connection.send(createBeginTransaction(connectionInfo, txid)); Message message = createMessage(producerInfo, destination); message.setPersistent(true); message.setTransactionId(txid); connection.send(message); // Prepare connection.send(createPrepareTransaction(connectionInfo, txid)); } Response response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER)); assertNotNull(response); DataArrayResponse dar = (DataArrayResponse) response; assertEquals(4, dar.getData().length); // view prepared in kahadb view if (broker.getPersistenceAdapter() instanceof KahaDBPersistenceAdapter) { PersistenceAdapterViewMBean kahadbView = getProxyToPersistenceAdapter(broker.getPersistenceAdapter().toString()); String txFromView = kahadbView.getTransactions(); LOG.info("Tx view fromm PA:" + txFromView); assertTrue("xid with our dud format in transaction string " + txFromView, txFromView.contains("XID:[55,")); } // restart the broker. restartBroker(); connection = createConnection(); connectionInfo = createConnectionInfo(); connection.send(connectionInfo); response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER)); assertNotNull(response); dar = (DataArrayResponse) response; assertEquals(4, dar.getData().length); // validate destination depth via jmx DestinationViewMBean destinationView = getProxyToDestination(destinationList(destination)[0]); assertEquals("enqueue count does not see prepared", 0, destinationView.getQueueSize()); TransactionId first = (TransactionId) dar.getData()[0]; int commitCount = 0; // via jmx, force outcome for (int i = 0; i < 4; i++) { RecoveredXATransactionViewMBean mbean = getProxyToPreparedTransactionViewMBean((TransactionId) dar.getData()[i]); if (i % 2 == 0) { mbean.heuristicCommit(); commitCount++; } else { mbean.heuristicRollback(); } } // verify all completed response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER)); assertNotNull(response); dar = (DataArrayResponse) response; assertEquals(0, dar.getData().length); // verify messages available assertEquals("enqueue count reflects outcome", commitCount, destinationView.getQueueSize()); // verify mbeans gone try { RecoveredXATransactionViewMBean gone = getProxyToPreparedTransactionViewMBean(first); gone.heuristicRollback(); fail("Excepted not found"); } catch (InstanceNotFoundException expectedNotfound) { } }
12. AbortSlowConsumer0Test#testAbortConsumerOnDeadConnection()
Project: activemq-artemis
File: AbortSlowConsumer0Test.java
File: AbortSlowConsumer0Test.java
@Test public void testAbortConsumerOnDeadConnection() throws Exception { TransportConnector transportConnector = broker.addConnector("tcp://0.0.0.0:0"); transportConnector.setBrokerService(broker); transportConnector.setTaskRunnerFactory(broker.getTaskRunnerFactory()); transportConnector.start(); SocketProxy socketProxy = new SocketProxy(transportConnector.getPublishableConnectURI()); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(socketProxy.getUrl()); ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy(); prefetchPolicy.setAll(4); connectionFactory.setPrefetchPolicy(prefetchPolicy); Connection c = connectionFactory.createConnection(); connections.add(c); c.start(); Session session = c.createSession(false, Session.CLIENT_ACKNOWLEDGE); final ActiveMQMessageConsumer messageconsumer = (ActiveMQMessageConsumer) session.createConsumer(destination); startProducers(destination, 10); messageconsumer.receive(4000).acknowledge(); assertNotNull(messageconsumer.receive(4000)); assertNotNull(messageconsumer.receive(4000)); assertNotNull(messageconsumer.receive(4000)); // close control command won't get through socketProxy.pause(); ActiveMQDestination amqDest = (ActiveMQDestination) destination; ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost"); final DestinationViewMBean destView = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true); assertTrue("Consumer gone from broker view", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { LOG.info("DestView {} comsumerCount {}", destView, destView.getConsumerCount()); return 0 == destView.getConsumerCount(); } })); socketProxy.goOn(); assertTrue("consumer was closed", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { boolean closed = false; try { messageconsumer.receive(400); } catch (javax.jms.IllegalStateException expected) { closed = expected.toString().contains("closed"); } return closed; } })); }
13. AbortSlowConsumer0Test#testSlowConsumerIsAbortedViaJmx()
Project: activemq-artemis
File: AbortSlowConsumer0Test.java
File: AbortSlowConsumer0Test.java
@Test public void testSlowConsumerIsAbortedViaJmx() throws Exception { // so jmx does the abort underTest.setMaxSlowDuration(60 * 1000); startConsumers(withPrefetch(2, destination)); Entry<MessageConsumer, MessageIdList> consumertoAbort = consumers.entrySet().iterator().next(); consumertoAbort.getValue().setProcessingDelay(8 * 1000); for (Connection c : connections) { c.setExceptionListener(this); } startProducers(destination, 100); consumertoAbort.getValue().assertMessagesReceived(1); ActiveMQDestination amqDest = (ActiveMQDestination) destination; ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost"); DestinationViewMBean queue = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true); ObjectName slowConsumerPolicyMBeanName = queue.getSlowConsumerStrategy(); assertNotNull(slowConsumerPolicyMBeanName); AbortSlowConsumerStrategyViewMBean abortPolicy = (AbortSlowConsumerStrategyViewMBean) broker.getManagementContext().newProxyInstance(slowConsumerPolicyMBeanName, AbortSlowConsumerStrategyViewMBean.class, true); TimeUnit.SECONDS.sleep(3); TabularData slowOnes = abortPolicy.getSlowConsumers(); assertEquals("one slow consumers", 1, slowOnes.size()); LOG.info("slow ones:" + slowOnes); CompositeData slowOne = (CompositeData) slowOnes.values().iterator().next(); LOG.info("Slow one: " + slowOne); assertTrue("we have an object name", slowOne.get("subscription") instanceof ObjectName); abortPolicy.abortConsumer((ObjectName) slowOne.get("subscription")); consumertoAbort.getValue().assertAtMostMessagesReceived(1); slowOnes = abortPolicy.getSlowConsumers(); assertEquals("no slow consumers left", 0, slowOnes.size()); // verify mbean gone with destination broker.getAdminView().removeTopic(amqDest.getPhysicalName()); try { abortPolicy.getSlowConsumers(); fail("expect not found post destination removal"); } catch (UndeclaredThrowableException expected) { assertTrue("correct exception: " + expected.getCause(), expected.getCause() instanceof InstanceNotFoundException); } }