summaryrefslogtreecommitdiff
path: root/qpid/java/tools/src/main/java/org/apache/qpid/tools/MercuryBase.java
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/java/tools/src/main/java/org/apache/qpid/tools/MercuryBase.java')
-rw-r--r--qpid/java/tools/src/main/java/org/apache/qpid/tools/MercuryBase.java81
1 files changed, 23 insertions, 58 deletions
diff --git a/qpid/java/tools/src/main/java/org/apache/qpid/tools/MercuryBase.java b/qpid/java/tools/src/main/java/org/apache/qpid/tools/MercuryBase.java
index 121e94cea1..097b021b3e 100644
--- a/qpid/java/tools/src/main/java/org/apache/qpid/tools/MercuryBase.java
+++ b/qpid/java/tools/src/main/java/org/apache/qpid/tools/MercuryBase.java
@@ -21,7 +21,6 @@
package org.apache.qpid.tools;
import java.net.InetAddress;
-import java.text.DecimalFormat;
import java.util.UUID;
import javax.jms.Connection;
@@ -32,14 +31,17 @@ import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.qpid.client.AMQAnyDestination;
-import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQSession_0_10;
-import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.messaging.Address;
+import org.apache.qpid.tools.TestConfiguration.MessageType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public class PerfBase
+public class MercuryBase
{
+ private static final Logger _logger = LoggerFactory.getLogger(MercuryBase.class);
+
public final static String CODE = "CODE";
public final static String ID = "ID";
public final static String REPLY_ADDR = "REPLY_ADDR";
@@ -54,14 +56,13 @@ public class PerfBase
String CONTROLLER_ADDR = System.getProperty("CONT_ADDR","CONTROLLER;{create: always, node:{x-declare:{auto-delete:true}}}");
- TestParams params;
+ TestConfiguration config;
Connection con;
Session session;
Session controllerSession;
Destination dest;
Destination myControlQueue;
Destination controllerQueue;
- DecimalFormat df = new DecimalFormat("###.##");
String id;
String myControlQueueAddr;
@@ -69,7 +70,8 @@ public class PerfBase
MessageConsumer receiveFromController;
String prefix = "";
- enum OPCode {
+ enum OPCode
+ {
REGISTER_CONSUMER, REGISTER_PRODUCER,
PRODUCER_STARTWARMUP, CONSUMER_STARTWARMUP,
CONSUMER_READY, PRODUCER_READY,
@@ -79,39 +81,11 @@ public class PerfBase
CONTINUE_TEST, STOP_TEST
};
- enum MessageType {
- BYTES, TEXT, MAP, OBJECT;
-
- public static MessageType getType(String s) throws Exception
- {
- if ("text".equalsIgnoreCase(s))
- {
- return TEXT;
- }
- else if ("bytes".equalsIgnoreCase(s))
- {
- return BYTES;
- }
- /*else if ("map".equalsIgnoreCase(s))
- {
- return MAP;
- }
- else if ("object".equalsIgnoreCase(s))
- {
- return OBJECT;
- }*/
- else
- {
- throw new Exception("Unsupported message type");
- }
- }
- };
-
MessageType msgType = MessageType.BYTES;
- public PerfBase(String prefix)
+ public MercuryBase(TestConfiguration config,String prefix)
{
- params = new TestParams();
+ this.config = config;
String host = "";
try
{
@@ -127,25 +101,16 @@ public class PerfBase
public void setUp() throws Exception
{
- if (params.getHost().equals("") || params.getPort() == -1)
- {
- con = new AMQConnection(params.getUrl());
- }
- else
- {
- con = new AMQConnection(params.getHost(),params.getPort(),"guest","guest","test","test");
- }
+ con = config.createConnection();
con.start();
- session = con.createSession(params.isTransacted(),
- params.isTransacted()? Session.SESSION_TRANSACTED:params.getAckMode());
controllerSession = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
dest = createDestination();
- controllerQueue = new AMQAnyDestination(CONTROLLER_ADDR);
+ controllerQueue = AMQDestination.createDestination(CONTROLLER_ADDR);
myControlQueue = session.createQueue(myControlQueueAddr);
- msgType = MessageType.getType(params.getMessageType());
- System.out.println("Using " + msgType + " messages");
+ msgType = MessageType.getType(config.getMessageType());
+ _logger.debug("Using " + msgType + " messages");
sendToController = controllerSession.createProducer(controllerQueue);
receiveFromController = controllerSession.createConsumer(myControlQueue);
@@ -153,11 +118,11 @@ public class PerfBase
private Destination createDestination() throws Exception
{
- if (params.isUseUniqueDests())
+ if (config.isUseUniqueDests())
{
- System.out.println("Prefix : " + prefix);
- Address addr = Address.parse(params.getAddress());
- AMQAnyDestination temp = new AMQAnyDestination(params.getAddress());
+ _logger.debug("Prefix : " + prefix);
+ Address addr = Address.parse(config.getAddress());
+ AMQDestination temp = (AMQDestination) AMQDestination.createDestination(config.getAddress());
int type = ((AMQSession_0_10)session).resolveAddressType(temp);
if ( type == AMQDestination.TOPIC_TYPE)
@@ -171,11 +136,11 @@ public class PerfBase
System.out.println("Setting name : " + addr);
}
- return new AMQAnyDestination(addr);
+ return AMQDestination.createDestination(addr.toString());
}
else
{
- return new AMQAnyDestination(params.getAddress());
+ return AMQDestination.createDestination(config.getAddress());
}
}
@@ -190,7 +155,7 @@ public class PerfBase
{
MapMessage m = (MapMessage)receiveFromController.receive();
OPCode code = OPCode.values()[m.getInt(CODE)];
- System.out.println("Received Code : " + code);
+ _logger.debug("Received Code : " + code);
if (expected != code)
{
throw new Exception("Expected OPCode : " + expected + " but received : " + code);
@@ -202,7 +167,7 @@ public class PerfBase
{
MapMessage m = (MapMessage)receiveFromController.receive();
OPCode code = OPCode.values()[m.getInt(CODE)];
- System.out.println("Received Code : " + code);
+ _logger.debug("Received Code : " + code);
return (code == OPCode.CONTINUE_TEST);
}