Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 11086 invoked from network); 27 Feb 2007 01:33:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 Feb 2007 01:33:07 -0000 Received: (qmail 714 invoked by uid 500); 27 Feb 2007 01:33:15 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 699 invoked by uid 500); 27 Feb 2007 01:33:15 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 690 invoked by uid 99); 27 Feb 2007 01:33:15 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Feb 2007 17:33:15 -0800 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Feb 2007 17:33:06 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 689F81A981A; Mon, 26 Feb 2007 17:32:46 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r512103 - /activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/TimeStampTest.java Date: Tue, 27 Feb 2007 01:32:46 -0000 To: commits@activemq.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070227013246.689F81A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: chirino Date: Mon Feb 26 17:32:45 2007 New Revision: 512103 URL: http://svn.apache.org/viewvc?view=rev&rev=512103 Log: Adding test case in AMQ-1165 Added: activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/TimeStampTest.java Added: activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/TimeStampTest.java URL: http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/TimeStampTest.java?view=auto&rev=512103 ============================================================================== --- activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/TimeStampTest.java (added) +++ activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/TimeStampTest.java Mon Feb 26 17:32:45 2007 @@ -0,0 +1,99 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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; + + +import junit.framework.TestCase; +import org.apache.activemq.broker.BrokerPlugin; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.util.UDPTraceBrokerPlugin; +import org.apache.activemq.broker.view.ConnectionDotFilePlugin; + +import javax.jms.Connection; +import javax.jms.DeliveryMode; +import javax.jms.Destination; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; + +public class TimeStampTest extends TestCase { + public void test() throws Exception { + BrokerService broker = new BrokerService(); + broker.setPersistent(false); + broker.setUseJmx(true); + broker.setPlugins(new BrokerPlugin[] { new ConnectionDotFilePlugin(), new UDPTraceBrokerPlugin() }); + broker.addConnector("tcp://localhost:61616"); + broker.addConnector("stomp://localhost:61613"); + broker.start(); + + // Create a ConnectionFactory + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); + + // Create a Connection + Connection connection = connectionFactory.createConnection(); + connection.start(); + + // Create a Session + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Create the destination Queue + Destination destination = session.createQueue("TEST.FOO"); + + // Create a MessageProducer from the Session to the Topic or Queue + MessageProducer producer = session.createProducer(destination); + producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + + // Create a messages + Message sentMessage = session.createMessage(); + + // Tell the producer to send the message + long beforeSend = System.currentTimeMillis(); + producer.send(sentMessage); + long afterSend = System.currentTimeMillis(); + + // assert message timestamp is in window + assertTrue(beforeSend <= sentMessage.getJMSTimestamp() && sentMessage.getJMSTimestamp() <= afterSend); + + // Create a MessageConsumer from the Session to the Topic or Queue + MessageConsumer consumer = session.createConsumer(destination); + + // Wait for a message + Message receivedMessage = consumer.receive(1000); + + // assert we got the same message ID we sent + assertEquals(sentMessage.getJMSMessageID(), receivedMessage.getJMSMessageID()); + + // assert message timestamp is in window + assertTrue("JMS Message Timestamp should be set during the send method: \n" + + " beforeSend = " + beforeSend + "\n" + + " getJMSTimestamp = " + receivedMessage.getJMSTimestamp() + "\n" + + " afterSend = " + afterSend + "\n", + beforeSend <= receivedMessage.getJMSTimestamp() && receivedMessage.getJMSTimestamp() <= afterSend); + + // assert message timestamp is unchanged + assertEquals("JMS Message Timestamp of recieved message should be the same as the sent message\n ", + sentMessage.getJMSTimestamp(), receivedMessage.getJMSTimestamp()); + + // Clean up + producer.close(); + consumer.close(); + session.close(); + connection.close(); + broker.stop(); + } +}