[jboss-cvs] jboss-jms/tests/src/org/jboss/test/messaging/jms ...
Timothy Fox
tim.fox at jboss.com
Thu Jul 27 15:01:57 EDT 2006
User: timfox
Date: 06/07/27 15:01:57
Modified: tests/src/org/jboss/test/messaging/jms
MessageConsumerTest.java
Added: tests/src/org/jboss/test/messaging/jms
MessageWithReadResolveTest.java
Log:
Mainly http://jira.jboss.com/jira/browse/JBMESSAGING-434 plus a few other bits and pieces
Revision Changes Path
1.86 +3 -3 jboss-jms/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MessageConsumerTest.java
===================================================================
RCS file: /cvsroot/jboss/jboss-jms/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -b -r1.85 -r1.86
--- MessageConsumerTest.java 17 Jul 2006 17:14:52 -0000 1.85
+++ MessageConsumerTest.java 27 Jul 2006 19:01:57 -0000 1.86
@@ -61,9 +61,9 @@
/**
* @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.85 $</tt>
+ * @version <tt>$Revision: 1.86 $</tt>
*
- * $Id: MessageConsumerTest.java,v 1.85 2006/07/17 17:14:52 timfox Exp $
+ * $Id: MessageConsumerTest.java,v 1.86 2006/07/27 19:01:57 timfox Exp $
*/
public class MessageConsumerTest extends MessagingTestCase
{
@@ -1884,7 +1884,7 @@
worker1.start();
- Thread.sleep(100);
+ Thread.sleep(1000);
try
{
1.1 date: 2006/07/27 19:01:57; author: timfox; state: Exp;jboss-jms/tests/src/org/jboss/test/messaging/jms/MessageWithReadResolveTest.java
Index: MessageWithReadResolveTest.java
===================================================================
/*
* 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.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.Session;
import javax.naming.InitialContext;
import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.serial.io.JBossObjectInputStream;
import org.jboss.serial.io.JBossObjectOutputStream;
import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
/**
* A MessageWithReadResolveTest
*
* See http://jira.jboss.com/jira/browse/JBMESSAGING-442
*
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @version <tt>$Revision: 1.1 $</tt>
*
* $Id: MessageWithReadResolveTest.java,v 1.1 2006/07/27 19:01:57 timfox Exp $
*
*/
public class MessageWithReadResolveTest extends MessagingTestCase
{
// Constants -----------------------------------------------------
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
protected InitialContext initialContext;
protected JBossConnectionFactory cf;
protected Queue queue;
// Constructors --------------------------------------------------
public MessageWithReadResolveTest(String name)
{
super(name);
}
// TestCase overrides -------------------------------------------
public void setUp() throws Exception
{
super.setUp();
ServerManagement.start("all");
initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
ServerManagement.undeployQueue("Queue");
ServerManagement.deployQueue("Queue");
queue = (Queue)initialContext.lookup("/queue/Queue");
}
public void tearDown() throws Exception
{
ServerManagement.undeployQueue("Queue");
super.tearDown();
}
// Public --------------------------------------------------------
public void testSendReceiveMessage() throws Exception
{
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue);
//Make persistent to make sure message gets serialized
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
MessageConsumer cons = sess.createConsumer(queue);
TestMessage tm = new TestMessage(123, false);
ObjectMessage om = sess.createObjectMessage();
om.setObject(tm);
conn.start();
prod.send(om);
ObjectMessage om2 = (ObjectMessage)cons.receive(1000);
assertNotNull(om2);
TestMessage tm2 = (TestMessage)om2.getObject();
assertEquals(123, tm2.getId());
conn.close();
}
/* Now test using serialization directly */
public void testUseSerializationDirectly() throws Exception
{
TestMessage tm = new TestMessage(456, false);
ByteArrayOutputStream os = new ByteArrayOutputStream();
JBossObjectOutputStream oos = new JBossObjectOutputStream(os);
oos.writeObject(tm);
oos.close();
byte[] bytes = os.toByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
JBossObjectInputStream ois = new JBossObjectInputStream(is);
TestMessage tm2 = (TestMessage)ois.readObject();
assertEquals(tm.id, tm2.id);
ois.close();
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
/* This class would trigger the exception when serialized with jboss serialization */
public static class TestMessage implements Serializable
{
private long id;
private Object clazz;
public TestMessage(long id, boolean useSimpleObject)
{
this.id = id;
if (useSimpleObject)
{
clazz = String.class;
}
else
{
clazz = TestEnum.class;
}
}
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append("TestMessage(");
sb.append("id=" + id);
sb.append(", clazz=" + clazz);
sb.append(")");
return sb.toString();
}
public long getId()
{
return id;
}
}
public static class TestEnum implements Serializable
{
public Object readResolve()
{
return null;
}
}
// Inner classes -------------------------------------------------
}
More information about the jboss-cvs-commits
mailing list