added transacted topic test

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@946725 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2010-05-20 17:39:09 +00:00
parent cd6f4f5650
commit e2a383690c
2 changed files with 55 additions and 8 deletions

View File

@ -0,0 +1,34 @@
/**
* 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.activemq.perf;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
/**
* @version $Revision: 1.3 $
*/
public class KahaDBDurableTransactedTopicTest extends SimpleDurableTopicTest {
@Override
protected PerfProducer createProducer(ConnectionFactory fac, Destination dest, int number, byte[] payload) throws JMSException {
return new PerfProducer(fac, dest, payload);
}
}

View File

@ -18,7 +18,6 @@ package org.apache.activemq.perf;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
@ -34,17 +33,28 @@ public class PerfProducer implements Runnable {
protected Connection connection;
protected MessageProducer producer;
protected PerfRate rate = new PerfRate();
private byte[] payload;
private final byte[] payload;
private Session session;
private final CountDownLatch stopped = new CountDownLatch(1);
private boolean running;
private final boolean transacted;
private int sleep = 0;
public PerfProducer(ConnectionFactory fac, Destination dest, byte[] palyload) throws JMSException {
public PerfProducer(ConnectionFactory fac, Destination dest, byte[] payload) throws JMSException {
this(fac, dest, payload, false);
}
public PerfProducer(ConnectionFactory fac, Destination dest, byte[] payload, boolean transacted)
throws JMSException {
connection = fac.createConnection();
this.transacted = transacted;
if (transacted) {
session = connection.createSession(true, Session.SESSION_TRANSACTED);
} else {
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
producer = session.createProducer(dest);
this.payload = palyload;
this.payload = payload;
}
public void setDeliveryMode(int mode) throws JMSException {
@ -93,6 +103,9 @@ public class PerfProducer implements Runnable {
msg = session.createBytesMessage();
msg.writeBytes(payload);
producer.send(msg);
if(this.transacted) {
this.session.commit();
}
rate.increment();
if (sleep > 0) {
Thread.sleep(sleep);