From 8e1ff7c63667dc95865808d22de90cb70fde0fac Mon Sep 17 00:00:00 2001 From: Bhupendra Bhusman Bhardwaj Date: Tue, 16 Jan 2007 15:34:03 +0000 Subject: Tests under this directory are actually ping tests -Comment from Rupert git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@496731 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/ping/TestPingClient.java | 138 ++++++++++++ .../org/apache/qpid/ping/TestPingProducer.java | 243 +++++++++++++++++++++ .../org/apache/qpid/ping/TestPingPublisher.java | 197 +++++++++++++++++ .../org/apache/qpid/ping/TestPingSubscriber.java | 134 ++++++++++++ .../org/apache/qpid/pingpong/TestPingClient.java | 138 ------------ .../org/apache/qpid/pingpong/TestPingProducer.java | 243 --------------------- .../apache/qpid/pingpong/TestPingPublisher.java | 197 ----------------- .../apache/qpid/pingpong/TestPingSubscriber.java | 134 ------------ 8 files changed, 712 insertions(+), 712 deletions(-) create mode 100644 java/perftests/src/main/java/org/apache/qpid/ping/TestPingClient.java create mode 100644 java/perftests/src/main/java/org/apache/qpid/ping/TestPingProducer.java create mode 100644 java/perftests/src/main/java/org/apache/qpid/ping/TestPingPublisher.java create mode 100644 java/perftests/src/main/java/org/apache/qpid/ping/TestPingSubscriber.java delete mode 100644 java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingClient.java delete mode 100644 java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java delete mode 100644 java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java delete mode 100644 java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingSubscriber.java (limited to 'java/perftests/src') diff --git a/java/perftests/src/main/java/org/apache/qpid/ping/TestPingClient.java b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingClient.java new file mode 100644 index 0000000000..c96f6bd61d --- /dev/null +++ b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingClient.java @@ -0,0 +1,138 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.qpid.pingpong; + +import org.apache.log4j.Logger; +import org.apache.log4j.Level; +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.jms.Session; + +import javax.jms.*; +import java.net.InetAddress; + +public class TestPingClient +{ + private static final Logger _logger = Logger.getLogger(TestPingClient.class); + + private static class TestPingMessageListener implements MessageListener + { + public TestPingMessageListener() + { + } + + long _lastTimestamp = 0L; + long _lastTimestampString = 0L; + + public void onMessage(javax.jms.Message message) + { + if (_logger.isInfoEnabled()) + { + long timestamp = 0L; + long timestampString = 0L; + + try + { + timestamp = message.getLongProperty("timestamp"); + timestampString = Long.parseLong(message.getStringProperty("timestampString")); + + if (timestampString != timestamp) + { + _logger.info("Timetamps differ!:\n" + + "timestamp:" + timestamp + "\n" + + "timestampString:" + timestampString); + } + + } + catch (JMSException jmse) + { + //ignore + } + + long diff = timestamp - _lastTimestamp; + _lastTimestamp = timestamp; + + long stringDiff = timestampString - _lastTimestampString; + + _lastTimestampString = timestampString; + + _logger.info("Ping: T:" + diff + "ms, TS:" + stringDiff); + + // _logger.info(_name + " got message '" + message + "\n"); + } + } + } + + public static void main(String[] args) + { + _logger.setLevel(Level.INFO); + + _logger.info("Starting..."); + + if (args.length < 4) + { + System.out.println("Usage: brokerdetails username password virtual-path [selector] "); + System.exit(1); + } + try + { + InetAddress address = InetAddress.getLocalHost(); + AMQConnection con1 = new AMQConnection(args[0], args[1], args[2], + address.getHostName(), args[3]); + + + _logger.info("Connected with URL:" + con1.toURL()); + + final org.apache.qpid.jms.Session session1 = (org.apache.qpid.jms.Session) + con1.createSession(false, Session.AUTO_ACKNOWLEDGE); + + + String selector = null; + + if (args.length == 5) + { + selector = args[4]; + _logger.info("Message selector is <" + selector + ">..."); + } + else + { + _logger.info("Not using message selector"); + } + + + Queue q = new AMQQueue("ping"); + + MessageConsumer consumer1 = session1.createConsumer(q, + 1, false, false, selector); + + consumer1.setMessageListener(new TestPingMessageListener()); + con1.start(); + } + catch (Throwable t) + { + System.err.println("Fatal error: " + t); + t.printStackTrace(); + } + + System.out.println("Waiting..."); + } +} + diff --git a/java/perftests/src/main/java/org/apache/qpid/ping/TestPingProducer.java b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingProducer.java new file mode 100644 index 0000000000..bb9e17615e --- /dev/null +++ b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingProducer.java @@ -0,0 +1,243 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.qpid.pingpong; + +import org.apache.log4j.Logger; +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.AMQException; +import org.apache.qpid.url.URLSyntaxException; +import org.apache.qpid.client.AMQNoConsumersException; +import org.apache.qpid.client.BasicMessageProducer; +import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.client.message.TestMessageFactory; +import org.apache.qpid.jms.MessageProducer; +import org.apache.qpid.jms.Session; + +import javax.jms.*; +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** + * A client that behaves as follows: + * + */ +public class TestPingProducer implements ExceptionListener +{ + private static final Logger _log = Logger.getLogger(TestPingProducer.class); + + private AMQConnection _connection; + + private static int _messageSize = 0; + private boolean _publish; + + private long SLEEP_TIME = 250L; + +// private class CallbackHandler implements MessageListener +// { +// +// private int _actualMessageCount; +// +// +// public void onMessage(Message m) +// { +// if (_log.isDebugEnabled()) +// { +// _log.debug("Message received: " + m); +// } +// _actualMessageCount++; +// if (_actualMessageCount % 1000 == 0) +// { +// _log.info("Received message count: " + _actualMessageCount); +// } +// } +// } + + public TestPingProducer(boolean TRANSACTED, String brokerDetails, String clientID, + String virtualpath) throws AMQException, URLSyntaxException + { + try + { + createConnection(brokerDetails, clientID, virtualpath); + + Session session; + + if (TRANSACTED) + { + session = (Session) _connection.createSession(true, Session.SESSION_TRANSACTED); + } + else + { + session = (Session) _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + } + + String queue = "ping"; + AMQQueue destination = new AMQQueue(queue); + MessageProducer producer = (MessageProducer) session.createProducer(destination); + + _connection.setExceptionListener(this); + + _connection.start(); + + while (_publish) + { +/* + TextMessage msg = session.createTextMessage( + "Presented to in conjunction with Mahnah Mahnah and the Snowths: " + ++messageNumber); +*/ + ObjectMessage msg = null; + if (_messageSize != 0) + { + msg = TestMessageFactory.newObjectMessage(session, _messageSize); + } + else + { + msg = session.createObjectMessage(); + } + + msg.setStringProperty("timestampString", Long.toString(System.currentTimeMillis())); + msg.setLongProperty("timestamp", System.currentTimeMillis()); + + ((BasicMessageProducer) producer).send(msg, DeliveryMode.NON_PERSISTENT, true); + _log.info("Message Sent."); + _log.debug(msg); + + + if (TRANSACTED) + { + try + { + session.commit(); + _log.debug("Session Commited."); + } + catch (JMSException e) + { + _log.trace("JMSException on commit:" + e); + try + { + session.rollback(); + _log.debug("Message rolled back."); + } + catch (JMSException jsme) + { + _log.trace("JMSE on rollback:" + jsme); + } + + + if (e.getLinkedException() instanceof AMQNoConsumersException) + { + _log.info("No Consumers on queue:'" + queue + "'"); + continue; + } + } + } + + + if (SLEEP_TIME > 0) + { + try + { + Thread.sleep(SLEEP_TIME); + } + catch (InterruptedException ie) + { + //do nothing + } + } + + + } + + } + catch (JMSException e) + { + _publish = false; + e.printStackTrace(); + } + } + + private void createConnection(String brokerDetails, String clientID, String virtualpath) throws AMQException, URLSyntaxException + { + _publish = true; + _connection = new AMQConnection(brokerDetails, "guest", "guest", + clientID, virtualpath); + _log.info("Connected with URL:" + _connection.toURL()); + } + + /** + * @param args argument 1 if present specifies the name of the temporary queue to create. Leaving it blank + * means the server will allocate a name. + */ + public static void main(String[] args) + { + if (args.length < 2) + { + System.err.println("Usage: TestPingPublisher [transacted] [message size in bytes]"); + System.exit(0); + } + try + { + InetAddress address = InetAddress.getLocalHost(); + String clientID = address.getHostName() + System.currentTimeMillis(); + boolean transacted = false; + if (args.length == 3 ) + { + transacted = Boolean.parseBoolean(args[2]); + } + else if (args.length > 3 ) + { + transacted = Boolean.parseBoolean(args[2]); + _messageSize = Integer.parseInt(args[3]); + } + + new TestPingProducer(transacted, args[0], clientID, args[1]); + } + catch (UnknownHostException e) + { + e.printStackTrace(); + } + catch (AMQException e) + { + System.err.println("Error in client: " + e); + e.printStackTrace(); + } + catch (URLSyntaxException e) + { + System.err.println("Error in connection arguments : " + e); + } + + //System.exit(0); + } + + /** + * @see javax.jms.ExceptionListener#onException(javax.jms.JMSException) + */ + public void onException(JMSException e) + { + System.err.println(e.getMessage()); + + _publish = false; + e.printStackTrace(System.err); + } +} diff --git a/java/perftests/src/main/java/org/apache/qpid/ping/TestPingPublisher.java b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingPublisher.java new file mode 100644 index 0000000000..3b2dcc4d36 --- /dev/null +++ b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingPublisher.java @@ -0,0 +1,197 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.qpid.pingpong; + +import org.apache.log4j.Logger; +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.AMQException; +import org.apache.qpid.url.URLSyntaxException; +import org.apache.qpid.client.AMQTopic; +import org.apache.qpid.client.BasicMessageProducer; +import org.apache.qpid.client.message.TestMessageFactory; +import org.apache.qpid.jms.MessageProducer; +import org.apache.qpid.jms.Session; + +import javax.jms.*; +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** + * A client that behaves as follows: + *
  • Connects to a queue, whose name is specified as a cmd-line argument
  • + *
  • Creates a temporary queue
  • + *
  • Creates messages containing a property that is the name of the temporary queue
  • + *
  • Fires off a message on the original queue and waits for a response on the temporary queue
  • + *
+ */ +public class TestPingPublisher implements ExceptionListener +{ + private static final Logger _log = Logger.getLogger(TestPingPublisher.class); + + private AMQConnection _connection; + + private boolean _publish; + private static int _messageSize = 0; + private long SLEEP_TIME = 0L; + +// private class CallbackHandler implements MessageListener +// { +// +// private int _actualMessageCount; +// +// +// public void onMessage(Message m) +// { +// if (_log.isDebugEnabled()) +// { +// _log.debug("Message received: " + m); +// } +// _actualMessageCount++; +// if (_actualMessageCount % 1000 == 0) +// { +// _log.info("Received message count: " + _actualMessageCount); +// } +// } +// } + + public TestPingPublisher(String brokerDetails, String clientID, String virtualpath) throws AMQException, URLSyntaxException + { + try + { + createConnection(brokerDetails, clientID, virtualpath); + + Session session = (Session) _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + //AMQQueue destination = new AMQQueue("ping"); + AMQTopic destination = new AMQTopic("ping"); + MessageProducer producer = (MessageProducer) session.createProducer(destination); + + _connection.setExceptionListener(this); + + _connection.start(); + + int msgCount = 0; + while (_publish) + { +/* + TextMessage msg = session.createTextMessage( + "Presented to in conjunction with Mahnah Mahnah and the Snowths: " + ++messageNumber); +*/ + ObjectMessage msg = null; + if (_messageSize != 0) + { + msg = TestMessageFactory.newObjectMessage(session, _messageSize); + } + else + { + msg = session.createObjectMessage(); + } + + Long time = System.nanoTime(); + msg.setStringProperty("timestampString", Long.toString(time)); + msg.setLongProperty("timestamp", time); + + ((BasicMessageProducer) producer).send(msg, DeliveryMode.PERSISTENT, true); + + _log.info("Message Sent:" + msgCount++); + _log.debug(msg); + + if (msgCount == Integer.MAX_VALUE) + { + _publish = false; + } + + if (SLEEP_TIME > 0) + { + try + { + Thread.sleep(SLEEP_TIME); + } + catch (InterruptedException ie) + { + //do nothing + } + } + } + + } + catch (JMSException e) + { + e.printStackTrace(); + } + } + + private void createConnection(String brokerDetails, String clientID, String virtualpath) throws AMQException, URLSyntaxException + { + _publish = true; + _connection = new AMQConnection(brokerDetails, "guest", "guest", clientID, virtualpath); + _log.info("Connected with URL:" + _connection.toURL()); + } + + /** + * @param args argument 1 if present specifies the name of the temporary queue to create. Leaving it blank + * means the server will allocate a name. + */ + public static void main(String[] args) + { + if (args.length < 2) + { + System.err.println("Usage: TestPingPublisher [message size in bytes]"); + System.exit(0); + } + try + { + InetAddress address = InetAddress.getLocalHost(); + String clientID = address.getHostName() + System.currentTimeMillis(); + if (args.length > 2 ) + { + _messageSize = Integer.parseInt(args[2]); + } + new TestPingPublisher(args[0], clientID, args[1]); + } + catch (UnknownHostException e) + { + e.printStackTrace(); + } + catch (AMQException e) + { + System.err.println("Error in client: " + e); + e.printStackTrace(); + } + catch (URLSyntaxException e) + { + System.err.println("Error in connection arguments : " + e); + } + + //System.exit(0); + } + + /** + * @see javax.jms.ExceptionListener#onException(javax.jms.JMSException) + */ + public void onException(JMSException e) + { + System.err.println(e.getMessage()); + + _publish = false; + e.printStackTrace(System.err); + } +} diff --git a/java/perftests/src/main/java/org/apache/qpid/ping/TestPingSubscriber.java b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingSubscriber.java new file mode 100644 index 0000000000..001f1e3568 --- /dev/null +++ b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingSubscriber.java @@ -0,0 +1,134 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.qpid.pingpong; + +import org.apache.log4j.Logger; +import org.apache.log4j.Level; +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.client.AMQTopic; +import org.apache.qpid.jms.Session; + +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.Topic; +import javax.jms.JMSException; +import java.net.InetAddress; + +public class TestPingSubscriber +{ + private static final Logger _logger = Logger.getLogger(TestPingSubscriber.class); + + private static class TestPingMessageListener implements MessageListener + { + public TestPingMessageListener() + { + } + + long _lastTimestamp = 0L; + long _lastTimestampString = 0L; + + public void onMessage(javax.jms.Message message) + { + Long time = System.nanoTime(); + + if (_logger.isInfoEnabled()) + { + long timestampString = 0L; + + try + { + long timestamp = message.getLongProperty("timestamp"); + timestampString = Long.parseLong(message.getStringProperty("timestampString")); + + if (timestampString != timestamp) + { + _logger.info("Timetamps differ!:\n" + + "timestamp:" + timestamp + "\n" + + "timestampString:" + timestampString); + } + + } + catch (JMSException jmse) + { + // ignore + } + + + long stringDiff = time - timestampString; + + _logger.info("Ping: TS:" + stringDiff / 1000 + "us"); + + // _logger.info(_name + " got message '" + message + "\n"); + } + } + } + + public static void main(String[] args) + { + _logger.info("Starting..."); + + if (args.length < 4) + { + System.out.println("Usage: brokerdetails username password virtual-path [selector] "); + System.exit(1); + } + try + { + InetAddress address = InetAddress.getLocalHost(); + AMQConnection con1 = new AMQConnection(args[0], args[1], args[2], + address.getHostName(), args[3]); + + _logger.info("Connected with URL:" + con1.toURL()); + + final org.apache.qpid.jms.Session session1 = (org.apache.qpid.jms.Session) + con1.createSession(false, Session.AUTO_ACKNOWLEDGE); + + + String selector = null; + + if (args.length == 5) + { + selector = args[4]; + _logger.info("Message selector is <" + selector + ">..."); + } + else + { + _logger.info("Not using message selector "); + } + + Topic t = new AMQTopic("ping"); + + MessageConsumer consumer1 = session1.createConsumer(t, + 1, false, false, selector); + + consumer1.setMessageListener(new TestPingMessageListener()); + con1.start(); + } + catch (Throwable t) + { + System.err.println("Fatal error: " + t); + t.printStackTrace(); + } + + System.out.println("Waiting..."); + } +} + diff --git a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingClient.java b/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingClient.java deleted file mode 100644 index c96f6bd61d..0000000000 --- a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingClient.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.qpid.pingpong; - -import org.apache.log4j.Logger; -import org.apache.log4j.Level; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQQueue; -import org.apache.qpid.jms.Session; - -import javax.jms.*; -import java.net.InetAddress; - -public class TestPingClient -{ - private static final Logger _logger = Logger.getLogger(TestPingClient.class); - - private static class TestPingMessageListener implements MessageListener - { - public TestPingMessageListener() - { - } - - long _lastTimestamp = 0L; - long _lastTimestampString = 0L; - - public void onMessage(javax.jms.Message message) - { - if (_logger.isInfoEnabled()) - { - long timestamp = 0L; - long timestampString = 0L; - - try - { - timestamp = message.getLongProperty("timestamp"); - timestampString = Long.parseLong(message.getStringProperty("timestampString")); - - if (timestampString != timestamp) - { - _logger.info("Timetamps differ!:\n" + - "timestamp:" + timestamp + "\n" + - "timestampString:" + timestampString); - } - - } - catch (JMSException jmse) - { - //ignore - } - - long diff = timestamp - _lastTimestamp; - _lastTimestamp = timestamp; - - long stringDiff = timestampString - _lastTimestampString; - - _lastTimestampString = timestampString; - - _logger.info("Ping: T:" + diff + "ms, TS:" + stringDiff); - - // _logger.info(_name + " got message '" + message + "\n"); - } - } - } - - public static void main(String[] args) - { - _logger.setLevel(Level.INFO); - - _logger.info("Starting..."); - - if (args.length < 4) - { - System.out.println("Usage: brokerdetails username password virtual-path [selector] "); - System.exit(1); - } - try - { - InetAddress address = InetAddress.getLocalHost(); - AMQConnection con1 = new AMQConnection(args[0], args[1], args[2], - address.getHostName(), args[3]); - - - _logger.info("Connected with URL:" + con1.toURL()); - - final org.apache.qpid.jms.Session session1 = (org.apache.qpid.jms.Session) - con1.createSession(false, Session.AUTO_ACKNOWLEDGE); - - - String selector = null; - - if (args.length == 5) - { - selector = args[4]; - _logger.info("Message selector is <" + selector + ">..."); - } - else - { - _logger.info("Not using message selector"); - } - - - Queue q = new AMQQueue("ping"); - - MessageConsumer consumer1 = session1.createConsumer(q, - 1, false, false, selector); - - consumer1.setMessageListener(new TestPingMessageListener()); - con1.start(); - } - catch (Throwable t) - { - System.err.println("Fatal error: " + t); - t.printStackTrace(); - } - - System.out.println("Waiting..."); - } -} - diff --git a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java b/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java deleted file mode 100644 index bb9e17615e..0000000000 --- a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.qpid.pingpong; - -import org.apache.log4j.Logger; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.AMQException; -import org.apache.qpid.url.URLSyntaxException; -import org.apache.qpid.client.AMQNoConsumersException; -import org.apache.qpid.client.BasicMessageProducer; -import org.apache.qpid.client.AMQQueue; -import org.apache.qpid.client.message.TestMessageFactory; -import org.apache.qpid.jms.MessageProducer; -import org.apache.qpid.jms.Session; - -import javax.jms.*; -import java.net.InetAddress; -import java.net.UnknownHostException; - -/** - * A client that behaves as follows: - *
  • Connects to a queue, whose name is specified as a cmd-line argument
  • - *
  • Creates a temporary queue
  • - *
  • Creates messages containing a property that is the name of the temporary queue
  • - *
  • Fires off a message on the original queue and waits for a response on the temporary queue
  • - *
- */ -public class TestPingProducer implements ExceptionListener -{ - private static final Logger _log = Logger.getLogger(TestPingProducer.class); - - private AMQConnection _connection; - - private static int _messageSize = 0; - private boolean _publish; - - private long SLEEP_TIME = 250L; - -// private class CallbackHandler implements MessageListener -// { -// -// private int _actualMessageCount; -// -// -// public void onMessage(Message m) -// { -// if (_log.isDebugEnabled()) -// { -// _log.debug("Message received: " + m); -// } -// _actualMessageCount++; -// if (_actualMessageCount % 1000 == 0) -// { -// _log.info("Received message count: " + _actualMessageCount); -// } -// } -// } - - public TestPingProducer(boolean TRANSACTED, String brokerDetails, String clientID, - String virtualpath) throws AMQException, URLSyntaxException - { - try - { - createConnection(brokerDetails, clientID, virtualpath); - - Session session; - - if (TRANSACTED) - { - session = (Session) _connection.createSession(true, Session.SESSION_TRANSACTED); - } - else - { - session = (Session) _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - } - - String queue = "ping"; - AMQQueue destination = new AMQQueue(queue); - MessageProducer producer = (MessageProducer) session.createProducer(destination); - - _connection.setExceptionListener(this); - - _connection.start(); - - while (_publish) - { -/* - TextMessage msg = session.createTextMessage( - "Presented to in conjunction with Mahnah Mahnah and the Snowths: " + ++messageNumber); -*/ - ObjectMessage msg = null; - if (_messageSize != 0) - { - msg = TestMessageFactory.newObjectMessage(session, _messageSize); - } - else - { - msg = session.createObjectMessage(); - } - - msg.setStringProperty("timestampString", Long.toString(System.currentTimeMillis())); - msg.setLongProperty("timestamp", System.currentTimeMillis()); - - ((BasicMessageProducer) producer).send(msg, DeliveryMode.NON_PERSISTENT, true); - _log.info("Message Sent."); - _log.debug(msg); - - - if (TRANSACTED) - { - try - { - session.commit(); - _log.debug("Session Commited."); - } - catch (JMSException e) - { - _log.trace("JMSException on commit:" + e); - try - { - session.rollback(); - _log.debug("Message rolled back."); - } - catch (JMSException jsme) - { - _log.trace("JMSE on rollback:" + jsme); - } - - - if (e.getLinkedException() instanceof AMQNoConsumersException) - { - _log.info("No Consumers on queue:'" + queue + "'"); - continue; - } - } - } - - - if (SLEEP_TIME > 0) - { - try - { - Thread.sleep(SLEEP_TIME); - } - catch (InterruptedException ie) - { - //do nothing - } - } - - - } - - } - catch (JMSException e) - { - _publish = false; - e.printStackTrace(); - } - } - - private void createConnection(String brokerDetails, String clientID, String virtualpath) throws AMQException, URLSyntaxException - { - _publish = true; - _connection = new AMQConnection(brokerDetails, "guest", "guest", - clientID, virtualpath); - _log.info("Connected with URL:" + _connection.toURL()); - } - - /** - * @param args argument 1 if present specifies the name of the temporary queue to create. Leaving it blank - * means the server will allocate a name. - */ - public static void main(String[] args) - { - if (args.length < 2) - { - System.err.println("Usage: TestPingPublisher [transacted] [message size in bytes]"); - System.exit(0); - } - try - { - InetAddress address = InetAddress.getLocalHost(); - String clientID = address.getHostName() + System.currentTimeMillis(); - boolean transacted = false; - if (args.length == 3 ) - { - transacted = Boolean.parseBoolean(args[2]); - } - else if (args.length > 3 ) - { - transacted = Boolean.parseBoolean(args[2]); - _messageSize = Integer.parseInt(args[3]); - } - - new TestPingProducer(transacted, args[0], clientID, args[1]); - } - catch (UnknownHostException e) - { - e.printStackTrace(); - } - catch (AMQException e) - { - System.err.println("Error in client: " + e); - e.printStackTrace(); - } - catch (URLSyntaxException e) - { - System.err.println("Error in connection arguments : " + e); - } - - //System.exit(0); - } - - /** - * @see javax.jms.ExceptionListener#onException(javax.jms.JMSException) - */ - public void onException(JMSException e) - { - System.err.println(e.getMessage()); - - _publish = false; - e.printStackTrace(System.err); - } -} diff --git a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java b/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java deleted file mode 100644 index 3b2dcc4d36..0000000000 --- a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.qpid.pingpong; - -import org.apache.log4j.Logger; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.AMQException; -import org.apache.qpid.url.URLSyntaxException; -import org.apache.qpid.client.AMQTopic; -import org.apache.qpid.client.BasicMessageProducer; -import org.apache.qpid.client.message.TestMessageFactory; -import org.apache.qpid.jms.MessageProducer; -import org.apache.qpid.jms.Session; - -import javax.jms.*; -import java.net.InetAddress; -import java.net.UnknownHostException; - -/** - * A client that behaves as follows: - *
  • Connects to a queue, whose name is specified as a cmd-line argument
  • - *
  • Creates a temporary queue
  • - *
  • Creates messages containing a property that is the name of the temporary queue
  • - *
  • Fires off a message on the original queue and waits for a response on the temporary queue
  • - *
- */ -public class TestPingPublisher implements ExceptionListener -{ - private static final Logger _log = Logger.getLogger(TestPingPublisher.class); - - private AMQConnection _connection; - - private boolean _publish; - private static int _messageSize = 0; - private long SLEEP_TIME = 0L; - -// private class CallbackHandler implements MessageListener -// { -// -// private int _actualMessageCount; -// -// -// public void onMessage(Message m) -// { -// if (_log.isDebugEnabled()) -// { -// _log.debug("Message received: " + m); -// } -// _actualMessageCount++; -// if (_actualMessageCount % 1000 == 0) -// { -// _log.info("Received message count: " + _actualMessageCount); -// } -// } -// } - - public TestPingPublisher(String brokerDetails, String clientID, String virtualpath) throws AMQException, URLSyntaxException - { - try - { - createConnection(brokerDetails, clientID, virtualpath); - - Session session = (Session) _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - //AMQQueue destination = new AMQQueue("ping"); - AMQTopic destination = new AMQTopic("ping"); - MessageProducer producer = (MessageProducer) session.createProducer(destination); - - _connection.setExceptionListener(this); - - _connection.start(); - - int msgCount = 0; - while (_publish) - { -/* - TextMessage msg = session.createTextMessage( - "Presented to in conjunction with Mahnah Mahnah and the Snowths: " + ++messageNumber); -*/ - ObjectMessage msg = null; - if (_messageSize != 0) - { - msg = TestMessageFactory.newObjectMessage(session, _messageSize); - } - else - { - msg = session.createObjectMessage(); - } - - Long time = System.nanoTime(); - msg.setStringProperty("timestampString", Long.toString(time)); - msg.setLongProperty("timestamp", time); - - ((BasicMessageProducer) producer).send(msg, DeliveryMode.PERSISTENT, true); - - _log.info("Message Sent:" + msgCount++); - _log.debug(msg); - - if (msgCount == Integer.MAX_VALUE) - { - _publish = false; - } - - if (SLEEP_TIME > 0) - { - try - { - Thread.sleep(SLEEP_TIME); - } - catch (InterruptedException ie) - { - //do nothing - } - } - } - - } - catch (JMSException e) - { - e.printStackTrace(); - } - } - - private void createConnection(String brokerDetails, String clientID, String virtualpath) throws AMQException, URLSyntaxException - { - _publish = true; - _connection = new AMQConnection(brokerDetails, "guest", "guest", clientID, virtualpath); - _log.info("Connected with URL:" + _connection.toURL()); - } - - /** - * @param args argument 1 if present specifies the name of the temporary queue to create. Leaving it blank - * means the server will allocate a name. - */ - public static void main(String[] args) - { - if (args.length < 2) - { - System.err.println("Usage: TestPingPublisher [message size in bytes]"); - System.exit(0); - } - try - { - InetAddress address = InetAddress.getLocalHost(); - String clientID = address.getHostName() + System.currentTimeMillis(); - if (args.length > 2 ) - { - _messageSize = Integer.parseInt(args[2]); - } - new TestPingPublisher(args[0], clientID, args[1]); - } - catch (UnknownHostException e) - { - e.printStackTrace(); - } - catch (AMQException e) - { - System.err.println("Error in client: " + e); - e.printStackTrace(); - } - catch (URLSyntaxException e) - { - System.err.println("Error in connection arguments : " + e); - } - - //System.exit(0); - } - - /** - * @see javax.jms.ExceptionListener#onException(javax.jms.JMSException) - */ - public void onException(JMSException e) - { - System.err.println(e.getMessage()); - - _publish = false; - e.printStackTrace(System.err); - } -} diff --git a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingSubscriber.java b/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingSubscriber.java deleted file mode 100644 index 001f1e3568..0000000000 --- a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingSubscriber.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.qpid.pingpong; - -import org.apache.log4j.Logger; -import org.apache.log4j.Level; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQTopic; -import org.apache.qpid.jms.Session; - -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.Topic; -import javax.jms.JMSException; -import java.net.InetAddress; - -public class TestPingSubscriber -{ - private static final Logger _logger = Logger.getLogger(TestPingSubscriber.class); - - private static class TestPingMessageListener implements MessageListener - { - public TestPingMessageListener() - { - } - - long _lastTimestamp = 0L; - long _lastTimestampString = 0L; - - public void onMessage(javax.jms.Message message) - { - Long time = System.nanoTime(); - - if (_logger.isInfoEnabled()) - { - long timestampString = 0L; - - try - { - long timestamp = message.getLongProperty("timestamp"); - timestampString = Long.parseLong(message.getStringProperty("timestampString")); - - if (timestampString != timestamp) - { - _logger.info("Timetamps differ!:\n" + - "timestamp:" + timestamp + "\n" + - "timestampString:" + timestampString); - } - - } - catch (JMSException jmse) - { - // ignore - } - - - long stringDiff = time - timestampString; - - _logger.info("Ping: TS:" + stringDiff / 1000 + "us"); - - // _logger.info(_name + " got message '" + message + "\n"); - } - } - } - - public static void main(String[] args) - { - _logger.info("Starting..."); - - if (args.length < 4) - { - System.out.println("Usage: brokerdetails username password virtual-path [selector] "); - System.exit(1); - } - try - { - InetAddress address = InetAddress.getLocalHost(); - AMQConnection con1 = new AMQConnection(args[0], args[1], args[2], - address.getHostName(), args[3]); - - _logger.info("Connected with URL:" + con1.toURL()); - - final org.apache.qpid.jms.Session session1 = (org.apache.qpid.jms.Session) - con1.createSession(false, Session.AUTO_ACKNOWLEDGE); - - - String selector = null; - - if (args.length == 5) - { - selector = args[4]; - _logger.info("Message selector is <" + selector + ">..."); - } - else - { - _logger.info("Not using message selector "); - } - - Topic t = new AMQTopic("ping"); - - MessageConsumer consumer1 = session1.createConsumer(t, - 1, false, false, selector); - - consumer1.setMessageListener(new TestPingMessageListener()); - con1.start(); - } - catch (Throwable t) - { - System.err.println("Fatal error: " + t); - t.printStackTrace(); - } - - System.out.println("Waiting..."); - } -} - -- cgit v1.2.1