You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/02/02 12:24:20 UTC
svn commit: r374360 - in /incubator/servicemix/trunk/servicemix-core/src:
main/java/org/apache/servicemix/jbi/container/
main/java/org/apache/servicemix/jbi/management/
main/java/org/apache/servicemix/tck/
test/java/org/apache/servicemix/examples/ test...
Author: gnodet
Date: Thu Feb 2 03:24:04 2006
New Revision: 374360
URL: http://svn.apache.org/viewcvs?rev=374360&view=rev
Log:
Ensure that all threads are destroyed when running unit tests
so that we do not end with thousands of them.
Modified:
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseStandardMBean.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/MBeanBuilder.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/ManagementContext.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/SpringTestSupport.java
incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/examples/AbstractSpringTestSupport.java
incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditorTest.java
incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/nmr/SubscriptionTest.java
incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/nmr/flow/jms/SimpleClusterSendSyncTest.java
incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/tck/ExamplePojoTest.java
incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/jbi/nmr/flow/jms/client.xml
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java Thu Feb 2 03:24:04 2006
@@ -45,6 +45,7 @@
import org.apache.activemq.util.IdGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.connector.work.GeronimoWorkManager;
import org.apache.servicemix.JbiConstants;
import org.apache.servicemix.MessageExchangeListener;
import org.apache.servicemix.components.util.ComponentAdaptor;
@@ -100,12 +101,13 @@
protected AutoDeploymentService autoDeployService = new AutoDeploymentService();
protected Registry registry = new Registry();
protected WorkManager workManager;
+ protected boolean isWorkManagerCreated;
protected boolean autoEnlistInTransaction = false;
protected boolean persistent = false;
protected List listeners = new CopyOnWriteArrayList();
protected boolean embedded = false;
protected boolean notifyStatistics = false;
-
+
/**
* Default Constructor
*/
@@ -386,6 +388,7 @@
if (containerInitialized.compareAndSet(false, true)) {
if (this.workManager == null) {
this.workManager = createWorkManager();
+ this.isWorkManagerCreated = true;
}
if (this.namingContext == null) {
try {
@@ -477,6 +480,13 @@
super.shutDown();
managementContext.unregisterMBean(this);
managementContext.shutDown();
+ if (isWorkManagerCreated && workManager instanceof GeronimoWorkManager) {
+ try {
+ ((GeronimoWorkManager) workManager).doStop();
+ } catch (Exception e) {
+ throw new JBIException("Could not stop workManager", e);
+ }
+ }
}
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseStandardMBean.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseStandardMBean.java?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseStandardMBean.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseStandardMBean.java Thu Feb 2 03:24:04 2006
@@ -16,7 +16,6 @@
package org.apache.servicemix.jbi.management;
import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
-import edu.emory.mathcs.backport.java.util.concurrent.Executors;
import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.beanutils.PropertyUtilsBean;
@@ -89,16 +88,17 @@
* @param description
* @param attrs
* @param ops
+ * @param executorService2
* @throws ReflectionException
* @throws NotCompliantMBeanException
*/
public BaseStandardMBean(Object object, Class interfaceMBean, String description, MBeanAttributeInfo[] attrs,
- MBeanOperationInfo[] ops) throws ReflectionException, NotCompliantMBeanException {
+ MBeanOperationInfo[] ops, ExecutorService executorService) throws ReflectionException, NotCompliantMBeanException {
super(object, interfaceMBean);
this.attributeInfos = attrs;
buildAttributes(object, this.attributeInfos);
this.beanInfo = new MBeanInfo(object.getClass().getName(), description, attrs, null, ops, getNotificationInfo());
- this.executorService = Executors.newCachedThreadPool();
+ this.executorService = executorService;
}
/**
@@ -355,7 +355,6 @@
* Called after removal from the MBeanServer
*/
public void postDeregister() {
- executorService.shutdown();
}
/**
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/MBeanBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/MBeanBuilder.java?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/MBeanBuilder.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/MBeanBuilder.java Thu Feb 2 03:24:04 2006
@@ -19,6 +19,8 @@
import javax.management.JMException;
import javax.management.StandardMBean;
+import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
+
/**
* Builds a DynamicMBean wrappers for existing objects
*
@@ -33,16 +35,22 @@
* @param theObject
* @param interfaceMBean
* @param description
+ * @param executorService
* @return the MBean wrapper
* @throws JMException
*/
- static DynamicMBean buildStandardMBean(Object theObject, Class interfaceMBean, String description) throws JMException {
+ static DynamicMBean buildStandardMBean(Object theObject, Class interfaceMBean, String description, ExecutorService executorService) throws JMException {
DynamicMBean result = null;
if (theObject != null) {
if (theObject instanceof MBeanInfoProvider) {
MBeanInfoProvider info = (MBeanInfoProvider) theObject;
- result = new BaseStandardMBean(info.getObjectToManage(),interfaceMBean, description, info.getAttributeInfos(), info
- .getOperationInfos());
+ result = new BaseStandardMBean(
+ info.getObjectToManage(),
+ interfaceMBean,
+ description,
+ info.getAttributeInfos(),
+ info.getOperationInfos(),
+ executorService);
info.setPropertyChangeListener((BaseStandardMBean)result);
}
else {
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/ManagementContext.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/ManagementContext.java?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/ManagementContext.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/ManagementContext.java Thu Feb 2 03:24:04 2006
@@ -32,6 +32,8 @@
import org.apache.servicemix.jbi.container.JBIContainer;
import org.apache.servicemix.jbi.framework.ComponentMBeanImpl;
import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
+import edu.emory.mathcs.backport.java.util.concurrent.Executors;
/**
* Management Context applied to a ServiceMix container
@@ -50,6 +52,7 @@
private Map beanMap = new ConcurrentHashMap();
protected Map systemServices = new ConcurrentHashMap();
private MBeanServerContext mbeanServerContext = new MBeanServerContext();
+ private ExecutorService executors;
/**
* Default Constructor
@@ -140,6 +143,7 @@
}catch(IOException e){
log.error("Failed to start mbeanServerContext",e);
}
+ this.executors = Executors.newCachedThreadPool();
registerSystemService(this, ManagementContextMBean.class);
}
@@ -182,6 +186,7 @@
}catch(IOException e){
log.debug("Failed to shutdown mbeanServerContext cleanly",e);
}
+ executors.shutdown();
}
/**
@@ -397,7 +402,7 @@
public void registerMBean(ObjectName name, Object resource, Class interfaceMBean, String description)
throws JMException {
if (mbeanServerContext.getMBeanServer() != null) {
- Object mbean = MBeanBuilder.buildStandardMBean(resource, interfaceMBean, description);
+ Object mbean = MBeanBuilder.buildStandardMBean(resource, interfaceMBean, description, executors);
if (mbeanServerContext.getMBeanServer().isRegistered(name)) {
mbeanServerContext.getMBeanServer().unregisterMBean(name);
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/SpringTestSupport.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/SpringTestSupport.java?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/SpringTestSupport.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/SpringTestSupport.java Thu Feb 2 03:24:04 2006
@@ -100,8 +100,10 @@
String text = DOMUtil.getElementText(element);
return text;
}
- else {
+ else if (root != null) {
return root.getNodeValue();
+ } else {
+ return null;
}
}
Modified: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/examples/AbstractSpringTestSupport.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/examples/AbstractSpringTestSupport.java?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/examples/AbstractSpringTestSupport.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/examples/AbstractSpringTestSupport.java Thu Feb 2 03:24:04 2006
@@ -47,6 +47,12 @@
assertNotNull("JBI Container not found in spring!", jbi);
}
+
+ protected void tearDown() throws Exception {
+ if (context != null) {
+ context.close();
+ }
+ }
protected abstract AbstractXmlApplicationContext createBeanFactory();
Modified: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditorTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditorTest.java?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditorTest.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditorTest.java Thu Feb 2 03:24:04 2006
@@ -36,6 +36,7 @@
private DataSource dataSource;
private Connection connection;
+ private JBIContainer jbi;
protected void setUp() throws Exception {
@@ -44,25 +45,30 @@
ds.setUser("sa");
dataSource = ds;
connection = dataSource.getConnection();
+ jbi = new JBIContainer();
}
protected void tearDown() throws Exception {
- connection.close();
+ if (jbi != null) {
+ jbi.shutDown();
+ }
+ if (connection != null) {
+ connection.close();
+ }
}
public void testInsertUpdate() throws Exception {
- JBIContainer container = new JBIContainer();
- container.setFlowName("st");
- container.init();
- container.start();
+ jbi.setFlowName("st");
+ jbi.init();
+ jbi.start();
SenderComponent sender = new SenderComponent();
ReceiverComponent receiver = new ReceiverComponent();
- container.activateComponent(sender, "sender");
- container.activateComponent(receiver, "receiver");
+ jbi.activateComponent(sender, "sender");
+ jbi.activateComponent(receiver, "receiver");
JdbcAuditor auditor = new JdbcAuditor();
- auditor.setContainer(container);
+ auditor.setContainer(jbi);
auditor.setDataSource(dataSource);
auditor.afterPropertiesSet();
Modified: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/nmr/SubscriptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/nmr/SubscriptionTest.java?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/nmr/SubscriptionTest.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/nmr/SubscriptionTest.java Thu Feb 2 03:24:04 2006
@@ -86,6 +86,7 @@
private void runTest(String flowName, String subscriptionFlowName, boolean sync) throws Exception {
JBIContainer container = new JBIContainer();
try {
+ container.setEmbedded(true);
container.getBroker().setFlow(FlowProvider.getFlow(flowName));
if (subscriptionFlowName != null) {
container.getBroker().getSubscriptionManager().setFlow(FlowProvider.getFlow(subscriptionFlowName));
Modified: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/nmr/flow/jms/SimpleClusterSendSyncTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/nmr/flow/jms/SimpleClusterSendSyncTest.java?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/nmr/flow/jms/SimpleClusterSendSyncTest.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/nmr/flow/jms/SimpleClusterSendSyncTest.java Thu Feb 2 03:24:04 2006
@@ -25,7 +25,6 @@
import org.apache.servicemix.jbi.container.SpringJBIContainer;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
-import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.xbean.spring.context.ClassPathXmlApplicationContext;
@@ -34,36 +33,38 @@
*/
public class SimpleClusterSendSyncTest extends TestCase {
protected SpringJBIContainer jbi;
+ protected AbstractXmlApplicationContext context;
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
- super.setUp();
- AbstractXmlApplicationContext context = new ClassPathXmlApplicationContext("org/apache/servicemix/jbi/nmr/flow/jms/broker.xml");
+ context = new ClassPathXmlApplicationContext("org/apache/servicemix/jbi/nmr/flow/jms/broker.xml");
jbi = (SpringJBIContainer) context.getBean("jbi");
- jbi.init();
- jbi.start();
assertNotNull("JBI Container not found in spring!", jbi);
}
protected void tearDown() throws Exception {
- super.tearDown();
+ context.close();
}
public void testSendSync() throws Exception {
- ApplicationContext ctx = new ClassPathXmlApplicationContext("org/apache/servicemix/jbi/nmr/flow/jms/client.xml");
- ServiceMixClient client = (ServiceMixClient) ctx.getBean("client");
- Thread.sleep(500);
- InOut exchange = client.createInOutExchange();
- exchange.setService(new QName("http://www.habuma.com/foo", "pingService"));
- NormalizedMessage in = exchange.getInMessage();
- in.setContent(new StringSource("<ping>Pinging you</ping>"));
- System.out.println("SENDING; exchange.status=" + exchange.getStatus());
- client.sendSync(exchange);
- assertNotNull(exchange.getOutMessage());
- System.out.println("GOT RESPONSE; exchange.out=" + new SourceTransformer().toString(exchange.getOutMessage().getContent()));
- client.done(exchange);
+ AbstractXmlApplicationContext ctx = new ClassPathXmlApplicationContext("org/apache/servicemix/jbi/nmr/flow/jms/client.xml");
+ try {
+ ServiceMixClient client = (ServiceMixClient) ctx.getBean("client");
+ Thread.sleep(2000);
+ InOut exchange = client.createInOutExchange();
+ exchange.setService(new QName("http://www.habuma.com/foo", "pingService"));
+ NormalizedMessage in = exchange.getInMessage();
+ in.setContent(new StringSource("<ping>Pinging you</ping>"));
+ System.out.println("SENDING; exchange.status=" + exchange.getStatus());
+ client.sendSync(exchange);
+ assertNotNull(exchange.getOutMessage());
+ System.out.println("GOT RESPONSE; exchange.out=" + new SourceTransformer().toString(exchange.getOutMessage().getContent()));
+ client.done(exchange);
+ } finally {
+ ctx.close();
+ }
}
}
Modified: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/tck/ExamplePojoTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/tck/ExamplePojoTest.java?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/tck/ExamplePojoTest.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/tck/ExamplePojoTest.java Thu Feb 2 03:24:04 2006
@@ -38,8 +38,6 @@
}
protected void setUp() throws Exception {
-
-
container.init();
container.start();
receiver = new ReceiverComponent();
Modified: incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/jbi/nmr/flow/jms/client.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/jbi/nmr/flow/jms/client.xml?rev=374360&r1=374359&r2=374360&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/jbi/nmr/flow/jms/client.xml (original)
+++ incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/jbi/nmr/flow/jms/client.xml Thu Feb 2 03:24:04 2006
@@ -13,6 +13,7 @@
name="jbi"/>
<bean id="client"
- class="org.apache.servicemix.client.RemoteServiceMixClient"
- init-method="start"/>
+ class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
</beans>