You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2012/10/20 00:19:38 UTC
svn commit: r1400317 - in /activemq/trunk:
activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.java
kahadb/src/main/java/org/apache/kahadb/page/Transaction.java
Author: gtully
Date: Fri Oct 19 22:19:38 2012
New Revision: 1400317
URL: http://svn.apache.org/viewvc?rev=1400317&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-4118 - resolve with test. keep cache uptodate when overflow chain is released so new end page is visible as terminus
Added:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.java (with props)
Modified:
activemq/trunk/kahadb/src/main/java/org/apache/kahadb/page/Transaction.java
Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.java?rev=1400317&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.java Fri Oct 19 22:19:38 2012
@@ -0,0 +1,248 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.usecases;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import junit.framework.Test;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.ActiveMQXAConnectionFactory;
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
+import org.apache.activemq.store.kahadb.KahaDBStore;
+import org.apache.activemq.util.Wait;
+import org.apache.kahadb.page.ThreadTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest extends org.apache.activemq.TestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.class);
+ public int messageCount = 10000;
+ private BrokerService broker;
+ private ActiveMQTopic topic;
+ private List<Throwable> exceptions = new ArrayList<Throwable>();
+
+ protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + getName(true));
+ connectionFactory.setWatchTopicAdvisories(false);
+ return connectionFactory;
+ }
+
+ @Override
+ protected Connection createConnection() throws Exception {
+ return createConnection("id");
+ }
+
+ protected Connection createConnection(String name) throws Exception {
+ Connection con = getConnectionFactory().createConnection();
+ con.setClientID(name);
+ con.start();
+ return con;
+ }
+
+ public static Test suite() {
+ return suite(DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.class);
+ }
+
+ protected void setUp() throws Exception {
+ exceptions.clear();
+ topic = (ActiveMQTopic) createDestination();
+ createBroker();
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ ThreadTracker.result();
+ super.tearDown();
+ destroyBroker();
+ }
+
+ private void createBroker() throws Exception {
+ createBroker(true);
+ }
+
+ private void createBroker(boolean deleteAllMessages) throws Exception {
+ broker = BrokerFactory.createBroker("broker:(vm://" + getName(true) + ")");
+ broker.setBrokerName(getName(true));
+ broker.setDeleteAllMessagesOnStartup(deleteAllMessages);
+ broker.getManagementContext().setCreateConnector(false);
+ broker.setAdvisorySupport(false);
+ broker.addConnector("tcp://0.0.0.0:0");
+
+ setDefaultPersistenceAdapter(broker);
+
+ ((KahaDBPersistenceAdapter)broker.getPersistenceAdapter()).getStore().getPageFile().setPageSize(1024);
+
+ broker.start();
+ }
+
+ private void destroyBroker() throws Exception {
+ if (broker != null)
+ broker.stop();
+ }
+
+ public void testIndexPageUsage() throws Exception {
+ Connection con = createConnection();
+ Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ session.createDurableSubscriber(topic, "true", "filter = 'true'", true);
+ session.close();
+
+ session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ session.createDurableSubscriber(topic, "false", "filter = 'false'", true);
+ session.close();
+
+ session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ session.createDurableSubscriber(topic, "all", null, true);
+ session.close();
+
+ session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ session.createDurableSubscriber(topic, "all2", null, true);
+ session.close();
+
+ con.close();
+
+ // send messages
+
+ final CountDownLatch goOn = new CountDownLatch(1);
+ Thread sendThread = new Thread() {
+ public void run() {
+ try {
+
+ final Connection sendCon = createConnection("send");
+ final Session sendSession = sendCon.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ final MessageProducer producer = sendSession.createProducer(null);
+
+ for (int i = 0; i < messageCount; i++) {
+ boolean filter = i % 2 == 1;
+ Message message = sendSession.createMessage();
+ message.setStringProperty("filter", filter ? "true" : "false");
+ producer.send(topic, message);
+
+ if (i > 0 && i % 10000 == 0) {
+ LOG.info("Sent:" + i);
+ }
+ if (i> messageCount/2) {
+ goOn.countDown();
+ }
+ }
+ sendSession.close();
+ sendCon.close();
+ } catch (Exception e) {
+ exceptions.add(e);
+ }
+ }
+ };
+ sendThread.start();
+
+ goOn.await(5, TimeUnit.MINUTES);
+ LOG.info("Activating consumers");
+
+ // consume messages in parallel
+ con = createConnection();
+ session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer consumerTrue = session.createDurableSubscriber(topic, "true", "filter = 'true'", true);
+ Listener listenerT = new Listener();
+ consumerTrue.setMessageListener(listenerT);
+
+ MessageConsumer consumerFalse = session.createDurableSubscriber(topic, "false", "filter = 'false'", true);
+ Listener listenerF = new Listener();
+ consumerFalse.setMessageListener(listenerF);
+
+ MessageConsumer consumerAll = session.createDurableSubscriber(topic, "all", null, true);
+ Listener listenerA = new Listener();
+ consumerAll.setMessageListener(listenerA);
+
+ MessageConsumer consumerAll2 = session.createDurableSubscriber(topic, "all2", null, true);
+ Listener listenerA2 = new Listener();
+ consumerAll2.setMessageListener(listenerA2);
+
+ waitFor(listenerA, messageCount);
+ assertEquals(messageCount, listenerA.count);
+
+ waitFor(listenerA2, messageCount);
+ assertEquals(messageCount, listenerA2.count);
+
+ assertEquals(messageCount / 2, listenerT.count);
+ assertEquals(messageCount / 2, listenerF.count);
+
+ consumerTrue.close();
+ session.unsubscribe("true");
+
+ consumerFalse.close();
+ session.unsubscribe("false");
+
+ consumerAll.close();
+ session.unsubscribe("all");
+
+ session.close();
+ con.close();
+
+ final KahaDBStore store = ((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).getStore();
+ LOG.info("Store page count: " + store.getPageFile().getPageCount());
+ LOG.info("Store free page count: " + store.getPageFile().getFreePageCount());
+ LOG.info("Store page in-use: " + (store.getPageFile().getPageCount() - store.getPageFile().getFreePageCount()));
+
+ assertTrue("no leak of pages, always use just 10", Wait.waitFor(new Wait.Condition() {
+ @Override
+ public boolean isSatisified() throws Exception {
+ return 10 == store.getPageFile().getPageCount() -
+ store.getPageFile().getFreePageCount();
+ }
+ }, TimeUnit.SECONDS.toMillis(10)));
+ }
+
+ private void waitFor(final Listener listener, final int count) throws Exception {
+
+ assertTrue("got all messages on time", Wait.waitFor(new Wait.Condition() {
+ @Override
+ public boolean isSatisified() throws Exception {
+ return listener.count == count;
+ }
+ }, TimeUnit.MINUTES.toMillis(10)));
+
+ }
+
+ public static class Listener implements MessageListener {
+ int count = 0;
+ String id = null;
+
+ Listener() {
+ }
+
+ public void onMessage(Message message) {
+ count++;
+ if (id != null) {
+ try {
+ LOG.info(id + ", " + message.getJMSMessageID());
+ } catch (Exception ignored) {
+ }
+ }
+ }
+ }
+}
Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: activemq/trunk/kahadb/src/main/java/org/apache/kahadb/page/Transaction.java
URL: http://svn.apache.org/viewvc/activemq/trunk/kahadb/src/main/java/org/apache/kahadb/page/Transaction.java?rev=1400317&r1=1400316&r2=1400317&view=diff
==============================================================================
--- activemq/trunk/kahadb/src/main/java/org/apache/kahadb/page/Transaction.java (original)
+++ activemq/trunk/kahadb/src/main/java/org/apache/kahadb/page/Transaction.java Fri Oct 19 22:19:38 2012
@@ -338,6 +338,9 @@ public class Transaction implements Iter
current.makePageEnd(pos, getWriteTransactionId());
+ // make visible as end page
+ pageFile.addToCache(current);
+
// Write the header..
pos = 0;
current.write(this);