mirror of https://github.com/apache/activemq.git
Remove dependence on fixed port.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1186494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
54ff0ce448
commit
1fd39c991e
|
@ -17,7 +17,6 @@
|
|||
package org.apache.activemq.command;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.JMSException;
|
||||
|
@ -30,37 +29,30 @@ import junit.framework.TestCase;
|
|||
import org.apache.activemq.ActiveMQConnection;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
|
||||
public class MessageCompressionTest extends TestCase {
|
||||
|
||||
private static final String BROKER_URL = "tcp://localhost:61216";
|
||||
private static final String BROKER_URL = "tcp://localhost:0";
|
||||
// The following text should compress well
|
||||
private static final String TEXT = "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. ";
|
||||
private static final String TEXT = "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
|
||||
+ "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. ";
|
||||
|
||||
protected BrokerService broker;
|
||||
private BrokerService broker;
|
||||
private ActiveMQQueue queue;
|
||||
private String connectionUri;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
broker = new BrokerService();
|
||||
|
||||
TransportConnector tc = new TransportConnector();
|
||||
tc.setUri(new URI(BROKER_URL));
|
||||
tc.setName("tcp");
|
||||
|
||||
queue = new ActiveMQQueue("TEST." + System.currentTimeMillis());
|
||||
|
||||
broker.addConnector(tc);
|
||||
connectionUri = broker.addConnector(BROKER_URL).getPublishableConnectString();
|
||||
broker.start();
|
||||
|
||||
queue = new ActiveMQQueue("TEST." + System.currentTimeMillis());
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
|
@ -71,45 +63,48 @@ public class MessageCompressionTest extends TestCase {
|
|||
|
||||
public void testTextMessageCompression() throws Exception {
|
||||
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(BROKER_URL);
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri);
|
||||
factory.setUseCompression(true);
|
||||
sendTestMessage(factory, TEXT);
|
||||
ActiveMQTextMessage message = receiveTestMessage(factory);
|
||||
int compressedSize = message.getContent().getLength();
|
||||
|
||||
factory = new ActiveMQConnectionFactory(BROKER_URL);
|
||||
factory = new ActiveMQConnectionFactory(connectionUri);
|
||||
factory.setUseCompression(false);
|
||||
sendTestMessage(factory, TEXT);
|
||||
message = receiveTestMessage(factory);
|
||||
int unCompressedSize = message.getContent().getLength();
|
||||
|
||||
assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", compressedSize < unCompressedSize);
|
||||
assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
|
||||
compressedSize < unCompressedSize);
|
||||
}
|
||||
|
||||
public void testBytesMessageCompression() throws Exception {
|
||||
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(BROKER_URL);
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri);
|
||||
factory.setUseCompression(true);
|
||||
sendTestBytesMessage(factory, TEXT);
|
||||
ActiveMQBytesMessage message = receiveTestBytesMessage(factory);
|
||||
int compressedSize = message.getContent().getLength();
|
||||
byte[] bytes = new byte[TEXT.getBytes("UTF8").length];
|
||||
message.readBytes(bytes);
|
||||
assertTrue(message.readBytes( new byte[255]) == -1);
|
||||
assertTrue(message.readBytes(new byte[255]) == -1);
|
||||
String rcvString = new String(bytes, "UTF8");
|
||||
assertEquals(TEXT, rcvString);
|
||||
assertTrue(message.isCompressed());
|
||||
|
||||
factory = new ActiveMQConnectionFactory(BROKER_URL);
|
||||
factory = new ActiveMQConnectionFactory(connectionUri);
|
||||
factory.setUseCompression(false);
|
||||
sendTestBytesMessage(factory, TEXT);
|
||||
message = receiveTestBytesMessage(factory);
|
||||
int unCompressedSize = message.getContent().getLength();
|
||||
|
||||
assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", compressedSize < unCompressedSize);
|
||||
assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
|
||||
compressedSize < unCompressedSize);
|
||||
}
|
||||
|
||||
private void sendTestMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
|
||||
ActiveMQConnection connection = (ActiveMQConnection)factory.createConnection();
|
||||
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageProducer producer = session.createProducer(queue);
|
||||
producer.send(session.createTextMessage(message));
|
||||
|
@ -117,17 +112,17 @@ public class MessageCompressionTest extends TestCase {
|
|||
}
|
||||
|
||||
private ActiveMQTextMessage receiveTestMessage(ActiveMQConnectionFactory factory) throws JMSException {
|
||||
ActiveMQConnection connection = (ActiveMQConnection)factory.createConnection();
|
||||
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
|
||||
connection.start();
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageConsumer consumer = session.createConsumer(queue);
|
||||
ActiveMQTextMessage rc = (ActiveMQTextMessage)consumer.receive();
|
||||
ActiveMQTextMessage rc = (ActiveMQTextMessage) consumer.receive();
|
||||
connection.close();
|
||||
return rc;
|
||||
}
|
||||
|
||||
private void sendTestBytesMessage(ActiveMQConnectionFactory factory, String message) throws JMSException, UnsupportedEncodingException {
|
||||
ActiveMQConnection connection = (ActiveMQConnection)factory.createConnection();
|
||||
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageProducer producer = session.createProducer(queue);
|
||||
BytesMessage bytesMessage = session.createBytesMessage();
|
||||
|
@ -137,21 +132,12 @@ public class MessageCompressionTest extends TestCase {
|
|||
}
|
||||
|
||||
private ActiveMQBytesMessage receiveTestBytesMessage(ActiveMQConnectionFactory factory) throws JMSException, UnsupportedEncodingException {
|
||||
ActiveMQConnection connection = (ActiveMQConnection)factory.createConnection();
|
||||
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
|
||||
connection.start();
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageConsumer consumer = session.createConsumer(queue);
|
||||
ActiveMQBytesMessage rc = (ActiveMQBytesMessage)consumer.receive();
|
||||
ActiveMQBytesMessage rc = (ActiveMQBytesMessage) consumer.receive();
|
||||
connection.close();
|
||||
return rc;
|
||||
}
|
||||
|
||||
// public void testJavaUtilZip() throws Exception {
|
||||
// String str = "When the going gets weird, the weird turn pro.";
|
||||
// byte[] bytes = str.getBytes();
|
||||
//
|
||||
// ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length);
|
||||
// DeflaterOutputStream dos = new DeflaterOutputStream(baos);
|
||||
// dos.
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue