added test case for closing just the session

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@386382 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-03-16 17:06:09 +00:00
parent baab4b209e
commit 05ea5d4795
1 changed files with 62 additions and 4 deletions

View File

@ -189,6 +189,51 @@ abstract public class JmsTransactionTestSupport extends TestSupport implements M
* @throws Exception * @throws Exception
*/ */
public void testSendSessionClose() throws Exception { public void testSendSessionClose() throws Exception {
Message[] outbound = new Message[]{
session.createTextMessage("First Message"),
session.createTextMessage("Second Message")
};
//sends a message
producer.send(outbound[0]);
session.commit();
//sends a message that gets rollbacked
producer.send(session.createTextMessage("I'm going to get rolled back."));
consumer.close();
reconnectSession();
//sends a message
producer.send(outbound[1]);
session.commit();
//receives the first message
ArrayList messages = new ArrayList();
log.info("About to consume message 1");
Message message = consumer.receive(1000);
messages.add(message);
log.info("Received: " + message);
//receives the second message
log.info("About to consume message 2");
message = consumer.receive(4000);
messages.add(message);
log.info("Received: " + message);
//validates that the rollbacked was not consumed
session.commit();
Message inbound[] = new Message[messages.size()];
messages.toArray(inbound);
assertTextMessagesEqual("Rollback did not work.", outbound, inbound);
}
/**
* Sends a batch of messages and validates that the message sent before session close is not consumed.
*
* @throws Exception
*/
public void testSendSessionAndConnectionClose() throws Exception {
Message[] outbound = new Message[]{ Message[] outbound = new Message[]{
session.createTextMessage("First Message"), session.createTextMessage("First Message"),
session.createTextMessage("Second Message") session.createTextMessage("Second Message")
@ -491,13 +536,26 @@ abstract public class JmsTransactionTestSupport extends TestSupport implements M
// Close the previous connection. // Close the previous connection.
connection.close(); connection.close();
} }
session = null;
connection = resourceProvider.createConnection(connectionFactory); connection = resourceProvider.createConnection(connectionFactory);
reconnectSession();
connection.start();
}
/**
* Recreates the connection.
*
* @throws JMSException
*/
protected void reconnectSession() throws JMSException {
if (session != null) {
session.close();
}
session = resourceProvider.createSession(connection); session = resourceProvider.createSession(connection);
destination = resourceProvider.createDestination(session, getSubject()); destination = resourceProvider.createDestination(session, getSubject());
producer = resourceProvider.createProducer(session, destination); producer = resourceProvider.createProducer(session, destination);
consumer = resourceProvider.createConsumer(session, destination); consumer = resourceProvider.createConsumer(session, destination);
connection.start();
} }
/** /**