Author: clebert.suconic(a)jboss.com
Date: 2011-04-28 19:03:27 -0400 (Thu, 28 Apr 2011)
New Revision: 10574
Added:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ExpiryMessageTest.java
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSClusteredTestBase.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSTestBase.java
Log:
There's no such thing as enough tests.. just wrote a test and decided to commit it
Added:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ExpiryMessageTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ExpiryMessageTest.java
(rev 0)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ExpiryMessageTest.java 2011-04-28
23:03:27 UTC (rev 10574)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat 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.hornetq.tests.integration.jms.client;
+
+import javax.jms.Connection;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+
+import org.hornetq.api.jms.management.TopicControl;
+import org.hornetq.core.config.Configuration;
+import org.hornetq.tests.integration.management.ManagementControlHelper;
+import org.hornetq.tests.util.JMSTestBase;
+
+/**
+ *
+ * A MessageTest
+ *
+ * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class ExpiryMessageTest extends JMSTestBase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ @Override
+ protected Configuration createDefaultConfig(boolean netty)
+ {
+ Configuration conf = super.createDefaultConfig(netty);
+
+ conf.setMessageExpiryScanPeriod(1000);
+
+ return conf;
+ }
+
+ public void testSendTopicNoSubscription() throws Exception
+ {
+
+ Topic topic = createTopic("test-topic");
+ TopicControl control = ManagementControlHelper.createTopicControl(topic,
mbeanServer);
+
+ System.out.println("size = " + control.getMessageCount());
+
+ Connection conn2 = cf.createConnection();
+
+ conn2.setClientID("client1");
+
+ Session sess2 = conn2.createSession(true, Session.SESSION_TRANSACTED);
+
+ sess2.createDurableSubscriber(topic, "client-sub1");
+ sess2.createDurableSubscriber(topic, "client-sub2");
+
+ conn2.close();
+
+ Connection conn = cf.createConnection();
+ Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
+ MessageProducer prod = sess.createProducer(topic);
+ prod.setTimeToLive(1000);
+
+ for (int i = 0 ; i < 100; i++)
+ {
+ TextMessage txt = sess.createTextMessage("txt");
+ prod.send(txt);
+ }
+
+ sess.commit();
+
+ conn.close();
+
+ // minimal time needed
+ Thread.sleep(2000);
+
+ long timeout = System.currentTimeMillis() + 10000;
+
+ // We will wait some time, but we will wait as minimal as possible
+ while (control.getMessageCount() != 0 && System.currentTimeMillis() >
timeout)
+ {
+ Thread.sleep(100);
+ }
+
+ assertEquals(0, control.getMessageCount());
+
+
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+ // Inner classes -------------------------------------------------
+}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSClusteredTestBase.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSClusteredTestBase.java 2011-04-28
23:02:24 UTC (rev 10573)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSClusteredTestBase.java 2011-04-28
23:03:27 UTC (rev 10574)
@@ -151,7 +151,7 @@
"server2",
1000,
true,
- true,
+ false,
MAX_HOPS,
1024,
toOtherServerPair, false));
@@ -196,7 +196,7 @@
"server1",
1000,
true,
- true,
+ false,
MAX_HOPS,
1024,
toOtherServerPair, false));
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSTestBase.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSTestBase.java 2011-04-28
23:02:24 UTC (rev 10573)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSTestBase.java 2011-04-28
23:03:27 UTC (rev 10574)
@@ -19,6 +19,8 @@
import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.jms.Topic;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
import javax.naming.NamingException;
import org.hornetq.api.core.TransportConfiguration;
@@ -45,6 +47,8 @@
protected HornetQServer server;
protected JMSServerManagerImpl jmsServer;
+
+ protected MBeanServer mbeanServer;
protected ConnectionFactory cf;
@@ -101,15 +105,15 @@
protected void setUp() throws Exception
{
super.setUp();
+
+ mbeanServer = MBeanServerFactory.createMBeanServer();
Configuration conf = createDefaultConfig(false);
- conf.setSecurityEnabled(false);
- conf.setJMXManagementEnabled(true);
conf.getAcceptorConfigurations().add(new
TransportConfiguration(NettyAcceptorFactory.class.getName()));
conf.getConnectorConfigurations().put("netty", new
TransportConfiguration(NettyConnectorFactory.class.getName()));
- server = HornetQServers.newHornetQServer(conf, usePersistence());
+ server = HornetQServers.newHornetQServer(conf, mbeanServer, usePersistence());
jmsServer = new JMSServerManagerImpl(server);
context = new InVMContext();
@@ -118,6 +122,17 @@
registerConnectionFactory();
}
+
+ @Override
+ protected Configuration createDefaultConfig(boolean netty)
+ {
+ Configuration conf = super.createDefaultConfig(netty);
+
+ conf.setSecurityEnabled(false);
+ conf.setJMXManagementEnabled(true);
+
+ return conf;
+ }
protected void restartServer() throws Exception
{
@@ -149,7 +164,14 @@
context = null;
+ MBeanServerFactory.releaseMBeanServer(mbeanServer);
+
+ mbeanServer = null;
+
super.tearDown();
+
+
+ super.tearDown();
}
// Private -------------------------------------------------------