You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2011/03/25 15:32:46 UTC
svn commit: r1085404 - in /servicemix/utils/trunk/src:
main/java/org/apache/servicemix/converter/
main/java/org/apache/servicemix/executors/
main/java/org/apache/servicemix/executors/impl/
test/java/org/apache/servicemix/converter/ test/java/org/apache...
Author: gertv
Date: Fri Mar 25 14:32:45 2011
New Revision: 1085404
URL: http://svn.apache.org/viewvc?rev=1085404&view=rev
Log:
SM-2063: Allow overriding parts of the executor configuration
Added:
servicemix/utils/trunk/src/main/java/org/apache/servicemix/converter/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/converter/Converters.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/converter/
servicemix/utils/trunk/src/test/java/org/apache/servicemix/converter/ConvertersTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/
servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/ExecutorConfigTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/ExecutorFactoryImplTest.java
Modified:
servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/ExecutorFactory.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorConfig.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorFactoryImpl.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorImpl.java
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/converter/Converters.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/converter/Converters.java?rev=1085404&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/converter/Converters.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/converter/Converters.java Fri Mar 25 14:32:45 2011
@@ -0,0 +1,124 @@
+/*
+ * 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.servicemix.converter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A set of helper methods and classes to convert a few basic types
+ * NOTE: if this grows any bigger, we might want to consider moving to Camel @Converter's for this
+ */
+public class Converters {
+
+ private Map<Class<?>, Converter<?>> converters = new HashMap<Class<?>, Converter<?>>();
+
+ public Converters() {
+ converters.put(Boolean.class, new BooleanConverter());
+ converters.put(Integer.class, new IntegerConverter());
+ converters.put(Long.class, new LongConverter());
+ }
+
+ /**
+ * Convert an object to another type. If the object is <code>null</code>, this method will always return
+ * <code>null</code>.
+ *
+ * @param value the object to be converted
+ * @param target the target object type
+ * @return the converted object value or <code>null</code> if no suitable conversion was found
+ */
+ public<T> T as(Object value, Class<T> target) {
+ if (value == null) {
+ return null;
+ }
+ return getConverter(target).convert(value);
+
+ }
+
+ private<T> Converter<T> getConverter(Class<T> target) {
+ return (Converter<T>) converters.get(target);
+ }
+
+
+ private interface Converter<T> {
+
+ public T convert(Object value);
+
+ }
+
+ /*
+ * {@link Converter} implementation for converting objects to Boolean
+ */
+ private class BooleanConverter implements Converter<Boolean> {
+
+ public Boolean convert(Object value) {
+ if (value instanceof Boolean) {
+ return (Boolean) value;
+ } else {
+ String string = value.toString();
+ if ("true".equalsIgnoreCase(string) || "false".equalsIgnoreCase(string)) {
+ return Boolean.parseBoolean(string);
+ } else {
+ return null;
+ }
+ }
+ }
+ }
+
+
+ /*
+ * {@link Converter} implementation for converting objects to Integer
+ */
+ private class IntegerConverter implements Converter<Integer> {
+
+ public Integer convert(Object value) {
+ if (value instanceof Integer) {
+ return (Integer) value;
+ } else if (value instanceof String) {
+ try {
+ return Integer.parseInt((String) value);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+ }
+
+ /*
+ * {@link Converter} implementation for converting objects to Long
+ */
+ private class LongConverter implements Converter<Long> {
+
+ public Long convert(Object value) {
+ if (value instanceof Long) {
+ return (Long) value;
+ } else if (value instanceof Integer) {
+ return ((Integer) value).longValue();
+ } else if (value instanceof String) {
+ try {
+ return Long.parseLong((String) value);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+ }
+}
Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/ExecutorFactory.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/ExecutorFactory.java?rev=1085404&r1=1085403&r2=1085404&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/ExecutorFactory.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/ExecutorFactory.java Fri Mar 25 14:32:45 2011
@@ -16,6 +16,10 @@
*/
package org.apache.servicemix.executors;
+import org.apache.servicemix.executors.impl.ExecutorConfig;
+
+import java.util.Map;
+
/**
* Factory to create <code>Executor</code>s.
*
@@ -23,6 +27,20 @@ package org.apache.servicemix.executors;
*/
public interface ExecutorFactory {
+ /*
+ * Configuration properties than can be passed along when creating an executor.
+ * Every ExecutorFactory implementation can support one or more of these options, ignoring the unsupported ones.
+ */
+ String ALLOW_CORE_THREADS_TIMEOUT = ExecutorFactory.class.getName() + ".AllowCoreThreadsTimeout";
+ String BYPASS_IF_SYNCHRONOUS = ExecutorFactory.class.getName() + ".BypassIfSynchronous";
+ String CORE_POOL_SIZE = ExecutorFactory.class.getName() + ".CorePoolSize";
+ String KEEP_ALIVE_TIME = ExecutorFactory.class.getName() + ".KeepAliveTime";
+ String MAXIMUM_POOL_SIZE = ExecutorFactory.class.getName() + ".MaximumPoolSize";
+ String QUEUE_SIZE = ExecutorFactory.class.getName() + ".QueueSize";
+ String SHUTDOWN_DELAY = ExecutorFactory.class.getName() + ".ShutdownDelay";
+ String THREAD_DAEMON = ExecutorFactory.class.getName() + ".ThreadDaemon";
+ String THREAD_PRIORITY = ExecutorFactory.class.getName() + ".ThreadPriority";
+
/**
* Create a new executor for the given Id.
* The id may be used to provide per executor
@@ -34,6 +52,19 @@ public interface ExecutorFactory {
Executor createExecutor(String id);
/**
+ * Create a new executor for the given id
+ * using the additional configuration options provided.
+ *
+ * Note that not every ExecutorFactory implementation will support all available options. If the factory does
+ * not support the option, it will get ignored.
+ *
+ * @param id the id of the executor to create
+ * @param config the additional executor configuration options
+ * @return a configured Executor
+ */
+ Executor createExecutor(String id, Map<String, Object> config);
+
+ /**
* Create a new daemon executor for the given Id.
* The excutor should use daemon thread underlying
* The id may be used to provide per executor
Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorConfig.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorConfig.java?rev=1085404&r1=1085403&r2=1085404&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorConfig.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorConfig.java Fri Mar 25 14:32:45 2011
@@ -16,6 +16,13 @@
*/
package org.apache.servicemix.executors.impl;
+import org.apache.servicemix.converter.Converters;
+import org.apache.servicemix.executors.ExecutorFactory;
+
+import java.util.Map;
+
+import static org.apache.servicemix.executors.ExecutorFactory.*;
+
/**
* This bean holds configuration attributes for a given Executor.
*
@@ -92,7 +99,7 @@ public class ExecutorConfig {
* @param corePoolSize
* the corePoolSize to set
*/
- public void setCorePoolSize(int corePoolSize) {
+ public void setCorePoolSize(Integer corePoolSize) {
this.corePoolSize = corePoolSize;
}
@@ -107,7 +114,7 @@ public class ExecutorConfig {
* @param keepAlive
* the keepAlive to set
*/
- public void setKeepAliveTime(long keepAlive) {
+ public void setKeepAliveTime(Long keepAlive) {
this.keepAliveTime = keepAlive;
}
@@ -122,7 +129,7 @@ public class ExecutorConfig {
* @param maximumPoolSize
* the maximumPoolSize to set
*/
- public void setMaximumPoolSize(int maximumPoolSize) {
+ public void setMaximumPoolSize(Integer maximumPoolSize) {
this.maximumPoolSize = maximumPoolSize;
}
@@ -137,7 +144,7 @@ public class ExecutorConfig {
* @param queueSize
* the queueSize to set
*/
- public void setQueueSize(int queueSize) {
+ public void setQueueSize(Integer queueSize) {
this.queueSize = queueSize;
}
@@ -152,7 +159,7 @@ public class ExecutorConfig {
* @param threadDaemon
* the threadDaemon to set
*/
- public void setThreadDaemon(boolean threadDaemon) {
+ public void setThreadDaemon(Boolean threadDaemon) {
this.threadDaemon = threadDaemon;
}
@@ -167,7 +174,7 @@ public class ExecutorConfig {
* @param threadPriority
* the threadPriority to set
*/
- public void setThreadPriority(int threadPriority) {
+ public void setThreadPriority(Integer threadPriority) {
this.threadPriority = threadPriority;
}
@@ -182,7 +189,7 @@ public class ExecutorConfig {
* @param shutdownDelay
* the shutdownDelay to set
*/
- public void setShutdownDelay(long shutdownDelay) {
+ public void setShutdownDelay(Long shutdownDelay) {
this.shutdownDelay = shutdownDelay;
}
@@ -197,7 +204,7 @@ public class ExecutorConfig {
* @param allowCoreThreadsTimeout
* the allowCoreThreadsTimeout to set
*/
- public void setAllowCoreThreadsTimeout(boolean allowCoreThreadsTimeout) {
+ public void setAllowCoreThreadsTimeout(Boolean allowCoreThreadsTimeout) {
this.allowCoreThreadsTimeout = allowCoreThreadsTimeout;
}
@@ -211,7 +218,7 @@ public class ExecutorConfig {
/**
* @param bypassIfSynchronous if synchronous tasks should bypass the executor
*/
- public void setBypassIfSynchronous(boolean bypassIfSynchronous) {
+ public void setBypassIfSynchronous(Boolean bypassIfSynchronous) {
this.bypassIfSynchronous = bypassIfSynchronous;
}
@@ -222,4 +229,30 @@ public class ExecutorConfig {
public void setParent(ExecutorConfig parent) {
this.parent = parent;
}
+
+ /**
+ * Create an ExecutorConfig instance based on the information in the options map.
+ *
+ * @param options the map of executor configuration options that will get set on the ExecutorConfig instance
+ * @param parent (optionally) the parent ExecutorConfig instance
+ * @return the configured instance
+ */
+ public static ExecutorConfig create(Map<String, Object> options, ExecutorConfig parent) {
+ Converters converter = new Converters();
+
+ ExecutorConfig result = new ExecutorConfig(false, parent);
+ result.setCorePoolSize(converter.as(options.get(CORE_POOL_SIZE), Integer.class));
+ result.setMaximumPoolSize(converter.as(options.get(MAXIMUM_POOL_SIZE), Integer.class));
+ result.setQueueSize(converter.as(options.get(QUEUE_SIZE), Integer.class));
+ result.setThreadPriority(converter.as(options.get(THREAD_PRIORITY), Integer.class));
+
+ result.setKeepAliveTime(converter.as(options.get(KEEP_ALIVE_TIME), Long.class));
+ result.setShutdownDelay(converter.as(options.get(SHUTDOWN_DELAY), Long.class));
+
+ result.setAllowCoreThreadsTimeout(converter.as(options.get(ALLOW_CORE_THREADS_TIMEOUT), Boolean.class));
+ result.setBypassIfSynchronous(converter.as(options.get(BYPASS_IF_SYNCHRONOUS), Boolean.class));
+ result.setThreadDaemon(converter.as(options.get(THREAD_DAEMON), Boolean.class));
+
+ return result;
+ }
}
Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorFactoryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorFactoryImpl.java?rev=1085404&r1=1085403&r2=1085404&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorFactoryImpl.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorFactoryImpl.java Fri Mar 25 14:32:45 2011
@@ -57,20 +57,24 @@ public class ExecutorFactoryImpl impleme
private Map<Executor, ObjectName> executorNames = new HashMap<Executor, ObjectName>();
public Executor createExecutor(String id) {
- ExecutorConfig config = getConfig(id);
- ExecutorImpl executor = new ExecutorImpl(this, createService(id, config), config.getShutdownDelay(), config.isBypassIfSynchronous());
- try {
- registerMBean(id, executor, config);
- } catch (Exception ex) {
- LOG.error("Unable to register MBean for the executor with id " + id, ex);
- }
- return executor;
+ return doCreateExecutor(id, getConfig(id));
+ }
+
+ public Executor createExecutor(String id, Map<String, Object> configuration) {
+ return doCreateExecutor(id, ExecutorConfig.create(configuration, getConfig(id)));
}
public Executor createDaemonExecutor(String id) {
ExecutorConfig config = getConfig(id);
config.setThreadDaemon(true);
- ExecutorImpl executor = new ExecutorImpl(this, createService(id, config), config.getShutdownDelay(), config.isBypassIfSynchronous());
+ return doCreateExecutor(id, config);
+ }
+
+ /**
+ * Create an executor with the given id and configuration
+ */
+ private Executor doCreateExecutor(String id, ExecutorConfig config) {
+ ExecutorImpl executor = new ExecutorImpl(this, createService(id, config), config);
try {
registerMBean(id, executor, config);
} catch (Exception ex) {
Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorImpl.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorImpl.java?rev=1085404&r1=1085403&r2=1085404&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorImpl.java (original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/executors/impl/ExecutorImpl.java Fri Mar 25 14:32:45 2011
@@ -33,21 +33,18 @@ public class ExecutorImpl implements Exe
private final ThreadPoolExecutor threadPool;
- private final long shutdownDelay;
-
- private final boolean bypassIfSynchronous;
-
private ExecutorFactoryImpl executorFactory;
- public ExecutorImpl(ExecutorFactoryImpl executorFactory, ThreadPoolExecutor threadPool, long shutdownDelay, boolean bypassIfSynchronous) {
+ private final ExecutorConfig config;
+
+ public ExecutorImpl(ExecutorFactoryImpl executorFactory, ThreadPoolExecutor threadPool, ExecutorConfig config) {
this.executorFactory = executorFactory;
this.threadPool = threadPool;
- this.shutdownDelay = shutdownDelay;
- this.bypassIfSynchronous = bypassIfSynchronous;
+ this.config = config;
}
public void execute(Runnable command) {
- if (bypassIfSynchronous && command instanceof ExecutorAwareRunnable) {
+ if (config.isBypassIfSynchronous() && command instanceof ExecutorAwareRunnable) {
if (((ExecutorAwareRunnable) command).shouldRunSynchronously()) {
command.run();
return;
@@ -63,11 +60,11 @@ public class ExecutorImpl implements Exe
// ignored
}
threadPool.shutdown();
- if (!threadPool.isTerminated() && shutdownDelay > 0) {
+ if (!threadPool.isTerminated() && config.getShutdownDelay() > 0) {
new Thread(new Runnable() {
public void run() {
try {
- if (!threadPool.awaitTermination(shutdownDelay, TimeUnit.MILLISECONDS)) {
+ if (!threadPool.awaitTermination(config.getShutdownDelay(), TimeUnit.MILLISECONDS)) {
threadPool.shutdownNow();
}
} catch (InterruptedException e) {
@@ -91,4 +88,13 @@ public class ExecutorImpl implements Exe
public ThreadPoolExecutor getThreadPoolExecutor() {
return this.threadPool;
}
+
+ /**
+ * The configuration used for creating this executor instance
+ *
+ * @return the configuration object
+ */
+ protected ExecutorConfig getConfig() {
+ return config;
+ }
}
Added: servicemix/utils/trunk/src/test/java/org/apache/servicemix/converter/ConvertersTest.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/test/java/org/apache/servicemix/converter/ConvertersTest.java?rev=1085404&view=auto
==============================================================================
--- servicemix/utils/trunk/src/test/java/org/apache/servicemix/converter/ConvertersTest.java (added)
+++ servicemix/utils/trunk/src/test/java/org/apache/servicemix/converter/ConvertersTest.java Fri Mar 25 14:32:45 2011
@@ -0,0 +1,50 @@
+/*
+ * 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.servicemix.converter;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test cases for {@link Converters}
+ */
+public class ConvertersTest {
+
+ private final Converters converters = new Converters();
+
+ @Test
+ public void testIntegers() {
+ assertEquals((Integer) 10, converters.as(10, Integer.class));
+ assertEquals((Integer) 10, converters.as("10", Integer.class));
+ assertEquals(null, converters.as("ILLEGAL_VALUE", Integer.class));
+ }
+
+ @Test
+ public void testLongs() {
+ assertEquals((Long) 10l, converters.as(10l, Long.class));
+ assertEquals((Long) 10l, converters.as(10, Long.class));
+ assertEquals((Long) 10l, converters.as("10", Long.class));
+ assertEquals(null, converters.as("ILLEGAL_VALUE", Long.class));
+ }
+
+ @Test
+ public void testBooleans() {
+ assertEquals(true, converters.as(true, Boolean.class));
+ assertEquals(false, converters.as("false", Boolean.class));
+ assertEquals(null, converters.as("ILLEGAL_VALUE", Boolean.class));
+ }
+}
Added: servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/ExecutorConfigTest.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/ExecutorConfigTest.java?rev=1085404&view=auto
==============================================================================
--- servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/ExecutorConfigTest.java (added)
+++ servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/ExecutorConfigTest.java Fri Mar 25 14:32:45 2011
@@ -0,0 +1,106 @@
+/*
+ * 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.servicemix.executors.impl;
+
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.apache.servicemix.executors.ExecutorFactory.*;
+import static org.junit.Assert.*;
+
+/**
+ * Test cases for {@link ExecutorConfig}
+ */
+public class ExecutorConfigTest {
+
+ @Test
+ public void testCreateMethod() {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put(CORE_POOL_SIZE, 5);
+ data.put(MAXIMUM_POOL_SIZE, 10);
+ data.put(QUEUE_SIZE, 50);
+ data.put(KEEP_ALIVE_TIME, 3000l);
+ data.put(SHUTDOWN_DELAY, 9000l);
+ data.put(THREAD_PRIORITY, 9);
+ data.put(ALLOW_CORE_THREADS_TIMEOUT, true);
+ data.put(BYPASS_IF_SYNCHRONOUS, false);
+ data.put(THREAD_DAEMON, true);
+
+ ExecutorConfig config = ExecutorConfig.create(data, null);
+ assertEquals(5, config.getCorePoolSize());
+ assertEquals(10, config.getMaximumPoolSize());
+ assertEquals(50, config.getQueueSize());
+ assertEquals(3000, config.getKeepAliveTime());
+ assertEquals(9000, config.getShutdownDelay());
+ assertEquals(9, config.getThreadPriority());
+ assertEquals(true, config.isAllowCoreThreadsTimeout());
+ assertEquals(false, config.isBypassIfSynchronous());
+ assertEquals(true, config.isThreadDaemon());
+ }
+
+ @Test
+ public void testCreateMethodWithStringValues() {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put(CORE_POOL_SIZE, "5");
+ data.put(MAXIMUM_POOL_SIZE, "10");
+ data.put(QUEUE_SIZE, "50");
+ data.put(KEEP_ALIVE_TIME, "3000");
+ data.put(SHUTDOWN_DELAY, "9000");
+ data.put(THREAD_PRIORITY, "9");
+ data.put(ALLOW_CORE_THREADS_TIMEOUT, "true");
+ data.put(BYPASS_IF_SYNCHRONOUS, "false");
+ data.put(THREAD_DAEMON, "true");
+
+ ExecutorConfig config = ExecutorConfig.create(data, null);
+ assertEquals(5, config.getCorePoolSize());
+ assertEquals(10, config.getMaximumPoolSize());
+ assertEquals(50, config.getQueueSize());
+ assertEquals(3000, config.getKeepAliveTime());
+ assertEquals(9000, config.getShutdownDelay());
+ assertEquals(9, config.getThreadPriority());
+ assertEquals(true, config.isAllowCoreThreadsTimeout());
+ assertEquals(false, config.isBypassIfSynchronous());
+ assertEquals(true, config.isThreadDaemon());
+ }
+
+ @Test
+ public void testCreateMethodIllegalValuesIgnored() {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put(CORE_POOL_SIZE, "SOME");
+ data.put(MAXIMUM_POOL_SIZE, "ILLEGAL");
+ data.put(QUEUE_SIZE, "VALUE");
+ data.put(KEEP_ALIVE_TIME, "3000");
+ data.put(SHUTDOWN_DELAY, "9000");
+ data.put(THREAD_PRIORITY, "9");
+ data.put(ALLOW_CORE_THREADS_TIMEOUT, "true");
+ data.put(BYPASS_IF_SYNCHRONOUS, "false");
+ data.put(THREAD_DAEMON, "true");
+
+ ExecutorConfig config = ExecutorConfig.create(data, new ExecutorConfig());
+ assertEquals(ExecutorConfig.DEFAULT_CORE_POOL_SIZE, config.getCorePoolSize());
+ assertEquals(ExecutorConfig.DEFAULT_MAXIMUM_POOL_SIZE, config.getMaximumPoolSize());
+ assertEquals(ExecutorConfig.DEFAULT_QUEUE_SIZE, config.getQueueSize());
+ assertEquals(3000, config.getKeepAliveTime());
+ assertEquals(9000, config.getShutdownDelay());
+ assertEquals(9, config.getThreadPriority());
+ assertEquals(true, config.isAllowCoreThreadsTimeout());
+ assertEquals(false, config.isBypassIfSynchronous());
+ assertEquals(true, config.isThreadDaemon());
+ }
+}
Added: servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/ExecutorFactoryImplTest.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/ExecutorFactoryImplTest.java?rev=1085404&view=auto
==============================================================================
--- servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/ExecutorFactoryImplTest.java (added)
+++ servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/ExecutorFactoryImplTest.java Fri Mar 25 14:32:45 2011
@@ -0,0 +1,60 @@
+/*
+ * 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.servicemix.executors.impl;
+
+import org.apache.servicemix.executors.ExecutorFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test cases for {@link ExecutorFactoryImpl}
+ */
+public class ExecutorFactoryImplTest {
+
+ private ExecutorConfig defaultConfig;
+ private ExecutorFactoryImpl factory;
+
+ @Before
+ public void setupExecutorFactory() {
+ factory = new ExecutorFactoryImpl();
+
+ defaultConfig = new ExecutorConfig();
+ defaultConfig.setCorePoolSize(1);
+ defaultConfig.setMaximumPoolSize(2);
+ defaultConfig.setQueueSize(3);
+ defaultConfig.setAllowCoreThreadsTimeout(true);
+ factory.setDefaultConfig(defaultConfig);
+ }
+
+ @Test
+ public void testAdditionalConfig() {
+ Map<String, Object> config = new HashMap<String, Object>();
+ config.put(ExecutorFactory.MAXIMUM_POOL_SIZE, 10);
+ ExecutorImpl impl = (ExecutorImpl) factory.createExecutor("test", config);
+ assertEquals("Core pool size is the default",
+ defaultConfig.getCorePoolSize(), impl.getConfig().getCorePoolSize());
+ assertEquals("Maximum pool size has been altered",
+ 10, impl.getConfig().getMaximumPoolSize());
+
+ }
+
+}