[Jboss-cvs] JBoss Messaging SVN: r1280 - in branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms: . crash
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 12 17:36:26 EDT 2006
Author: clebert.suconic at jboss.com
Date: 2006-09-12 17:36:25 -0400 (Tue, 12 Sep 2006)
New Revision: 1280
Added:
branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/CreateTwoClientOnServerCommand.java
Modified:
branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/ClientCrashTest.java
Log:
JBMESSAGING-541- adding failing testcase
Added: branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/CreateTwoClientOnServerCommand.java
===================================================================
--- branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/CreateTwoClientOnServerCommand.java 2006-09-12 18:13:47 UTC (rev 1279)
+++ branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/CreateTwoClientOnServerCommand.java 2006-09-12 21:36:25 UTC (rev 1280)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.messaging.jms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+
+import org.jboss.jms.client.JBossConnection;
+import org.jboss.test.messaging.tools.jmx.rmi.Command;
+
+/**
+ *
+ * A CreateClientOnServerCommand.
+ *
+ * @author <a href="tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="clebert.suconic at jboss.com">Clebert Suconic</a>
+ * @version 1.1
+ *
+ * CreateClientOnServerCommand.java,v 1.1 2006/02/21 07:44:02 timfox Exp
+ */
+public class CreateTwoClientOnServerCommand implements Command
+{
+ private static final long serialVersionUID = -997724797145152821L;
+
+ private ConnectionFactory cf;
+
+ private Queue queue;
+
+ private boolean retainReference;
+
+ private static List commands = new ArrayList();
+
+ Topic topic;
+ Connection conn1;
+ Connection conn2;
+
+ Session sess1;
+ Session sess2;
+
+ MessageConsumer durable;
+ MessageConsumer durable2;
+
+ MessageProducer prod;
+
+ public CreateTwoClientOnServerCommand(ConnectionFactory cf, Topic topic, boolean retainReference)
+ {
+ this.cf = cf;
+ this.topic = topic;
+
+ this.retainReference = retainReference;
+ }
+
+ /*
+ * Just create a connection, send and receive a message and leave the connection open.
+ */
+ public Object execute() throws Exception
+ {
+ if (retainReference)
+ {
+ commands.add(this);
+ }
+
+ conn1 = cf.createConnection();
+ conn1.setClientID("test1");
+ conn1.start();
+
+ conn2 = cf.createConnection();
+ conn2.setClientID("test2");
+ conn2.start();
+
+ sess1 = conn1.createSession(true, Session.AUTO_ACKNOWLEDGE);
+ sess2 = conn2.createSession(true, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sess1.createProducer(topic);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ durable = sess1.createDurableSubscriber(topic, "subs1");
+ durable2 = sess2.createDurableSubscriber(topic, "subs2");
+
+
+ for (int i=0;i<10;i++)
+ {
+ prod.send(sess1.createTextMessage("k"+i));
+ }
+ sess1.commit();
+
+ for (int i=0;i<2;i++)
+ {
+ TextMessage tm = (TextMessage)durable.receive(1000);
+ sess1.commit();
+ System.out.println(tm.getText());
+ }
+
+ Object read = durable2.receive(1000);
+ if (read==null)
+ {
+ throw new RuntimeException("Couldn't read message from durable2");
+ }
+
+ System.out.println("Object read now=" + read);
+
+ String arrays[] = new String[2];
+ arrays[0] = ((JBossConnection)conn1).getRemotingClientSessionId();
+ arrays[1] = ((JBossConnection)conn2).getRemotingClientSessionId();
+
+ System.out.println("conn1=" + arrays[0]);
+ System.out.println("conn2=" + arrays[1]);
+
+ //Return the remoting client session id for the connection
+ return arrays;
+ }
+
+ }
Modified: branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/ClientCrashTest.java
===================================================================
--- branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/ClientCrashTest.java 2006-09-12 18:13:47 UTC (rev 1279)
+++ branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/crash/ClientCrashTest.java 2006-09-12 21:36:25 UTC (rev 1280)
@@ -21,14 +21,21 @@
*/
package org.jboss.test.messaging.jms.crash;
+import javax.jms.Connection;
import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
import javax.naming.InitialContext;
import org.jboss.jms.server.ConnectionManager;
+import org.jboss.jms.server.connectionmanager.SimpleConnectionManager;
import org.jboss.logging.Logger;
import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.jms.CreateClientOnServerCommand;
+import org.jboss.test.messaging.jms.CreateTwoClientOnServerCommand;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.jmx.ServiceContainer;
import org.jboss.test.messaging.tools.jmx.rmi.LocalTestServer;
@@ -84,6 +91,7 @@
localServer.setAttribute(ServiceContainer.REMOTING_OBJECT_NAME, "LeasePeriod", "3000");
localServer.deployQueue("Queue", null);
+ localServer.deployTopic("Topic", null);
// Connect to the remote server, but don't start a servicecontainer on it. We are only using
// the remote server to open a client connection to the local server.
@@ -131,7 +139,96 @@
assertFalse(cm.containsSession(remotingSessionId));
}
+ /**
+ * Test that when a remote jms client crashes, server side resources for connections are
+ * cleaned-up.
+ */
+ public void testClientCrashWithTwoConnections() throws Exception
+ {
+ InitialContext ic = new InitialContext(InVMInitialContextFactory.getJNDIEnvironment());
+ Topic topic = (Topic)ic.lookup("/topic/Topic");
+
+ ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+
+ CreateTwoClientOnServerCommand command = new CreateTwoClientOnServerCommand(cf,topic, true);
+
+ String[] remotingSessionId = (String[])remoteServer.executeCommand(command);
+
+ ConnectionManager cm = localServer.getServerPeer().getConnectionManager();
+
+ log.info("server(0) = " + remotingSessionId[0]);
+ log.info("server(1) = " + remotingSessionId[1]);
+ log.info("we have = " + ((SimpleConnectionManager)cm).getClients().size() + " clients registered on SimpleconnectionManager");
+
+ assertTrue(cm.containsSession(remotingSessionId[0]));
+ assertTrue(cm.containsSession(remotingSessionId[1]));
+
+ // Now we should have a client connection from the remote server to the local server
+
+ remoteServer.exit();
+ log.info("killed remote server");
+
+ // Wait for connection resources to be cleared up
+ Thread.sleep(30000);
+
+ // See if we still have a connection with this id
+
+ //Connection state shouldn't have been cleared up by now
+ assertFalse(cm.containsSession(remotingSessionId[0]));
+ assertFalse(cm.containsSession(remotingSessionId[1]));
+
+ log.info("Servers = " + ((SimpleConnectionManager)cm).getClients().size());
+
+ assertEquals(0,((SimpleConnectionManager)cm).getClients().size());
+
+
+ executeRecoveryAfterCrash(cf, topic);
+ }
+ private void executeRecoveryAfterCrash(ConnectionFactory cf, Topic topic) throws Exception
+ {
+ Connection conn = null;
+ Session s = null;
+ MessageConsumer durable = null;
+
+ Connection conn2 = cf.createConnection();
+ conn2.setClientID("client2");
+ conn2.start();
+ Session s2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer durable2 = s2.createDurableSubscriber(topic, "subs2");
+
+ conn = cf.createConnection();
+ conn.setClientID("client1");
+ conn.start();
+ s = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
+ durable = s.createDurableSubscriber(topic, "subs1");
+
+ int count=0;
+ for (int i=2;i<10;i++)
+ {
+ TextMessage tm = (TextMessage)durable.receive(1000);
+ assertNotNull(tm);
+ s.commit();
+ count++;
+ }
+
+ assertEquals(count,8);
+
+ count=0;
+ for (int i=0;i<9;i++)
+ {
+ count++;
+ TextMessage tm = (TextMessage)durable2.receive(1000);
+ assertNotNull(tm);
+ tm.acknowledge();
+ }
+
+ assertEquals(count,9);
+ }
+
+
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
More information about the jboss-cvs-commits
mailing list