mirror of https://github.com/apache/activemq.git
Fix a bunch of warnings covering deprecated asserts and such.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1443267 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
46e67a10cc
commit
c7d559fbcd
|
@ -22,7 +22,6 @@ import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.jms.ExceptionListener;
|
import javax.jms.ExceptionListener;
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
|
@ -83,7 +82,7 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
|
||||||
assertTrue(cf.isUseAsyncSend());
|
assertTrue(cf.isUseAsyncSend());
|
||||||
// the broker url have been adjusted.
|
// the broker url have been adjusted.
|
||||||
assertEquals("vm:(broker:()/localhost)", cf.getBrokerURL());
|
assertEquals("vm:(broker:()/localhost)", cf.getBrokerURL());
|
||||||
|
|
||||||
cf = new ActiveMQConnectionFactory("vm://localhost?jms.auditDepth=5000");
|
cf = new ActiveMQConnectionFactory("vm://localhost?jms.auditDepth=5000");
|
||||||
assertEquals(5000, cf.getAuditDepth());
|
assertEquals(5000, cf.getAuditDepth());
|
||||||
}
|
}
|
||||||
|
@ -142,7 +141,7 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
|
||||||
public void testCreateTcpConnectionUsingKnownLocalPort() throws Exception {
|
public void testCreateTcpConnectionUsingKnownLocalPort() throws Exception {
|
||||||
broker = new BrokerService();
|
broker = new BrokerService();
|
||||||
broker.setPersistent(false);
|
broker.setPersistent(false);
|
||||||
TransportConnector connector = broker.addConnector("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
|
broker.addConnector("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
|
||||||
broker.start();
|
broker.start();
|
||||||
|
|
||||||
// This should create the connection.
|
// This should create the connection.
|
||||||
|
@ -178,56 +177,58 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
|
||||||
cf = (ActiveMQConnectionFactory)objectsIn.readObject();
|
cf = (ActiveMQConnectionFactory)objectsIn.readObject();
|
||||||
assertEquals(cf.getClientID(), clientID);
|
assertEquals(cf.getClientID(), clientID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetExceptionListener() throws Exception {
|
public void testSetExceptionListener() throws Exception {
|
||||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
|
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
assertNull(connection.getExceptionListener());
|
assertNull(connection.getExceptionListener());
|
||||||
|
|
||||||
ExceptionListener exListener = new ExceptionListener() {
|
ExceptionListener exListener = new ExceptionListener() {
|
||||||
public void onException(JMSException arg0) {
|
@Override
|
||||||
}
|
public void onException(JMSException arg0) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
cf.setExceptionListener(exListener);
|
cf.setExceptionListener(exListener);
|
||||||
connection.close();
|
connection.close();
|
||||||
|
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
assertNotNull(connection.getExceptionListener());
|
assertNotNull(connection.getExceptionListener());
|
||||||
assertEquals(exListener, connection.getExceptionListener());
|
assertEquals(exListener, connection.getExceptionListener());
|
||||||
connection.close();
|
connection.close();
|
||||||
|
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
assertEquals(exListener, connection.getExceptionListener());
|
assertEquals(exListener, connection.getExceptionListener());
|
||||||
|
|
||||||
assertEquals(exListener, cf.getExceptionListener());
|
assertEquals(exListener, cf.getExceptionListener());
|
||||||
connection.close();
|
connection.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testSetClientInternalExceptionListener() throws Exception {
|
public void testSetClientInternalExceptionListener() throws Exception {
|
||||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
|
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
assertNull(connection.getClientInternalExceptionListener());
|
assertNull(connection.getClientInternalExceptionListener());
|
||||||
|
|
||||||
ClientInternalExceptionListener listener = new ClientInternalExceptionListener() {
|
ClientInternalExceptionListener listener = new ClientInternalExceptionListener() {
|
||||||
|
@Override
|
||||||
public void onException(Throwable exception) {
|
public void onException(Throwable exception) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
connection.setClientInternalExceptionListener(listener);
|
connection.setClientInternalExceptionListener(listener);
|
||||||
cf.setClientInternalExceptionListener(listener);
|
cf.setClientInternalExceptionListener(listener);
|
||||||
connection.close();
|
connection.close();
|
||||||
|
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
assertNotNull(connection.getClientInternalExceptionListener());
|
assertNotNull(connection.getClientInternalExceptionListener());
|
||||||
assertEquals(listener, connection.getClientInternalExceptionListener());
|
assertEquals(listener, connection.getClientInternalExceptionListener());
|
||||||
connection.close();
|
connection.close();
|
||||||
|
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
assertEquals(listener, connection.getClientInternalExceptionListener());
|
assertEquals(listener, connection.getClientInternalExceptionListener());
|
||||||
assertEquals(listener, cf.getClientInternalExceptionListener());
|
assertEquals(listener, cf.getClientInternalExceptionListener());
|
||||||
connection.close();
|
connection.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertCreateConnection(String uri) throws Exception {
|
protected void assertCreateConnection(String uri) throws Exception {
|
||||||
|
|
|
@ -20,25 +20,16 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
import javax.jms.ExceptionListener;
|
|
||||||
import javax.jms.JMSException;
|
|
||||||
import javax.jms.Session;
|
|
||||||
import javax.net.ssl.KeyManager;
|
import javax.net.ssl.KeyManager;
|
||||||
import javax.net.ssl.KeyManagerFactory;
|
import javax.net.ssl.KeyManagerFactory;
|
||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
import javax.net.ssl.TrustManagerFactory;
|
import javax.net.ssl.TrustManagerFactory;
|
||||||
|
|
||||||
import org.apache.activemq.broker.BrokerRegistry;
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.SslBrokerService;
|
import org.apache.activemq.broker.SslBrokerService;
|
||||||
import org.apache.activemq.broker.TransportConnector;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -50,10 +41,10 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore";
|
public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore";
|
||||||
public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore";
|
public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore";
|
||||||
|
|
||||||
private TransportConnector connector;
|
|
||||||
private ActiveMQConnection connection;
|
private ActiveMQConnection connection;
|
||||||
private BrokerService broker;
|
private BrokerService broker;
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
// Try our best to close any previously opend connection.
|
// Try our best to close any previously opend connection.
|
||||||
try {
|
try {
|
||||||
|
@ -77,7 +68,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
assertNotNull(connection);
|
assertNotNull(connection);
|
||||||
connection.start();
|
connection.start();
|
||||||
connection.stop();
|
connection.stop();
|
||||||
brokerStop();
|
brokerStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateFailoverTcpConnectionUsingKnownPort() throws Exception {
|
public void testCreateFailoverTcpConnectionUsingKnownPort() throws Exception {
|
||||||
|
@ -90,12 +81,12 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
assertNotNull(connection);
|
assertNotNull(connection);
|
||||||
connection.start();
|
connection.start();
|
||||||
connection.stop();
|
connection.stop();
|
||||||
brokerStop();
|
brokerStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateSslConnection() throws Exception {
|
public void testCreateSslConnection() throws Exception {
|
||||||
// Create SSL/TLS connection with trusted cert from truststore.
|
// Create SSL/TLS connection with trusted cert from truststore.
|
||||||
String sslUri = "ssl://localhost:61611";
|
String sslUri = "ssl://localhost:61611";
|
||||||
broker = createSslBroker(sslUri);
|
broker = createSslBroker(sslUri);
|
||||||
assertNotNull(broker);
|
assertNotNull(broker);
|
||||||
|
|
||||||
|
@ -113,7 +104,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
|
|
||||||
public void testFailoverSslConnection() throws Exception {
|
public void testFailoverSslConnection() throws Exception {
|
||||||
// Create SSL/TLS connection with trusted cert from truststore.
|
// Create SSL/TLS connection with trusted cert from truststore.
|
||||||
String sslUri = "ssl://localhost:61611";
|
String sslUri = "ssl://localhost:61611";
|
||||||
broker = createSslBroker(sslUri);
|
broker = createSslBroker(sslUri);
|
||||||
assertNotNull(broker);
|
assertNotNull(broker);
|
||||||
|
|
||||||
|
@ -148,7 +139,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
|
|
||||||
public void testNegativeCreateSslConnectionWithWrongPassword() throws Exception {
|
public void testNegativeCreateSslConnectionWithWrongPassword() throws Exception {
|
||||||
// Create SSL/TLS connection with trusted cert from truststore.
|
// Create SSL/TLS connection with trusted cert from truststore.
|
||||||
String sslUri = "ssl://localhost:61611";
|
String sslUri = "ssl://localhost:61611";
|
||||||
broker = createSslBroker(sslUri);
|
broker = createSslBroker(sslUri);
|
||||||
assertNotNull(broker);
|
assertNotNull(broker);
|
||||||
|
|
||||||
|
@ -160,8 +151,8 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
}
|
}
|
||||||
catch (javax.jms.JMSException ignore) {
|
catch (javax.jms.JMSException ignore) {
|
||||||
// Expected exception
|
// Expected exception
|
||||||
LOG.info("Expected java.io.Exception [" + ignore + "]");
|
LOG.info("Expected java.io.Exception [" + ignore + "]");
|
||||||
}
|
}
|
||||||
assertNull(connection);
|
assertNull(connection);
|
||||||
|
|
||||||
|
@ -170,7 +161,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
|
|
||||||
public void testNegativeCreateSslConnectionWithWrongCert() throws Exception {
|
public void testNegativeCreateSslConnectionWithWrongCert() throws Exception {
|
||||||
// Create SSL/TLS connection with trusted cert from truststore.
|
// Create SSL/TLS connection with trusted cert from truststore.
|
||||||
String sslUri = "ssl://localhost:61611";
|
String sslUri = "ssl://localhost:61611";
|
||||||
broker = createSslBroker(sslUri);
|
broker = createSslBroker(sslUri);
|
||||||
assertNotNull(broker);
|
assertNotNull(broker);
|
||||||
|
|
||||||
|
@ -182,8 +173,8 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
}
|
}
|
||||||
catch (javax.jms.JMSException ignore) {
|
catch (javax.jms.JMSException ignore) {
|
||||||
// Expected exception
|
// Expected exception
|
||||||
LOG.info("Expected SSLHandshakeException [" + ignore + "]");
|
LOG.info("Expected SSLHandshakeException [" + ignore + "]");
|
||||||
}
|
}
|
||||||
assertNull(connection);
|
assertNull(connection);
|
||||||
|
|
||||||
|
@ -195,26 +186,26 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
BrokerService service = new BrokerService();
|
BrokerService service = new BrokerService();
|
||||||
service.setPersistent(false);
|
service.setPersistent(false);
|
||||||
service.setUseJmx(false);
|
service.setUseJmx(false);
|
||||||
connector = service.addConnector(uri);
|
service.addConnector(uri);
|
||||||
service.start();
|
service.start();
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BrokerService createSslBroker(String uri) throws Exception {
|
protected BrokerService createSslBroker(String uri) throws Exception {
|
||||||
|
|
||||||
// http://java.sun.com/javase/javaseforbusiness/docs/TLSReadme.html
|
// http://java.sun.com/javase/javaseforbusiness/docs/TLSReadme.html
|
||||||
// work around: javax.net.ssl.SSLHandshakeException: renegotiation is not allowed
|
// work around: javax.net.ssl.SSLHandshakeException: renegotiation is not allowed
|
||||||
//System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
|
//System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
|
||||||
|
|
||||||
SslBrokerService service = new SslBrokerService();
|
SslBrokerService service = new SslBrokerService();
|
||||||
service.setPersistent(false);
|
service.setPersistent(false);
|
||||||
|
|
||||||
KeyManager[] km = getKeyManager();
|
KeyManager[] km = getKeyManager();
|
||||||
TrustManager[] tm = getTrustManager();
|
TrustManager[] tm = getTrustManager();
|
||||||
connector = service.addSslConnector(uri, km, tm, null);
|
service.addSslConnector(uri, km, tm, null);
|
||||||
service.start();
|
service.start();
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,32 +216,32 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
public static TrustManager[] getTrustManager() throws Exception {
|
public static TrustManager[] getTrustManager() throws Exception {
|
||||||
TrustManager[] trustStoreManagers = null;
|
TrustManager[] trustStoreManagers = null;
|
||||||
KeyStore trustedCertStore = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE);
|
KeyStore trustedCertStore = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE);
|
||||||
|
|
||||||
trustedCertStore.load(new FileInputStream(ActiveMQSslConnectionFactoryTest.TRUST_KEYSTORE), null);
|
trustedCertStore.load(new FileInputStream(ActiveMQSslConnectionFactoryTest.TRUST_KEYSTORE), null);
|
||||||
TrustManagerFactory tmf =
|
TrustManagerFactory tmf =
|
||||||
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||||
|
|
||||||
tmf.init(trustedCertStore);
|
tmf.init(trustedCertStore);
|
||||||
trustStoreManagers = tmf.getTrustManagers();
|
trustStoreManagers = tmf.getTrustManagers();
|
||||||
return trustStoreManagers;
|
return trustStoreManagers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KeyManager[] getKeyManager() throws Exception {
|
public static KeyManager[] getKeyManager() throws Exception {
|
||||||
KeyManagerFactory kmf =
|
KeyManagerFactory kmf =
|
||||||
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||||
KeyStore ks = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE);
|
KeyStore ks = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE);
|
||||||
KeyManager[] keystoreManagers = null;
|
KeyManager[] keystoreManagers = null;
|
||||||
|
|
||||||
byte[] sslCert = loadClientCredential(ActiveMQSslConnectionFactoryTest.SERVER_KEYSTORE);
|
byte[] sslCert = loadClientCredential(ActiveMQSslConnectionFactoryTest.SERVER_KEYSTORE);
|
||||||
|
|
||||||
|
|
||||||
if (sslCert != null && sslCert.length > 0) {
|
if (sslCert != null && sslCert.length > 0) {
|
||||||
ByteArrayInputStream bin = new ByteArrayInputStream(sslCert);
|
ByteArrayInputStream bin = new ByteArrayInputStream(sslCert);
|
||||||
ks.load(bin, ActiveMQSslConnectionFactoryTest.PASSWORD.toCharArray());
|
ks.load(bin, ActiveMQSslConnectionFactoryTest.PASSWORD.toCharArray());
|
||||||
kmf.init(ks, ActiveMQSslConnectionFactoryTest.PASSWORD.toCharArray());
|
kmf.init(ks, ActiveMQSslConnectionFactoryTest.PASSWORD.toCharArray());
|
||||||
keystoreManagers = kmf.getKeyManagers();
|
keystoreManagers = kmf.getKeyManagers();
|
||||||
}
|
}
|
||||||
return keystoreManagers;
|
return keystoreManagers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] loadClientCredential(String fileName) throws IOException {
|
private static byte[] loadClientCredential(String fileName) throws IOException {
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.broker.Broker;
|
import org.apache.activemq.broker.Broker;
|
||||||
import org.apache.activemq.broker.BrokerFactory;
|
import org.apache.activemq.broker.BrokerFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
@ -48,8 +49,9 @@ public class ClientTestSupport extends TestCase {
|
||||||
protected long idGenerator;
|
protected long idGenerator;
|
||||||
|
|
||||||
private ActiveMQConnectionFactory connFactory;
|
private ActiveMQConnectionFactory connFactory;
|
||||||
private String brokerURL = "vm://localhost?broker.persistent=false";
|
private final String brokerURL = "vm://localhost?broker.persistent=false";
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
final AtomicBoolean connected = new AtomicBoolean(false);
|
final AtomicBoolean connected = new AtomicBoolean(false);
|
||||||
TransportConnector connector;
|
TransportConnector connector;
|
||||||
|
@ -57,10 +59,11 @@ public class ClientTestSupport extends TestCase {
|
||||||
// Start up a broker with a tcp connector.
|
// Start up a broker with a tcp connector.
|
||||||
try {
|
try {
|
||||||
broker = BrokerFactory.createBroker(new URI(this.brokerURL));
|
broker = BrokerFactory.createBroker(new URI(this.brokerURL));
|
||||||
String brokerId = broker.getBrokerName();
|
broker.getBrokerName();
|
||||||
connector = new TransportConnector(TransportFactory.bind(new URI(this.brokerURL))) {
|
connector = new TransportConnector(TransportFactory.bind(new URI(this.brokerURL))) {
|
||||||
// Hook into the connector so we can assert that the server
|
// Hook into the connector so we can assert that the server
|
||||||
// accepted a connection.
|
// accepted a connection.
|
||||||
|
@Override
|
||||||
protected org.apache.activemq.broker.Connection createConnection(org.apache.activemq.transport.Transport transport) throws IOException {
|
protected org.apache.activemq.broker.Connection createConnection(org.apache.activemq.transport.Transport transport) throws IOException {
|
||||||
connected.set(true);
|
connected.set(true);
|
||||||
return super.createConnection(transport);
|
return super.createConnection(transport);
|
||||||
|
@ -82,6 +85,7 @@ public class ClientTestSupport extends TestCase {
|
||||||
connFactory = new ActiveMQConnectionFactory(connectURI);
|
connFactory = new ActiveMQConnectionFactory(connectURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
if (broker != null) {
|
if (broker != null) {
|
||||||
|
|
|
@ -65,12 +65,12 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(CombinationTestSupport.class);
|
private static final Logger LOG = LoggerFactory.getLogger(CombinationTestSupport.class);
|
||||||
|
|
||||||
private HashMap<String, ComboOption> comboOptions = new HashMap<String, ComboOption>();
|
private final HashMap<String, ComboOption> comboOptions = new HashMap<String, ComboOption>();
|
||||||
private boolean combosEvaluated;
|
private boolean combosEvaluated;
|
||||||
private Map<String, Object> options;
|
private Map<String, Object> options;
|
||||||
protected File basedir;
|
protected File basedir;
|
||||||
|
|
||||||
static protected File basedir(Class clazz) {
|
static protected File basedir(Class<?> clazz) {
|
||||||
try {
|
try {
|
||||||
ProtectionDomain protectionDomain = clazz.getProtectionDomain();
|
ProtectionDomain protectionDomain = clazz.getProtectionDomain();
|
||||||
return new File(new File(protectionDomain.getCodeSource().getLocation().getPath()), "../..").getCanonicalFile();
|
return new File(new File(protectionDomain.getCodeSource().getLocation().getPath()), "../..").getCanonicalFile();
|
||||||
|
@ -101,6 +101,7 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void runBare() throws Throwable {
|
public void runBare() throws Throwable {
|
||||||
if (combosEvaluated) {
|
if (combosEvaluated) {
|
||||||
super.runBare();
|
super.runBare();
|
||||||
|
@ -253,6 +254,7 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport {
|
||||||
return parameters.length == 0 && name.startsWith("test") && returnType.equals(Void.TYPE);
|
return parameters.length == 0 && name.startsWith("test") && returnType.equals(Void.TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return getName(false);
|
return getName(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import javax.jms.Message;
|
||||||
import javax.jms.MessageConsumer;
|
import javax.jms.MessageConsumer;
|
||||||
import javax.jms.MessageProducer;
|
import javax.jms.MessageProducer;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
import junit.framework.Assert;
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
||||||
import org.apache.activemq.broker.region.policy.PolicyMap;
|
import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||||
|
@ -33,6 +33,7 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
|
||||||
|
|
||||||
private static final String VM_BROKER_URL = "vm://localhost";
|
private static final String VM_BROKER_URL = "vm://localhost";
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createBroker() throws Exception {
|
protected BrokerService createBroker() throws Exception {
|
||||||
BrokerService answer = new BrokerService();
|
BrokerService answer = new BrokerService();
|
||||||
answer.setPersistent(false);
|
answer.setPersistent(false);
|
||||||
|
@ -40,7 +41,7 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
|
||||||
PolicyEntry entry = new PolicyEntry();
|
PolicyEntry entry = new PolicyEntry();
|
||||||
entry.setAllConsumersExclusiveByDefault(true);
|
entry.setAllConsumersExclusiveByDefault(true);
|
||||||
map.setDefaultEntry(entry);
|
map.setDefaultEntry(entry);
|
||||||
answer.setDestinationPolicy(map);
|
answer.setDestinationPolicy(map);
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,15 +88,13 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
||||||
// Verify exclusive consumer receives the message.
|
// Verify exclusive consumer receives the message.
|
||||||
Assert.assertNotNull(exclusiveConsumer.receive(100));
|
assertNotNull(exclusiveConsumer.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
fallbackSession.close();
|
fallbackSession.close();
|
||||||
senderSession.close();
|
senderSession.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFailoverToAnotherExclusiveConsumerCreatedFirst() throws JMSException,
|
public void testFailoverToAnotherExclusiveConsumerCreatedFirst() throws JMSException,
|
||||||
|
@ -132,9 +131,9 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
||||||
// Verify exclusive consumer receives the message.
|
// Verify exclusive consumer receives the message.
|
||||||
Assert.assertNotNull(exclusiveConsumer1.receive(100));
|
assertNotNull(exclusiveConsumer1.receive(100));
|
||||||
Assert.assertNull(exclusiveConsumer2.receive(100));
|
assertNull(exclusiveConsumer2.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
// Close the exclusive consumer to verify the non-exclusive consumer
|
// Close the exclusive consumer to verify the non-exclusive consumer
|
||||||
// takes over
|
// takes over
|
||||||
|
@ -143,8 +142,8 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
|
|
||||||
Assert.assertNotNull("Should have received a message", exclusiveConsumer2.receive(100));
|
assertNotNull("Should have received a message", exclusiveConsumer2.receive(100));
|
||||||
Assert.assertNull("Should not have received a message", fallbackConsumer.receive(100));
|
assertNull("Should not have received a message", fallbackConsumer.receive(100));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
fallbackSession.close();
|
fallbackSession.close();
|
||||||
|
@ -184,8 +183,8 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
||||||
// Verify exclusive consumer receives the message.
|
// Verify exclusive consumer receives the message.
|
||||||
Assert.assertNotNull(exclusiveConsumer.receive(100));
|
assertNotNull(exclusiveConsumer.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
// Close the exclusive consumer to verify the non-exclusive consumer
|
// Close the exclusive consumer to verify the non-exclusive consumer
|
||||||
// takes over
|
// takes over
|
||||||
|
@ -193,14 +192,12 @@ public class ExclusiveConsumerStartupDestinationTest extends EmbeddedBrokerTestS
|
||||||
|
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
|
|
||||||
Assert.assertNotNull(fallbackConsumer.receive(100));
|
assertNotNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
fallbackSession.close();
|
fallbackSession.close();
|
||||||
senderSession.close();
|
senderSession.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ import javax.jms.MessageConsumer;
|
||||||
import javax.jms.MessageProducer;
|
import javax.jms.MessageProducer;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
|
|
||||||
public class ExclusiveConsumerTest extends TestCase {
|
public class ExclusiveConsumerTest extends TestCase {
|
||||||
|
@ -36,10 +36,12 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
@ -83,8 +85,8 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
||||||
// Verify exclusive consumer receives the message.
|
// Verify exclusive consumer receives the message.
|
||||||
Assert.assertNotNull(exclusiveConsumer.receive(100));
|
assertNotNull(exclusiveConsumer.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
fallbackSession.close();
|
fallbackSession.close();
|
||||||
|
@ -122,8 +124,8 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
||||||
// Verify exclusive consumer receives the message.
|
// Verify exclusive consumer receives the message.
|
||||||
Assert.assertNotNull(exclusiveConsumer.receive(100));
|
assertNotNull(exclusiveConsumer.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
fallbackSession.close();
|
fallbackSession.close();
|
||||||
|
@ -167,9 +169,9 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
||||||
// Verify exclusive consumer receives the message.
|
// Verify exclusive consumer receives the message.
|
||||||
Assert.assertNotNull(exclusiveConsumer1.receive(100));
|
assertNotNull(exclusiveConsumer1.receive(100));
|
||||||
Assert.assertNull(exclusiveConsumer2.receive(100));
|
assertNull(exclusiveConsumer2.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
// Close the exclusive consumer to verify the non-exclusive consumer
|
// Close the exclusive consumer to verify the non-exclusive consumer
|
||||||
// takes over
|
// takes over
|
||||||
|
@ -178,8 +180,8 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
|
|
||||||
Assert.assertNotNull(exclusiveConsumer2.receive(100));
|
assertNotNull(exclusiveConsumer2.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
fallbackSession.close();
|
fallbackSession.close();
|
||||||
|
@ -224,9 +226,9 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
||||||
// Verify exclusive consumer receives the message.
|
// Verify exclusive consumer receives the message.
|
||||||
Assert.assertNotNull(exclusiveConsumer1.receive(100));
|
assertNotNull(exclusiveConsumer1.receive(100));
|
||||||
Assert.assertNull(exclusiveConsumer2.receive(100));
|
assertNull(exclusiveConsumer2.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
// Close the exclusive consumer to verify the non-exclusive consumer
|
// Close the exclusive consumer to verify the non-exclusive consumer
|
||||||
// takes over
|
// takes over
|
||||||
|
@ -235,8 +237,8 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
|
|
||||||
Assert.assertNotNull(exclusiveConsumer2.receive(1000));
|
assertNotNull(exclusiveConsumer2.receive(1000));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
fallbackSession.close();
|
fallbackSession.close();
|
||||||
|
@ -276,8 +278,8 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
||||||
// Verify exclusive consumer receives the message.
|
// Verify exclusive consumer receives the message.
|
||||||
Assert.assertNotNull(exclusiveConsumer.receive(100));
|
assertNotNull(exclusiveConsumer.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
// Close the exclusive consumer to verify the non-exclusive consumer
|
// Close the exclusive consumer to verify the non-exclusive consumer
|
||||||
// takes over
|
// takes over
|
||||||
|
@ -285,7 +287,7 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
|
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
|
|
||||||
Assert.assertNotNull(fallbackConsumer.receive(100));
|
assertNotNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
fallbackSession.close();
|
fallbackSession.close();
|
||||||
|
@ -325,8 +327,8 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
||||||
// Verify exclusive consumer receives the message.
|
// Verify exclusive consumer receives the message.
|
||||||
Assert.assertNotNull(exclusiveConsumer.receive(100));
|
assertNotNull(exclusiveConsumer.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
// Close the exclusive consumer to verify the non-exclusive consumer
|
// Close the exclusive consumer to verify the non-exclusive consumer
|
||||||
// takes over
|
// takes over
|
||||||
|
@ -335,15 +337,15 @@ public class ExclusiveConsumerTest extends TestCase {
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
|
|
||||||
// Verify other non-exclusive consumer receices the message.
|
// Verify other non-exclusive consumer receices the message.
|
||||||
Assert.assertNotNull(fallbackConsumer.receive(100));
|
assertNotNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
// Create exclusive consumer to determine if it will start receiving
|
// Create exclusive consumer to determine if it will start receiving
|
||||||
// the messages.
|
// the messages.
|
||||||
exclusiveConsumer = exclusiveSession.createConsumer(exclusiveQueue);
|
exclusiveConsumer = exclusiveSession.createConsumer(exclusiveQueue);
|
||||||
|
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
Assert.assertNotNull(exclusiveConsumer.receive(100));
|
assertNotNull(exclusiveConsumer.receive(100));
|
||||||
Assert.assertNull(fallbackConsumer.receive(100));
|
assertNull(fallbackConsumer.receive(100));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
fallbackSession.close();
|
fallbackSession.close();
|
||||||
|
|
|
@ -36,7 +36,9 @@ import javax.jms.Session;
|
||||||
import javax.jms.TextMessage;
|
import javax.jms.TextMessage;
|
||||||
import javax.jms.Topic;
|
import javax.jms.Topic;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
|
||||||
import org.apache.activemq.broker.jmx.DestinationViewMBean;
|
import org.apache.activemq.broker.jmx.DestinationViewMBean;
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
|
@ -45,8 +47,8 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases used to test the JMS message consumer.
|
* Test cases used to test the JMS message consumer.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JMSConsumerTest extends JmsTestSupport {
|
public class JMSConsumerTest extends JmsTestSupport {
|
||||||
|
|
||||||
|
@ -85,6 +87,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
destination = createDestination(session, destinationType);
|
destination = createDestination(session, destinationType);
|
||||||
ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer)session.createConsumer(destination);
|
ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer)session.createConsumer(destination);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message m) {
|
public void onMessage(Message m) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
if (counter.get() == 1) {
|
if (counter.get() == 1) {
|
||||||
|
@ -121,35 +124,37 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
|
|
||||||
final AtomicInteger counter = new AtomicInteger(0);
|
final AtomicInteger counter = new AtomicInteger(0);
|
||||||
final CountDownLatch closeDone = new CountDownLatch(1);
|
final CountDownLatch closeDone = new CountDownLatch(1);
|
||||||
|
|
||||||
connection.start();
|
connection.start();
|
||||||
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
||||||
destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
|
destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
|
||||||
|
|
||||||
// preload the queue
|
// preload the queue
|
||||||
sendMessages(session, destination, 2000);
|
sendMessages(session, destination, 2000);
|
||||||
|
|
||||||
|
|
||||||
final ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer)session.createConsumer(destination);
|
final ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer)session.createConsumer(destination);
|
||||||
|
|
||||||
final Map<Thread, Throwable> exceptions =
|
final Map<Thread, Throwable> exceptions =
|
||||||
Collections.synchronizedMap(new HashMap<Thread, Throwable>());
|
Collections.synchronizedMap(new HashMap<Thread, Throwable>());
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
||||||
|
@Override
|
||||||
public void uncaughtException(Thread t, Throwable e) {
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
LOG.error("Uncaught exception:", e);
|
LOG.error("Uncaught exception:", e);
|
||||||
exceptions.put(t, e);
|
exceptions.put(t, e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final class AckAndClose implements Runnable {
|
final class AckAndClose implements Runnable {
|
||||||
private Message message;
|
private final Message message;
|
||||||
|
|
||||||
public AckAndClose(Message m) {
|
public AckAndClose(Message m) {
|
||||||
this.message = m;
|
this.message = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
int count = counter.incrementAndGet();
|
int count = counter.incrementAndGet();
|
||||||
if (count == 590) {
|
if (count == 590) {
|
||||||
// close in a separate thread is ok by jms
|
// close in a separate thread is ok by jms
|
||||||
|
@ -161,16 +166,17 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
// ack every 200
|
// ack every 200
|
||||||
message.acknowledge();
|
message.acknowledge();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Exception on close or ack:", e);
|
LOG.error("Exception on close or ack:", e);
|
||||||
exceptions.put(Thread.currentThread(), e);
|
exceptions.put(Thread.currentThread(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final ExecutorService executor = Executors.newCachedThreadPool();
|
final ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
public void onMessage(Message m) {
|
@Override
|
||||||
|
public void onMessage(Message m) {
|
||||||
// ack and close eventually in separate thread
|
// ack and close eventually in separate thread
|
||||||
executor.execute(new AckAndClose(m));
|
executor.execute(new AckAndClose(m));
|
||||||
}
|
}
|
||||||
|
@ -182,7 +188,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
|
assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void initCombosForTestMutiReceiveWithPrefetch1() {
|
public void initCombosForTestMutiReceiveWithPrefetch1() {
|
||||||
addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)});
|
addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)});
|
||||||
addCombinationValues("ackMode", new Object[] {Integer.valueOf(Session.AUTO_ACKNOWLEDGE), Integer.valueOf(Session.DUPS_OK_ACKNOWLEDGE),
|
addCombinationValues("ackMode", new Object[] {Integer.valueOf(Session.AUTO_ACKNOWLEDGE), Integer.valueOf(Session.DUPS_OK_ACKNOWLEDGE),
|
||||||
|
@ -310,6 +316,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
|
|
||||||
// See if the message get sent to the listener
|
// See if the message get sent to the listener
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message m) {
|
public void onMessage(Message m) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
if (counter.get() == 4) {
|
if (counter.get() == 4) {
|
||||||
|
@ -339,6 +346,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
destination = createDestination(session, destinationType);
|
destination = createDestination(session, destinationType);
|
||||||
MessageConsumer consumer = session.createConsumer(destination, new MessageListener() {
|
MessageConsumer consumer = session.createConsumer(destination, new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message m) {
|
public void onMessage(Message m) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
if (counter.get() == 4) {
|
if (counter.get() == 4) {
|
||||||
|
@ -346,6 +354,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
assertNotNull(consumer);
|
||||||
|
|
||||||
// Send the messages
|
// Send the messages
|
||||||
sendMessages(session, destination, 4);
|
sendMessages(session, destination, 4);
|
||||||
|
@ -357,14 +366,14 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
assertEquals(4, counter.get());
|
assertEquals(4, counter.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initCombosForTestMessageListenerOnMessageCloseUnackedWithPrefetch1StayInQueue() {
|
public void initCombosForTestMessageListenerOnMessageCloseUnackedWithPrefetch1StayInQueue() {
|
||||||
addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)});
|
addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)});
|
||||||
addCombinationValues("ackMode", new Object[] {Integer.valueOf(Session.CLIENT_ACKNOWLEDGE)});
|
addCombinationValues("ackMode", new Object[] {Integer.valueOf(Session.CLIENT_ACKNOWLEDGE)});
|
||||||
addCombinationValues("destinationType", new Object[] {Byte.valueOf(ActiveMQDestination.QUEUE_TYPE)});
|
addCombinationValues("destinationType", new Object[] {Byte.valueOf(ActiveMQDestination.QUEUE_TYPE)});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMessageListenerOnMessageCloseUnackedWithPrefetch1StayInQueue() throws Exception {
|
public void testMessageListenerOnMessageCloseUnackedWithPrefetch1StayInQueue() throws Exception {
|
||||||
|
|
||||||
final AtomicInteger counter = new AtomicInteger(0);
|
final AtomicInteger counter = new AtomicInteger(0);
|
||||||
final CountDownLatch sendDone = new CountDownLatch(1);
|
final CountDownLatch sendDone = new CountDownLatch(1);
|
||||||
final CountDownLatch got2Done = new CountDownLatch(1);
|
final CountDownLatch got2Done = new CountDownLatch(1);
|
||||||
|
@ -383,6 +392,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
destination = createDestination(session, destinationType);
|
destination = createDestination(session, destinationType);
|
||||||
MessageConsumer consumer = session.createConsumer(destination);
|
MessageConsumer consumer = session.createConsumer(destination);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message m) {
|
public void onMessage(Message m) {
|
||||||
try {
|
try {
|
||||||
TextMessage tm = (TextMessage)m;
|
TextMessage tm = (TextMessage)m;
|
||||||
|
@ -420,6 +430,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
session = connection.createSession(false, ackMode);
|
session = connection.createSession(false, ackMode);
|
||||||
consumer = session.createConsumer(destination);
|
consumer = session.createConsumer(destination);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message m) {
|
public void onMessage(Message m) {
|
||||||
try {
|
try {
|
||||||
TextMessage tm = (TextMessage)m;
|
TextMessage tm = (TextMessage)m;
|
||||||
|
@ -440,7 +451,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
|
|
||||||
// assert msg 2 was redelivered as close() from onMessages() will only ack in auto_ack and dups_ok mode
|
// assert msg 2 was redelivered as close() from onMessages() will only ack in auto_ack and dups_ok mode
|
||||||
assertEquals(5, counter.get());
|
assertEquals(5, counter.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initCombosForTestMessageListenerAutoAckOnCloseWithPrefetch1() {
|
public void initCombosForTestMessageListenerAutoAckOnCloseWithPrefetch1() {
|
||||||
|
@ -450,7 +461,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMessageListenerAutoAckOnCloseWithPrefetch1() throws Exception {
|
public void testMessageListenerAutoAckOnCloseWithPrefetch1() throws Exception {
|
||||||
|
|
||||||
final AtomicInteger counter = new AtomicInteger(0);
|
final AtomicInteger counter = new AtomicInteger(0);
|
||||||
final CountDownLatch sendDone = new CountDownLatch(1);
|
final CountDownLatch sendDone = new CountDownLatch(1);
|
||||||
final CountDownLatch got2Done = new CountDownLatch(1);
|
final CountDownLatch got2Done = new CountDownLatch(1);
|
||||||
|
@ -469,6 +480,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
destination = createDestination(session, destinationType);
|
destination = createDestination(session, destinationType);
|
||||||
MessageConsumer consumer = session.createConsumer(destination);
|
MessageConsumer consumer = session.createConsumer(destination);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message m) {
|
public void onMessage(Message m) {
|
||||||
try {
|
try {
|
||||||
TextMessage tm = (TextMessage)m;
|
TextMessage tm = (TextMessage)m;
|
||||||
|
@ -506,6 +518,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
session = connection.createSession(false, ackMode);
|
session = connection.createSession(false, ackMode);
|
||||||
consumer = session.createConsumer(destination);
|
consumer = session.createConsumer(destination);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message m) {
|
public void onMessage(Message m) {
|
||||||
try {
|
try {
|
||||||
TextMessage tm = (TextMessage)m;
|
TextMessage tm = (TextMessage)m;
|
||||||
|
@ -547,6 +560,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
destination = createDestination(session, destinationType);
|
destination = createDestination(session, destinationType);
|
||||||
MessageConsumer consumer = session.createConsumer(destination);
|
MessageConsumer consumer = session.createConsumer(destination);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message m) {
|
public void onMessage(Message m) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
if (counter.get() == 4) {
|
if (counter.get() == 4) {
|
||||||
|
@ -582,6 +596,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
destination = createDestination(session, destinationType);
|
destination = createDestination(session, destinationType);
|
||||||
MessageConsumer consumer = session.createConsumer(destination);
|
MessageConsumer consumer = session.createConsumer(destination);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message m) {
|
public void onMessage(Message m) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
if (counter.get() == 4) {
|
if (counter.get() == 4) {
|
||||||
|
@ -756,7 +771,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
assertNull(consumer.receiveNoWait());
|
assertNull(consumer.receiveNoWait());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testDupsOkConsumer() throws Exception {
|
public void testDupsOkConsumer() throws Exception {
|
||||||
|
|
||||||
// Receive a message with the JMS API
|
// Receive a message with the JMS API
|
||||||
|
@ -774,10 +789,10 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
assertNotNull(m);
|
assertNotNull(m);
|
||||||
}
|
}
|
||||||
assertNull(consumer.receive(1000));
|
assertNull(consumer.receive(1000));
|
||||||
|
|
||||||
// Close out the consumer.. no other messages should be left on the queue.
|
// Close out the consumer.. no other messages should be left on the queue.
|
||||||
consumer.close();
|
consumer.close();
|
||||||
|
|
||||||
consumer = session.createConsumer(destination);
|
consumer = session.createConsumer(destination);
|
||||||
assertNull(consumer.receive(1000));
|
assertNull(consumer.receive(1000));
|
||||||
}
|
}
|
||||||
|
@ -787,55 +802,55 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
connection.start();
|
connection.start();
|
||||||
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
|
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
|
||||||
destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
|
destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
|
||||||
|
|
||||||
sendMessages(connection, destination, 2);
|
sendMessages(connection, destination, 2);
|
||||||
|
|
||||||
MessageConsumer consumer = session.createConsumer(destination);
|
MessageConsumer consumer = session.createConsumer(destination);
|
||||||
assertNotNull(consumer.receive(1000));
|
assertNotNull(consumer.receive(1000));
|
||||||
assertNotNull(consumer.receive(1000));
|
assertNotNull(consumer.receive(1000));
|
||||||
|
|
||||||
// install another consumer while message dispatch is unacked/uncommitted
|
// install another consumer while message dispatch is unacked/uncommitted
|
||||||
Session redispatchSession = connection.createSession(true, Session.SESSION_TRANSACTED);
|
Session redispatchSession = connection.createSession(true, Session.SESSION_TRANSACTED);
|
||||||
MessageConsumer redispatchConsumer = redispatchSession.createConsumer(destination);
|
MessageConsumer redispatchConsumer = redispatchSession.createConsumer(destination);
|
||||||
|
|
||||||
// no commit so will auto rollback and get re-dispatched to redisptachConsumer
|
// no commit so will auto rollback and get re-dispatched to redisptachConsumer
|
||||||
session.close();
|
session.close();
|
||||||
|
|
||||||
Message msg = redispatchConsumer.receive(1000);
|
Message msg = redispatchConsumer.receive(1000);
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
assertTrue("redelivered flag set", msg.getJMSRedelivered());
|
assertTrue("redelivered flag set", msg.getJMSRedelivered());
|
||||||
assertEquals(2, msg.getLongProperty("JMSXDeliveryCount"));
|
assertEquals(2, msg.getLongProperty("JMSXDeliveryCount"));
|
||||||
|
|
||||||
msg = redispatchConsumer.receive(1000);
|
msg = redispatchConsumer.receive(1000);
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
assertTrue(msg.getJMSRedelivered());
|
assertTrue(msg.getJMSRedelivered());
|
||||||
assertEquals(2, msg.getLongProperty("JMSXDeliveryCount"));
|
assertEquals(2, msg.getLongProperty("JMSXDeliveryCount"));
|
||||||
redispatchSession.commit();
|
redispatchSession.commit();
|
||||||
|
|
||||||
assertNull(redispatchConsumer.receive(500));
|
assertNull(redispatchConsumer.receive(500));
|
||||||
redispatchSession.close();
|
redispatchSession.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testRedispatchOfRolledbackTx() throws Exception {
|
public void testRedispatchOfRolledbackTx() throws Exception {
|
||||||
|
|
||||||
connection.start();
|
connection.start();
|
||||||
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
|
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
|
||||||
destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
|
destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
|
||||||
|
|
||||||
sendMessages(connection, destination, 2);
|
sendMessages(connection, destination, 2);
|
||||||
|
|
||||||
MessageConsumer consumer = session.createConsumer(destination);
|
MessageConsumer consumer = session.createConsumer(destination);
|
||||||
assertNotNull(consumer.receive(1000));
|
assertNotNull(consumer.receive(1000));
|
||||||
assertNotNull(consumer.receive(1000));
|
assertNotNull(consumer.receive(1000));
|
||||||
|
|
||||||
// install another consumer while message dispatch is unacked/uncommitted
|
// install another consumer while message dispatch is unacked/uncommitted
|
||||||
Session redispatchSession = connection.createSession(true, Session.SESSION_TRANSACTED);
|
Session redispatchSession = connection.createSession(true, Session.SESSION_TRANSACTED);
|
||||||
MessageConsumer redispatchConsumer = redispatchSession.createConsumer(destination);
|
MessageConsumer redispatchConsumer = redispatchSession.createConsumer(destination);
|
||||||
|
|
||||||
session.rollback();
|
session.rollback();
|
||||||
session.close();
|
session.close();
|
||||||
|
|
||||||
Message msg = redispatchConsumer.receive(1000);
|
Message msg = redispatchConsumer.receive(1000);
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
assertTrue(msg.getJMSRedelivered());
|
assertTrue(msg.getJMSRedelivered());
|
||||||
|
@ -845,31 +860,31 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
assertTrue(msg.getJMSRedelivered());
|
assertTrue(msg.getJMSRedelivered());
|
||||||
assertEquals(2, msg.getLongProperty("JMSXDeliveryCount"));
|
assertEquals(2, msg.getLongProperty("JMSXDeliveryCount"));
|
||||||
redispatchSession.commit();
|
redispatchSession.commit();
|
||||||
|
|
||||||
assertNull(redispatchConsumer.receive(500));
|
assertNull(redispatchConsumer.receive(500));
|
||||||
redispatchSession.close();
|
redispatchSession.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void initCombosForTestAckOfExpired() {
|
public void initCombosForTestAckOfExpired() {
|
||||||
addCombinationValues("destinationType",
|
addCombinationValues("destinationType",
|
||||||
new Object[] {Byte.valueOf(ActiveMQDestination.QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TOPIC_TYPE)});
|
new Object[] {Byte.valueOf(ActiveMQDestination.QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TOPIC_TYPE)});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAckOfExpired() throws Exception {
|
public void testAckOfExpired() throws Exception {
|
||||||
|
|
||||||
ActiveMQConnectionFactory fact = new ActiveMQConnectionFactory("vm://localhost?jms.prefetchPolicy.all=4&jms.sendAcksAsync=false");
|
ActiveMQConnectionFactory fact = new ActiveMQConnectionFactory("vm://localhost?jms.prefetchPolicy.all=4&jms.sendAcksAsync=false");
|
||||||
connection = fact.createActiveMQConnection();
|
connection = fact.createActiveMQConnection();
|
||||||
|
|
||||||
connection.start();
|
connection.start();
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
destination = (ActiveMQDestination) (destinationType == ActiveMQDestination.QUEUE_TYPE ?
|
destination = (ActiveMQDestination) (destinationType == ActiveMQDestination.QUEUE_TYPE ?
|
||||||
session.createQueue("test") : session.createTopic("test"));
|
session.createQueue("test") : session.createTopic("test"));
|
||||||
|
|
||||||
MessageConsumer consumer = session.createConsumer(destination);
|
MessageConsumer consumer = session.createConsumer(destination);
|
||||||
connection.setStatsEnabled(true);
|
connection.setStatsEnabled(true);
|
||||||
|
|
||||||
Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
MessageProducer producer = sendSession.createProducer(destination);
|
MessageProducer producer = sendSession.createProducer(destination);
|
||||||
producer.setTimeToLive(1000);
|
producer.setTimeToLive(1000);
|
||||||
final int count = 4;
|
final int count = 4;
|
||||||
|
@ -877,37 +892,37 @@ public class JMSConsumerTest extends JmsTestSupport {
|
||||||
TextMessage message = sendSession.createTextMessage("" + i);
|
TextMessage message = sendSession.createTextMessage("" + i);
|
||||||
producer.send(message);
|
producer.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// let first bunch in queue expire
|
// let first bunch in queue expire
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
|
|
||||||
producer.setTimeToLive(0);
|
producer.setTimeToLive(0);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
TextMessage message = sendSession.createTextMessage("no expiry" + i);
|
TextMessage message = sendSession.createTextMessage("no expiry" + i);
|
||||||
producer.send(message);
|
producer.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
ActiveMQMessageConsumer amqConsumer = (ActiveMQMessageConsumer) consumer;
|
ActiveMQMessageConsumer amqConsumer = (ActiveMQMessageConsumer) consumer;
|
||||||
|
|
||||||
for(int i=0; i<count; i++) {
|
for(int i=0; i<count; i++) {
|
||||||
TextMessage msg = (TextMessage) amqConsumer.receive();
|
TextMessage msg = (TextMessage) amqConsumer.receive();
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
assertTrue("message has \"no expiry\" text: " + msg.getText(), msg.getText().contains("no expiry"));
|
assertTrue("message has \"no expiry\" text: " + msg.getText(), msg.getText().contains("no expiry"));
|
||||||
|
|
||||||
// force an ack when there are expired messages
|
// force an ack when there are expired messages
|
||||||
amqConsumer.acknowledge();
|
amqConsumer.acknowledge();
|
||||||
}
|
}
|
||||||
assertEquals("consumer has expiredMessages", count, amqConsumer.getConsumerStats().getExpiredMessageCount().getCount());
|
assertEquals("consumer has expiredMessages", count, amqConsumer.getConsumerStats().getExpiredMessageCount().getCount());
|
||||||
|
|
||||||
DestinationViewMBean view = createView(destination);
|
DestinationViewMBean view = createView(destination);
|
||||||
|
|
||||||
assertEquals("Wrong inFlightCount: " + view.getInFlightCount(), 0, view.getInFlightCount());
|
assertEquals("Wrong inFlightCount: " + view.getInFlightCount(), 0, view.getInFlightCount());
|
||||||
assertEquals("Wrong dispatch count: " + view.getDispatchCount(), 8, view.getDispatchCount());
|
assertEquals("Wrong dispatch count: " + view.getDispatchCount(), 8, view.getDispatchCount());
|
||||||
assertEquals("Wrong dequeue count: " + view.getDequeueCount(), 8, view.getDequeueCount());
|
assertEquals("Wrong dequeue count: " + view.getDequeueCount(), 8, view.getDequeueCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DestinationViewMBean createView(ActiveMQDestination destination) throws Exception {
|
protected DestinationViewMBean createView(ActiveMQDestination destination) throws Exception {
|
||||||
|
|
||||||
String domain = "org.apache.activemq";
|
String domain = "org.apache.activemq";
|
||||||
ObjectName name;
|
ObjectName name;
|
||||||
if (destination.isQueue()) {
|
if (destination.isQueue()) {
|
||||||
|
|
|
@ -438,7 +438,7 @@ public class JMSMessageTest extends JmsTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Enumeration getPropertyNames() throws JMSException {
|
public Enumeration<?> getPropertyNames() throws JMSException {
|
||||||
return new Vector<String>(props.keySet()).elements();
|
return new Vector<String>(props.keySet()).elements();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,9 @@ import javax.jms.MessageProducer;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
|
||||||
import org.apache.activemq.broker.BrokerFactory;
|
import org.apache.activemq.broker.BrokerFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.TransportConnector;
|
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -50,8 +50,8 @@ import org.slf4j.LoggerFactory;
|
||||||
* same destination. Make sure you run with jvm option -server (makes a big
|
* same destination. Make sure you run with jvm option -server (makes a big
|
||||||
* difference). The tests simulate storing 1000 1k jms messages to see the rate
|
* difference). The tests simulate storing 1000 1k jms messages to see the rate
|
||||||
* of processing msg/sec.
|
* of processing msg/sec.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JmsBenchmark extends JmsTestSupport {
|
public class JmsBenchmark extends JmsTestSupport {
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(JmsBenchmark.class);
|
private static final transient Logger LOG = LoggerFactory.getLogger(JmsBenchmark.class);
|
||||||
|
@ -76,12 +76,14 @@ public class JmsBenchmark extends JmsTestSupport {
|
||||||
addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST")});
|
addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST")});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createBroker() throws Exception {
|
protected BrokerService createBroker() throws Exception {
|
||||||
return BrokerFactory.createBroker(new URI("broker://(tcp://localhost:0)?persistent=false"));
|
return BrokerFactory.createBroker(new URI("broker://(tcp://localhost:0)?persistent=false"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected ConnectionFactory createConnectionFactory() throws URISyntaxException, IOException {
|
protected ConnectionFactory createConnectionFactory() throws URISyntaxException, IOException {
|
||||||
return new ActiveMQConnectionFactory(((TransportConnector)broker.getTransportConnectors().get(0)).getServer().getConnectURI());
|
return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getServer().getConnectURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,7 +98,8 @@ public class JmsBenchmark extends JmsTestSupport {
|
||||||
final AtomicInteger producedMessages = new AtomicInteger(0);
|
final AtomicInteger producedMessages = new AtomicInteger(0);
|
||||||
final AtomicInteger receivedMessages = new AtomicInteger(0);
|
final AtomicInteger receivedMessages = new AtomicInteger(0);
|
||||||
|
|
||||||
final Callable producer = new Callable() {
|
final Callable<Object> producer = new Callable<Object>() {
|
||||||
|
@Override
|
||||||
public Object call() throws JMSException, InterruptedException {
|
public Object call() throws JMSException, InterruptedException {
|
||||||
Connection connection = factory.createConnection();
|
Connection connection = factory.createConnection();
|
||||||
connections.add(connection);
|
connections.add(connection);
|
||||||
|
@ -119,7 +122,8 @@ public class JmsBenchmark extends JmsTestSupport {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final Callable consumer = new Callable() {
|
final Callable<Object> consumer = new Callable<Object>() {
|
||||||
|
@Override
|
||||||
public Object call() throws JMSException, InterruptedException {
|
public Object call() throws JMSException, InterruptedException {
|
||||||
Connection connection = factory.createConnection();
|
Connection connection = factory.createConnection();
|
||||||
connections.add(connection);
|
connections.add(connection);
|
||||||
|
@ -127,6 +131,7 @@ public class JmsBenchmark extends JmsTestSupport {
|
||||||
MessageConsumer consumer = session.createConsumer(destination);
|
MessageConsumer consumer = session.createConsumer(destination);
|
||||||
|
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message msg) {
|
public void onMessage(Message msg) {
|
||||||
receivedMessages.incrementAndGet();
|
receivedMessages.incrementAndGet();
|
||||||
}
|
}
|
||||||
|
@ -145,6 +150,7 @@ public class JmsBenchmark extends JmsTestSupport {
|
||||||
final Throwable workerError[] = new Throwable[1];
|
final Throwable workerError[] = new Throwable[1];
|
||||||
for (int i = 0; i < PRODUCER_COUNT; i++) {
|
for (int i = 0; i < PRODUCER_COUNT; i++) {
|
||||||
new Thread("Producer:" + i) {
|
new Thread("Producer:" + i) {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
producer.call();
|
producer.call();
|
||||||
|
@ -158,6 +164,7 @@ public class JmsBenchmark extends JmsTestSupport {
|
||||||
|
|
||||||
for (int i = 0; i < CONSUMER_COUNT; i++) {
|
for (int i = 0; i < CONSUMER_COUNT; i++) {
|
||||||
new Thread("Consumer:" + i) {
|
new Thread("Consumer:" + i) {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
consumer.call();
|
consumer.call();
|
||||||
|
@ -198,7 +205,5 @@ public class JmsBenchmark extends JmsTestSupport {
|
||||||
if (workerError[0] != null) {
|
if (workerError[0] != null) {
|
||||||
throw workerError[0];
|
throw workerError[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,10 @@ package org.apache.activemq;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.SynchronousQueue;
|
import java.util.concurrent.SynchronousQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.jms.Connection;
|
import javax.jms.Connection;
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
import javax.jms.Message;
|
import javax.jms.Message;
|
||||||
|
@ -35,7 +32,7 @@ import javax.jms.TextMessage;
|
||||||
import javax.jms.Topic;
|
import javax.jms.Topic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JmsConnectionStartStopTest extends TestSupport {
|
public class JmsConnectionStartStopTest extends TestSupport {
|
||||||
|
|
||||||
|
@ -48,6 +45,7 @@ public class JmsConnectionStartStopTest extends TestSupport {
|
||||||
/**
|
/**
|
||||||
* @see junit.framework.TestCase#setUp()
|
* @see junit.framework.TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
|
||||||
LOG.info(getClass().getClassLoader().getResource("log4j.properties"));
|
LOG.info(getClass().getClassLoader().getResource("log4j.properties"));
|
||||||
|
@ -61,6 +59,7 @@ public class JmsConnectionStartStopTest extends TestSupport {
|
||||||
/**
|
/**
|
||||||
* @see junit.framework.TestCase#tearDown()
|
* @see junit.framework.TestCase#tearDown()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
stoppedConnection.close();
|
stoppedConnection.close();
|
||||||
startedConnection.close();
|
startedConnection.close();
|
||||||
|
@ -69,7 +68,7 @@ public class JmsConnectionStartStopTest extends TestSupport {
|
||||||
/**
|
/**
|
||||||
* Tests if the consumer receives the messages that were sent before the
|
* Tests if the consumer receives the messages that were sent before the
|
||||||
* connection was started.
|
* connection was started.
|
||||||
*
|
*
|
||||||
* @throws JMSException
|
* @throws JMSException
|
||||||
*/
|
*/
|
||||||
public void testStoppedConsumerHoldsMessagesTillStarted() throws JMSException {
|
public void testStoppedConsumerHoldsMessagesTillStarted() throws JMSException {
|
||||||
|
@ -104,7 +103,7 @@ public class JmsConnectionStartStopTest extends TestSupport {
|
||||||
/**
|
/**
|
||||||
* Tests if the consumer is able to receive messages eveb when the
|
* Tests if the consumer is able to receive messages eveb when the
|
||||||
* connecction restarts multiple times.
|
* connecction restarts multiple times.
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void testMultipleConnectionStops() throws Exception {
|
public void testMultipleConnectionStops() throws Exception {
|
||||||
|
@ -123,6 +122,7 @@ public class JmsConnectionStartStopTest extends TestSupport {
|
||||||
final Vector<Throwable> exceptions = new Vector<Throwable>();
|
final Vector<Throwable> exceptions = new Vector<Throwable>();
|
||||||
final Random rand = new Random();
|
final Random rand = new Random();
|
||||||
Runnable createSessionTask = new Runnable() {
|
Runnable createSessionTask = new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
TimeUnit.MILLISECONDS.sleep(rand.nextInt(10));
|
TimeUnit.MILLISECONDS.sleep(rand.nextInt(10));
|
||||||
|
@ -134,6 +134,7 @@ public class JmsConnectionStartStopTest extends TestSupport {
|
||||||
};
|
};
|
||||||
|
|
||||||
Runnable startStopTask = new Runnable() {
|
Runnable startStopTask = new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
TimeUnit.MILLISECONDS.sleep(rand.nextInt(10));
|
TimeUnit.MILLISECONDS.sleep(rand.nextInt(10));
|
||||||
|
|
|
@ -19,18 +19,19 @@ package org.apache.activemq;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.jms.Message;
|
import javax.jms.Message;
|
||||||
import javax.jms.MessageConsumer;
|
import javax.jms.MessageConsumer;
|
||||||
import javax.jms.MessageProducer;
|
import javax.jms.MessageProducer;
|
||||||
import javax.jms.Queue;
|
|
||||||
import javax.jms.QueueBrowser;
|
import javax.jms.QueueBrowser;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
import javax.jms.Connection;
|
|
||||||
import javax.jms.TextMessage;
|
import javax.jms.TextMessage;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
import javax.management.openmbean.CompositeData;
|
import javax.management.openmbean.CompositeData;
|
||||||
import javax.management.openmbean.TabularData;
|
import javax.management.openmbean.TabularData;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.jmx.QueueViewMBean;
|
import org.apache.activemq.broker.jmx.QueueViewMBean;
|
||||||
import org.apache.activemq.broker.region.BaseDestination;
|
import org.apache.activemq.broker.region.BaseDestination;
|
||||||
|
@ -39,7 +40,7 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JmsQueueBrowserTest extends JmsTestSupport {
|
public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
|
private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
|
||||||
|
@ -80,16 +81,16 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
consumer.close();
|
consumer.close();
|
||||||
//Thread.sleep(200);
|
//Thread.sleep(200);
|
||||||
|
|
||||||
QueueBrowser browser = session.createBrowser((Queue) destination);
|
QueueBrowser browser = session.createBrowser(destination);
|
||||||
Enumeration enumeration = browser.getEnumeration();
|
Enumeration<?> enumeration = browser.getEnumeration();
|
||||||
|
|
||||||
// browse the second
|
// browse the second
|
||||||
assertTrue("should have received the second message", enumeration.hasMoreElements());
|
assertTrue("should have received the second message", enumeration.hasMoreElements());
|
||||||
assertEquals(outbound[1], (Message) enumeration.nextElement());
|
assertEquals(outbound[1], enumeration.nextElement());
|
||||||
|
|
||||||
// browse the third.
|
// browse the third.
|
||||||
assertTrue("Should have received the third message", enumeration.hasMoreElements());
|
assertTrue("Should have received the third message", enumeration.hasMoreElements());
|
||||||
assertEquals(outbound[2], (Message) enumeration.nextElement());
|
assertEquals(outbound[2], enumeration.nextElement());
|
||||||
|
|
||||||
// There should be no more.
|
// There should be no more.
|
||||||
boolean tooMany = false;
|
boolean tooMany = false;
|
||||||
|
@ -135,8 +136,8 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
producer.send(outbound[i]);
|
producer.send(outbound[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueBrowser browser = session.createBrowser((Queue) destination);
|
QueueBrowser browser = session.createBrowser(destination);
|
||||||
Enumeration enumeration = browser.getEnumeration();
|
Enumeration<?> enumeration = browser.getEnumeration();
|
||||||
|
|
||||||
for (int i=0; i<outbound.length; i++) {
|
for (int i=0; i<outbound.length; i++) {
|
||||||
assertTrue("should have a", enumeration.hasMoreElements());
|
assertTrue("should have a", enumeration.hasMoreElements());
|
||||||
|
@ -149,7 +150,7 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify second batch is visible to browse
|
// verify second batch is visible to browse
|
||||||
browser = session.createBrowser((Queue) destination);
|
browser = session.createBrowser(destination);
|
||||||
enumeration = browser.getEnumeration();
|
enumeration = browser.getEnumeration();
|
||||||
for (int j=0; j<2;j++) {
|
for (int j=0; j<2;j++) {
|
||||||
for (int i=0; i<outbound.length; i++) {
|
for (int i=0; i<outbound.length; i++) {
|
||||||
|
@ -272,7 +273,7 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
public void testBrowseReceive() throws Exception {
|
public void testBrowseReceive() throws Exception {
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
ActiveMQQueue destination = new ActiveMQQueue("TEST");
|
ActiveMQQueue destination = new ActiveMQQueue("TEST");
|
||||||
|
|
||||||
connection.start();
|
connection.start();
|
||||||
|
|
||||||
// create consumer
|
// create consumer
|
||||||
|
@ -285,18 +286,18 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
session.createTextMessage("Second Message"),
|
session.createTextMessage("Second Message"),
|
||||||
session.createTextMessage("Third Message")};
|
session.createTextMessage("Third Message")};
|
||||||
|
|
||||||
|
|
||||||
MessageProducer producer = session.createProducer(destination);
|
MessageProducer producer = session.createProducer(destination);
|
||||||
producer.send(outbound[0]);
|
producer.send(outbound[0]);
|
||||||
|
|
||||||
// create browser first
|
// create browser first
|
||||||
QueueBrowser browser = session.createBrowser((Queue) destination);
|
QueueBrowser browser = session.createBrowser(destination);
|
||||||
Enumeration enumeration = browser.getEnumeration();
|
Enumeration<?> enumeration = browser.getEnumeration();
|
||||||
|
|
||||||
// browse the first message
|
// browse the first message
|
||||||
assertTrue("should have received the first message", enumeration.hasMoreElements());
|
assertTrue("should have received the first message", enumeration.hasMoreElements());
|
||||||
assertEquals(outbound[0], (Message) enumeration.nextElement());
|
assertEquals(outbound[0], enumeration.nextElement());
|
||||||
|
|
||||||
// Receive the first message.
|
// Receive the first message.
|
||||||
assertEquals(outbound[0], consumer.receive(1000));
|
assertEquals(outbound[0], consumer.receive(1000));
|
||||||
consumer.close();
|
consumer.close();
|
||||||
|
@ -317,7 +318,7 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueBrowser browser = session.createBrowser(destination);
|
QueueBrowser browser = session.createBrowser(destination);
|
||||||
Enumeration enumeration = browser.getEnumeration();
|
Enumeration<?> enumeration = browser.getEnumeration();
|
||||||
|
|
||||||
assertTrue(enumeration.hasMoreElements());
|
assertTrue(enumeration.hasMoreElements());
|
||||||
|
|
||||||
|
@ -334,14 +335,14 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
producer.close();
|
producer.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testQueueBrowserWith2Consumers() throws Exception {
|
public void testQueueBrowserWith2Consumers() throws Exception {
|
||||||
final int numMessages = 1000;
|
final int numMessages = 1000;
|
||||||
connection.setAlwaysSyncSend(false);
|
connection.setAlwaysSyncSend(false);
|
||||||
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
||||||
ActiveMQQueue destination = new ActiveMQQueue("TEST");
|
ActiveMQQueue destination = new ActiveMQQueue("TEST");
|
||||||
ActiveMQQueue destinationPrefetch10 = new ActiveMQQueue("TEST?jms.prefetchSize=10");
|
ActiveMQQueue destinationPrefetch10 = new ActiveMQQueue("TEST?jms.prefetchSize=10");
|
||||||
ActiveMQQueue destinationPrefetch1 = new ActiveMQQueue("TEST?jms.prefetchsize=1");
|
ActiveMQQueue destinationPrefetch1 = new ActiveMQQueue("TEST?jms.prefetchsize=1");
|
||||||
connection.start();
|
connection.start();
|
||||||
|
|
||||||
ActiveMQConnection connection2 = (ActiveMQConnection)factory.createConnection(userName, password);
|
ActiveMQConnection connection2 = (ActiveMQConnection)factory.createConnection(userName, password);
|
||||||
|
@ -355,15 +356,16 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
// lets consume any outstanding messages from previous test runs
|
// lets consume any outstanding messages from previous test runs
|
||||||
while (consumer.receive(1000) != null) {
|
while (consumer.receive(1000) != null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i<numMessages; i++) {
|
for (int i=0; i<numMessages; i++) {
|
||||||
TextMessage message = session.createTextMessage("Message: " + i);
|
TextMessage message = session.createTextMessage("Message: " + i);
|
||||||
producer.send(message);
|
producer.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueBrowser browser = session2.createBrowser(destinationPrefetch1);
|
QueueBrowser browser = session2.createBrowser(destinationPrefetch1);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Enumeration<Message> browserView = browser.getEnumeration();
|
Enumeration<Message> browserView = browser.getEnumeration();
|
||||||
|
|
||||||
List<Message> messages = new ArrayList<Message>();
|
List<Message> messages = new ArrayList<Message>();
|
||||||
for (int i = 0; i < numMessages; i++) {
|
for (int i = 0; i < numMessages; i++) {
|
||||||
Message m1 = consumer.receive(5000);
|
Message m1 = consumer.receive(5000);
|
||||||
|
@ -378,7 +380,7 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
assertNotNull("m2 is null for index: " + i, m2);
|
assertNotNull("m2 is null for index: " + i, m2);
|
||||||
assertEquals(m1.getJMSMessageID(), m2.getJMSMessageID());
|
assertEquals(m1.getJMSMessageID(), m2.getJMSMessageID());
|
||||||
}
|
}
|
||||||
|
|
||||||
// currently browse max page size is ignored for a queue browser consumer
|
// currently browse max page size is ignored for a queue browser consumer
|
||||||
// only guarantee is a page size - but a snapshot of pagedinpending is
|
// only guarantee is a page size - but a snapshot of pagedinpending is
|
||||||
// used so it is most likely more
|
// used so it is most likely more
|
||||||
|
@ -412,19 +414,16 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
|
|
||||||
|
|
||||||
// create browser first
|
// create browser first
|
||||||
QueueBrowser browser = session.createBrowser((Queue) destination);
|
QueueBrowser browser = session.createBrowser(destination);
|
||||||
Enumeration enumeration = browser.getEnumeration();
|
Enumeration<?> enumeration = browser.getEnumeration();
|
||||||
|
|
||||||
|
|
||||||
// browse some messages
|
// browse some messages
|
||||||
assertEquals(outbound[0], (Message) enumeration.nextElement());
|
assertEquals(outbound[0], enumeration.nextElement());
|
||||||
assertEquals(outbound[1], (Message) enumeration.nextElement());
|
assertEquals(outbound[1], enumeration.nextElement());
|
||||||
//assertEquals(outbound[2], (Message) enumeration.nextElement());
|
//assertEquals(outbound[2], (Message) enumeration.nextElement());
|
||||||
|
|
||||||
|
|
||||||
browser.close();
|
browser.close();
|
||||||
|
|
||||||
|
|
||||||
// Receive the first message.
|
// Receive the first message.
|
||||||
TextMessage msg = (TextMessage)consumer.receive(1000);
|
TextMessage msg = (TextMessage)consumer.receive(1000);
|
||||||
assertEquals("Expected " + outbound[0].getText() + " but received " + msg.getText(), outbound[0], msg);
|
assertEquals("Expected " + outbound[0].getText() + " but received " + msg.getText(), outbound[0], msg);
|
||||||
|
@ -435,9 +434,9 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
|
|
||||||
consumer.close();
|
consumer.close();
|
||||||
producer.close();
|
producer.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createBroker() throws Exception {
|
protected BrokerService createBroker() throws Exception {
|
||||||
BrokerService brokerService = super.createBroker();
|
BrokerService brokerService = super.createBroker();
|
||||||
PolicyMap policyMap = new PolicyMap();
|
PolicyMap policyMap = new PolicyMap();
|
||||||
|
@ -447,5 +446,4 @@ public class JmsQueueBrowserTest extends JmsTestSupport {
|
||||||
brokerService.setDestinationPolicy(policyMap);
|
brokerService.setDestinationPolicy(policyMap);
|
||||||
return brokerService;
|
return brokerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,19 +17,18 @@
|
||||||
package org.apache.activemq;
|
package org.apache.activemq;
|
||||||
|
|
||||||
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
|
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JmsQueueSendReceiveTwoConnectionsTest extends JmsTopicSendReceiveWithTwoConnectionsTest {
|
public class JmsQueueSendReceiveTwoConnectionsTest extends JmsTopicSendReceiveWithTwoConnectionsTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the test with a queue and using two connections.
|
* Set up the test with a queue and using two connections.
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#setUp()
|
* @see junit.framework.TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
topic = false;
|
topic = false;
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
|
@ -40,6 +40,7 @@ import javax.jms.TemporaryQueue;
|
||||||
import javax.jms.TextMessage;
|
import javax.jms.TextMessage;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.transport.TransportListener;
|
import org.apache.activemq.transport.TransportListener;
|
||||||
import org.apache.activemq.transport.vm.VMTransport;
|
import org.apache.activemq.transport.vm.VMTransport;
|
||||||
import org.apache.activemq.util.Wait;
|
import org.apache.activemq.util.Wait;
|
||||||
|
@ -56,6 +57,7 @@ public class JmsTempDestinationTest extends TestCase {
|
||||||
private ActiveMQConnectionFactory factory;
|
private ActiveMQConnectionFactory factory;
|
||||||
protected List<Connection> connections = Collections.synchronizedList(new ArrayList<Connection>());
|
protected List<Connection> connections = Collections.synchronizedList(new ArrayList<Connection>());
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
factory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
|
factory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
|
||||||
factory.setAlwaysSyncSend(true);
|
factory.setAlwaysSyncSend(true);
|
||||||
|
@ -66,9 +68,10 @@ public class JmsTempDestinationTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* @see junit.framework.TestCase#tearDown()
|
* @see junit.framework.TestCase#tearDown()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
for (Iterator iter = connections.iterator(); iter.hasNext();) {
|
for (Iterator<Connection> iter = connections.iterator(); iter.hasNext();) {
|
||||||
Connection conn = (Connection)iter.next();
|
Connection conn = iter.next();
|
||||||
try {
|
try {
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -79,7 +82,7 @@ public class JmsTempDestinationTest extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure Temp destination can only be consumed by local connection
|
* Make sure Temp destination can only be consumed by local connection
|
||||||
*
|
*
|
||||||
* @throws JMSException
|
* @throws JMSException
|
||||||
*/
|
*/
|
||||||
public void testTempDestOnlyConsumedByLocalConn() throws JMSException {
|
public void testTempDestOnlyConsumedByLocalConn() throws JMSException {
|
||||||
|
@ -120,7 +123,7 @@ public class JmsTempDestinationTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Make sure that a temp queue does not drop message if there is an active
|
* Make sure that a temp queue does not drop message if there is an active
|
||||||
* consumers.
|
* consumers.
|
||||||
*
|
*
|
||||||
* @throws JMSException
|
* @throws JMSException
|
||||||
*/
|
*/
|
||||||
public void testTempQueueHoldsMessagesWithConsumers() throws JMSException {
|
public void testTempQueueHoldsMessagesWithConsumers() throws JMSException {
|
||||||
|
@ -143,7 +146,7 @@ public class JmsTempDestinationTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Make sure that a temp queue does not drop message if there are no active
|
* Make sure that a temp queue does not drop message if there are no active
|
||||||
* consumers.
|
* consumers.
|
||||||
*
|
*
|
||||||
* @throws JMSException
|
* @throws JMSException
|
||||||
*/
|
*/
|
||||||
public void testTempQueueHoldsMessagesWithoutConsumers() throws JMSException {
|
public void testTempQueueHoldsMessagesWithoutConsumers() throws JMSException {
|
||||||
|
@ -166,14 +169,14 @@ public class JmsTempDestinationTest extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test temp queue works under load
|
* Test temp queue works under load
|
||||||
*
|
*
|
||||||
* @throws JMSException
|
* @throws JMSException
|
||||||
*/
|
*/
|
||||||
public void testTmpQueueWorksUnderLoad() throws JMSException {
|
public void testTmpQueueWorksUnderLoad() throws JMSException {
|
||||||
int count = 500;
|
int count = 500;
|
||||||
int dataSize = 1024;
|
int dataSize = 1024;
|
||||||
|
|
||||||
ArrayList list = new ArrayList(count);
|
ArrayList<BytesMessage> list = new ArrayList<BytesMessage>(count);
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
Queue queue = session.createTemporaryQueue();
|
Queue queue = session.createTemporaryQueue();
|
||||||
MessageProducer producer = session.createProducer(queue);
|
MessageProducer producer = session.createProducer(queue);
|
||||||
|
@ -201,13 +204,13 @@ public class JmsTempDestinationTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Make sure you cannot publish to a temp destination that does not exist
|
* Make sure you cannot publish to a temp destination that does not exist
|
||||||
* anymore.
|
* anymore.
|
||||||
*
|
*
|
||||||
* @throws JMSException
|
* @throws JMSException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
* @throws URISyntaxException
|
* @throws URISyntaxException
|
||||||
*/
|
*/
|
||||||
public void testPublishFailsForClosedConnection() throws Exception {
|
public void testPublishFailsForClosedConnection() throws Exception {
|
||||||
|
|
||||||
Connection tempConnection = factory.createConnection();
|
Connection tempConnection = factory.createConnection();
|
||||||
connections.add(tempConnection);
|
connections.add(tempConnection);
|
||||||
Session tempSession = tempConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session tempSession = tempConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
@ -249,7 +252,7 @@ public class JmsTempDestinationTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Make sure you cannot publish to a temp destination that does not exist
|
* Make sure you cannot publish to a temp destination that does not exist
|
||||||
* anymore.
|
* anymore.
|
||||||
*
|
*
|
||||||
* @throws JMSException
|
* @throws JMSException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
|
@ -295,7 +298,7 @@ public class JmsTempDestinationTest extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test you can't delete a Destination with Active Subscribers
|
* Test you can't delete a Destination with Active Subscribers
|
||||||
*
|
*
|
||||||
* @throws JMSException
|
* @throws JMSException
|
||||||
*/
|
*/
|
||||||
public void testDeleteDestinationWithSubscribersFails() throws JMSException {
|
public void testDeleteDestinationWithSubscribersFails() throws JMSException {
|
||||||
|
|
|
@ -42,8 +42,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import javax.jms.Destination;
|
import javax.jms.Destination;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -60,9 +60,9 @@ public final class LargeStreamletTest extends TestCase {
|
||||||
protected Exception writerException;
|
protected Exception writerException;
|
||||||
protected Exception readerException;
|
protected Exception readerException;
|
||||||
|
|
||||||
private AtomicInteger totalRead = new AtomicInteger();
|
private final AtomicInteger totalRead = new AtomicInteger();
|
||||||
private AtomicInteger totalWritten = new AtomicInteger();
|
private final AtomicInteger totalWritten = new AtomicInteger();
|
||||||
private AtomicBoolean stopThreads = new AtomicBoolean(false);
|
private final AtomicBoolean stopThreads = new AtomicBoolean(false);
|
||||||
|
|
||||||
public void testStreamlets() throws Exception {
|
public void testStreamlets() throws Exception {
|
||||||
final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(BROKER_URL);
|
final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(BROKER_URL);
|
||||||
|
@ -75,6 +75,7 @@ public final class LargeStreamletTest extends TestCase {
|
||||||
final Destination destination = session.createQueue("wibble");
|
final Destination destination = session.createQueue("wibble");
|
||||||
final Thread readerThread = new Thread(new Runnable() {
|
final Thread readerThread = new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
totalRead.set(0);
|
totalRead.set(0);
|
||||||
try {
|
try {
|
||||||
|
@ -100,6 +101,7 @@ public final class LargeStreamletTest extends TestCase {
|
||||||
final Thread writerThread = new Thread(new Runnable() {
|
final Thread writerThread = new Thread(new Runnable() {
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
totalWritten.set(0);
|
totalWritten.set(0);
|
||||||
int count = MESSAGE_COUNT;
|
int count = MESSAGE_COUNT;
|
||||||
|
@ -147,7 +149,7 @@ public final class LargeStreamletTest extends TestCase {
|
||||||
assertTrue("Should not have received a reader exception", readerException == null);
|
assertTrue("Should not have received a reader exception", readerException == null);
|
||||||
assertTrue("Should not have received a writer exception", writerException == null);
|
assertTrue("Should not have received a writer exception", writerException == null);
|
||||||
|
|
||||||
Assert.assertEquals("Not all messages accounted for", totalWritten.get(), totalRead.get());
|
assertEquals("Not all messages accounted for", totalWritten.get(), totalRead.get());
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
session.close();
|
session.close();
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq;
|
package org.apache.activemq;
|
||||||
|
|
||||||
import static junit.framework.Assert.fail;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -41,7 +41,6 @@ import javax.jms.Topic;
|
||||||
|
|
||||||
import org.apache.activemq.advisory.AdvisorySupport;
|
import org.apache.activemq.advisory.AdvisorySupport;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.TransportConnector;
|
|
||||||
import org.apache.activemq.broker.region.policy.ConstantPendingMessageLimitStrategy;
|
import org.apache.activemq.broker.region.policy.ConstantPendingMessageLimitStrategy;
|
||||||
import org.apache.activemq.broker.region.policy.FilePendingSubscriberMessageStoragePolicy;
|
import org.apache.activemq.broker.region.policy.FilePendingSubscriberMessageStoragePolicy;
|
||||||
import org.apache.activemq.broker.region.policy.OldestMessageEvictionStrategy;
|
import org.apache.activemq.broker.region.policy.OldestMessageEvictionStrategy;
|
||||||
|
@ -53,10 +52,10 @@ import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.apache.activemq.command.ActiveMQMessage;
|
import org.apache.activemq.command.ActiveMQMessage;
|
||||||
import org.apache.activemq.command.ActiveMQTopic;
|
import org.apache.activemq.command.ActiveMQTopic;
|
||||||
import org.apache.activemq.util.Wait;
|
import org.apache.activemq.util.Wait;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class MessageEvictionTest {
|
public class MessageEvictionTest {
|
||||||
static final Logger LOG = LoggerFactory.getLogger(MessageEvictionTest.class);
|
static final Logger LOG = LoggerFactory.getLogger(MessageEvictionTest.class);
|
||||||
|
@ -78,45 +77,47 @@ public class MessageEvictionTest {
|
||||||
session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
|
||||||
destination = session.createTopic(destinationName);
|
destination = session.createTopic(destinationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
connection.stop();
|
connection.stop();
|
||||||
broker.stop();
|
broker.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMessageEvictionMemoryUsageFileCursor() throws Exception {
|
public void testMessageEvictionMemoryUsageFileCursor() throws Exception {
|
||||||
setUp(new FilePendingSubscriberMessageStoragePolicy());
|
setUp(new FilePendingSubscriberMessageStoragePolicy());
|
||||||
doTestMessageEvictionMemoryUsage();
|
doTestMessageEvictionMemoryUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMessageEvictionMemoryUsageVmCursor() throws Exception {
|
public void testMessageEvictionMemoryUsageVmCursor() throws Exception {
|
||||||
setUp(new VMPendingSubscriberMessageStoragePolicy());
|
setUp(new VMPendingSubscriberMessageStoragePolicy());
|
||||||
doTestMessageEvictionMemoryUsage();
|
doTestMessageEvictionMemoryUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMessageEvictionDiscardedAdvisory() throws Exception {
|
public void testMessageEvictionDiscardedAdvisory() throws Exception {
|
||||||
setUp(new VMPendingSubscriberMessageStoragePolicy());
|
setUp(new VMPendingSubscriberMessageStoragePolicy());
|
||||||
|
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
final CountDownLatch consumerRegistered = new CountDownLatch(1);
|
final CountDownLatch consumerRegistered = new CountDownLatch(1);
|
||||||
final CountDownLatch gotAdvisory = new CountDownLatch(1);
|
final CountDownLatch gotAdvisory = new CountDownLatch(1);
|
||||||
final CountDownLatch advisoryIsGood = new CountDownLatch(1);
|
final CountDownLatch advisoryIsGood = new CountDownLatch(1);
|
||||||
|
|
||||||
executor.execute(new Runnable() {
|
executor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
ActiveMQTopic discardedAdvisoryDestination =
|
ActiveMQTopic discardedAdvisoryDestination =
|
||||||
AdvisorySupport.getMessageDiscardedAdvisoryTopic(destination);
|
AdvisorySupport.getMessageDiscardedAdvisoryTopic(destination);
|
||||||
// use separate session rather than asyncDispatch on consumer session
|
// use separate session rather than asyncDispatch on consumer session
|
||||||
// as we want consumer session to block
|
// as we want consumer session to block
|
||||||
Session advisorySession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session advisorySession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
final MessageConsumer consumer = advisorySession.createConsumer(discardedAdvisoryDestination);
|
final MessageConsumer consumer = advisorySession.createConsumer(discardedAdvisoryDestination);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
int advisoriesReceived = 0;
|
int advisoriesReceived = 0;
|
||||||
|
@Override
|
||||||
public void onMessage(Message message) {
|
public void onMessage(Message message) {
|
||||||
try {
|
try {
|
||||||
LOG.info("advisory:" + message);
|
LOG.info("advisory:" + message);
|
||||||
|
@ -131,7 +132,7 @@ public class MessageEvictionTest {
|
||||||
} finally {
|
} finally {
|
||||||
gotAdvisory.countDown();
|
gotAdvisory.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
consumerRegistered.countDown();
|
consumerRegistered.countDown();
|
||||||
gotAdvisory.await(120, TimeUnit.SECONDS);
|
gotAdvisory.await(120, TimeUnit.SECONDS);
|
||||||
|
@ -148,18 +149,20 @@ public class MessageEvictionTest {
|
||||||
assertTrue("got an advisory for discarded", gotAdvisory.await(0, TimeUnit.SECONDS));
|
assertTrue("got an advisory for discarded", gotAdvisory.await(0, TimeUnit.SECONDS));
|
||||||
assertTrue("advisory is good",advisoryIsGood.await(0, TimeUnit.SECONDS));
|
assertTrue("advisory is good",advisoryIsGood.await(0, TimeUnit.SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doTestMessageEvictionMemoryUsage() throws Exception {
|
public void doTestMessageEvictionMemoryUsage() throws Exception {
|
||||||
|
|
||||||
ExecutorService executor = Executors.newCachedThreadPool();
|
ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
final CountDownLatch doAck = new CountDownLatch(1);
|
final CountDownLatch doAck = new CountDownLatch(1);
|
||||||
final CountDownLatch ackDone = new CountDownLatch(1);
|
final CountDownLatch ackDone = new CountDownLatch(1);
|
||||||
final CountDownLatch consumerRegistered = new CountDownLatch(1);
|
final CountDownLatch consumerRegistered = new CountDownLatch(1);
|
||||||
executor.execute(new Runnable() {
|
executor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final MessageConsumer consumer = session.createConsumer(destination);
|
final MessageConsumer consumer = session.createConsumer(destination);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message message) {
|
public void onMessage(Message message) {
|
||||||
try {
|
try {
|
||||||
// very slow, only ack once
|
// very slow, only ack once
|
||||||
|
@ -168,13 +171,13 @@ public class MessageEvictionTest {
|
||||||
message.acknowledge();
|
message.acknowledge();
|
||||||
ackDone.countDown();
|
ackDone.countDown();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail(e.toString());
|
fail(e.toString());
|
||||||
} finally {
|
} finally {
|
||||||
consumerRegistered.countDown();
|
consumerRegistered.countDown();
|
||||||
ackDone.countDown();
|
ackDone.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
consumerRegistered.countDown();
|
consumerRegistered.countDown();
|
||||||
ackDone.await(60, TimeUnit.SECONDS);
|
ackDone.await(60, TimeUnit.SECONDS);
|
||||||
|
@ -185,12 +188,13 @@ public class MessageEvictionTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
assertTrue("we have a consumer", consumerRegistered.await(10, TimeUnit.SECONDS));
|
assertTrue("we have a consumer", consumerRegistered.await(10, TimeUnit.SECONDS));
|
||||||
|
|
||||||
final AtomicInteger sent = new AtomicInteger(0);
|
final AtomicInteger sent = new AtomicInteger(0);
|
||||||
final CountDownLatch sendDone = new CountDownLatch(1);
|
final CountDownLatch sendDone = new CountDownLatch(1);
|
||||||
executor.execute(new Runnable() {
|
executor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MessageProducer producer;
|
MessageProducer producer;
|
||||||
try {
|
try {
|
||||||
|
@ -209,17 +213,18 @@ public class MessageEvictionTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
assertTrue("messages sending done", sendDone.await(180, TimeUnit.SECONDS));
|
assertTrue("messages sending done", sendDone.await(180, TimeUnit.SECONDS));
|
||||||
assertEquals("all message were sent", numMessages, sent.get());
|
assertEquals("all message were sent", numMessages, sent.get());
|
||||||
|
|
||||||
doAck.countDown();
|
doAck.countDown();
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
executor.awaitTermination(30, TimeUnit.SECONDS);
|
executor.awaitTermination(30, TimeUnit.SECONDS);
|
||||||
|
|
||||||
assertTrue("usage goes to 0 once consumer goes away", Wait.waitFor(new Wait.Condition() {
|
assertTrue("usage goes to 0 once consumer goes away", Wait.waitFor(new Wait.Condition() {
|
||||||
|
@Override
|
||||||
public boolean isSatisified() throws Exception {
|
public boolean isSatisified() throws Exception {
|
||||||
return 0 == TestSupport.getDestination(broker,
|
return 0 == TestSupport.getDestination(broker,
|
||||||
ActiveMQDestination.transform(destination)).getMemoryUsage().getPercentUsage();
|
ActiveMQDestination.transform(destination)).getMemoryUsage().getPercentUsage();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -230,22 +235,22 @@ public class MessageEvictionTest {
|
||||||
brokerService.addConnector("tcp://localhost:0");
|
brokerService.addConnector("tcp://localhost:0");
|
||||||
brokerService.setUseJmx(false);
|
brokerService.setUseJmx(false);
|
||||||
brokerService.setDeleteAllMessagesOnStartup(true);
|
brokerService.setDeleteAllMessagesOnStartup(true);
|
||||||
|
|
||||||
// spooling to disk early so topic memory limit is not reached
|
// spooling to disk early so topic memory limit is not reached
|
||||||
brokerService.getSystemUsage().getMemoryUsage().setLimit(500*1024);
|
brokerService.getSystemUsage().getMemoryUsage().setLimit(500*1024);
|
||||||
|
|
||||||
final List<PolicyEntry> policyEntries = new ArrayList<PolicyEntry>();
|
final List<PolicyEntry> policyEntries = new ArrayList<PolicyEntry>();
|
||||||
final PolicyEntry entry = new PolicyEntry();
|
final PolicyEntry entry = new PolicyEntry();
|
||||||
entry.setTopic(">");
|
entry.setTopic(">");
|
||||||
|
|
||||||
entry.setAdvisoryForDiscardingMessages(true);
|
entry.setAdvisoryForDiscardingMessages(true);
|
||||||
|
|
||||||
// so consumer does not get over run while blocked limit the prefetch
|
// so consumer does not get over run while blocked limit the prefetch
|
||||||
entry.setTopicPrefetch(50);
|
entry.setTopicPrefetch(50);
|
||||||
|
|
||||||
|
|
||||||
entry.setPendingSubscriberPolicy(pendingSubscriberPolicy);
|
entry.setPendingSubscriberPolicy(pendingSubscriberPolicy);
|
||||||
|
|
||||||
// limit the number of outstanding messages, large enough to use the file store
|
// limit the number of outstanding messages, large enough to use the file store
|
||||||
// or small enough not to blow memory limit
|
// or small enough not to blow memory limit
|
||||||
int pendingMessageLimit = 50;
|
int pendingMessageLimit = 50;
|
||||||
|
@ -261,7 +266,7 @@ public class MessageEvictionTest {
|
||||||
// whether to check expiry before eviction, default limit 1000 is fine as no ttl set in this test
|
// whether to check expiry before eviction, default limit 1000 is fine as no ttl set in this test
|
||||||
//messageEvictionStrategy.setEvictExpiredMessagesHighWatermark(1000);
|
//messageEvictionStrategy.setEvictExpiredMessagesHighWatermark(1000);
|
||||||
entry.setMessageEvictionStrategy(messageEvictionStrategy);
|
entry.setMessageEvictionStrategy(messageEvictionStrategy);
|
||||||
|
|
||||||
// let evicted messaged disappear
|
// let evicted messaged disappear
|
||||||
entry.setDeadLetterStrategy(null);
|
entry.setDeadLetterStrategy(null);
|
||||||
policyEntries.add(entry);
|
policyEntries.add(entry);
|
||||||
|
@ -269,12 +274,12 @@ public class MessageEvictionTest {
|
||||||
final PolicyMap policyMap = new PolicyMap();
|
final PolicyMap policyMap = new PolicyMap();
|
||||||
policyMap.setPolicyEntries(policyEntries);
|
policyMap.setPolicyEntries(policyEntries);
|
||||||
brokerService.setDestinationPolicy(policyMap);
|
brokerService.setDestinationPolicy(policyMap);
|
||||||
|
|
||||||
return brokerService;
|
return brokerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionFactory createConnectionFactory() throws Exception {
|
ConnectionFactory createConnectionFactory() throws Exception {
|
||||||
String url = ((TransportConnector) broker.getTransportConnectors().get(0)).getServer().getConnectURI().toString();
|
String url = broker.getTransportConnectors().get(0).getServer().getConnectURI().toString();
|
||||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
|
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
|
||||||
factory.setWatchTopicAdvisories(false);
|
factory.setWatchTopicAdvisories(false);
|
||||||
return factory;
|
return factory;
|
||||||
|
|
|
@ -24,8 +24,8 @@ import javax.jms.MessageConsumer;
|
||||||
import javax.jms.MessageProducer;
|
import javax.jms.MessageProducer;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
|
|
||||||
public class QueueConsumerPriorityTest extends TestCase {
|
public class QueueConsumerPriorityTest extends TestCase {
|
||||||
|
@ -36,10 +36,12 @@ public class QueueConsumerPriorityTest extends TestCase {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
@ -64,6 +66,7 @@ public class QueueConsumerPriorityTest extends TestCase {
|
||||||
|
|
||||||
consumerLowPriority = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
consumerLowPriority = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
consumerHighPriority = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
consumerHighPriority = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
assertNotNull(consumerHighPriority);
|
||||||
senderSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
senderSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
String queueName = getClass().getName();
|
String queueName = getClass().getName();
|
||||||
ActiveMQQueue low = new ActiveMQQueue(queueName+"?consumer.priority=1");
|
ActiveMQQueue low = new ActiveMQQueue(queueName+"?consumer.priority=1");
|
||||||
|
@ -79,17 +82,13 @@ public class QueueConsumerPriorityTest extends TestCase {
|
||||||
Message msg = senderSession.createTextMessage("test");
|
Message msg = senderSession.createTextMessage("test");
|
||||||
for (int i =0; i< 10000;i++) {
|
for (int i =0; i< 10000;i++) {
|
||||||
producer.send(msg);
|
producer.send(msg);
|
||||||
Assert.assertNotNull("null on iteration: " + i, highConsumer.receive(500));
|
assertNotNull("null on iteration: " + i, highConsumer.receive(500));
|
||||||
}
|
}
|
||||||
Assert.assertNull(lowConsumer.receive(2000));
|
assertNull(lowConsumer.receive(2000));
|
||||||
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,25 +22,26 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.context.support.AbstractApplicationContext;
|
import org.springframework.context.support.AbstractApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A useful base class for spring based unit test cases
|
* A useful base class for spring based unit test cases
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class SpringTestSupport extends TestCase {
|
public abstract class SpringTestSupport extends TestCase {
|
||||||
|
|
||||||
protected AbstractApplicationContext context;
|
protected AbstractApplicationContext context;
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
context = createApplicationContext();
|
context = createApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract AbstractApplicationContext createApplicationContext();;
|
protected abstract AbstractApplicationContext createApplicationContext();;
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
context.destroy();
|
context.destroy();
|
||||||
|
@ -55,7 +56,7 @@ public abstract class SpringTestSupport extends TestCase {
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertSetEquals(String description, Object[] expected, Set actual) {
|
protected void assertSetEquals(String description, Object[] expected, Set<?> actual) {
|
||||||
Set<Object> expectedSet = new HashSet<Object>();
|
Set<Object> expectedSet = new HashSet<Object>();
|
||||||
expectedSet.addAll(Arrays.asList(expected));
|
expectedSet.addAll(Arrays.asList(expected));
|
||||||
assertEquals(description, expectedSet, actual);
|
assertEquals(description, expectedSet, actual);
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.activemq;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.jms.Connection;
|
import javax.jms.Connection;
|
||||||
|
@ -27,8 +26,6 @@ import javax.jms.JMSException;
|
||||||
import javax.jms.Message;
|
import javax.jms.Message;
|
||||||
import javax.jms.TextMessage;
|
import javax.jms.TextMessage;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.region.DestinationStatistics;
|
import org.apache.activemq.broker.region.DestinationStatistics;
|
||||||
import org.apache.activemq.broker.region.RegionBroker;
|
import org.apache.activemq.broker.region.RegionBroker;
|
||||||
|
@ -42,13 +39,11 @@ import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
|
||||||
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
|
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
|
||||||
import org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter;
|
import org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter;
|
||||||
import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
|
import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful base class for unit test cases
|
* Useful base class for unit test cases
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class TestSupport extends CombinationTestSupport {
|
public abstract class TestSupport extends CombinationTestSupport {
|
||||||
|
|
||||||
|
@ -146,7 +141,7 @@ public abstract class TestSupport extends CombinationTestSupport {
|
||||||
recursiveDelete(new File(System.getProperty("derby.system.home")));
|
recursiveDelete(new File(System.getProperty("derby.system.home")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DestinationStatistics getDestinationStatistics(BrokerService broker, ActiveMQDestination destination) {
|
public static DestinationStatistics getDestinationStatistics(BrokerService broker, ActiveMQDestination destination) {
|
||||||
DestinationStatistics result = null;
|
DestinationStatistics result = null;
|
||||||
org.apache.activemq.broker.region.Destination dest = getDestination(broker, destination);
|
org.apache.activemq.broker.region.Destination dest = getDestination(broker, destination);
|
||||||
|
@ -155,7 +150,7 @@ public abstract class TestSupport extends CombinationTestSupport {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static org.apache.activemq.broker.region.Destination getDestination(BrokerService target, ActiveMQDestination destination) {
|
public static org.apache.activemq.broker.region.Destination getDestination(BrokerService target, ActiveMQDestination destination) {
|
||||||
org.apache.activemq.broker.region.Destination result = null;
|
org.apache.activemq.broker.region.Destination result = null;
|
||||||
for (org.apache.activemq.broker.region.Destination dest : getDestinationMap(target, destination).values()) {
|
for (org.apache.activemq.broker.region.Destination dest : getDestinationMap(target, destination).values()) {
|
||||||
|
@ -184,7 +179,7 @@ public abstract class TestSupport extends CombinationTestSupport {
|
||||||
public PersistenceAdapter setDefaultPersistenceAdapter(BrokerService broker) throws IOException {
|
public PersistenceAdapter setDefaultPersistenceAdapter(BrokerService broker) throws IOException {
|
||||||
return setPersistenceAdapter(broker, defaultPersistenceAdapter);
|
return setPersistenceAdapter(broker, defaultPersistenceAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PersistenceAdapter setPersistenceAdapter(BrokerService broker, PersistenceAdapterChoice choice) throws IOException {
|
public PersistenceAdapter setPersistenceAdapter(BrokerService broker, PersistenceAdapterChoice choice) throws IOException {
|
||||||
PersistenceAdapter adapter = null;
|
PersistenceAdapter adapter = null;
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
|
@ -212,7 +207,7 @@ public abstract class TestSupport extends CombinationTestSupport {
|
||||||
* Test if base directory contains spaces
|
* Test if base directory contains spaces
|
||||||
*/
|
*/
|
||||||
protected void assertBaseDirectoryContainsSpaces() {
|
protected void assertBaseDirectoryContainsSpaces() {
|
||||||
assertFalse("Base directory cannot contain spaces.", new File(System.getProperty("basedir", ".")).getAbsoluteFile().toString().contains(" "));
|
assertFalse("Base directory cannot contain spaces.", new File(System.getProperty("basedir", ".")).getAbsoluteFile().toString().contains(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,13 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
import org.apache.activemq.command.ConsumerControl;
|
import org.apache.activemq.command.ConsumerControl;
|
||||||
import org.apache.activemq.command.ConsumerInfo;
|
|
||||||
import org.apache.activemq.command.ExceptionResponse;
|
import org.apache.activemq.command.ExceptionResponse;
|
||||||
import org.apache.activemq.spring.SpringConsumer;
|
import org.apache.activemq.spring.SpringConsumer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
}
|
}
|
||||||
// now lets receive it
|
// now lets receive it
|
||||||
MessageConsumer consumer = session.createConsumer(queue);
|
MessageConsumer consumer = session.createConsumer(queue);
|
||||||
|
|
||||||
session.createConsumer(queue);
|
session.createConsumer(queue);
|
||||||
TextMessage answer = (TextMessage)consumer.receive(5000);
|
TextMessage answer = (TextMessage)consumer.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg1");
|
assertEquals("Should have received a message!", answer.getText(), "Msg1");
|
||||||
|
@ -145,7 +144,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
answer = (TextMessage)consumer.receiveNoWait();
|
answer = (TextMessage)consumer.receiveNoWait();
|
||||||
assertNull("Should have not received a message!", answer);
|
assertNull("Should have not received a message!", answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTwoConsumers() throws Exception {
|
public void testTwoConsumers() throws Exception {
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
|
||||||
|
@ -164,7 +163,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
answer = (TextMessage)consumer2.receiveNoWait();
|
answer = (TextMessage)consumer2.receiveNoWait();
|
||||||
assertNull("Should have not received a message!", answer);
|
assertNull("Should have not received a message!", answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://issues.apache.org/activemq/browse/AMQ-2567
|
// https://issues.apache.org/activemq/browse/AMQ-2567
|
||||||
public void testManyMessageConsumer() throws Exception {
|
public void testManyMessageConsumer() throws Exception {
|
||||||
doTestManyMessageConsumer(true);
|
doTestManyMessageConsumer(true);
|
||||||
|
@ -173,7 +172,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
public void testManyMessageConsumerNoTransaction() throws Exception {
|
public void testManyMessageConsumerNoTransaction() throws Exception {
|
||||||
doTestManyMessageConsumer(false);
|
doTestManyMessageConsumer(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestManyMessageConsumer(boolean transacted) throws Exception {
|
private void doTestManyMessageConsumer(boolean transacted) throws Exception {
|
||||||
Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
|
||||||
|
@ -191,7 +190,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
}
|
}
|
||||||
// now lets receive it
|
// now lets receive it
|
||||||
MessageConsumer consumer = session.createConsumer(queue);
|
MessageConsumer consumer = session.createConsumer(queue);
|
||||||
|
|
||||||
MessageConsumer consumer2 = session.createConsumer(queue);
|
MessageConsumer consumer2 = session.createConsumer(queue);
|
||||||
TextMessage answer = (TextMessage)consumer.receive(5000);
|
TextMessage answer = (TextMessage)consumer.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg1");
|
assertEquals("Should have received a message!", answer.getText(), "Msg1");
|
||||||
|
@ -214,26 +213,26 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
if (transacted) {
|
if (transacted) {
|
||||||
session.commit();
|
session.commit();
|
||||||
}
|
}
|
||||||
// Now using other consumer
|
// Now using other consumer
|
||||||
// this call should return the next message (Msg5) still left on the queue
|
// this call should return the next message (Msg5) still left on the queue
|
||||||
answer = (TextMessage)consumer2.receive(5000);
|
answer = (TextMessage)consumer2.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg5");
|
assertEquals("Should have received a message!", answer.getText(), "Msg5");
|
||||||
if (transacted) {
|
if (transacted) {
|
||||||
session.commit();
|
session.commit();
|
||||||
}
|
}
|
||||||
// Now using other consumer
|
// Now using other consumer
|
||||||
// this call should return the next message (Msg5) still left on the queue
|
// this call should return the next message (Msg5) still left on the queue
|
||||||
answer = (TextMessage)consumer.receive(5000);
|
answer = (TextMessage)consumer.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg6");
|
assertEquals("Should have received a message!", answer.getText(), "Msg6");
|
||||||
// read one more message without commit
|
// read one more message without commit
|
||||||
// Now using other consumer
|
// Now using other consumer
|
||||||
// this call should return the next message (Msg5) still left on the queue
|
// this call should return the next message (Msg5) still left on the queue
|
||||||
answer = (TextMessage)consumer.receive(5000);
|
answer = (TextMessage)consumer.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg7");
|
assertEquals("Should have received a message!", answer.getText(), "Msg7");
|
||||||
if (transacted) {
|
if (transacted) {
|
||||||
session.commit();
|
session.commit();
|
||||||
}
|
}
|
||||||
// Now using other consumer
|
// Now using other consumer
|
||||||
// this call should return the next message (Msg5) still left on the queue
|
// this call should return the next message (Msg5) still left on the queue
|
||||||
answer = (TextMessage)consumer2.receive(5000);
|
answer = (TextMessage)consumer2.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg8");
|
assertEquals("Should have received a message!", answer.getText(), "Msg8");
|
||||||
|
@ -251,7 +250,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
public void testManyMessageConsumerWithSendNoTransaction() throws Exception {
|
public void testManyMessageConsumerWithSendNoTransaction() throws Exception {
|
||||||
doTestManyMessageConsumerWithSend(false);
|
doTestManyMessageConsumerWithSend(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestManyMessageConsumerWithSend(boolean transacted) throws Exception {
|
private void doTestManyMessageConsumerWithSend(boolean transacted) throws Exception {
|
||||||
Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
|
||||||
|
@ -269,7 +268,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
}
|
}
|
||||||
// now lets receive it
|
// now lets receive it
|
||||||
MessageConsumer consumer = session.createConsumer(queue);
|
MessageConsumer consumer = session.createConsumer(queue);
|
||||||
|
|
||||||
MessageConsumer consumer2 = session.createConsumer(queue);
|
MessageConsumer consumer2 = session.createConsumer(queue);
|
||||||
TextMessage answer = (TextMessage)consumer.receive(5000);
|
TextMessage answer = (TextMessage)consumer.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg1");
|
assertEquals("Should have received a message!", answer.getText(), "Msg1");
|
||||||
|
@ -297,23 +296,23 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
if (transacted) {
|
if (transacted) {
|
||||||
session.commit();
|
session.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
answer = (TextMessage)consumer.receive(5000);
|
answer = (TextMessage)consumer.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg6");
|
assertEquals("Should have received a message!", answer.getText(), "Msg6");
|
||||||
// read one more message without commit
|
// read one more message without commit
|
||||||
// and using other consumer
|
// and using other consumer
|
||||||
answer = (TextMessage)consumer2.receive(5000);
|
answer = (TextMessage)consumer2.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg7");
|
assertEquals("Should have received a message!", answer.getText(), "Msg7");
|
||||||
if (transacted) {
|
if (transacted) {
|
||||||
session.commit();
|
session.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
answer = (TextMessage)consumer2.receive(5000);
|
answer = (TextMessage)consumer2.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg8");
|
assertEquals("Should have received a message!", answer.getText(), "Msg8");
|
||||||
if (transacted) {
|
if (transacted) {
|
||||||
session.commit();
|
session.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
answer = (TextMessage)consumer.receive(5000);
|
answer = (TextMessage)consumer.receive(5000);
|
||||||
assertEquals("Should have received a message!", answer.getText(), "Msg9");
|
assertEquals("Should have received a message!", answer.getText(), "Msg9");
|
||||||
if (transacted) {
|
if (transacted) {
|
||||||
|
@ -372,6 +371,7 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
return brokerService;
|
return brokerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
bindAddress = "tcp://localhost:0";
|
bindAddress = "tcp://localhost:0";
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
@ -380,12 +380,14 @@ public class ZeroPrefetchConsumerTest extends EmbeddedBrokerTestSupport {
|
||||||
connection.start();
|
connection.start();
|
||||||
queue = createQueue();
|
queue = createQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void startBroker() throws Exception {
|
protected void startBroker() throws Exception {
|
||||||
super.startBroker();
|
super.startBroker();
|
||||||
bindAddress = broker.getTransportConnectors().get(0).getConnectUri().toString();
|
bindAddress = broker.getTransportConnectors().get(0).getConnectUri().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
connection.close();
|
connection.close();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
|
|
@ -16,7 +16,23 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.advisory;
|
package org.apache.activemq.advisory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.jms.BytesMessage;
|
||||||
|
import javax.jms.Connection;
|
||||||
|
import javax.jms.ConnectionFactory;
|
||||||
|
import javax.jms.Message;
|
||||||
|
import javax.jms.MessageConsumer;
|
||||||
|
import javax.jms.MessageListener;
|
||||||
|
import javax.jms.MessageProducer;
|
||||||
|
import javax.jms.Queue;
|
||||||
|
import javax.jms.Session;
|
||||||
|
import javax.jms.TemporaryQueue;
|
||||||
|
import javax.jms.Topic;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnection;
|
import org.apache.activemq.ActiveMQConnection;
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
@ -26,10 +42,6 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.apache.activemq.command.ActiveMQMessage;
|
import org.apache.activemq.command.ActiveMQMessage;
|
||||||
|
|
||||||
import javax.jms.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AdvisoryTempDestinationTests extends TestCase {
|
public class AdvisoryTempDestinationTests extends TestCase {
|
||||||
|
|
||||||
protected static final int MESSAGE_COUNT = 2000;
|
protected static final int MESSAGE_COUNT = 2000;
|
||||||
|
@ -44,6 +56,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
|
||||||
TemporaryQueue queue = s.createTemporaryQueue();
|
TemporaryQueue queue = s.createTemporaryQueue();
|
||||||
MessageConsumer consumer = s.createConsumer(queue);
|
MessageConsumer consumer = s.createConsumer(queue);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message message) {
|
public void onMessage(Message message) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -66,6 +79,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
|
||||||
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
TemporaryQueue queue = s.createTemporaryQueue();
|
TemporaryQueue queue = s.createTemporaryQueue();
|
||||||
MessageConsumer consumer = s.createConsumer(queue);
|
MessageConsumer consumer = s.createConsumer(queue);
|
||||||
|
assertNotNull(consumer);
|
||||||
|
|
||||||
Topic advisoryTopic = AdvisorySupport
|
Topic advisoryTopic = AdvisorySupport
|
||||||
.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
|
.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
|
||||||
|
@ -86,6 +100,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
|
||||||
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
TemporaryQueue queue = s.createTemporaryQueue();
|
TemporaryQueue queue = s.createTemporaryQueue();
|
||||||
MessageConsumer consumer = s.createConsumer(queue);
|
MessageConsumer consumer = s.createConsumer(queue);
|
||||||
|
assertNotNull(consumer);
|
||||||
|
|
||||||
Topic advisoryTopic = AdvisorySupport.getMessageDeliveredAdvisoryTopic((ActiveMQDestination) queue);
|
Topic advisoryTopic = AdvisorySupport.getMessageDeliveredAdvisoryTopic((ActiveMQDestination) queue);
|
||||||
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
||||||
|
@ -130,6 +145,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
|
||||||
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
Queue queue = s.createQueue(getClass().getName());
|
Queue queue = s.createQueue(getClass().getName());
|
||||||
MessageConsumer consumer = s.createConsumer(queue);
|
MessageConsumer consumer = s.createConsumer(queue);
|
||||||
|
assertNotNull(consumer);
|
||||||
|
|
||||||
Topic advisoryTopic = AdvisorySupport.getExpiredMessageTopic((ActiveMQDestination) queue);
|
Topic advisoryTopic = AdvisorySupport.getExpiredMessageTopic((ActiveMQDestination) queue);
|
||||||
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
||||||
|
@ -146,6 +162,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
if (broker == null) {
|
if (broker == null) {
|
||||||
broker = createBroker();
|
broker = createBroker();
|
||||||
|
@ -156,6 +173,7 @@ public class AdvisoryTempDestinationTests extends TestCase {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
connection.close();
|
connection.close();
|
||||||
|
|
|
@ -26,7 +26,9 @@ import javax.jms.MessageProducer;
|
||||||
import javax.jms.Queue;
|
import javax.jms.Queue;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
import javax.jms.Topic;
|
import javax.jms.Topic;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnection;
|
import org.apache.activemq.ActiveMQConnection;
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.ActiveMQPrefetchPolicy;
|
import org.apache.activemq.ActiveMQPrefetchPolicy;
|
||||||
|
@ -38,7 +40,7 @@ import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.apache.activemq.command.ActiveMQMessage;
|
import org.apache.activemq.command.ActiveMQMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AdvisoryTests extends TestCase {
|
public class AdvisoryTests extends TestCase {
|
||||||
protected static final int MESSAGE_COUNT = 2000;
|
protected static final int MESSAGE_COUNT = 2000;
|
||||||
|
@ -46,13 +48,14 @@ public class AdvisoryTests extends TestCase {
|
||||||
protected Connection connection;
|
protected Connection connection;
|
||||||
protected String bindAddress = ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL;
|
protected String bindAddress = ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL;
|
||||||
protected int topicCount;
|
protected int topicCount;
|
||||||
|
|
||||||
|
|
||||||
public void testNoSlowConsumerAdvisory() throws Exception {
|
public void testNoSlowConsumerAdvisory() throws Exception {
|
||||||
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
Queue queue = s.createQueue(getClass().getName());
|
Queue queue = s.createQueue(getClass().getName());
|
||||||
MessageConsumer consumer = s.createConsumer(queue);
|
MessageConsumer consumer = s.createConsumer(queue);
|
||||||
consumer.setMessageListener(new MessageListener() {
|
consumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message message) {
|
public void onMessage(Message message) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -70,12 +73,13 @@ public class AdvisoryTests extends TestCase {
|
||||||
Message msg = advisoryConsumer.receive(1000);
|
Message msg = advisoryConsumer.receive(1000);
|
||||||
assertNull(msg);
|
assertNull(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSlowConsumerAdvisory() throws Exception {
|
public void testSlowConsumerAdvisory() throws Exception {
|
||||||
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
Queue queue = s.createQueue(getClass().getName());
|
Queue queue = s.createQueue(getClass().getName());
|
||||||
MessageConsumer consumer = s.createConsumer(queue);
|
MessageConsumer consumer = s.createConsumer(queue);
|
||||||
|
assertNotNull(consumer);
|
||||||
|
|
||||||
Topic advisoryTopic = AdvisorySupport
|
Topic advisoryTopic = AdvisorySupport
|
||||||
.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
|
.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
|
||||||
s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
@ -90,56 +94,58 @@ public class AdvisoryTests extends TestCase {
|
||||||
Message msg = advisoryConsumer.receive(1000);
|
Message msg = advisoryConsumer.receive(1000);
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMessageDeliveryAdvisory() throws Exception {
|
public void testMessageDeliveryAdvisory() throws Exception {
|
||||||
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
Queue queue = s.createQueue(getClass().getName());
|
Queue queue = s.createQueue(getClass().getName());
|
||||||
MessageConsumer consumer = s.createConsumer(queue);
|
MessageConsumer consumer = s.createConsumer(queue);
|
||||||
|
assertNotNull(consumer);
|
||||||
|
|
||||||
Topic advisoryTopic = AdvisorySupport.getMessageDeliveredAdvisoryTopic((ActiveMQDestination) queue);
|
Topic advisoryTopic = AdvisorySupport.getMessageDeliveredAdvisoryTopic((ActiveMQDestination) queue);
|
||||||
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
||||||
//start throwing messages at the consumer
|
//start throwing messages at the consumer
|
||||||
MessageProducer producer = s.createProducer(queue);
|
MessageProducer producer = s.createProducer(queue);
|
||||||
|
|
||||||
BytesMessage m = s.createBytesMessage();
|
BytesMessage m = s.createBytesMessage();
|
||||||
m.writeBytes(new byte[1024]);
|
m.writeBytes(new byte[1024]);
|
||||||
producer.send(m);
|
producer.send(m);
|
||||||
|
|
||||||
Message msg = advisoryConsumer.receive(1000);
|
Message msg = advisoryConsumer.receive(1000);
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMessageConsumedAdvisory() throws Exception {
|
public void testMessageConsumedAdvisory() throws Exception {
|
||||||
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
Queue queue = s.createQueue(getClass().getName());
|
Queue queue = s.createQueue(getClass().getName());
|
||||||
MessageConsumer consumer = s.createConsumer(queue);
|
MessageConsumer consumer = s.createConsumer(queue);
|
||||||
|
|
||||||
Topic advisoryTopic = AdvisorySupport.getMessageConsumedAdvisoryTopic((ActiveMQDestination) queue);
|
Topic advisoryTopic = AdvisorySupport.getMessageConsumedAdvisoryTopic((ActiveMQDestination) queue);
|
||||||
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
||||||
//start throwing messages at the consumer
|
//start throwing messages at the consumer
|
||||||
MessageProducer producer = s.createProducer(queue);
|
MessageProducer producer = s.createProducer(queue);
|
||||||
|
|
||||||
BytesMessage m = s.createBytesMessage();
|
BytesMessage m = s.createBytesMessage();
|
||||||
m.writeBytes(new byte[1024]);
|
m.writeBytes(new byte[1024]);
|
||||||
producer.send(m);
|
producer.send(m);
|
||||||
String id = m.getJMSMessageID();
|
String id = m.getJMSMessageID();
|
||||||
Message msg = consumer.receive(1000);
|
Message msg = consumer.receive(1000);
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
|
|
||||||
msg = advisoryConsumer.receive(1000);
|
msg = advisoryConsumer.receive(1000);
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
|
|
||||||
ActiveMQMessage message = (ActiveMQMessage) msg;
|
ActiveMQMessage message = (ActiveMQMessage) msg;
|
||||||
ActiveMQMessage payload = (ActiveMQMessage) message.getDataStructure();
|
ActiveMQMessage payload = (ActiveMQMessage) message.getDataStructure();
|
||||||
String originalId = payload.getJMSMessageID();
|
String originalId = payload.getJMSMessageID();
|
||||||
assertEquals(originalId, id);
|
assertEquals(originalId, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMessageExpiredAdvisory() throws Exception {
|
public void testMessageExpiredAdvisory() throws Exception {
|
||||||
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
Queue queue = s.createQueue(getClass().getName());
|
Queue queue = s.createQueue(getClass().getName());
|
||||||
MessageConsumer consumer = s.createConsumer(queue);
|
MessageConsumer consumer = s.createConsumer(queue);
|
||||||
|
assertNotNull(consumer);
|
||||||
|
|
||||||
Topic advisoryTopic = AdvisorySupport.getExpiredMessageTopic((ActiveMQDestination) queue);
|
Topic advisoryTopic = AdvisorySupport.getExpiredMessageTopic((ActiveMQDestination) queue);
|
||||||
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
||||||
//start throwing messages at the consumer
|
//start throwing messages at the consumer
|
||||||
|
@ -150,16 +156,17 @@ public class AdvisoryTests extends TestCase {
|
||||||
m.writeBytes(new byte[1024]);
|
m.writeBytes(new byte[1024]);
|
||||||
producer.send(m);
|
producer.send(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
Message msg = advisoryConsumer.receive(2000);
|
Message msg = advisoryConsumer.receive(2000);
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void xtestMessageDiscardedAdvisory() throws Exception {
|
public void xtestMessageDiscardedAdvisory() throws Exception {
|
||||||
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
Topic topic = s.createTopic(getClass().getName());
|
Topic topic = s.createTopic(getClass().getName());
|
||||||
MessageConsumer consumer = s.createConsumer(topic);
|
MessageConsumer consumer = s.createConsumer(topic);
|
||||||
|
assertNotNull(consumer);
|
||||||
|
|
||||||
Topic advisoryTopic = AdvisorySupport.getMessageDiscardedAdvisoryTopic((ActiveMQDestination) topic);
|
Topic advisoryTopic = AdvisorySupport.getMessageDiscardedAdvisoryTopic((ActiveMQDestination) topic);
|
||||||
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
|
||||||
//start throwing messages at the consumer
|
//start throwing messages at the consumer
|
||||||
|
@ -169,12 +176,12 @@ public class AdvisoryTests extends TestCase {
|
||||||
BytesMessage m = s.createBytesMessage();
|
BytesMessage m = s.createBytesMessage();
|
||||||
producer.send(m);
|
producer.send(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
Message msg = advisoryConsumer.receive(1000);
|
Message msg = advisoryConsumer.receive(1000);
|
||||||
assertNotNull(msg);
|
assertNotNull(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
if (broker == null) {
|
if (broker == null) {
|
||||||
broker = createBroker();
|
broker = createBroker();
|
||||||
|
@ -185,6 +192,7 @@ public class AdvisoryTests extends TestCase {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
connection.close();
|
connection.close();
|
||||||
|
|
|
@ -30,8 +30,8 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements ProducerListener {
|
public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements ProducerListener {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ProducerListenerTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ProducerListenerTest.class);
|
||||||
|
@ -78,10 +78,12 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P
|
||||||
assertConsumerEvent(0, false);
|
assertConsumerEvent(0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onProducerEvent(ProducerEvent event) {
|
public void onProducerEvent(ProducerEvent event) {
|
||||||
eventQueue.add(event);
|
eventQueue.add(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
|
@ -91,6 +93,7 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P
|
||||||
producerEventSource.setProducerListener(this);
|
producerEventSource.setProducerListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
if (producerEventSource != null) {
|
if (producerEventSource != null) {
|
||||||
producerEventSource.stop();
|
producerEventSource.stop();
|
||||||
|
@ -119,6 +122,8 @@ public class ProducerListenerTest extends EmbeddedBrokerTestSupport implements P
|
||||||
|
|
||||||
Session answer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session answer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
MessageProducer producer = answer.createProducer(destination);
|
MessageProducer producer = answer.createProducer(destination);
|
||||||
|
assertNotNull(producer);
|
||||||
|
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,6 @@ import java.net.URL;
|
||||||
|
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
import org.apache.activemq.command.ActiveMQBlobMessage;
|
import org.apache.activemq.command.ActiveMQBlobMessage;
|
||||||
|
|
||||||
public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
|
public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
|
||||||
|
@ -34,7 +32,7 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
|
||||||
|
|
||||||
public void testDownload() throws Exception {
|
public void testDownload() throws Exception {
|
||||||
setConnection();
|
setConnection();
|
||||||
|
|
||||||
// create file
|
// create file
|
||||||
File uploadFile = new File(ftpHomeDirFile, "test.txt");
|
File uploadFile = new File(ftpHomeDirFile, "test.txt");
|
||||||
FileWriter wrt = new FileWriter(uploadFile);
|
FileWriter wrt = new FileWriter(uploadFile);
|
||||||
|
@ -46,7 +44,7 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
wrt.close();
|
wrt.close();
|
||||||
|
|
||||||
ActiveMQBlobMessage message = new ActiveMQBlobMessage();
|
ActiveMQBlobMessage message = new ActiveMQBlobMessage();
|
||||||
BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(new BlobTransferPolicy());
|
BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(new BlobTransferPolicy());
|
||||||
InputStream stream;
|
InputStream stream;
|
||||||
|
@ -59,16 +57,16 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
|
||||||
sb.append((char)i);
|
sb.append((char)i);
|
||||||
i = stream.read();
|
i = stream.read();
|
||||||
}
|
}
|
||||||
Assert.assertEquals("hello world", sb.toString().substring(0, "hello world".length()));
|
assertEquals("hello world", sb.toString().substring(0, "hello world".length()));
|
||||||
Assert.assertEquals(FILE_SIZE, sb.toString().substring("hello world".length()).length());
|
assertEquals(FILE_SIZE, sb.toString().substring("hello world".length()).length());
|
||||||
|
|
||||||
assertTrue(uploadFile.exists());
|
assertTrue(uploadFile.exists());
|
||||||
strategy.deleteFile(message);
|
strategy.deleteFile(message);
|
||||||
assertFalse(uploadFile.exists());
|
assertFalse(uploadFile.exists());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Assert.assertTrue(false);
|
assertTrue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,15 +77,15 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
|
||||||
message.setURL(new URL("ftp://" + userNamePass + "_wrong:" + userNamePass + "@localhost:" + ftpPort + "/ftptest/"));
|
message.setURL(new URL("ftp://" + userNamePass + "_wrong:" + userNamePass + "@localhost:" + ftpPort + "/ftptest/"));
|
||||||
strategy.getInputStream(message);
|
strategy.getInputStream(message);
|
||||||
} catch(JMSException e) {
|
} catch(JMSException e) {
|
||||||
Assert.assertEquals("Wrong Exception", "Cant Authentificate to FTP-Server", e.getMessage());
|
assertEquals("Wrong Exception", "Cant Authentificate to FTP-Server", e.getMessage());
|
||||||
return;
|
return;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
Assert.assertTrue("Wrong Exception "+ e, false);
|
assertTrue("Wrong Exception "+ e, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertTrue("Expect Exception", false);
|
assertTrue("Expect Exception", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWrongFTPPort() throws MalformedURLException {
|
public void testWrongFTPPort() throws MalformedURLException {
|
||||||
|
@ -97,15 +95,14 @@ public class FTPBlobDownloadStrategyTest extends FTPTestSupport {
|
||||||
message.setURL(new URL("ftp://" + userNamePass + ":" + userNamePass + "@localhost:" + 422 + "/ftptest/"));
|
message.setURL(new URL("ftp://" + userNamePass + ":" + userNamePass + "@localhost:" + 422 + "/ftptest/"));
|
||||||
strategy.getInputStream(message);
|
strategy.getInputStream(message);
|
||||||
} catch(JMSException e) {
|
} catch(JMSException e) {
|
||||||
Assert.assertEquals("Wrong Exception", "Problem connecting the FTP-server", e.getMessage());
|
assertEquals("Wrong Exception", "Problem connecting the FTP-server", e.getMessage());
|
||||||
return;
|
return;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Assert.assertTrue("Wrong Exception "+ e, false);
|
assertTrue("Wrong Exception "+ e, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertTrue("Expect Exception", false);
|
assertTrue("Expect Exception", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,10 @@ import javax.jms.MessageConsumer;
|
||||||
import javax.jms.MessageProducer;
|
import javax.jms.MessageProducer;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQSession;
|
import org.apache.activemq.ActiveMQSession;
|
||||||
import org.apache.activemq.BlobMessage;
|
import org.apache.activemq.BlobMessage;
|
||||||
import org.apache.activemq.command.ActiveMQBlobMessage;
|
import org.apache.activemq.command.ActiveMQBlobMessage;
|
||||||
|
|
||||||
|
|
||||||
public class FTPBlobTest extends FTPTestSupport {
|
public class FTPBlobTest extends FTPTestSupport {
|
||||||
|
|
||||||
public void testBlobFile() throws Exception {
|
public void testBlobFile() throws Exception {
|
||||||
|
@ -57,7 +54,7 @@ public class FTPBlobTest extends FTPTestSupport {
|
||||||
|
|
||||||
// check message send
|
// check message send
|
||||||
Message msg = consumer.receive(1000);
|
Message msg = consumer.receive(1000);
|
||||||
Assert.assertTrue(msg instanceof ActiveMQBlobMessage);
|
assertTrue(msg instanceof ActiveMQBlobMessage);
|
||||||
|
|
||||||
assertEquals("name is correct", "fileName", ((ActiveMQBlobMessage)msg).getName());
|
assertEquals("name is correct", "fileName", ((ActiveMQBlobMessage)msg).getName());
|
||||||
InputStream input = ((ActiveMQBlobMessage) msg).getInputStream();
|
InputStream input = ((ActiveMQBlobMessage) msg).getInputStream();
|
||||||
|
@ -68,8 +65,8 @@ public class FTPBlobTest extends FTPTestSupport {
|
||||||
i = input.read();
|
i = input.read();
|
||||||
}
|
}
|
||||||
input.close();
|
input.close();
|
||||||
File uploaded = new File(ftpHomeDirFile, msg.getJMSMessageID().toString().replace(":", "_"));
|
File uploaded = new File(ftpHomeDirFile, msg.getJMSMessageID().toString().replace(":", "_"));
|
||||||
Assert.assertEquals(content, b.toString());
|
assertEquals(content, b.toString());
|
||||||
assertTrue(uploaded.exists());
|
assertTrue(uploaded.exists());
|
||||||
((ActiveMQBlobMessage)msg).deleteFile();
|
((ActiveMQBlobMessage)msg).deleteFile();
|
||||||
assertFalse(uploaded.exists());
|
assertFalse(uploaded.exists());
|
||||||
|
|
|
@ -23,8 +23,6 @@ import java.io.FileWriter;
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnection;
|
import org.apache.activemq.ActiveMQConnection;
|
||||||
import org.apache.activemq.ActiveMQSession;
|
import org.apache.activemq.ActiveMQSession;
|
||||||
import org.apache.activemq.command.ActiveMQBlobMessage;
|
import org.apache.activemq.command.ActiveMQBlobMessage;
|
||||||
|
@ -35,22 +33,22 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport {
|
||||||
|
|
||||||
public void testFileUpload() throws Exception {
|
public void testFileUpload() throws Exception {
|
||||||
setConnection();
|
setConnection();
|
||||||
File file = File.createTempFile("amq-data-file-", ".dat");
|
File file = File.createTempFile("amq-data-file-", ".dat");
|
||||||
// lets write some data
|
// lets write some data
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
||||||
writer.append("hello world");
|
writer.append("hello world");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
((ActiveMQConnection)connection).setCopyMessageOnSend(false);
|
((ActiveMQConnection)connection).setCopyMessageOnSend(false);
|
||||||
|
|
||||||
ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file);
|
ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file);
|
||||||
message.setMessageId(new MessageId("testmessage"));
|
message.setMessageId(new MessageId("testmessage"));
|
||||||
message.onSend();
|
message.onSend();
|
||||||
Assert.assertEquals(ftpUrl + "testmessage", message.getURL().toString());
|
assertEquals(ftpUrl + "testmessage", message.getURL().toString());
|
||||||
File uploaded = new File(ftpHomeDirFile, "testmessage");
|
File uploaded = new File(ftpHomeDirFile, "testmessage");
|
||||||
assertTrue("File doesn't exists", uploaded.exists());
|
assertTrue("File doesn't exists", uploaded.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteDenied() throws Exception {
|
public void testWriteDenied() throws Exception {
|
||||||
userNamePass = "guest";
|
userNamePass = "guest";
|
||||||
|
@ -60,10 +58,10 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport {
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
||||||
writer.append("hello world");
|
writer.append("hello world");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
((ActiveMQConnection)connection).setCopyMessageOnSend(false);
|
((ActiveMQConnection)connection).setCopyMessageOnSend(false);
|
||||||
|
|
||||||
ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file);
|
ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file);
|
||||||
message.setMessageId(new MessageId("testmessage"));
|
message.setMessageId(new MessageId("testmessage"));
|
||||||
try {
|
try {
|
||||||
|
@ -74,5 +72,5 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport {
|
||||||
}
|
}
|
||||||
fail("Should have failed with permission denied exception!");
|
fail("Should have failed with permission denied exception!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,6 @@ import javax.jms.MessageConsumer;
|
||||||
import javax.jms.MessageProducer;
|
import javax.jms.MessageProducer;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQSession;
|
import org.apache.activemq.ActiveMQSession;
|
||||||
import org.apache.activemq.BlobMessage;
|
import org.apache.activemq.BlobMessage;
|
||||||
import org.apache.activemq.EmbeddedBrokerTestSupport;
|
import org.apache.activemq.EmbeddedBrokerTestSupport;
|
||||||
|
@ -40,23 +38,23 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class FilesystemBlobTest extends EmbeddedBrokerTestSupport {
|
public class FilesystemBlobTest extends EmbeddedBrokerTestSupport {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(FilesystemBlobTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(FilesystemBlobTest.class);
|
||||||
|
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private String tmpDir = System.getProperty("user.dir") + "/target/FilesystemBlobTest";
|
private final String tmpDir = System.getProperty("user.dir") + "/target/FilesystemBlobTest";
|
||||||
public void setUp() throws Exception {
|
@Override
|
||||||
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
// replace \ with / to let it work on windows too
|
// replace \ with / to let it work on windows too
|
||||||
String fileUrl = "file:///" +tmpDir.replaceAll("\\\\", "/");
|
String fileUrl = "file:///" +tmpDir.replaceAll("\\\\", "/");
|
||||||
LOG.info("Using file: " + fileUrl);
|
LOG.info("Using file: " + fileUrl);
|
||||||
bindAddress = "vm://localhost?jms.blobTransferPolicy.defaultUploadUrl=" + fileUrl;
|
bindAddress = "vm://localhost?jms.blobTransferPolicy.defaultUploadUrl=" + fileUrl;
|
||||||
|
|
||||||
connectionFactory = createConnectionFactory();
|
connectionFactory = createConnectionFactory();
|
||||||
|
|
||||||
connection = createConnection();
|
connection = createConnection();
|
||||||
connection.start();
|
connection.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testBlobFile() throws Exception {
|
public void testBlobFile() throws Exception {
|
||||||
// first create Message
|
// first create Message
|
||||||
File file = File.createTempFile("amq-data-file-", ".dat");
|
File file = File.createTempFile("amq-data-file-", ".dat");
|
||||||
|
@ -77,7 +75,7 @@ public class FilesystemBlobTest extends EmbeddedBrokerTestSupport {
|
||||||
|
|
||||||
// check message send
|
// check message send
|
||||||
Message msg = consumer.receive(1000);
|
Message msg = consumer.receive(1000);
|
||||||
Assert.assertTrue(msg instanceof ActiveMQBlobMessage);
|
assertTrue(msg instanceof ActiveMQBlobMessage);
|
||||||
|
|
||||||
InputStream input = ((ActiveMQBlobMessage) msg).getInputStream();
|
InputStream input = ((ActiveMQBlobMessage) msg).getInputStream();
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
|
@ -87,19 +85,20 @@ public class FilesystemBlobTest extends EmbeddedBrokerTestSupport {
|
||||||
i = input.read();
|
i = input.read();
|
||||||
}
|
}
|
||||||
input.close();
|
input.close();
|
||||||
File uploaded = new File(tmpDir, msg.getJMSMessageID().toString().replace(":", "_"));
|
File uploaded = new File(tmpDir, msg.getJMSMessageID().toString().replace(":", "_"));
|
||||||
Assert.assertEquals(content, b.toString());
|
assertEquals(content, b.toString());
|
||||||
assertTrue(uploaded.exists());
|
assertTrue(uploaded.exists());
|
||||||
((ActiveMQBlobMessage)msg).deleteFile();
|
((ActiveMQBlobMessage)msg).deleteFile();
|
||||||
assertFalse(uploaded.exists());
|
assertFalse(uploaded.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
connection.stop();
|
connection.stop();
|
||||||
}
|
}
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
|
||||||
IOHelper.deleteFile(new File(tmpDir));
|
IOHelper.deleteFile(new File(tmpDir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.broker.jmx;
|
package org.apache.activemq.broker.jmx;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnection;
|
import org.apache.activemq.ActiveMQConnection;
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
@ -28,9 +32,6 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class TransportConnectorMBeanTest {
|
public class TransportConnectorMBeanTest {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(TransportConnectorMBeanTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(TransportConnectorMBeanTest.class);
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ public class TransportConnectorMBeanTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String extractLocalPort(ActiveMQConnection connection) throws Exception {
|
private String extractLocalPort(ActiveMQConnection connection) throws Exception {
|
||||||
Socket socket = (Socket) connection.getTransport().narrow(Socket.class);
|
Socket socket = connection.getTransport().narrow(Socket.class);
|
||||||
return String.valueOf(socket.getLocalPort());
|
return String.valueOf(socket.getLocalPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,12 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IndividualDeadLetterTest extends DeadLetterTest {
|
public class IndividualDeadLetterTest extends DeadLetterTest {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(IndividualDeadLetterTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(IndividualDeadLetterTest.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createBroker() throws Exception {
|
protected BrokerService createBroker() throws Exception {
|
||||||
BrokerService broker = super.createBroker();
|
BrokerService broker = super.createBroker();
|
||||||
|
|
||||||
|
@ -56,11 +57,12 @@ public class IndividualDeadLetterTest extends DeadLetterTest {
|
||||||
return broker;
|
return broker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected Destination createDlqDestination() {
|
protected Destination createDlqDestination() {
|
||||||
String prefix = topic ? "ActiveMQ.DLQ.Topic." : "ActiveMQ.DLQ.Queue.";
|
String prefix = topic ? "ActiveMQ.DLQ.Topic." : "ActiveMQ.DLQ.Queue.";
|
||||||
return new ActiveMQQueue(prefix + getClass().getName() + "." + getName());
|
return new ActiveMQQueue(prefix + getClass().getName() + "." + getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDLQBrowsing() throws Exception {
|
public void testDLQBrowsing() throws Exception {
|
||||||
super.topic = false;
|
super.topic = false;
|
||||||
deliveryMode = DeliveryMode.PERSISTENT;
|
deliveryMode = DeliveryMode.PERSISTENT;
|
||||||
|
@ -97,9 +99,9 @@ public class IndividualDeadLetterTest extends DeadLetterTest {
|
||||||
assertNull("The message shouldn't be sent to another DLQ", testConsumer.receive(1000));
|
assertNull("The message shouldn't be sent to another DLQ", testConsumer.receive(1000));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void browseDlq() throws Exception {
|
protected void browseDlq() throws Exception {
|
||||||
Enumeration messages = dlqBrowser.getEnumeration();
|
Enumeration<?> messages = dlqBrowser.getEnumeration();
|
||||||
while (messages.hasMoreElements()) {
|
while (messages.hasMoreElements()) {
|
||||||
LOG.info("Browsing: " + messages.nextElement());
|
LOG.info("Browsing: " + messages.nextElement());
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,10 @@ package org.apache.activemq.broker.policy;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.RedeliveryPolicy;
|
import org.apache.activemq.RedeliveryPolicy;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class NoRetryDeadLetterTest extends DeadLetterTest {
|
public class NoRetryDeadLetterTest extends DeadLetterTest {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(NoRetryDeadLetterTest.class);
|
|
||||||
|
|
||||||
|
@Override
|
||||||
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
||||||
ActiveMQConnectionFactory connectionFactory = super.createConnectionFactory();
|
ActiveMQConnectionFactory connectionFactory = super.createConnectionFactory();
|
||||||
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
|
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
|
||||||
|
@ -31,5 +29,5 @@ public class NoRetryDeadLetterTest extends DeadLetterTest {
|
||||||
connectionFactory.setRedeliveryPolicy(redeliveryPolicy);
|
connectionFactory.setRedeliveryPolicy(redeliveryPolicy);
|
||||||
return connectionFactory;
|
return connectionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,21 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.broker.policy;
|
package org.apache.activemq.broker.policy;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import javax.jms.DeliveryMode;
|
|
||||||
import javax.jms.Destination;
|
import javax.jms.Destination;
|
||||||
import javax.jms.Message;
|
|
||||||
import javax.jms.MessageConsumer;
|
|
||||||
import javax.jms.Queue;
|
|
||||||
import org.apache.activemq.ActiveMQConnection;
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.region.policy.DeadLetterStrategy;
|
|
||||||
import org.apache.activemq.broker.region.policy.IndividualDeadLetterStrategy;
|
import org.apache.activemq.broker.region.policy.IndividualDeadLetterStrategy;
|
||||||
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
||||||
import org.apache.activemq.broker.region.policy.PolicyMap;
|
import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for durable subs, allow a dlq per subscriber such that poison messages are not duplicates
|
* for durable subs, allow a dlq per subscriber such that poison messages are not duplicates
|
||||||
|
@ -38,10 +30,10 @@ import org.slf4j.LoggerFactory;
|
||||||
* https://issues.apache.org/jira/browse/AMQ-3003
|
* https://issues.apache.org/jira/browse/AMQ-3003
|
||||||
*/
|
*/
|
||||||
public class PerDurableConsumerDeadLetterTest extends DeadLetterTest {
|
public class PerDurableConsumerDeadLetterTest extends DeadLetterTest {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(PerDurableConsumerDeadLetterTest.class);
|
|
||||||
|
|
||||||
private static final String CLIENT_ID = "george";
|
private static final String CLIENT_ID = "george";
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createBroker() throws Exception {
|
protected BrokerService createBroker() throws Exception {
|
||||||
BrokerService broker = super.createBroker();
|
BrokerService broker = super.createBroker();
|
||||||
|
|
||||||
|
@ -59,10 +51,12 @@ public class PerDurableConsumerDeadLetterTest extends DeadLetterTest {
|
||||||
return broker;
|
return broker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected String createClientId() {
|
protected String createClientId() {
|
||||||
return CLIENT_ID;
|
return CLIENT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected Destination createDlqDestination() {
|
protected Destination createDlqDestination() {
|
||||||
String prefix = topic ? "ActiveMQ.DLQ.Topic." : "ActiveMQ.DLQ.Queue.";
|
String prefix = topic ? "ActiveMQ.DLQ.Topic." : "ActiveMQ.DLQ.Queue.";
|
||||||
String destinationName = prefix + getClass().getName() + "." + getName();
|
String destinationName = prefix + getClass().getName() + "." + getName();
|
||||||
|
|
|
@ -16,23 +16,26 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.broker.policy;
|
package org.apache.activemq.broker.policy;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.ConnectionContext;
|
import org.apache.activemq.broker.ConnectionContext;
|
||||||
import org.apache.activemq.broker.region.Subscription;
|
import org.apache.activemq.broker.region.Subscription;
|
||||||
import org.apache.activemq.broker.region.TopicSubscription;
|
import org.apache.activemq.broker.region.TopicSubscription;
|
||||||
import org.apache.activemq.broker.region.policy.PriorityNetworkDispatchPolicy;
|
import org.apache.activemq.broker.region.policy.PriorityNetworkDispatchPolicy;
|
||||||
import org.apache.activemq.command.*;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
|
import org.apache.activemq.command.ActiveMQMessage;
|
||||||
|
import org.apache.activemq.command.ConsumerId;
|
||||||
|
import org.apache.activemq.command.ConsumerInfo;
|
||||||
|
import org.apache.activemq.command.MessageId;
|
||||||
import org.apache.activemq.usage.SystemUsage;
|
import org.apache.activemq.usage.SystemUsage;
|
||||||
import org.apache.derby.iapi.jdbc.BrokeredStatement;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class PriorityNetworkDispatchPolicyTest {
|
public class PriorityNetworkDispatchPolicyTest {
|
||||||
|
|
||||||
PriorityNetworkDispatchPolicy underTest = new PriorityNetworkDispatchPolicy();
|
PriorityNetworkDispatchPolicy underTest = new PriorityNetworkDispatchPolicy();
|
||||||
|
|
|
@ -18,6 +18,8 @@ package org.apache.activemq.broker.policy;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.jms.MessageConsumer;
|
||||||
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.QueueSubscriptionTest;
|
import org.apache.activemq.broker.QueueSubscriptionTest;
|
||||||
import org.apache.activemq.broker.region.policy.FixedCountSubscriptionRecoveryPolicy;
|
import org.apache.activemq.broker.region.policy.FixedCountSubscriptionRecoveryPolicy;
|
||||||
|
@ -28,6 +30,7 @@ import org.apache.activemq.util.MessageIdList;
|
||||||
|
|
||||||
public class SimpleDispatchPolicyTest extends QueueSubscriptionTest {
|
public class SimpleDispatchPolicyTest extends QueueSubscriptionTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createBroker() throws Exception {
|
protected BrokerService createBroker() throws Exception {
|
||||||
BrokerService broker = super.createBroker();
|
BrokerService broker = super.createBroker();
|
||||||
|
|
||||||
|
@ -42,24 +45,26 @@ public class SimpleDispatchPolicyTest extends QueueSubscriptionTest {
|
||||||
return broker;
|
return broker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception {
|
public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception {
|
||||||
super.testOneProducerTwoConsumersSmallMessagesLargePrefetch();
|
super.testOneProducerTwoConsumersSmallMessagesLargePrefetch();
|
||||||
|
|
||||||
// One consumer should have received all messages, and the rest none
|
// One consumer should have received all messages, and the rest none
|
||||||
// assertOneConsumerReceivedAllMessages(messageCount);
|
// assertOneConsumerReceivedAllMessages(messageCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception {
|
public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception {
|
||||||
super.testOneProducerTwoConsumersLargeMessagesLargePrefetch();
|
super.testOneProducerTwoConsumersLargeMessagesLargePrefetch();
|
||||||
|
|
||||||
// One consumer should have received all messages, and the rest none
|
// One consumer should have received all messages, and the rest none
|
||||||
// assertOneConsumerReceivedAllMessages(messageCount);
|
// assertOneConsumerReceivedAllMessages(messageCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertOneConsumerReceivedAllMessages(int messageCount) throws Exception {
|
public void assertOneConsumerReceivedAllMessages(int messageCount) throws Exception {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (Iterator i = consumers.keySet().iterator(); i.hasNext();) {
|
for (Iterator<MessageConsumer> i = consumers.keySet().iterator(); i.hasNext();) {
|
||||||
MessageIdList messageIdList = (MessageIdList)consumers.get(i.next());
|
MessageIdList messageIdList = consumers.get(i.next());
|
||||||
int count = messageIdList.getMessageCount();
|
int count = messageIdList.getMessageCount();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if (found) {
|
if (found) {
|
||||||
|
|
|
@ -18,6 +18,8 @@ package org.apache.activemq.broker.policy;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.jms.MessageConsumer;
|
||||||
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.TopicSubscriptionTest;
|
import org.apache.activemq.broker.TopicSubscriptionTest;
|
||||||
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
||||||
|
@ -27,6 +29,7 @@ import org.apache.activemq.util.MessageIdList;
|
||||||
|
|
||||||
public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
|
public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createBroker() throws Exception {
|
protected BrokerService createBroker() throws Exception {
|
||||||
BrokerService broker = super.createBroker();
|
BrokerService broker = super.createBroker();
|
||||||
|
|
||||||
|
@ -41,48 +44,56 @@ public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
|
||||||
return broker;
|
return broker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testOneProducerTwoConsumersLargeMessagesOnePrefetch() throws Exception {
|
public void testOneProducerTwoConsumersLargeMessagesOnePrefetch() throws Exception {
|
||||||
super.testOneProducerTwoConsumersLargeMessagesOnePrefetch();
|
super.testOneProducerTwoConsumersLargeMessagesOnePrefetch();
|
||||||
|
|
||||||
assertReceivedMessagesAreOrdered();
|
assertReceivedMessagesAreOrdered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testOneProducerTwoConsumersSmallMessagesOnePrefetch() throws Exception {
|
public void testOneProducerTwoConsumersSmallMessagesOnePrefetch() throws Exception {
|
||||||
super.testOneProducerTwoConsumersSmallMessagesOnePrefetch();
|
super.testOneProducerTwoConsumersSmallMessagesOnePrefetch();
|
||||||
|
|
||||||
assertReceivedMessagesAreOrdered();
|
assertReceivedMessagesAreOrdered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception {
|
public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception {
|
||||||
super.testOneProducerTwoConsumersSmallMessagesLargePrefetch();
|
super.testOneProducerTwoConsumersSmallMessagesLargePrefetch();
|
||||||
|
|
||||||
assertReceivedMessagesAreOrdered();
|
assertReceivedMessagesAreOrdered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception {
|
public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception {
|
||||||
super.testOneProducerTwoConsumersLargeMessagesLargePrefetch();
|
super.testOneProducerTwoConsumersLargeMessagesLargePrefetch();
|
||||||
|
|
||||||
assertReceivedMessagesAreOrdered();
|
assertReceivedMessagesAreOrdered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testOneProducerManyConsumersFewMessages() throws Exception {
|
public void testOneProducerManyConsumersFewMessages() throws Exception {
|
||||||
super.testOneProducerManyConsumersFewMessages();
|
super.testOneProducerManyConsumersFewMessages();
|
||||||
|
|
||||||
assertReceivedMessagesAreOrdered();
|
assertReceivedMessagesAreOrdered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testOneProducerManyConsumersManyMessages() throws Exception {
|
public void testOneProducerManyConsumersManyMessages() throws Exception {
|
||||||
super.testOneProducerManyConsumersManyMessages();
|
super.testOneProducerManyConsumersManyMessages();
|
||||||
|
|
||||||
assertReceivedMessagesAreOrdered();
|
assertReceivedMessagesAreOrdered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testManyProducersOneConsumer() throws Exception {
|
public void testManyProducersOneConsumer() throws Exception {
|
||||||
super.testManyProducersOneConsumer();
|
super.testManyProducersOneConsumer();
|
||||||
|
|
||||||
assertReceivedMessagesAreOrdered();
|
assertReceivedMessagesAreOrdered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testManyProducersManyConsumers() throws Exception {
|
public void testManyProducersManyConsumers() throws Exception {
|
||||||
super.testManyProducersManyConsumers();
|
super.testManyProducersManyConsumers();
|
||||||
|
|
||||||
|
@ -96,7 +107,7 @@ public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get basis of order
|
// Get basis of order
|
||||||
Iterator i = consumers.keySet().iterator();
|
Iterator<MessageConsumer> i = consumers.keySet().iterator();
|
||||||
MessageIdList messageOrder = (MessageIdList)consumers.get(i.next());
|
MessageIdList messageOrder = (MessageIdList)consumers.get(i.next());
|
||||||
|
|
||||||
for (; i.hasNext();) {
|
for (; i.hasNext();) {
|
||||||
|
|
|
@ -34,29 +34,29 @@ import org.apache.activemq.JmsTestSupport;
|
||||||
import org.apache.activemq.broker.BrokerFactory;
|
import org.apache.activemq.broker.BrokerFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.ProgressPrinter;
|
import org.apache.activemq.broker.ProgressPrinter;
|
||||||
import org.apache.activemq.broker.TransportConnector;
|
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
import org.apache.activemq.memory.list.SimpleMessageList;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class LoadTester extends JmsTestSupport {
|
public class LoadTester extends JmsTestSupport {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(LoadTester.class);
|
private static final Logger LOG = LoggerFactory.getLogger(LoadTester.class);
|
||||||
|
|
||||||
protected int messageSize = 1024 * 64;
|
protected int messageSize = 1024 * 64;
|
||||||
protected int produceCount = 10000;
|
protected int produceCount = 10000;
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createBroker() throws Exception {
|
protected BrokerService createBroker() throws Exception {
|
||||||
return BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/broker/store/loadtester.xml"));
|
return BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/broker/store/loadtester.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected ConnectionFactory createConnectionFactory() throws URISyntaxException, IOException {
|
protected ConnectionFactory createConnectionFactory() throws URISyntaxException, IOException {
|
||||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(((TransportConnector)broker.getTransportConnectors().get(0)).getServer().getConnectURI());
|
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getServer().getConnectURI());
|
||||||
factory.setUseAsyncSend(true);
|
factory.setUseAsyncSend(true);
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package org.apache.activemq.bugs.amq1095;
|
package org.apache.activemq.bugs.amq1095;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -34,7 +33,6 @@ import javax.naming.Context;
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.broker.BrokerFactory;
|
import org.apache.activemq.broker.BrokerFactory;
|
||||||
|
@ -45,7 +43,7 @@ import org.apache.activemq.command.ActiveMQTopic;
|
||||||
* <p>
|
* <p>
|
||||||
* Common functionality for ActiveMQ test cases.
|
* Common functionality for ActiveMQ test cases.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Rainer Klute <a
|
* @author Rainer Klute <a
|
||||||
* href="mailto:rainer.klute@dp-itsolutions.de"><rainer.klute@dp-itsolutions.de></a>
|
* href="mailto:rainer.klute@dp-itsolutions.de"><rainer.klute@dp-itsolutions.de></a>
|
||||||
* @since 2007-08-10
|
* @since 2007-08-10
|
||||||
|
@ -57,15 +55,15 @@ public class ActiveMQTestCase extends TestCase
|
||||||
private BrokerService broker;
|
private BrokerService broker;
|
||||||
protected Connection connection;
|
protected Connection connection;
|
||||||
protected Destination destination;
|
protected Destination destination;
|
||||||
private List<MessageConsumer> consumersToEmpty = new LinkedList<MessageConsumer>();
|
private final List<MessageConsumer> consumersToEmpty = new LinkedList<MessageConsumer>();
|
||||||
protected final long RECEIVE_TIMEOUT = 500;
|
protected final long RECEIVE_TIMEOUT = 500;
|
||||||
|
|
||||||
|
|
||||||
/** <p>Constructor</p> */
|
/** <p>Constructor</p> */
|
||||||
public ActiveMQTestCase()
|
public ActiveMQTestCase()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/** <p>Constructor</p>
|
/** <p>Constructor</p>
|
||||||
* @param name the test case's name
|
* @param name the test case's name
|
||||||
*/
|
*/
|
||||||
public ActiveMQTestCase(final String name)
|
public ActiveMQTestCase(final String name)
|
||||||
|
@ -76,6 +74,7 @@ public class ActiveMQTestCase extends TestCase
|
||||||
/**
|
/**
|
||||||
* <p>Sets up the JUnit testing environment.
|
* <p>Sets up the JUnit testing environment.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void setUp()
|
protected void setUp()
|
||||||
{
|
{
|
||||||
URI uri;
|
URI uri;
|
||||||
|
@ -84,7 +83,7 @@ public class ActiveMQTestCase extends TestCase
|
||||||
/* Copy all system properties starting with "java.naming." to the initial context. */
|
/* Copy all system properties starting with "java.naming." to the initial context. */
|
||||||
final Properties systemProperties = System.getProperties();
|
final Properties systemProperties = System.getProperties();
|
||||||
final Properties jndiProperties = new Properties();
|
final Properties jndiProperties = new Properties();
|
||||||
for (final Iterator i = systemProperties.keySet().iterator(); i.hasNext();)
|
for (final Iterator<Object> i = systemProperties.keySet().iterator(); i.hasNext();)
|
||||||
{
|
{
|
||||||
final String key = (String) i.next();
|
final String key = (String) i.next();
|
||||||
if (key.startsWith("java.naming.") || key.startsWith("topic.") ||
|
if (key.startsWith("java.naming.") || key.startsWith("topic.") ||
|
||||||
|
@ -94,7 +93,7 @@ public class ActiveMQTestCase extends TestCase
|
||||||
jndiProperties.put(key, value);
|
jndiProperties.put(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context = new InitialContext(jndiProperties);
|
context = new InitialContext(jndiProperties);
|
||||||
uri = new URI("xbean:org/apache/activemq/bugs/amq1095/activemq.xml");
|
uri = new URI("xbean:org/apache/activemq/bugs/amq1095/activemq.xml");
|
||||||
broker = BrokerFactory.createBroker(uri);
|
broker = BrokerFactory.createBroker(uri);
|
||||||
broker.start();
|
broker.start();
|
||||||
|
@ -119,15 +118,15 @@ public class ActiveMQTestCase extends TestCase
|
||||||
catch (JMSException ex1)
|
catch (JMSException ex1)
|
||||||
{
|
{
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
Assert.fail(ex1.toString());
|
fail(ex1.toString());
|
||||||
}
|
}
|
||||||
catch (NamingException ex2) {
|
catch (NamingException ex2) {
|
||||||
ex2.printStackTrace();
|
ex2.printStackTrace();
|
||||||
Assert.fail(ex2.toString());
|
fail(ex2.toString());
|
||||||
}
|
}
|
||||||
catch (Throwable ex3) {
|
catch (Throwable ex3) {
|
||||||
ex3.printStackTrace();
|
ex3.printStackTrace();
|
||||||
Assert.fail(ex3.toString());
|
fail(ex3.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,19 +139,20 @@ public class ActiveMQTestCase extends TestCase
|
||||||
* to be empty.
|
* to be empty.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
TextMessage msg;
|
TextMessage msg;
|
||||||
try {
|
try {
|
||||||
for (final Iterator i = consumersToEmpty.iterator(); i.hasNext();)
|
for (final Iterator<MessageConsumer> i = consumersToEmpty.iterator(); i.hasNext();)
|
||||||
{
|
{
|
||||||
final MessageConsumer consumer = (MessageConsumer) i.next();
|
final MessageConsumer consumer = i.next();
|
||||||
if (consumer != null)
|
if (consumer != null)
|
||||||
do
|
do
|
||||||
msg = (TextMessage) consumer.receive(RECEIVE_TIMEOUT);
|
msg = (TextMessage) consumer.receive(RECEIVE_TIMEOUT);
|
||||||
while (msg != null);
|
while (msg != null);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
connection.stop();
|
connection.stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,11 @@ import javax.jms.Session;
|
||||||
import javax.jms.TextMessage;
|
import javax.jms.TextMessage;
|
||||||
import javax.jms.Topic;
|
import javax.jms.Topic;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Test cases for various ActiveMQ functionalities.
|
* Test cases for various ActiveMQ functionalities.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>
|
* <li>
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -50,7 +47,7 @@ import junit.framework.Assert;
|
||||||
* </p>
|
* </p>
|
||||||
* </li>
|
* </li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author Rainer Klute <a
|
* @author Rainer Klute <a
|
||||||
* href="mailto:rainer.klute@dp-itsolutions.de"><rainer.klute@dp-itsolutions.de></a>
|
* href="mailto:rainer.klute@dp-itsolutions.de"><rainer.klute@dp-itsolutions.de></a>
|
||||||
* @since 2007-08-09
|
* @since 2007-08-09
|
||||||
|
@ -64,7 +61,7 @@ public class MessageSelectorTest extends ActiveMQTestCase {
|
||||||
/** <p>Constructor</p> */
|
/** <p>Constructor</p> */
|
||||||
public MessageSelectorTest()
|
public MessageSelectorTest()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/** <p>Constructor</p>
|
/** <p>Constructor</p>
|
||||||
* @param name the test case's name
|
* @param name the test case's name
|
||||||
*/
|
*/
|
||||||
|
@ -102,7 +99,7 @@ public class MessageSelectorTest extends ActiveMQTestCase {
|
||||||
{
|
{
|
||||||
runMessageSelectorTest(false);
|
runMessageSelectorTest(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Tests whether message selectors work. This is done by sending two
|
* Tests whether message selectors work. This is done by sending two
|
||||||
|
@ -223,7 +220,7 @@ public class MessageSelectorTest extends ActiveMQTestCase {
|
||||||
catch (JMSException ex)
|
catch (JMSException ex)
|
||||||
{
|
{
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
Assert.fail();
|
fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,15 +26,16 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
|
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BrokerXmlConfigFromJNDITest extends JmsTopicSendReceiveWithTwoConnectionsTest {
|
public class BrokerXmlConfigFromJNDITest extends JmsTopicSendReceiveWithTwoConnectionsTest {
|
||||||
|
@Override
|
||||||
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
||||||
assertBaseDirectoryContainsSpaces();
|
assertBaseDirectoryContainsSpaces();
|
||||||
|
|
||||||
// we could put these properties into a jndi.properties
|
// we could put these properties into a jndi.properties
|
||||||
// on the classpath instead
|
// on the classpath instead
|
||||||
Hashtable properties = new Hashtable();
|
Hashtable<String, String> properties = new Hashtable<String, String>();
|
||||||
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
|
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
|
||||||
|
|
||||||
// configure the embedded broker using an XML config file
|
// configure the embedded broker using an XML config file
|
||||||
|
|
|
@ -22,6 +22,7 @@ import javax.jms.JMSException;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.ActiveMQMessageConsumer;
|
import org.apache.activemq.ActiveMQMessageConsumer;
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
|
@ -55,7 +56,7 @@ public class ConfigUsingDestinationOptions extends TestCase {
|
||||||
// JMS selector should be priority
|
// JMS selector should be priority
|
||||||
try {
|
try {
|
||||||
cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test||1");
|
cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test||1");
|
||||||
fail("Selector should be invalid");
|
fail("Selector should be invalid" + cons);
|
||||||
} catch (InvalidSelectorException e) {
|
} catch (InvalidSelectorException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,7 +64,7 @@ public class ConfigUsingDestinationOptions extends TestCase {
|
||||||
// Test setting using JMS destinations
|
// Test setting using JMS destinations
|
||||||
try {
|
try {
|
||||||
cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
|
cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
|
||||||
fail("Selector should be invalid");
|
fail("Selector should be invalid" + cons);
|
||||||
} catch (InvalidSelectorException e) {
|
} catch (InvalidSelectorException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,417 +52,417 @@ import org.springframework.context.support.AbstractApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
public class TestPurgeCommand extends TestCase {
|
public class TestPurgeCommand extends TestCase {
|
||||||
private static final Logger LOG = LoggerFactory
|
private static final Logger LOG = LoggerFactory
|
||||||
.getLogger(TestPurgeCommand.class);
|
.getLogger(TestPurgeCommand.class);
|
||||||
|
|
||||||
protected static final int MESSAGE_COUNT = 10;
|
protected static final int MESSAGE_COUNT = 10;
|
||||||
protected static final String PROPERTY_NAME = "XTestProperty";
|
protected static final String PROPERTY_NAME = "XTestProperty";
|
||||||
protected static final String PROPERTY_VALUE = "1:1";
|
protected static final String PROPERTY_VALUE = "1:1";
|
||||||
|
|
||||||
// check for existence of property
|
|
||||||
protected static final String MSG_SEL_WITH_PROPERTY = PROPERTY_NAME
|
|
||||||
+ " is not null";
|
|
||||||
|
|
||||||
// check for non-existence of property
|
// check for existence of property
|
||||||
protected static final String MSG_SEL_WITHOUT_PROPERTY = PROPERTY_NAME
|
protected static final String MSG_SEL_WITH_PROPERTY = PROPERTY_NAME
|
||||||
+ " is null";
|
+ " is not null";
|
||||||
|
|
||||||
// complex message selector query using XTestProperty and JMSPriority
|
|
||||||
protected static final String MSG_SEL_COMPLEX = PROPERTY_NAME + "='" +
|
|
||||||
"1:1" + "',JMSPriority>3";
|
|
||||||
|
|
||||||
// complex message selector query using XTestProperty AND JMSPriority
|
|
||||||
// but in SQL-92 syntax
|
|
||||||
protected static final String MSG_SEL_COMPLEX_SQL_AND = "(" + PROPERTY_NAME + "='" +
|
|
||||||
"1:1" + "') AND (JMSPriority>3)";
|
|
||||||
|
|
||||||
// complex message selector query using XTestProperty OR JMSPriority
|
// check for non-existence of property
|
||||||
// but in SQL-92 syntax
|
protected static final String MSG_SEL_WITHOUT_PROPERTY = PROPERTY_NAME
|
||||||
protected static final String MSG_SEL_COMPLEX_SQL_OR = "(" + PROPERTY_NAME + "='" +
|
+ " is null";
|
||||||
"1:1" + "') OR (JMSPriority>3)";
|
|
||||||
|
|
||||||
|
|
||||||
protected static final String QUEUE_NAME = "org.apache.activemq.network.jms.QueueBridgeTest";
|
|
||||||
|
|
||||||
protected AbstractApplicationContext context;
|
// complex message selector query using XTestProperty and JMSPriority
|
||||||
protected QueueConnection localConnection;
|
protected static final String MSG_SEL_COMPLEX = PROPERTY_NAME + "='" +
|
||||||
protected QueueRequestor requestor;
|
"1:1" + "',JMSPriority>3";
|
||||||
protected QueueSession requestServerSession;
|
|
||||||
protected MessageConsumer requestServerConsumer;
|
|
||||||
protected MessageProducer requestServerProducer;
|
|
||||||
protected Queue theQueue;
|
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
// complex message selector query using XTestProperty AND JMSPriority
|
||||||
super.setUp();
|
// but in SQL-92 syntax
|
||||||
|
protected static final String MSG_SEL_COMPLEX_SQL_AND = "(" + PROPERTY_NAME + "='" +
|
||||||
|
"1:1" + "') AND (JMSPriority>3)";
|
||||||
|
|
||||||
context = createApplicationContext();
|
// complex message selector query using XTestProperty OR JMSPriority
|
||||||
|
// but in SQL-92 syntax
|
||||||
|
protected static final String MSG_SEL_COMPLEX_SQL_OR = "(" + PROPERTY_NAME + "='" +
|
||||||
|
"1:1" + "') OR (JMSPriority>3)";
|
||||||
|
|
||||||
createConnections();
|
|
||||||
|
|
||||||
requestServerSession = localConnection.createQueueSession(false,
|
protected static final String QUEUE_NAME = "org.apache.activemq.network.jms.QueueBridgeTest";
|
||||||
Session.AUTO_ACKNOWLEDGE);
|
|
||||||
theQueue = requestServerSession.createQueue(QUEUE_NAME);
|
|
||||||
requestServerConsumer = requestServerSession.createConsumer(theQueue);
|
|
||||||
requestServerProducer = requestServerSession.createProducer(null);
|
|
||||||
|
|
||||||
QueueSession session = localConnection.createQueueSession(false,
|
protected AbstractApplicationContext context;
|
||||||
Session.AUTO_ACKNOWLEDGE);
|
protected QueueConnection localConnection;
|
||||||
requestor = new QueueRequestor(session, theQueue);
|
protected QueueRequestor requestor;
|
||||||
}
|
protected QueueSession requestServerSession;
|
||||||
|
protected MessageConsumer requestServerConsumer;
|
||||||
|
protected MessageProducer requestServerProducer;
|
||||||
|
protected Queue theQueue;
|
||||||
|
|
||||||
protected void createConnections() throws JMSException {
|
@Override
|
||||||
ActiveMQConnectionFactory fac = (ActiveMQConnectionFactory) context
|
protected void setUp() throws Exception {
|
||||||
.getBean("localFactory");
|
super.setUp();
|
||||||
localConnection = fac.createQueueConnection();
|
|
||||||
localConnection.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AbstractApplicationContext createApplicationContext() {
|
context = createApplicationContext();
|
||||||
return new ClassPathXmlApplicationContext("org/apache/activemq/console/command/activemq.xml");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void tearDown() throws Exception {
|
createConnections();
|
||||||
localConnection.close();
|
|
||||||
BrokerService broker = (BrokerService) context.getBean("localbroker");
|
|
||||||
broker.stop();
|
|
||||||
broker = (BrokerService) context.getBean("default");
|
|
||||||
broker.stop();
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
requestServerSession = localConnection.createQueueSession(false,
|
||||||
public int getMessageCount(QueueBrowser browser, String prefix)
|
Session.AUTO_ACKNOWLEDGE);
|
||||||
throws JMSException {
|
theQueue = requestServerSession.createQueue(QUEUE_NAME);
|
||||||
Enumeration e = browser.getEnumeration();
|
requestServerConsumer = requestServerSession.createConsumer(theQueue);
|
||||||
int with = 0;
|
requestServerProducer = requestServerSession.createProducer(null);
|
||||||
while (e.hasMoreElements()) {
|
|
||||||
Object o = e.nextElement();
|
|
||||||
System.out.println(prefix + o);
|
|
||||||
with++;
|
|
||||||
}
|
|
||||||
return with;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cleanup() throws JMSException {
|
QueueSession session = localConnection.createQueueSession(false,
|
||||||
for (int i = 0; i < MESSAGE_COUNT * 2; i++) {
|
Session.AUTO_ACKNOWLEDGE);
|
||||||
requestServerConsumer.receive();
|
requestor = new QueueRequestor(session, theQueue);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected MBeanServerConnection createJmxConnection() throws IOException {
|
protected void createConnections() throws JMSException {
|
||||||
return ManagementFactory.getPlatformMBeanServer();
|
ActiveMQConnectionFactory fac = (ActiveMQConnectionFactory) context
|
||||||
}
|
.getBean("localFactory");
|
||||||
|
localConnection = fac.createQueueConnection();
|
||||||
|
localConnection.start();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
protected AbstractApplicationContext createApplicationContext() {
|
||||||
public void purgeAllMessages() throws IOException, Exception {
|
return new ClassPathXmlApplicationContext("org/apache/activemq/console/command/activemq.xml");
|
||||||
List<String> tokens = Arrays.asList(new String[] { "*" });
|
}
|
||||||
for (String token : tokens) {
|
|
||||||
List<ObjectInstance> queueList = JmxMBeansUtil.queryMBeans(
|
|
||||||
createJmxConnection(), "Type=Queue,Destination=" + token
|
|
||||||
+ ",*");
|
|
||||||
for (ObjectInstance oi : queueList) {
|
|
||||||
ObjectName queueName = oi.getObjectName();
|
|
||||||
LOG.info("Purging all messages in queue: "
|
|
||||||
+ queueName.getKeyProperty("Destination"));
|
|
||||||
createJmxConnection().invoke(queueName, "purge",
|
|
||||||
new Object[] {}, new String[] {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMessages() throws IOException, Exception {
|
@Override
|
||||||
// first clean out any messages that may exist.
|
protected void tearDown() throws Exception {
|
||||||
purgeAllMessages();
|
localConnection.close();
|
||||||
|
BrokerService broker = (BrokerService) context.getBean("localbroker");
|
||||||
|
broker.stop();
|
||||||
|
broker = (BrokerService) context.getBean("default");
|
||||||
|
broker.stop();
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < MESSAGE_COUNT; i++) {
|
public int getMessageCount(QueueBrowser browser, String prefix) throws JMSException {
|
||||||
TextMessage msg = requestServerSession
|
Enumeration<?> e = browser.getEnumeration();
|
||||||
.createTextMessage("test msg: " + i);
|
int with = 0;
|
||||||
msg.setStringProperty(PROPERTY_NAME, PROPERTY_VALUE);
|
while (e.hasMoreElements()) {
|
||||||
requestServerProducer.send(theQueue, msg);
|
Object o = e.nextElement();
|
||||||
}
|
System.out.println(prefix + o);
|
||||||
for (int i = 0; i < MESSAGE_COUNT; i++) {
|
with++;
|
||||||
TextMessage msg = requestServerSession
|
}
|
||||||
.createTextMessage("test msg: " + i);
|
return with;
|
||||||
requestServerProducer.send(theQueue, msg);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
public void cleanup() throws JMSException {
|
||||||
|
for (int i = 0; i < MESSAGE_COUNT * 2; i++) {
|
||||||
|
requestServerConsumer.receive();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void validateCounts(int expectedWithCount, int expectedWithoutCount,
|
protected MBeanServerConnection createJmxConnection() throws IOException {
|
||||||
int expectedAllCount) throws JMSException {
|
return ManagementFactory.getPlatformMBeanServer();
|
||||||
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
|
}
|
||||||
theQueue, MSG_SEL_WITH_PROPERTY);
|
|
||||||
QueueBrowser withoutPropertyBrowser = requestServerSession
|
|
||||||
.createBrowser(theQueue, MSG_SEL_WITHOUT_PROPERTY);
|
|
||||||
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
|
|
||||||
|
|
||||||
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
|
@SuppressWarnings("unchecked")
|
||||||
int withoutCount = getMessageCount(withoutPropertyBrowser,
|
public void purgeAllMessages() throws IOException, Exception {
|
||||||
"withoutProperty ");
|
List<String> tokens = Arrays.asList(new String[] { "*" });
|
||||||
int allCount = getMessageCount(allBrowser, "allMessages ");
|
for (String token : tokens) {
|
||||||
|
List<ObjectInstance> queueList = JmxMBeansUtil.queryMBeans(
|
||||||
|
createJmxConnection(), "Type=Queue,Destination=" + token
|
||||||
|
+ ",*");
|
||||||
|
for (ObjectInstance oi : queueList) {
|
||||||
|
ObjectName queueName = oi.getObjectName();
|
||||||
|
LOG.info("Purging all messages in queue: "
|
||||||
|
+ queueName.getKeyProperty("Destination"));
|
||||||
|
createJmxConnection().invoke(queueName, "purge",
|
||||||
|
new Object[] {}, new String[] {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
withPropertyBrowser.close();
|
public void addMessages() throws IOException, Exception {
|
||||||
withoutPropertyBrowser.close();
|
// first clean out any messages that may exist.
|
||||||
allBrowser.close();
|
purgeAllMessages();
|
||||||
|
|
||||||
assertEquals("Expected withCount to be " + expectedWithCount + " was "
|
for (int i = 0; i < MESSAGE_COUNT; i++) {
|
||||||
+ withCount, expectedWithCount, withCount);
|
TextMessage msg = requestServerSession
|
||||||
assertEquals("Expected withoutCount to be " + expectedWithoutCount
|
.createTextMessage("test msg: " + i);
|
||||||
+ " was " + withoutCount, expectedWithoutCount, withoutCount);
|
msg.setStringProperty(PROPERTY_NAME, PROPERTY_VALUE);
|
||||||
assertEquals("Expected allCount to be " + expectedAllCount + " was "
|
requestServerProducer.send(theQueue, msg);
|
||||||
+ allCount, expectedAllCount, allCount);
|
}
|
||||||
LOG.info("withCount = " + withCount + "\n withoutCount = "
|
for (int i = 0; i < MESSAGE_COUNT; i++) {
|
||||||
+ withoutCount + "\n allCount = " + allCount + "\n = " + "\n");
|
TextMessage msg = requestServerSession
|
||||||
}
|
.createTextMessage("test msg: " + i);
|
||||||
|
requestServerProducer.send(theQueue, msg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
}
|
||||||
* This test ensures that the queueViewMbean will work.
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void testQueueViewMbean() throws Exception {
|
|
||||||
|
|
||||||
try {
|
public void validateCounts(int expectedWithCount, int expectedWithoutCount,
|
||||||
addMessages();
|
int expectedAllCount) throws JMSException {
|
||||||
|
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
|
||||||
|
theQueue, MSG_SEL_WITH_PROPERTY);
|
||||||
|
QueueBrowser withoutPropertyBrowser = requestServerSession
|
||||||
|
.createBrowser(theQueue, MSG_SEL_WITHOUT_PROPERTY);
|
||||||
|
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
|
||||||
|
|
||||||
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
|
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
|
||||||
|
int withoutCount = getMessageCount(withoutPropertyBrowser,
|
||||||
|
"withoutProperty ");
|
||||||
|
int allCount = getMessageCount(allBrowser, "allMessages ");
|
||||||
|
|
||||||
List<String> tokens = Arrays.asList(new String[] { "*" });
|
withPropertyBrowser.close();
|
||||||
for (String token : tokens) {
|
withoutPropertyBrowser.close();
|
||||||
List<ObjectInstance> queueList = JmxMBeansUtil.queryMBeans(
|
allBrowser.close();
|
||||||
createJmxConnection(), "Type=Queue,Destination="
|
|
||||||
+ token + ",*");
|
|
||||||
|
|
||||||
for (ObjectInstance queue : queueList) {
|
assertEquals("Expected withCount to be " + expectedWithCount + " was "
|
||||||
ObjectName queueName = ((ObjectInstance) queue)
|
+ withCount, expectedWithCount, withCount);
|
||||||
.getObjectName();
|
assertEquals("Expected withoutCount to be " + expectedWithoutCount
|
||||||
QueueViewMBean proxy = (QueueViewMBean) MBeanServerInvocationHandler
|
+ " was " + withoutCount, expectedWithoutCount, withoutCount);
|
||||||
.newProxyInstance(createJmxConnection(), queueName,
|
assertEquals("Expected allCount to be " + expectedAllCount + " was "
|
||||||
QueueViewMBean.class, true);
|
+ allCount, expectedAllCount, allCount);
|
||||||
int removed = proxy
|
LOG.info("withCount = " + withCount + "\n withoutCount = "
|
||||||
.removeMatchingMessages(MSG_SEL_WITH_PROPERTY);
|
+ withoutCount + "\n allCount = " + allCount + "\n = " + "\n");
|
||||||
LOG.info("Removed: " + removed);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT);
|
/**
|
||||||
|
* This test ensures that the queueViewMbean will work.
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void testQueueViewMbean() throws Exception {
|
||||||
|
|
||||||
} finally {
|
try {
|
||||||
purgeAllMessages();
|
addMessages();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPurgeCommandSimpleSelector() throws Exception {
|
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
|
||||||
try {
|
|
||||||
PurgeCommand purgeCommand = new PurgeCommand();
|
|
||||||
CommandContext context = new CommandContext();
|
|
||||||
|
|
||||||
context.setFormatter(new CommandShellOutputFormatter(System.out));
|
List<String> tokens = Arrays.asList(new String[] { "*" });
|
||||||
|
for (String token : tokens) {
|
||||||
|
List<ObjectInstance> queueList = JmxMBeansUtil.queryMBeans(
|
||||||
|
createJmxConnection(), "Type=Queue,Destination="
|
||||||
|
+ token + ",*");
|
||||||
|
|
||||||
purgeCommand.setCommandContext(context);
|
for (ObjectInstance queue : queueList) {
|
||||||
purgeCommand.setJmxUseLocal(true);
|
ObjectName queueName = queue
|
||||||
|
.getObjectName();
|
||||||
|
QueueViewMBean proxy = MBeanServerInvocationHandler
|
||||||
|
.newProxyInstance(createJmxConnection(), queueName,
|
||||||
|
QueueViewMBean.class, true);
|
||||||
|
int removed = proxy
|
||||||
|
.removeMatchingMessages(MSG_SEL_WITH_PROPERTY);
|
||||||
|
LOG.info("Removed: " + removed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<String> tokens = new ArrayList<String>();
|
validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT);
|
||||||
tokens.add("--msgsel");
|
|
||||||
tokens.add(MSG_SEL_WITH_PROPERTY);
|
|
||||||
|
|
||||||
addMessages();
|
|
||||||
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
|
|
||||||
|
|
||||||
purgeCommand.execute(tokens);
|
} finally {
|
||||||
|
purgeAllMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT);
|
public void testPurgeCommandSimpleSelector() throws Exception {
|
||||||
} finally {
|
try {
|
||||||
purgeAllMessages();
|
PurgeCommand purgeCommand = new PurgeCommand();
|
||||||
}
|
CommandContext context = new CommandContext();
|
||||||
}
|
|
||||||
|
|
||||||
public void testPurgeCommandComplexSelector() throws Exception {
|
|
||||||
try {
|
|
||||||
PurgeCommand purgeCommand = new PurgeCommand();
|
|
||||||
CommandContext context = new CommandContext();
|
|
||||||
|
|
||||||
context.setFormatter(new CommandShellOutputFormatter(System.out));
|
context.setFormatter(new CommandShellOutputFormatter(System.out));
|
||||||
|
|
||||||
purgeCommand.setCommandContext(context);
|
purgeCommand.setCommandContext(context);
|
||||||
purgeCommand.setJmxUseLocal(true);
|
purgeCommand.setJmxUseLocal(true);
|
||||||
|
|
||||||
List<String> tokens = new ArrayList<String>();
|
List<String> tokens = new ArrayList<String>();
|
||||||
tokens.add("--msgsel");
|
tokens.add("--msgsel");
|
||||||
tokens.add(MSG_SEL_COMPLEX);
|
tokens.add(MSG_SEL_WITH_PROPERTY);
|
||||||
|
|
||||||
addMessages();
|
|
||||||
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
|
|
||||||
|
|
||||||
purgeCommand.execute(tokens);
|
addMessages();
|
||||||
|
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
|
||||||
|
|
||||||
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
|
purgeCommand.execute(tokens);
|
||||||
theQueue, MSG_SEL_COMPLEX);
|
|
||||||
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
|
|
||||||
|
|
||||||
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
|
validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT);
|
||||||
int allCount = getMessageCount(allBrowser, "allMessages ");
|
} finally {
|
||||||
|
purgeAllMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
withPropertyBrowser.close();
|
public void testPurgeCommandComplexSelector() throws Exception {
|
||||||
allBrowser.close();
|
try {
|
||||||
|
PurgeCommand purgeCommand = new PurgeCommand();
|
||||||
assertEquals("Expected withCount to be " + "0" + " was "
|
CommandContext context = new CommandContext();
|
||||||
+ withCount, 0, withCount);
|
|
||||||
assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was "
|
|
||||||
+ allCount, MESSAGE_COUNT, allCount);
|
|
||||||
LOG.info("withCount = " + withCount + "\n allCount = " +
|
|
||||||
allCount + "\n = " + "\n");
|
|
||||||
} finally {
|
|
||||||
purgeAllMessages();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPurgeCommandComplexSQLSelector_AND() throws Exception {
|
|
||||||
try {
|
|
||||||
|
|
||||||
String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100";
|
|
||||||
String two = "\\*:100";
|
|
||||||
try {
|
|
||||||
if (one.matches(two))
|
|
||||||
LOG.info("String matches.");
|
|
||||||
else
|
|
||||||
LOG.info("string does not match.");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOG.error(ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
PurgeCommand purgeCommand = new PurgeCommand();
|
|
||||||
CommandContext context = new CommandContext();
|
|
||||||
|
|
||||||
context.setFormatter(new CommandShellOutputFormatter(System.out));
|
context.setFormatter(new CommandShellOutputFormatter(System.out));
|
||||||
|
|
||||||
purgeCommand.setCommandContext(context);
|
purgeCommand.setCommandContext(context);
|
||||||
purgeCommand.setJmxUseLocal(true);
|
purgeCommand.setJmxUseLocal(true);
|
||||||
|
|
||||||
List<String> tokens = new ArrayList<String>();
|
List<String> tokens = new ArrayList<String>();
|
||||||
tokens.add("--msgsel");
|
tokens.add("--msgsel");
|
||||||
tokens.add(MSG_SEL_COMPLEX_SQL_AND);
|
tokens.add(MSG_SEL_COMPLEX);
|
||||||
|
|
||||||
addMessages();
|
|
||||||
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
|
|
||||||
|
|
||||||
purgeCommand.execute(tokens);
|
addMessages();
|
||||||
|
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
|
||||||
|
|
||||||
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
|
purgeCommand.execute(tokens);
|
||||||
theQueue, MSG_SEL_COMPLEX_SQL_AND);
|
|
||||||
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
|
|
||||||
|
|
||||||
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
|
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
|
||||||
int allCount = getMessageCount(allBrowser, "allMessages ");
|
theQueue, MSG_SEL_COMPLEX);
|
||||||
|
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
|
||||||
|
|
||||||
withPropertyBrowser.close();
|
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
|
||||||
allBrowser.close();
|
int allCount = getMessageCount(allBrowser, "allMessages ");
|
||||||
|
|
||||||
assertEquals("Expected withCount to be " + "0" + " was "
|
|
||||||
+ withCount, 0, withCount);
|
|
||||||
assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was "
|
|
||||||
+ allCount, MESSAGE_COUNT, allCount);
|
|
||||||
LOG.info("withCount = " + withCount + "\n allCount = " +
|
|
||||||
allCount + "\n = " + "\n");
|
|
||||||
} finally {
|
|
||||||
purgeAllMessages();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPurgeCommandComplexSQLSelector_OR() throws Exception {
|
|
||||||
try {
|
|
||||||
PurgeCommand purgeCommand = new PurgeCommand();
|
|
||||||
CommandContext context = new CommandContext();
|
|
||||||
|
|
||||||
context.setFormatter(new CommandShellOutputFormatter(System.out));
|
withPropertyBrowser.close();
|
||||||
|
allBrowser.close();
|
||||||
|
|
||||||
purgeCommand.setCommandContext(context);
|
assertEquals("Expected withCount to be " + "0" + " was "
|
||||||
purgeCommand.setJmxUseLocal(true);
|
+ withCount, 0, withCount);
|
||||||
|
assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was "
|
||||||
|
+ allCount, MESSAGE_COUNT, allCount);
|
||||||
|
LOG.info("withCount = " + withCount + "\n allCount = " +
|
||||||
|
allCount + "\n = " + "\n");
|
||||||
|
} finally {
|
||||||
|
purgeAllMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<String> tokens = new ArrayList<String>();
|
public void testPurgeCommandComplexSQLSelector_AND() throws Exception {
|
||||||
tokens.add("--msgsel");
|
try {
|
||||||
tokens.add(MSG_SEL_COMPLEX_SQL_OR);
|
|
||||||
|
|
||||||
addMessages();
|
|
||||||
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
|
|
||||||
|
|
||||||
purgeCommand.execute(tokens);
|
String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100";
|
||||||
|
String two = "\\*:100";
|
||||||
|
try {
|
||||||
|
if (one.matches(two))
|
||||||
|
LOG.info("String matches.");
|
||||||
|
else
|
||||||
|
LOG.info("string does not match.");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.error(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
|
PurgeCommand purgeCommand = new PurgeCommand();
|
||||||
theQueue, MSG_SEL_COMPLEX_SQL_OR);
|
CommandContext context = new CommandContext();
|
||||||
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
|
|
||||||
|
|
||||||
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
|
context.setFormatter(new CommandShellOutputFormatter(System.out));
|
||||||
int allCount = getMessageCount(allBrowser, "allMessages ");
|
|
||||||
|
|
||||||
withPropertyBrowser.close();
|
purgeCommand.setCommandContext(context);
|
||||||
allBrowser.close();
|
purgeCommand.setJmxUseLocal(true);
|
||||||
|
|
||||||
assertEquals("Expected withCount to be 0 but was "
|
|
||||||
+ withCount, 0, withCount);
|
|
||||||
assertEquals("Expected allCount to be 0 but was "
|
|
||||||
+ allCount, 0, allCount);
|
|
||||||
LOG.info("withCount = " + withCount + "\n allCount = " +
|
|
||||||
allCount + "\n = " + "\n");
|
|
||||||
} finally {
|
|
||||||
purgeAllMessages();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDummy() throws Exception {
|
|
||||||
try {
|
|
||||||
|
|
||||||
String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100";
|
|
||||||
String two = "ID*:100";
|
|
||||||
try {
|
|
||||||
if (one.matches(two))
|
|
||||||
LOG.info("String matches.");
|
|
||||||
else
|
|
||||||
LOG.info("string does not match.");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOG.error(ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
PurgeCommand purgeCommand = new PurgeCommand();
|
|
||||||
CommandContext context = new CommandContext();
|
|
||||||
|
|
||||||
context.setFormatter(new CommandShellOutputFormatter(System.out));
|
List<String> tokens = new ArrayList<String>();
|
||||||
|
tokens.add("--msgsel");
|
||||||
|
tokens.add(MSG_SEL_COMPLEX_SQL_AND);
|
||||||
|
|
||||||
purgeCommand.setCommandContext(context);
|
addMessages();
|
||||||
purgeCommand.setJmxUseLocal(true);
|
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
|
||||||
|
|
||||||
List<String> tokens = new ArrayList<String>();
|
purgeCommand.execute(tokens);
|
||||||
tokens.add("--msgsel");
|
|
||||||
tokens.add("(XTestProperty LIKE '1:*') AND (JMSPriority>3)");
|
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
|
||||||
|
theQueue, MSG_SEL_COMPLEX_SQL_AND);
|
||||||
addMessages();
|
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
|
||||||
|
|
||||||
purgeCommand.execute(tokens);
|
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
|
||||||
|
int allCount = getMessageCount(allBrowser, "allMessages ");
|
||||||
|
|
||||||
|
withPropertyBrowser.close();
|
||||||
|
allBrowser.close();
|
||||||
|
|
||||||
|
assertEquals("Expected withCount to be " + "0" + " was "
|
||||||
|
+ withCount, 0, withCount);
|
||||||
|
assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was "
|
||||||
|
+ allCount, MESSAGE_COUNT, allCount);
|
||||||
|
LOG.info("withCount = " + withCount + "\n allCount = " +
|
||||||
|
allCount + "\n = " + "\n");
|
||||||
|
} finally {
|
||||||
|
purgeAllMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPurgeCommandComplexSQLSelector_OR() throws Exception {
|
||||||
|
try {
|
||||||
|
PurgeCommand purgeCommand = new PurgeCommand();
|
||||||
|
CommandContext context = new CommandContext();
|
||||||
|
|
||||||
|
context.setFormatter(new CommandShellOutputFormatter(System.out));
|
||||||
|
|
||||||
|
purgeCommand.setCommandContext(context);
|
||||||
|
purgeCommand.setJmxUseLocal(true);
|
||||||
|
|
||||||
|
List<String> tokens = new ArrayList<String>();
|
||||||
|
tokens.add("--msgsel");
|
||||||
|
tokens.add(MSG_SEL_COMPLEX_SQL_OR);
|
||||||
|
|
||||||
|
addMessages();
|
||||||
|
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
|
||||||
|
|
||||||
|
purgeCommand.execute(tokens);
|
||||||
|
|
||||||
|
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
|
||||||
|
theQueue, MSG_SEL_COMPLEX_SQL_OR);
|
||||||
|
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
|
||||||
|
|
||||||
|
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
|
||||||
|
int allCount = getMessageCount(allBrowser, "allMessages ");
|
||||||
|
|
||||||
|
withPropertyBrowser.close();
|
||||||
|
allBrowser.close();
|
||||||
|
|
||||||
|
assertEquals("Expected withCount to be 0 but was "
|
||||||
|
+ withCount, 0, withCount);
|
||||||
|
assertEquals("Expected allCount to be 0 but was "
|
||||||
|
+ allCount, 0, allCount);
|
||||||
|
LOG.info("withCount = " + withCount + "\n allCount = " +
|
||||||
|
allCount + "\n = " + "\n");
|
||||||
|
} finally {
|
||||||
|
purgeAllMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDummy() throws Exception {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100";
|
||||||
|
String two = "ID*:100";
|
||||||
|
try {
|
||||||
|
if (one.matches(two))
|
||||||
|
LOG.info("String matches.");
|
||||||
|
else
|
||||||
|
LOG.info("string does not match.");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.error(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
PurgeCommand purgeCommand = new PurgeCommand();
|
||||||
|
CommandContext context = new CommandContext();
|
||||||
|
|
||||||
|
context.setFormatter(new CommandShellOutputFormatter(System.out));
|
||||||
|
|
||||||
|
purgeCommand.setCommandContext(context);
|
||||||
|
purgeCommand.setJmxUseLocal(true);
|
||||||
|
|
||||||
|
List<String> tokens = new ArrayList<String>();
|
||||||
|
tokens.add("--msgsel");
|
||||||
|
tokens.add("(XTestProperty LIKE '1:*') AND (JMSPriority>3)");
|
||||||
|
|
||||||
|
addMessages();
|
||||||
|
|
||||||
|
purgeCommand.execute(tokens);
|
||||||
|
|
||||||
|
/*
|
||||||
|
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
|
||||||
|
theQueue, MSG_SEL_COMPLEX_SQL_AND);
|
||||||
|
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
|
||||||
|
|
||||||
|
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
|
||||||
|
int allCount = getMessageCount(allBrowser, "allMessages ");
|
||||||
|
|
||||||
|
withPropertyBrowser.close();
|
||||||
|
allBrowser.close();
|
||||||
|
|
||||||
|
assertEquals("Expected withCount to be " + "0" + " was "
|
||||||
|
+ withCount, 0, withCount);
|
||||||
|
assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was "
|
||||||
|
+ allCount, MESSAGE_COUNT, allCount);
|
||||||
|
LOG.info("withCount = " + withCount + "\n allCount = " +
|
||||||
|
allCount + "\n = " + "\n");
|
||||||
|
*/
|
||||||
|
} finally {
|
||||||
|
purgeAllMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
|
|
||||||
theQueue, MSG_SEL_COMPLEX_SQL_AND);
|
|
||||||
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
|
|
||||||
|
|
||||||
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
|
|
||||||
int allCount = getMessageCount(allBrowser, "allMessages ");
|
|
||||||
|
|
||||||
withPropertyBrowser.close();
|
|
||||||
allBrowser.close();
|
|
||||||
|
|
||||||
assertEquals("Expected withCount to be " + "0" + " was "
|
|
||||||
+ withCount, 0, withCount);
|
|
||||||
assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was "
|
|
||||||
+ allCount, MESSAGE_COUNT, allCount);
|
|
||||||
LOG.info("withCount = " + withCount + "\n allCount = " +
|
|
||||||
allCount + "\n = " + "\n");
|
|
||||||
*/
|
|
||||||
} finally {
|
|
||||||
purgeAllMessages();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,15 @@
|
||||||
package org.apache.activemq.filter;
|
package org.apache.activemq.filter;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.command.ActiveMQTempQueue;
|
import org.apache.activemq.command.ActiveMQTempQueue;
|
||||||
import org.apache.activemq.command.ConnectionId;
|
import org.apache.activemq.command.ConnectionId;
|
||||||
import org.apache.activemq.util.IdGenerator;
|
import org.apache.activemq.util.IdGenerator;
|
||||||
|
|
||||||
public class DestinationMapTempDestinationTest extends TestCase {
|
public class DestinationMapTempDestinationTest extends TestCase {
|
||||||
|
|
||||||
public void testtestTempDestinations() throws Exception {
|
public void testtestTempDestinations() throws Exception {
|
||||||
ConnectionId id = new ConnectionId(new IdGenerator().generateId());
|
ConnectionId id = new ConnectionId(new IdGenerator().generateId());
|
||||||
DestinationMap map = new DestinationMap();
|
DestinationMap map = new DestinationMap();
|
||||||
|
@ -36,7 +38,7 @@ public class DestinationMapTempDestinationTest extends TestCase {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
ActiveMQTempQueue queue = new ActiveMQTempQueue(id, i);
|
ActiveMQTempQueue queue = new ActiveMQTempQueue(id, i);
|
||||||
map.remove(queue, value);
|
map.remove(queue, value);
|
||||||
Set set = map.get(queue);
|
Set<?> set = map.get(queue);
|
||||||
assertTrue(set.isEmpty());
|
assertTrue(set.isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
import org.apache.activemq.command.ActiveMQTopic;
|
import org.apache.activemq.command.ActiveMQTopic;
|
||||||
|
@ -50,7 +51,6 @@ public class DestinationMapTest extends TestCase {
|
||||||
map.put(d1, d1);
|
map.put(d1, d1);
|
||||||
map.put(d2, d2);
|
map.put(d2, d2);
|
||||||
map.get(createDestination("TEST.BAR.D2,TEST.BAR.D3"));
|
map.get(createDestination("TEST.BAR.D2,TEST.BAR.D3"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleDestinations() throws Exception {
|
public void testSimpleDestinations() throws Exception {
|
||||||
|
@ -131,7 +131,7 @@ public class DestinationMapTest extends TestCase {
|
||||||
map.put(d2, v2);
|
map.put(d2, v2);
|
||||||
map.put(d3, v3);
|
map.put(d3, v3);
|
||||||
|
|
||||||
List allValues = Arrays.asList(new Object[] {v1, v2, v3});
|
List<Object> allValues = Arrays.asList(new Object[] {v1, v2, v3});
|
||||||
|
|
||||||
assertMapValue(">", allValues);
|
assertMapValue(">", allValues);
|
||||||
assertMapValue("TEST.>", allValues);
|
assertMapValue("TEST.>", allValues);
|
||||||
|
@ -305,10 +305,9 @@ public class DestinationMapTest extends TestCase {
|
||||||
put("FOO.B", v2);
|
put("FOO.B", v2);
|
||||||
assertMapValue("FOO.>", v1, v2);
|
assertMapValue("FOO.>", v1, v2);
|
||||||
|
|
||||||
Set set = map.removeAll(createDestination("FOO.A"));
|
map.removeAll(createDestination("FOO.A"));
|
||||||
|
|
||||||
assertMapValue("FOO.>", v2);
|
assertMapValue("FOO.>", v2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadSample2() {
|
protected void loadSample2() {
|
||||||
|
@ -371,7 +370,7 @@ public class DestinationMapTest extends TestCase {
|
||||||
assertMapValue(destinationName, Arrays.asList(new Object[] {expected1, expected2, expected3, expected4, expected5, expected6}));
|
assertMapValue(destinationName, Arrays.asList(new Object[] {expected1, expected2, expected3, expected4, expected5, expected6}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
protected void assertMapValue(ActiveMQDestination destination, Object expected) {
|
protected void assertMapValue(ActiveMQDestination destination, Object expected) {
|
||||||
List expectedList = null;
|
List expectedList = null;
|
||||||
if (expected == null) {
|
if (expected == null) {
|
||||||
|
|
|
@ -20,17 +20,21 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a destination based policy
|
* Represents a destination based policy
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DummyPolicy extends DestinationMap {
|
public class DummyPolicy extends DestinationMap {
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
@Override
|
||||||
protected Class getEntryClass() {
|
protected Class getEntryClass() {
|
||||||
return DummyPolicyEntry.class;
|
return DummyPolicyEntry.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
@Override
|
||||||
public void setEntries(List entries) {
|
public void setEntries(List entries) {
|
||||||
super.setEntries(entries);
|
super.setEntries(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,12 @@ public class DummyPolicyTest extends SpringTestSupport {
|
||||||
public void testPolicy() throws Exception {
|
public void testPolicy() throws Exception {
|
||||||
DummyPolicy policy = (DummyPolicy)getBean("policy");
|
DummyPolicy policy = (DummyPolicy)getBean("policy");
|
||||||
|
|
||||||
Set set = policy.get(new ActiveMQTopic("FOO.BAR"));
|
Set<?> set = policy.get(new ActiveMQTopic("FOO.BAR"));
|
||||||
|
|
||||||
assertSetEquals("FOO.BAR set", new Object[] {"Edam", "Cheddar"}, set);
|
assertSetEquals("FOO.BAR set", new Object[] {"Edam", "Cheddar"}, set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected AbstractApplicationContext createApplicationContext() {
|
protected AbstractApplicationContext createApplicationContext() {
|
||||||
return new ClassPathXmlApplicationContext("org/apache/activemq/filter/dummyPolicy.xml");
|
return new ClassPathXmlApplicationContext("org/apache/activemq/filter/dummyPolicy.xml");
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,16 +23,17 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
/**
|
/**
|
||||||
* Test case for AMQ-141
|
* Test case for AMQ-141
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CustomConnectionFactoryNameTest extends ActiveMQInitialContextFactoryTest {
|
public class CustomConnectionFactoryNameTest extends ActiveMQInitialContextFactoryTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
public void testConnectionFactoriesArePresent() throws NamingException {
|
public void testConnectionFactoriesArePresent() throws NamingException {
|
||||||
super.testConnectionFactoriesArePresent();
|
super.testConnectionFactoriesArePresent();
|
||||||
assertConnectionFactoryPresent("jms/Connection");
|
assertConnectionFactoryPresent("jms/Connection");
|
||||||
assertConnectionFactoryPresent("jms/DURABLE_SUB_CONNECTION_FACTORY");
|
assertConnectionFactoryPresent("jms/DURABLE_SUB_CONNECTION_FACTORY");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConnectionFactoriesAreConfigured() throws NamingException {
|
public void testConnectionFactoriesAreConfigured() throws NamingException {
|
||||||
super.testConnectionFactoriesArePresent();
|
super.testConnectionFactoriesArePresent();
|
||||||
ActiveMQConnectionFactory factory1 = (ActiveMQConnectionFactory) context.lookup("jms/Connection");
|
ActiveMQConnectionFactory factory1 = (ActiveMQConnectionFactory) context.lookup("jms/Connection");
|
||||||
|
@ -41,10 +42,12 @@ public class CustomConnectionFactoryNameTest extends ActiveMQInitialContextFacto
|
||||||
assertEquals("testclient", factory2.getClientID());
|
assertEquals("testclient", factory2.getClientID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected String getConnectionFactoryLookupName() {
|
protected String getConnectionFactoryLookupName() {
|
||||||
return "myConnectionFactory";
|
return "myConnectionFactory";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void configureEnvironment() {
|
protected void configureEnvironment() {
|
||||||
super.configureEnvironment();
|
super.configureEnvironment();
|
||||||
environment.put("connectionFactoryNames", " myConnectionFactory, jms/Connection, jms/DURABLE_SUB_CONNECTION_FACTORY");
|
environment.put("connectionFactoryNames", " myConnectionFactory, jms/Connection, jms/DURABLE_SUB_CONNECTION_FACTORY");
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.activemq.jndi;
|
||||||
/**
|
/**
|
||||||
* Test case for AMQ-140
|
* Test case for AMQ-140
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DestinationNameWithSlashTest extends JNDITestSupport {
|
public class DestinationNameWithSlashTest extends JNDITestSupport {
|
||||||
public void testNameWithSlash() throws Exception {
|
public void testNameWithSlash() throws Exception {
|
||||||
|
@ -28,6 +28,7 @@ public class DestinationNameWithSlashTest extends JNDITestSupport {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void configureEnvironment() {
|
protected void configureEnvironment() {
|
||||||
super.configureEnvironment();
|
super.configureEnvironment();
|
||||||
environment.put("queue.jms/Queue", "example.myqueue");
|
environment.put("queue.jms/Queue", "example.myqueue");
|
||||||
|
|
|
@ -28,17 +28,18 @@ import javax.naming.NamingException;
|
||||||
import javax.naming.spi.InitialContextFactory;
|
import javax.naming.spi.InitialContextFactory;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class JNDITestSupport extends TestCase {
|
public abstract class JNDITestSupport extends TestCase {
|
||||||
|
|
||||||
private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
|
private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
|
||||||
.getLog(JNDITestSupport.class);
|
.getLog(JNDITestSupport.class);
|
||||||
|
|
||||||
protected Hashtable environment = new Hashtable();
|
protected Hashtable<String, String> environment = new Hashtable<String, String>();
|
||||||
protected Context context;
|
protected Context context;
|
||||||
|
|
||||||
protected void assertConnectionFactoryPresent(String lookupName) throws NamingException {
|
protected void assertConnectionFactoryPresent(String lookupName) throws NamingException {
|
||||||
|
@ -53,15 +54,16 @@ public abstract class JNDITestSupport extends TestCase {
|
||||||
assertTrue("Should have got a child context but got: " + object, object instanceof Context);
|
assertTrue("Should have got a child context but got: " + object, object instanceof Context);
|
||||||
|
|
||||||
Context childContext = (Context) object;
|
Context childContext = (Context) object;
|
||||||
NamingEnumeration iter = childContext.listBindings("");
|
NamingEnumeration<Binding> iter = childContext.listBindings("");
|
||||||
while (iter.hasMore()) {
|
while (iter.hasMore()) {
|
||||||
Binding destinationBinding = (Binding) iter.next();
|
Binding destinationBinding = iter.next();
|
||||||
LOG.info("Found destination: " + destinationBinding.getName());
|
LOG.info("Found destination: " + destinationBinding.getName());
|
||||||
Object destination = destinationBinding.getObject();
|
Object destination = destinationBinding.getObject();
|
||||||
assertTrue("Should have a Destination but got: " + destination, destination instanceof Destination);
|
assertTrue("Should have a Destination but got: " + destination, destination instanceof Destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
|
@ -77,10 +79,11 @@ public abstract class JNDITestSupport extends TestCase {
|
||||||
*
|
*
|
||||||
* @throws javax.naming.NamingException
|
* @throws javax.naming.NamingException
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void tearDown() throws NamingException, JMSException {
|
protected void tearDown() throws NamingException, JMSException {
|
||||||
NamingEnumeration iter = context.listBindings("");
|
NamingEnumeration<Binding> iter = context.listBindings("");
|
||||||
while (iter.hasMore()) {
|
while (iter.hasMore()) {
|
||||||
Binding binding = (Binding) iter.next();
|
Binding binding = iter.next();
|
||||||
Object connFactory = binding.getObject();
|
Object connFactory = binding.getObject();
|
||||||
if (connFactory instanceof ActiveMQConnectionFactory) {
|
if (connFactory instanceof ActiveMQConnectionFactory) {
|
||||||
// ((ActiveMQConnectionFactory) connFactory).stop();
|
// ((ActiveMQConnectionFactory) connFactory).stop();
|
||||||
|
|
|
@ -24,25 +24,26 @@ import javax.jms.Destination;
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class LoadController extends LoadClient{
|
public class LoadController extends LoadClient{
|
||||||
|
|
||||||
private int numberOfBatches=1;
|
private int numberOfBatches=1;
|
||||||
private int batchSize =1000;
|
private int batchSize =1000;
|
||||||
private int count;
|
private int count;
|
||||||
private final CountDownLatch stopped = new CountDownLatch(1);
|
private final CountDownLatch stopped = new CountDownLatch(1);
|
||||||
|
|
||||||
|
|
||||||
public LoadController(String name,ConnectionFactory factory) {
|
public LoadController(String name,ConnectionFactory factory) {
|
||||||
super(name,factory);
|
super(name,factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int awaitTestComplete() throws InterruptedException {
|
public int awaitTestComplete() throws InterruptedException {
|
||||||
boolean complete = stopped.await(60*5,TimeUnit.SECONDS);
|
stopped.await(60*5,TimeUnit.SECONDS);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void stop() throws JMSException, InterruptedException {
|
public void stop() throws JMSException, InterruptedException {
|
||||||
running = false;
|
running = false;
|
||||||
stopped.countDown();
|
stopped.countDown();
|
||||||
|
@ -50,7 +51,8 @@ public class LoadController extends LoadClient{
|
||||||
this.connection.stop();
|
this.connection.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < numberOfBatches; i++) {
|
for (int i = 0; i < numberOfBatches; i++) {
|
||||||
|
@ -73,33 +75,29 @@ public class LoadController extends LoadClient{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getNumberOfBatches() {
|
public int getNumberOfBatches() {
|
||||||
return numberOfBatches;
|
return numberOfBatches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setNumberOfBatches(int numberOfBatches) {
|
public void setNumberOfBatches(int numberOfBatches) {
|
||||||
this.numberOfBatches = numberOfBatches;
|
this.numberOfBatches = numberOfBatches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getBatchSize() {
|
public int getBatchSize() {
|
||||||
return batchSize;
|
return batchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setBatchSize(int batchSize) {
|
public void setBatchSize(int batchSize) {
|
||||||
this.batchSize = batchSize;
|
this.batchSize = batchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected Destination getSendDestination() {
|
protected Destination getSendDestination() {
|
||||||
return startDestination;
|
return startDestination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected Destination getConsumeDestination() {
|
protected Destination getConsumeDestination() {
|
||||||
return nextDestination;
|
return nextDestination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,30 +16,25 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.memory;
|
package org.apache.activemq.memory;
|
||||||
|
|
||||||
import java.io.File;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
|
||||||
import org.apache.activemq.broker.BrokerFactory;
|
import org.apache.activemq.broker.BrokerFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.xbean.BrokerFactoryBean;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
public class MemoryPropertyTest extends TestCase {
|
public class MemoryPropertyTest extends TestCase {
|
||||||
|
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(MemoryPropertyTest.class);
|
private static final transient Logger LOG = LoggerFactory.getLogger(MemoryPropertyTest.class);
|
||||||
BrokerService broker;
|
BrokerService broker;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up a test where the producer and consumer have their own connection.
|
* Sets up a test where the producer and consumer have their own connection.
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#setUp()
|
* @see junit.framework.TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
// Create broker from resource
|
// Create broker from resource
|
||||||
LOG.info("Creating broker... ");
|
LOG.info("Creating broker... ");
|
||||||
|
@ -47,17 +42,17 @@ public class MemoryPropertyTest extends TestCase {
|
||||||
LOG.info("Success");
|
LOG.info("Success");
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BrokerService createBroker(String resource) throws Exception {
|
protected BrokerService createBroker(String resource) throws Exception {
|
||||||
return BrokerFactory.createBroker(resource);
|
return BrokerFactory.createBroker(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stops the Broker
|
* Stops the Broker
|
||||||
*
|
*
|
||||||
* @see junit.framework.TestCase#tearDown()
|
* @see junit.framework.TestCase#tearDown()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
LOG.info("Closing Broker");
|
LOG.info("Closing Broker");
|
||||||
if (broker != null) {
|
if (broker != null) {
|
||||||
|
@ -66,18 +61,15 @@ public class MemoryPropertyTest extends TestCase {
|
||||||
LOG.info("Broker closed...");
|
LOG.info("Broker closed...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void testBrokerInitialized() {
|
public void testBrokerInitialized() {
|
||||||
assertTrue("We should have a broker", broker != null);
|
assertTrue("We should have a broker", broker != null);
|
||||||
|
|
||||||
assertEquals("test-broker", broker.getBrokerName());
|
assertEquals("test-broker", broker.getBrokerName());
|
||||||
assertEquals(1024, broker.getSystemUsage().getMemoryUsage().getLimit());
|
assertEquals(1024, broker.getSystemUsage().getMemoryUsage().getLimit());
|
||||||
assertEquals(34, broker.getSystemUsage().getMemoryUsage().getPercentUsageMinDelta());
|
assertEquals(34, broker.getSystemUsage().getMemoryUsage().getPercentUsageMinDelta());
|
||||||
|
|
||||||
assertNotNull(broker.getSystemUsage().getStoreUsage().getStore());
|
assertNotNull(broker.getSystemUsage().getStoreUsage().getStore());
|
||||||
// non persistent broker so no temp storage
|
// non persistent broker so no temp storage
|
||||||
assertNull(broker.getSystemUsage().getTempUsage().getStore());
|
assertNull(broker.getSystemUsage().getTempUsage().getStore());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.network;
|
package org.apache.activemq.network;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertNotNull;
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.activemq.network;
|
||||||
import javax.jms.DeliveryMode;
|
import javax.jms.DeliveryMode;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
|
||||||
import org.apache.activemq.broker.StubConnection;
|
import org.apache.activemq.broker.StubConnection;
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.apache.activemq.command.ConnectionInfo;
|
import org.apache.activemq.command.ConnectionInfo;
|
||||||
|
@ -78,9 +79,10 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport {
|
||||||
|
|
||||||
// Make sure the message was delivered via the remote.
|
// Make sure the message was delivered via the remote.
|
||||||
assertTrue("message was received", Wait.waitFor(new Wait.Condition() {
|
assertTrue("message was received", Wait.waitFor(new Wait.Condition() {
|
||||||
|
@Override
|
||||||
public boolean isSatisified() throws Exception {
|
public boolean isSatisified() throws Exception {
|
||||||
return receiveMessage(connection2) != null;
|
return receiveMessage(connection2) != null;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,9 +124,10 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport {
|
||||||
// Send the message to the local boker.
|
// Send the message to the local boker.
|
||||||
connection1.request(createMessage(producerInfo, destination, deliveryMode));
|
connection1.request(createMessage(producerInfo, destination, deliveryMode));
|
||||||
// Make sure the message was delivered via the remote.
|
// Make sure the message was delivered via the remote.
|
||||||
Message m = receiveMessage(connection2);
|
receiveMessage(connection2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
|
NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
|
||||||
|
@ -135,6 +138,7 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport {
|
||||||
bridge.start();
|
bridge.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
bridge.stop();
|
bridge.stop();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
|
|
@ -16,16 +16,16 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.network;
|
package org.apache.activemq.network;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import javax.jms.MessageProducer;
|
import javax.jms.MessageProducer;
|
||||||
import javax.jms.TemporaryQueue;
|
import javax.jms.TemporaryQueue;
|
||||||
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.util.Wait;
|
import org.apache.activemq.util.Wait;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class DuplexNetworkTest extends SimpleNetworkTest {
|
public class DuplexNetworkTest extends SimpleNetworkTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,19 +16,20 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.network;
|
package org.apache.activemq.network;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import javax.jms.MessageProducer;
|
||||||
|
import javax.jms.TemporaryQueue;
|
||||||
|
|
||||||
import org.apache.activemq.advisory.AdvisorySupport;
|
import org.apache.activemq.advisory.AdvisorySupport;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.TransportConnection;
|
import org.apache.activemq.broker.TransportConnection;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.jms.MessageProducer;
|
|
||||||
import javax.jms.TemporaryQueue;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
import static junit.framework.Assert.assertFalse;
|
|
||||||
import static junit.framework.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
|
* @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -16,40 +16,22 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.network;
|
package org.apache.activemq.network;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.jms.Connection;
|
import javax.jms.Connection;
|
||||||
import javax.jms.DeliveryMode;
|
|
||||||
import javax.jms.Destination;
|
|
||||||
import javax.jms.JMSException;
|
|
||||||
import javax.jms.Message;
|
|
||||||
import javax.jms.MessageConsumer;
|
|
||||||
import javax.jms.MessageListener;
|
|
||||||
import javax.jms.MessageProducer;
|
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
import javax.jms.TextMessage;
|
|
||||||
import javax.jms.TopicRequestor;
|
|
||||||
import javax.jms.TopicSession;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.apache.activemq.command.ActiveMQTopic;
|
import org.apache.activemq.command.ActiveMQTopic;
|
||||||
import org.apache.activemq.xbean.BrokerFactoryBean;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.context.support.AbstractApplicationContext;
|
import org.springframework.context.support.AbstractApplicationContext;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
|
|
||||||
public class NetworkConnectionsCleanedupTest extends TestCase {
|
public class NetworkConnectionsCleanedupTest extends TestCase {
|
||||||
|
|
||||||
protected static final int MESSAGE_COUNT = 10;
|
protected static final int MESSAGE_COUNT = 10;
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(NetworkConnectionsCleanedupTest.class);
|
|
||||||
|
|
||||||
protected AbstractApplicationContext context;
|
protected AbstractApplicationContext context;
|
||||||
protected Connection localConnection;
|
protected Connection localConnection;
|
||||||
|
@ -65,28 +47,25 @@ public class NetworkConnectionsCleanedupTest extends TestCase {
|
||||||
// skip this test. it runs for an hour, doesn't assert anything, and could probably
|
// skip this test. it runs for an hour, doesn't assert anything, and could probably
|
||||||
// just be removed (seems like a throwaway impl for https://issues.apache.org/activemq/browse/AMQ-1202)
|
// just be removed (seems like a throwaway impl for https://issues.apache.org/activemq/browse/AMQ-1202)
|
||||||
public void skipTestNetworkConnections() throws Exception {
|
public void skipTestNetworkConnections() throws Exception {
|
||||||
String uri = "static:(tcp://localhost:61617)?initialReconnectDelay=100";
|
String uri = "static:(tcp://localhost:61617)?initialReconnectDelay=100";
|
||||||
List<ActiveMQDestination> list = new ArrayList<ActiveMQDestination>();
|
List<ActiveMQDestination> list = new ArrayList<ActiveMQDestination>();
|
||||||
for (int i =0;i < 100;i++){
|
for (int i =0;i < 100;i++){
|
||||||
list.add(new ActiveMQTopic("FOO"+i));
|
list.add(new ActiveMQTopic("FOO"+i));
|
||||||
}
|
}
|
||||||
String bindAddress = "tcp://localhost:61616";
|
String bindAddress = "tcp://localhost:61616";
|
||||||
BrokerService broker = new BrokerService();
|
BrokerService broker = new BrokerService();
|
||||||
broker.setUseJmx(false);
|
broker.setUseJmx(false);
|
||||||
broker.setPersistent(false);
|
broker.setPersistent(false);
|
||||||
broker.addConnector(bindAddress);
|
broker.addConnector(bindAddress);
|
||||||
NetworkConnector network = broker.addNetworkConnector(uri);
|
NetworkConnector network = broker.addNetworkConnector(uri);
|
||||||
network.setDynamicOnly(true);
|
|
||||||
network.setStaticallyIncludedDestinations(list);
|
|
||||||
uri = "static:(tcp://localhost:61618)?initialReconnectDelay=100";
|
|
||||||
network = broker.addNetworkConnector(uri);
|
|
||||||
network.setDynamicOnly(true);
|
network.setDynamicOnly(true);
|
||||||
network.setStaticallyIncludedDestinations(list);
|
network.setStaticallyIncludedDestinations(list);
|
||||||
broker.setUseShutdownHook(false);
|
uri = "static:(tcp://localhost:61618)?initialReconnectDelay=100";
|
||||||
broker.start();
|
network = broker.addNetworkConnector(uri);
|
||||||
Thread.sleep(1000 * 3600);
|
network.setDynamicOnly(true);
|
||||||
|
network.setStaticallyIncludedDestinations(list);
|
||||||
|
broker.setUseShutdownHook(false);
|
||||||
|
broker.start();
|
||||||
|
Thread.sleep(1000 * 3600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ import org.apache.activemq.ActiveMQConnection;
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.DestinationDoesNotExistException;
|
import org.apache.activemq.DestinationDoesNotExistException;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.region.policy.AbstractDeadLetterStrategy;
|
|
||||||
import org.apache.activemq.broker.region.policy.SharedDeadLetterStrategy;
|
import org.apache.activemq.broker.region.policy.SharedDeadLetterStrategy;
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
import org.apache.activemq.transport.TransportFilter;
|
import org.apache.activemq.transport.TransportFilter;
|
||||||
|
@ -62,9 +61,9 @@ public class NetworkFailoverTest extends TestCase {
|
||||||
protected Session localSession;
|
protected Session localSession;
|
||||||
protected Session remoteSession;
|
protected Session remoteSession;
|
||||||
protected ActiveMQQueue included=new ActiveMQQueue("include.test.foo");
|
protected ActiveMQQueue included=new ActiveMQQueue("include.test.foo");
|
||||||
private AtomicInteger replyToNonExistDest = new AtomicInteger(0);
|
private final AtomicInteger replyToNonExistDest = new AtomicInteger(0);
|
||||||
private AtomicInteger roundTripComplete = new AtomicInteger(0);
|
private final AtomicInteger roundTripComplete = new AtomicInteger(0);
|
||||||
private AtomicInteger remoteDLQCount = new AtomicInteger(0);
|
private final AtomicInteger remoteDLQCount = new AtomicInteger(0);
|
||||||
|
|
||||||
public void testRequestReply() throws Exception {
|
public void testRequestReply() throws Exception {
|
||||||
final MessageProducer remoteProducer = remoteSession.createProducer(null);
|
final MessageProducer remoteProducer = remoteSession.createProducer(null);
|
||||||
|
@ -116,7 +115,7 @@ public class NetworkFailoverTest extends TestCase {
|
||||||
remoteDLQCount.incrementAndGet();
|
remoteDLQCount.incrementAndGet();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// allow for consumer infos to perculate arround
|
// allow for consumer infos to perculate arround
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
long done = System.currentTimeMillis() + (MESSAGE_COUNT * 6000);
|
long done = System.currentTimeMillis() + (MESSAGE_COUNT * 6000);
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.activemq.command.ActiveMQTopic;
|
||||||
/**
|
/**
|
||||||
* Various Tests to show the memory leak suspect in network of brokers. This is
|
* Various Tests to show the memory leak suspect in network of brokers. This is
|
||||||
* for https://issues.apache.org/activemq/browse/AMQ-2530
|
* for https://issues.apache.org/activemq/browse/AMQ-2530
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NetworkRemovesSubscriptionsTest extends TestCase {
|
public class NetworkRemovesSubscriptionsTest extends TestCase {
|
||||||
private final static String frontEndAddress = "tcp://0.0.0.0:61617";
|
private final static String frontEndAddress = "tcp://0.0.0.0:61617";
|
||||||
|
@ -109,6 +109,7 @@ public class NetworkRemovesSubscriptionsTest extends TestCase {
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
|
TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
|
TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
|
||||||
|
assertNotNull(subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.close();
|
connection.close();
|
||||||
|
@ -121,7 +122,7 @@ public class NetworkRemovesSubscriptionsTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Running this test you can produce a leak of only 2 ConsumerInfo on BE
|
* Running this test you can produce a leak of only 2 ConsumerInfo on BE
|
||||||
* broker, NOT 200 as in other cases!
|
* broker, NOT 200 as in other cases!
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void testWithoutSessionAndSubsciberClosePlayAround() throws Exception {
|
public void testWithoutSessionAndSubsciberClosePlayAround() throws Exception {
|
||||||
|
|
||||||
|
@ -148,6 +149,7 @@ public class NetworkRemovesSubscriptionsTest extends TestCase {
|
||||||
|
|
||||||
class DummyMessageListener implements MessageListener {
|
class DummyMessageListener implements MessageListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onMessage(Message arg0) {
|
public void onMessage(Message arg0) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.apache.activemq.usage.SystemUsage;
|
||||||
|
|
||||||
public class NetworkTestSupport extends BrokerTestSupport {
|
public class NetworkTestSupport extends BrokerTestSupport {
|
||||||
|
|
||||||
protected ArrayList connections = new ArrayList();
|
protected ArrayList<StubConnection> connections = new ArrayList<StubConnection>();
|
||||||
|
|
||||||
protected TransportConnector connector;
|
protected TransportConnector connector;
|
||||||
|
|
||||||
|
@ -46,18 +46,19 @@ public class NetworkTestSupport extends BrokerTestSupport {
|
||||||
protected TransportConnector remoteConnector;
|
protected TransportConnector remoteConnector;
|
||||||
protected boolean useJmx = false;
|
protected boolean useJmx = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
remotePersistenceAdapter = createRemotePersistenceAdapter(true);
|
remotePersistenceAdapter = createRemotePersistenceAdapter(true);
|
||||||
remoteBroker = createRemoteBroker(remotePersistenceAdapter);
|
remoteBroker = createRemoteBroker(remotePersistenceAdapter);
|
||||||
remoteConnector = createRemoteConnector();
|
remoteConnector = createRemoteConnector();
|
||||||
remoteBroker.addConnector( remoteConnector );
|
remoteBroker.addConnector( remoteConnector );
|
||||||
BrokerRegistry.getInstance().bind("remotehost", remoteBroker);
|
BrokerRegistry.getInstance().bind("remotehost", remoteBroker);
|
||||||
remoteBroker.start();
|
remoteBroker.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createBroker() throws Exception {
|
protected BrokerService createBroker() throws Exception {
|
||||||
BrokerService broker = BrokerFactory.createBroker(new URI("broker:()/localhost?persistent=false&useJmx=false&"));
|
BrokerService broker = BrokerFactory.createBroker(new URI("broker:()/localhost?persistent=false&useJmx=false&"));
|
||||||
connector = createConnector();
|
connector = createConnector();
|
||||||
|
@ -66,7 +67,6 @@ public class NetworkTestSupport extends BrokerTestSupport {
|
||||||
return broker;
|
return broker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -111,6 +111,7 @@ public class NetworkTestSupport extends BrokerTestSupport {
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected StubConnection createConnection() throws Exception {
|
protected StubConnection createConnection() throws Exception {
|
||||||
Transport transport = TransportFactory.connect(connector.getServer().getConnectURI());
|
Transport transport = TransportFactory.connect(connector.getServer().getConnectURI());
|
||||||
StubConnection connection = new StubConnection(transport);
|
StubConnection connection = new StubConnection(transport);
|
||||||
|
@ -138,7 +139,7 @@ public class NetworkTestSupport extends BrokerTestSupport {
|
||||||
/**
|
/**
|
||||||
* Simulates a broker restart. The memory based persistence adapter is
|
* Simulates a broker restart. The memory based persistence adapter is
|
||||||
* reused so that it does not "loose" it's "persistent" messages.
|
* reused so that it does not "loose" it's "persistent" messages.
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected void restartRemoteBroker() throws Exception {
|
protected void restartRemoteBroker() throws Exception {
|
||||||
|
@ -150,16 +151,17 @@ public class NetworkTestSupport extends BrokerTestSupport {
|
||||||
remotePersistenceAdapter.stop();
|
remotePersistenceAdapter.stop();
|
||||||
remotePersistenceAdapter = createRemotePersistenceAdapter(false);
|
remotePersistenceAdapter = createRemotePersistenceAdapter(false);
|
||||||
remotePersistenceAdapter.start();
|
remotePersistenceAdapter.start();
|
||||||
|
|
||||||
remoteBroker = createRemoteBroker(remotePersistenceAdapter);
|
remoteBroker = createRemoteBroker(remotePersistenceAdapter);
|
||||||
remoteBroker.addConnector(getRemoteURI());
|
remoteBroker.addConnector(getRemoteURI());
|
||||||
remoteBroker.start();
|
remoteBroker.start();
|
||||||
BrokerRegistry.getInstance().bind("remotehost", remoteBroker);
|
BrokerRegistry.getInstance().bind("remotehost", remoteBroker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
for (Iterator iter = connections.iterator(); iter.hasNext();) {
|
for (Iterator<StubConnection> iter = connections.iterator(); iter.hasNext();) {
|
||||||
StubConnection connection = (StubConnection)iter.next();
|
StubConnection connection = iter.next();
|
||||||
connection.stop();
|
connection.stop();
|
||||||
iter.remove();
|
iter.remove();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,45 +20,43 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.apache.activemq.broker.BrokerFactory;
|
import org.apache.activemq.broker.BrokerFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test network reconnects over SSH tunnels. This case can be especially tricky
|
* Test network reconnects over SSH tunnels. This case can be especially tricky
|
||||||
* since the SSH tunnels fool the TCP transport into thinking that they are
|
* since the SSH tunnels fool the TCP transport into thinking that they are
|
||||||
* initially connected.
|
* initially connected.
|
||||||
*
|
*
|
||||||
* @author chirino
|
|
||||||
*/
|
*/
|
||||||
public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest {
|
public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest {
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(SSHTunnelNetworkReconnectTest.class);
|
|
||||||
|
|
||||||
ArrayList processes = new ArrayList();
|
ArrayList<Process> processes = new ArrayList<Process>();
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createFirstBroker() throws Exception {
|
protected BrokerService createFirstBroker() throws Exception {
|
||||||
return BrokerFactory
|
return BrokerFactory
|
||||||
.createBroker(new URI("xbean:org/apache/activemq/network/ssh-reconnect-broker1.xml"));
|
.createBroker(new URI("xbean:org/apache/activemq/network/ssh-reconnect-broker1.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected BrokerService createSecondBroker() throws Exception {
|
protected BrokerService createSecondBroker() throws Exception {
|
||||||
return BrokerFactory
|
return BrokerFactory
|
||||||
.createBroker(new URI("xbean:org/apache/activemq/network/ssh-reconnect-broker2.xml"));
|
.createBroker(new URI("xbean:org/apache/activemq/network/ssh-reconnect-broker2.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
startProcess("ssh -Nn -L60006:localhost:61616 localhost");
|
startProcess("ssh -Nn -L60006:localhost:61616 localhost");
|
||||||
startProcess("ssh -Nn -L60007:localhost:61617 localhost");
|
startProcess("ssh -Nn -L60007:localhost:61617 localhost");
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
for (Iterator iter = processes.iterator(); iter.hasNext();) {
|
for (Process p : processes) {
|
||||||
Process p = (Process)iter.next();
|
|
||||||
p.destroy();
|
p.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +65,7 @@ public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest {
|
||||||
final Process process = Runtime.getRuntime().exec(command);
|
final Process process = Runtime.getRuntime().exec(command);
|
||||||
processes.add(process);
|
processes.add(process);
|
||||||
new Thread("stdout: " + command) {
|
new Thread("stdout: " + command) {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
InputStream is = process.getInputStream();
|
InputStream is = process.getInputStream();
|
||||||
|
@ -79,6 +78,7 @@ public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest {
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
new Thread("stderr: " + command) {
|
new Thread("stderr: " + command) {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
InputStream is = process.getErrorStream();
|
InputStream is = process.getErrorStream();
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.network;
|
package org.apache.activemq.network;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static junit.framework.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -103,6 +103,7 @@ public class SimpleNetworkTest {
|
||||||
final MessageProducer remoteProducer = remoteSession.createProducer(null);
|
final MessageProducer remoteProducer = remoteSession.createProducer(null);
|
||||||
MessageConsumer remoteConsumer = remoteSession.createConsumer(included);
|
MessageConsumer remoteConsumer = remoteSession.createConsumer(included);
|
||||||
remoteConsumer.setMessageListener(new MessageListener() {
|
remoteConsumer.setMessageListener(new MessageListener() {
|
||||||
|
@Override
|
||||||
public void onMessage(Message msg) {
|
public void onMessage(Message msg) {
|
||||||
try {
|
try {
|
||||||
TextMessage textMsg = (TextMessage)msg;
|
TextMessage textMsg = (TextMessage)msg;
|
||||||
|
|
|
@ -16,7 +16,19 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.network.jms;
|
package org.apache.activemq.network.jms;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.jms.Connection;
|
||||||
|
import javax.jms.Destination;
|
||||||
|
import javax.jms.JMSException;
|
||||||
|
import javax.jms.Message;
|
||||||
|
import javax.jms.MessageConsumer;
|
||||||
|
import javax.jms.MessageProducer;
|
||||||
|
import javax.jms.Session;
|
||||||
|
import javax.jms.TextMessage;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
@ -25,17 +37,9 @@ import org.apache.activemq.util.Wait;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import javax.jms.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
public class QueueBridgeStandaloneReconnectTest {
|
public class QueueBridgeStandaloneReconnectTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(QueueBridgeStandaloneReconnectTest.class);
|
|
||||||
|
|
||||||
private SimpleJmsQueueConnector jmsQueueConnector;
|
private SimpleJmsQueueConnector jmsQueueConnector;
|
||||||
|
|
||||||
private BrokerService localBroker;
|
private BrokerService localBroker;
|
||||||
|
@ -47,7 +51,7 @@ public class QueueBridgeStandaloneReconnectTest {
|
||||||
private Destination outbound;
|
private Destination outbound;
|
||||||
private Destination inbound;
|
private Destination inbound;
|
||||||
|
|
||||||
private ArrayList<Connection> connections = new ArrayList<Connection>();
|
private final ArrayList<Connection> connections = new ArrayList<Connection>();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendAndReceiveOverConnectedBridges() throws Exception {
|
public void testSendAndReceiveOverConnectedBridges() throws Exception {
|
||||||
|
|
|
@ -16,7 +16,23 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.network.jms;
|
package org.apache.activemq.network.jms;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.jms.Connection;
|
||||||
|
import javax.jms.Destination;
|
||||||
|
import javax.jms.JMSException;
|
||||||
|
import javax.jms.Message;
|
||||||
|
import javax.jms.MessageConsumer;
|
||||||
|
import javax.jms.MessageProducer;
|
||||||
|
import javax.jms.Session;
|
||||||
|
import javax.jms.TextMessage;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
@ -25,13 +41,6 @@ import org.apache.activemq.util.Wait;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import javax.jms.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These test cases are used to verify that queue outbound bridge connections get
|
* These test cases are used to verify that queue outbound bridge connections get
|
||||||
|
@ -40,14 +49,12 @@ import java.util.concurrent.TimeUnit;
|
||||||
*/
|
*/
|
||||||
public class QueueOutboundBridgeReconnectTest {
|
public class QueueOutboundBridgeReconnectTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(QueueOutboundBridgeReconnectTest.class);
|
|
||||||
|
|
||||||
private BrokerService producerBroker;
|
private BrokerService producerBroker;
|
||||||
private BrokerService consumerBroker;
|
private BrokerService consumerBroker;
|
||||||
private ActiveMQConnectionFactory producerConnectionFactory;
|
private ActiveMQConnectionFactory producerConnectionFactory;
|
||||||
private ActiveMQConnectionFactory consumerConnectionFactory;
|
private ActiveMQConnectionFactory consumerConnectionFactory;
|
||||||
private Destination destination;
|
private Destination destination;
|
||||||
private ArrayList<Connection> connections = new ArrayList<Connection>();
|
private final ArrayList<Connection> connections = new ArrayList<Connection>();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleProducerBrokerRestarts() throws Exception {
|
public void testMultipleProducerBrokerRestarts() throws Exception {
|
||||||
|
|
|
@ -16,7 +16,19 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.network.jms;
|
package org.apache.activemq.network.jms;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.jms.Connection;
|
||||||
|
import javax.jms.Destination;
|
||||||
|
import javax.jms.JMSException;
|
||||||
|
import javax.jms.Message;
|
||||||
|
import javax.jms.MessageConsumer;
|
||||||
|
import javax.jms.MessageProducer;
|
||||||
|
import javax.jms.Session;
|
||||||
|
import javax.jms.TextMessage;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
@ -25,17 +37,9 @@ import org.apache.activemq.util.Wait;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import javax.jms.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
public class TopicBridgeStandaloneReconnectTest {
|
public class TopicBridgeStandaloneReconnectTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(TopicBridgeStandaloneReconnectTest.class);
|
|
||||||
|
|
||||||
private SimpleJmsTopicConnector jmsTopicConnector;
|
private SimpleJmsTopicConnector jmsTopicConnector;
|
||||||
|
|
||||||
private BrokerService localBroker;
|
private BrokerService localBroker;
|
||||||
|
@ -47,7 +51,7 @@ public class TopicBridgeStandaloneReconnectTest {
|
||||||
private Destination outbound;
|
private Destination outbound;
|
||||||
private Destination inbound;
|
private Destination inbound;
|
||||||
|
|
||||||
private ArrayList<Connection> connections = new ArrayList<Connection>();
|
private final ArrayList<Connection> connections = new ArrayList<Connection>();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendAndReceiveOverConnectedBridges() throws Exception {
|
public void testSendAndReceiveOverConnectedBridges() throws Exception {
|
||||||
|
|
|
@ -16,7 +16,23 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.network.jms;
|
package org.apache.activemq.network.jms;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.jms.Connection;
|
||||||
|
import javax.jms.Destination;
|
||||||
|
import javax.jms.JMSException;
|
||||||
|
import javax.jms.Message;
|
||||||
|
import javax.jms.MessageConsumer;
|
||||||
|
import javax.jms.MessageProducer;
|
||||||
|
import javax.jms.Session;
|
||||||
|
import javax.jms.TextMessage;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
@ -25,14 +41,6 @@ import org.apache.activemq.util.Wait;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import javax.jms.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These test cases are used to verify that queue outbound bridge connections get
|
* These test cases are used to verify that queue outbound bridge connections get
|
||||||
|
@ -41,14 +49,12 @@ import java.util.concurrent.TimeUnit;
|
||||||
*/
|
*/
|
||||||
public class TopicOutboundBridgeReconnectTest {
|
public class TopicOutboundBridgeReconnectTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(TopicOutboundBridgeReconnectTest.class);
|
|
||||||
|
|
||||||
private BrokerService producerBroker;
|
private BrokerService producerBroker;
|
||||||
private BrokerService consumerBroker;
|
private BrokerService consumerBroker;
|
||||||
private ActiveMQConnectionFactory producerConnectionFactory;
|
private ActiveMQConnectionFactory producerConnectionFactory;
|
||||||
private ActiveMQConnectionFactory consumerConnectionFactory;
|
private ActiveMQConnectionFactory consumerConnectionFactory;
|
||||||
private Destination destination;
|
private Destination destination;
|
||||||
private ArrayList<Connection> connections = new ArrayList<Connection>();
|
private final ArrayList<Connection> connections = new ArrayList<Connection>();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleProducerBrokerRestarts() throws Exception {
|
public void testMultipleProducerBrokerRestarts() throws Exception {
|
||||||
|
|
|
@ -26,7 +26,7 @@ import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BooleanStreamTest extends TestCase {
|
public class BooleanStreamTest extends TestCase {
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ public class BooleanStreamTest extends TestCase {
|
||||||
|
|
||||||
public void testBooleanMarshallingUsingAllTrue() throws Exception {
|
public void testBooleanMarshallingUsingAllTrue() throws Exception {
|
||||||
testBooleanStream(numberOfBytes, new BooleanValueSet() {
|
testBooleanStream(numberOfBytes, new BooleanValueSet() {
|
||||||
|
@Override
|
||||||
public boolean getBooleanValueFor(int index, int count) {
|
public boolean getBooleanValueFor(int index, int count) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -48,6 +49,7 @@ public class BooleanStreamTest extends TestCase {
|
||||||
|
|
||||||
public void testBooleanMarshallingUsingAllFalse() throws Exception {
|
public void testBooleanMarshallingUsingAllFalse() throws Exception {
|
||||||
testBooleanStream(numberOfBytes, new BooleanValueSet() {
|
testBooleanStream(numberOfBytes, new BooleanValueSet() {
|
||||||
|
@Override
|
||||||
public boolean getBooleanValueFor(int index, int count) {
|
public boolean getBooleanValueFor(int index, int count) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -56,6 +58,7 @@ public class BooleanStreamTest extends TestCase {
|
||||||
|
|
||||||
public void testBooleanMarshallingUsingOddAlternateTrueFalse() throws Exception {
|
public void testBooleanMarshallingUsingOddAlternateTrueFalse() throws Exception {
|
||||||
testBooleanStream(numberOfBytes, new BooleanValueSet() {
|
testBooleanStream(numberOfBytes, new BooleanValueSet() {
|
||||||
|
@Override
|
||||||
public boolean getBooleanValueFor(int index, int count) {
|
public boolean getBooleanValueFor(int index, int count) {
|
||||||
return (index & 1) == 0;
|
return (index & 1) == 0;
|
||||||
}
|
}
|
||||||
|
@ -64,6 +67,7 @@ public class BooleanStreamTest extends TestCase {
|
||||||
|
|
||||||
public void testBooleanMarshallingUsingEvenAlternateTrueFalse() throws Exception {
|
public void testBooleanMarshallingUsingEvenAlternateTrueFalse() throws Exception {
|
||||||
testBooleanStream(numberOfBytes, new BooleanValueSet() {
|
testBooleanStream(numberOfBytes, new BooleanValueSet() {
|
||||||
|
@Override
|
||||||
public boolean getBooleanValueFor(int index, int count) {
|
public boolean getBooleanValueFor(int index, int count) {
|
||||||
return (index & 1) != 0;
|
return (index & 1) != 0;
|
||||||
}
|
}
|
||||||
|
@ -121,13 +125,14 @@ public class BooleanStreamTest extends TestCase {
|
||||||
|
|
||||||
// lets try read and we should get an exception
|
// lets try read and we should get an exception
|
||||||
try {
|
try {
|
||||||
byte value = dis.readByte();
|
dis.readByte();
|
||||||
fail("Should have reached the end of the stream");
|
fail("Should have reached the end of the stream");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// worked!
|
// worked!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
openWireformat = createOpenWireFormat();
|
openWireformat = createOpenWireFormat();
|
||||||
|
|
|
@ -25,11 +25,8 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
public abstract class DataFileGenerator extends org.junit.Assert {
|
||||||
|
|
||||||
public abstract class DataFileGenerator extends Assert {
|
|
||||||
|
|
||||||
static final File MODULE_BASE_DIR;
|
static final File MODULE_BASE_DIR;
|
||||||
static final File CONTROL_DIR;
|
static final File CONTROL_DIR;
|
||||||
|
@ -52,16 +49,16 @@ public abstract class DataFileGenerator extends Assert {
|
||||||
* @throws InstantiationException
|
* @throws InstantiationException
|
||||||
* @throws IllegalAccessException
|
* @throws IllegalAccessException
|
||||||
*/
|
*/
|
||||||
public static ArrayList getAllDataFileGenerators() throws Exception {
|
public static ArrayList<DataFileGenerator> getAllDataFileGenerators() throws Exception {
|
||||||
// System.out.println("Looking for generators in : "+classFileDir);
|
// System.out.println("Looking for generators in : "+classFileDir);
|
||||||
ArrayList l = new ArrayList();
|
ArrayList<DataFileGenerator> l = new ArrayList<DataFileGenerator>();
|
||||||
File[] files = CLASS_FILE_DIR.listFiles();
|
File[] files = CLASS_FILE_DIR.listFiles();
|
||||||
for (int i = 0; files != null && i < files.length; i++) {
|
for (int i = 0; files != null && i < files.length; i++) {
|
||||||
File file = files[i];
|
File file = files[i];
|
||||||
if (file.getName().endsWith("Data.java")) {
|
if (file.getName().endsWith("Data.java")) {
|
||||||
String cn = file.getName();
|
String cn = file.getName();
|
||||||
cn = cn.substring(0, cn.length() - ".java".length());
|
cn = cn.substring(0, cn.length() - ".java".length());
|
||||||
Class clazz = DataFileGenerator.class.getClassLoader().loadClass("org.apache.activemq.openwire." + cn);
|
Class<?> clazz = DataFileGenerator.class.getClassLoader().loadClass("org.apache.activemq.openwire." + cn);
|
||||||
l.add((DataFileGenerator)clazz.newInstance());
|
l.add((DataFileGenerator)clazz.newInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,12 +66,11 @@ public abstract class DataFileGenerator extends Assert {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generateControlFiles() throws Exception {
|
private static void generateControlFiles() throws Exception {
|
||||||
ArrayList generators = getAllDataFileGenerators();
|
ArrayList<DataFileGenerator> generators = getAllDataFileGenerators();
|
||||||
for (Iterator iter = generators.iterator(); iter.hasNext();) {
|
for (DataFileGenerator element : generators) {
|
||||||
DataFileGenerator object = (DataFileGenerator)iter.next();
|
|
||||||
try {
|
try {
|
||||||
// System.out.println("Processing: "+object.getClass());
|
// System.out.println("Processing: "+object.getClass());
|
||||||
object.generateControlFile();
|
element.generateControlFile();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// System.err.println("Error while processing:
|
// System.err.println("Error while processing:
|
||||||
// "+object.getClass() + ". Reason: " + e);
|
// "+object.getClass() + ". Reason: " + e);
|
||||||
|
@ -112,11 +108,10 @@ public abstract class DataFileGenerator extends Assert {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertAllControlFileAreEqual() throws Exception {
|
public static void assertAllControlFileAreEqual() throws Exception {
|
||||||
ArrayList generators = getAllDataFileGenerators();
|
ArrayList<DataFileGenerator> generators = getAllDataFileGenerators();
|
||||||
for (Iterator iter = generators.iterator(); iter.hasNext();) {
|
for (DataFileGenerator element : generators) {
|
||||||
DataFileGenerator object = (DataFileGenerator)iter.next();
|
|
||||||
// System.out.println("Processing: "+object.getClass());
|
// System.out.println("Processing: "+object.getClass());
|
||||||
object.assertControlFileIsEqual();
|
element.assertControlFileIsEqual();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport {
|
||||||
} else if (expectedValue instanceof DataStructure) {
|
} else if (expectedValue instanceof DataStructure) {
|
||||||
assertBeansEqual(message + name, comparedObjects, expectedValue, actualValue);
|
assertBeansEqual(message + name, comparedObjects, expectedValue, actualValue);
|
||||||
} else if (expectedValue instanceof Enumeration) {
|
} else if (expectedValue instanceof Enumeration) {
|
||||||
assertEnumerationEqual(message + name, comparedObjects, (Enumeration)expectedValue, (Enumeration)actualValue);
|
assertEnumerationEqual(message + name, comparedObjects, (Enumeration<?>)expectedValue, (Enumeration<?>)actualValue);
|
||||||
} else {
|
} else {
|
||||||
assertEquals(message, expectedValue, actualValue);
|
assertEquals(message, expectedValue, actualValue);
|
||||||
}
|
}
|
||||||
|
@ -166,12 +166,12 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport {
|
||||||
assertPropertyValuesEqual(message + ". element: " + i, comparedObjects, expected[i], actual[i]);
|
assertPropertyValuesEqual(message + ". element: " + i, comparedObjects, expected[i], actual[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertEnumerationEqual(String message, Set<Object> comparedObjects, Enumeration expected, Enumeration actual) throws Exception {
|
protected void assertEnumerationEqual(String message, Set<Object> comparedObjects, Enumeration<?> expected, Enumeration<?> actual) throws Exception {
|
||||||
while (expected.hasMoreElements()) {
|
while (expected.hasMoreElements()) {
|
||||||
Object expectedElem = expected.nextElement();
|
Object expectedElem = expected.nextElement();
|
||||||
Object actualElem = actual.nextElement();
|
Object actualElem = actual.nextElement();
|
||||||
assertPropertyValuesEqual(message + ". element: " + expectedElem, comparedObjects, expectedElem, actualElem);
|
assertPropertyValuesEqual(message + ". element: " + expectedElem, comparedObjects, expectedElem, actualElem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,6 +204,7 @@ public abstract class DataFileGeneratorTestSupport extends TestSupport {
|
||||||
assertEquals(message, expected.getMessage(), actual.getMessage());
|
assertEquals(message, expected.getMessage(), actual.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
openWireformat = createOpenWireFormat();
|
openWireformat = createOpenWireFormat();
|
||||||
|
|
|
@ -23,13 +23,14 @@ import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.activemq.command.ActiveMQTextMessage;
|
import org.apache.activemq.command.ActiveMQTextMessage;
|
||||||
import org.apache.activemq.command.SessionId;
|
import org.apache.activemq.command.SessionId;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NumberRangesWhileMarshallingTest extends TestCase {
|
public class NumberRangesWhileMarshallingTest extends TestCase {
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ public class NumberRangesWhileMarshallingTest extends TestCase {
|
||||||
// lets try read and we should get an exception
|
// lets try read and we should get an exception
|
||||||
try {
|
try {
|
||||||
byte value = dis.readByte();
|
byte value = dis.readByte();
|
||||||
fail("Should have reached the end of the stream");
|
fail("Should have reached the end of the stream: " + value);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// worked!
|
// worked!
|
||||||
}
|
}
|
||||||
|
@ -124,6 +125,7 @@ public class NumberRangesWhileMarshallingTest extends TestCase {
|
||||||
assertEquals(Long.MAX_VALUE, wf.getMaxFrameSize());
|
assertEquals(Long.MAX_VALUE, wf.getMaxFrameSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
openWireformat = createOpenWireFormat();
|
openWireformat = createOpenWireFormat();
|
||||||
|
|
Loading…
Reference in New Issue