zapped some old test cases and added a new one which ensures that the activemq.xml file shipped with the distro actually works

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@517674 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2007-03-13 12:48:52 +00:00
parent ea42012ef1
commit 274a951901
4 changed files with 37 additions and 299 deletions

View File

@ -1,60 +0,0 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.config;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
import javax.naming.InitialContext;
import javax.naming.Context;
import java.io.File;
import java.util.Hashtable;
/**
* @version $Revision: 1.2 $
*/
public class BrokerXmlConfigFromJNDITest extends JmsTopicSendReceiveWithTwoConnectionsTest {
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
// START SNIPPET: example
System.err.print(System.getProperties());
// we could put these properties into a jndi.properties
// on the classpath instead
Hashtable properties = new Hashtable();
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
// configure the embedded broker using an XML config file
// which is either a URL or a resource on the classpath
File f = new File(System.getProperty("basedir", "."));
f = new File(f, "src/sample-conf/default.xml");
properties.put("brokerXmlConfig", "file:"+f.getPath());
properties.put(Context.PROVIDER_URL, "vm://localhost");
InitialContext context = new InitialContext(properties);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
// END SNIPPET: example
return connectionFactory;
}
}

View File

@ -17,35 +17,50 @@
*/
package org.apache.activemq.config;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import java.net.URI;
import javax.jms.Connection;
import javax.jms.JMSException;
/**
* @version $Revision: 1.2 $
*/
public class BrokerXmlConfigTest extends JmsTopicSendReceiveWithTwoConnectionsTest {
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
// START SNIPPET: bean
public class BrokerXmlConfigTest extends TestCase {
private BrokerService broker;
// configure the connection factory using
// normal Java Bean property methods
public void testStartBrokerUsingXmlConfig() throws Exception {
Connection connection = null;
try {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
// configure the embedded broker using an XML config file
// which is either a URL or a resource on the classpath
// TODO ...
//connectionFactory.setBrokerXmlConfig("file:src/sample-conf/default.xml");
// you only need to configure the broker URL if you wish to change the
// default connection mechanism, which in this test case we do
connectionFactory.setBrokerURL("vm://localhost");
// END SNIPPET: bean
return connectionFactory;
connection = connectionFactory.createConnection();
connection.start();
connection.close();
connection = null;
}
catch (Exception e) {
if (connection != null) {
try {
connection.close();
}
catch (JMSException e1) {
// ignore exception as we're throwing one anyway
}
}
throw e;
}
}
protected void setUp() throws Exception {
System.setProperty("activemq.base", "target");
broker = BrokerFactory.createBroker("file:src/release/conf/activemq.xml");
}
protected void tearDown() throws Exception {
if (broker != null) {
broker.stop();
}
}
}

View File

@ -1,37 +0,0 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.transport;
/**
* @version $Revision: 1.1.1.1 $
*/
public class QueueClusterTest extends TopicClusterTest {
protected void setUp() throws Exception{
topic = false;
super.setUp();
}
protected int expectedReceiveCount(){
return MESSAGE_COUNT * NUMBER_IN_CLUSTER;
}
}

View File

@ -1,180 +0,0 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.transport;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
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.TextMessage;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.util.ServiceStopper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @version $Revision: 1.1.1.1 $
*/
public class TopicClusterTest extends TestCase implements MessageListener {
protected final static Log log = LogFactory.getLog(TopicClusterTest.class);
protected Destination destination;
protected boolean topic = true;
protected AtomicInteger receivedMessageCount = new AtomicInteger(0);
protected static int MESSAGE_COUNT = 50;
protected static int NUMBER_IN_CLUSTER = 3;
protected int deliveryMode = DeliveryMode.NON_PERSISTENT;
protected MessageProducer[] producers;
protected Connection[] connections;
protected List services = new ArrayList();
protected void setUp() throws Exception {
connections = new Connection[NUMBER_IN_CLUSTER];
producers = new MessageProducer[NUMBER_IN_CLUSTER];
Destination destination = createDestination();
int portStart = 50000;
String root = System.getProperty("activemq.store.dir");
if (root == null) {
root = "target/store";
}
try {
for (int i = 0;i < NUMBER_IN_CLUSTER;i++) {
System.setProperty("activemq.store.dir", root + "_broker_" + i);
connections[i] = createConnection("broker-" + i);
connections[i].setClientID("ClusterTest" + i);
connections[i].start();
Session session = connections[i].createSession(false, Session.AUTO_ACKNOWLEDGE);
producers[i] = session.createProducer(destination);
producers[i].setDeliveryMode(deliveryMode);
MessageConsumer consumer = createMessageConsumer(session,destination);
consumer.setMessageListener(this);
}
log.info("Sleeping to ensure cluster is fully connected");
Thread.sleep(5000);
} finally {
System.setProperty("activemq.store.dir", root);
}
}
protected void tearDown() throws Exception {
if (connections != null) {
for (int i = 0;i < connections.length;i++) {
connections[i].close();
}
}
ServiceStopper stopper = new ServiceStopper();
stopper.stopServices(services);
}
protected MessageConsumer createMessageConsumer(Session session, Destination destination) throws JMSException{
return session.createConsumer(destination);
}
protected ActiveMQConnectionFactory createGenericClusterFactory(String brokerName) throws Exception {
BrokerService container = new BrokerService();
container.setBrokerName(brokerName);
String url = "tcp://localhost:0";
TransportConnector connector = container.addConnector(url);
connector.setDiscoveryUri(new URI("multicast://default"));
container.addNetworkConnector("multicast://default");
container.start();
services.add(container);
return new ActiveMQConnectionFactory("vm://"+brokerName);
}
protected int expectedReceiveCount() {
return MESSAGE_COUNT * NUMBER_IN_CLUSTER * NUMBER_IN_CLUSTER;
}
protected Connection createConnection(String name) throws Exception {
return createGenericClusterFactory(name).createConnection();
}
protected Destination createDestination() {
return createDestination(getClass().getName());
}
protected Destination createDestination(String name) {
if (topic) {
return new ActiveMQTopic(name);
}
else {
return new ActiveMQQueue(name);
}
}
/**
* @param msg
*/
public void onMessage(Message msg) {
//log.info("GOT: " + msg);
receivedMessageCount.incrementAndGet();
synchronized (receivedMessageCount) {
if (receivedMessageCount.get() >= expectedReceiveCount()) {
receivedMessageCount.notify();
}
}
}
/**
* @throws Exception
*/
public void testSendReceive() throws Exception {
for (int i = 0;i < MESSAGE_COUNT;i++) {
TextMessage textMessage = new ActiveMQTextMessage();
textMessage.setText("MSG-NO:" + i);
for (int x = 0;x < producers.length;x++) {
producers[x].send(textMessage);
}
}
synchronized (receivedMessageCount) {
if (receivedMessageCount.get() < expectedReceiveCount()) {
receivedMessageCount.wait(20000);
}
}
//sleep a little - to check we don't get too many messages
Thread.sleep(2000);
System.err.println("GOT: " + receivedMessageCount.get());
assertEquals("Expected message count not correct", expectedReceiveCount(), receivedMessageCount.get());
}
}