SPR-6368 The parser for the 'executor' element in the task namespace now creates a FactoryBean so that the pool-size range can be configured after property placeholder resolution when necessary.
This commit is contained in:
@@ -22,6 +22,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
@@ -56,6 +57,11 @@ public class ExecutorBeanDefinitionParserTests {
|
||||
assertEquals(42, this.getMaxPoolSize(executor));
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void invalidPoolSize() {
|
||||
this.context.getBean("invalidPoolSize");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rangeWithBoundedQueue() {
|
||||
Object executor = this.context.getBean("rangeWithBoundedQueue");
|
||||
@@ -74,6 +80,38 @@ public class ExecutorBeanDefinitionParserTests {
|
||||
assertEquals(Integer.MAX_VALUE, this.getQueueCapacity(executor));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderWithSingleSize() {
|
||||
Object executor = this.context.getBean("propertyPlaceholderWithSingleSize");
|
||||
assertEquals(123, this.getCorePoolSize(executor));
|
||||
assertEquals(123, this.getMaxPoolSize(executor));
|
||||
assertEquals(60, this.getKeepAliveSeconds(executor));
|
||||
assertEquals(false, this.getAllowCoreThreadTimeOut(executor));
|
||||
assertEquals(Integer.MAX_VALUE, this.getQueueCapacity(executor));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderWithRange() {
|
||||
Object executor = this.context.getBean("propertyPlaceholderWithRange");
|
||||
assertEquals(5, this.getCorePoolSize(executor));
|
||||
assertEquals(25, this.getMaxPoolSize(executor));
|
||||
assertEquals(false, this.getAllowCoreThreadTimeOut(executor));
|
||||
assertEquals(10, this.getQueueCapacity(executor));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderWithRangeAndCoreThreadTimeout() {
|
||||
Object executor = this.context.getBean("propertyPlaceholderWithRangeAndCoreThreadTimeout");
|
||||
assertEquals(99, this.getCorePoolSize(executor));
|
||||
assertEquals(99, this.getMaxPoolSize(executor));
|
||||
assertEquals(true, this.getAllowCoreThreadTimeOut(executor));
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void propertyPlaceholderWithInvalidPoolSize() {
|
||||
this.context.getBean("propertyPlaceholderWithInvalidPoolSize");
|
||||
}
|
||||
|
||||
|
||||
private int getCorePoolSize(Object executor) {
|
||||
return (Integer) new DirectFieldAccessor(executor).getPropertyValue("corePoolSize");
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:task="http://www.springframework.org/schema/task"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/task
|
||||
http://www.springframework.org/schema/task/spring-task.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:task="http://www.springframework.org/schema/task"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
|
||||
|
||||
<task:executor id="default"/>
|
||||
|
||||
@@ -15,4 +17,23 @@
|
||||
|
||||
<task:executor id="rangeWithUnboundedQueue" pool-size="0-9" keep-alive="37"/>
|
||||
|
||||
<task:executor id="invalidPoolSize" pool-size="zzz"/>
|
||||
|
||||
<task:executor id="propertyPlaceholderWithSingleSize" pool-size="${size.single}"/>
|
||||
|
||||
<task:executor id="propertyPlaceholderWithRange" pool-size="${size.range}" queue-capacity="10"/>
|
||||
|
||||
<task:executor id="propertyPlaceholderWithRangeAndCoreThreadTimeout" pool-size="${size.rangeFromZero}"/>
|
||||
|
||||
<task:executor id="propertyPlaceholderWithInvalidPoolSize" pool-size="${size.invalid}"/>
|
||||
|
||||
<context:property-placeholder properties-ref="props"/>
|
||||
|
||||
<util:properties id="props">
|
||||
<prop key="size.single">123</prop>
|
||||
<prop key="size.range">5-25</prop>
|
||||
<prop key="size.rangeFromZero">0-99</prop>
|
||||
<prop key="size.invalid">22-abc</prop>
|
||||
</util:properties>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user