Browse Source

Update default pools size for SockJS scheduler

This change updates the XML namespace to match a change already made
to the Java config.
pull/496/head
Rossen Stoyanchev 11 years ago
parent
commit
5caf36ae91
  1. 1
      spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceUtils.java
  2. 4
      spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java
  3. 10
      spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java
  4. 2
      spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java

1
spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceUtils.java

@ -138,6 +138,7 @@ class WebSocketNamespaceUtils {
RootBeanDefinition taskSchedulerDef = new RootBeanDefinition(ThreadPoolTaskScheduler.class); RootBeanDefinition taskSchedulerDef = new RootBeanDefinition(ThreadPoolTaskScheduler.class);
taskSchedulerDef.setSource(source); taskSchedulerDef.setSource(source);
taskSchedulerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); taskSchedulerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
taskSchedulerDef.getPropertyValues().add("poolSize", Runtime.getRuntime().availableProcessors());
taskSchedulerDef.getPropertyValues().add("threadNamePrefix", schedulerName + "-"); taskSchedulerDef.getPropertyValues().add("threadNamePrefix", schedulerName + "-");
parserContext.getRegistry().registerBeanDefinition(schedulerName, taskSchedulerDef); parserContext.getRegistry().registerBeanDefinition(schedulerName, taskSchedulerDef);
parserContext.registerComponent(new BeanComponentDefinition(taskSchedulerDef, schedulerName)); parserContext.registerComponent(new BeanComponentDefinition(taskSchedulerDef, schedulerName));

4
spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java

@ -46,6 +46,7 @@ import org.springframework.messaging.simp.user.UserSessionRegistry;
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler; import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
import org.springframework.messaging.support.AbstractSubscribableChannel; import org.springframework.messaging.support.AbstractSubscribableChannel;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.MimeTypeUtils; import org.springframework.util.MimeTypeUtils;
import org.springframework.web.HttpRequestHandler; import org.springframework.web.HttpRequestHandler;
import org.springframework.web.context.support.GenericWebApplicationContext; import org.springframework.web.context.support.GenericWebApplicationContext;
@ -134,6 +135,9 @@ public class MessageBrokerBeanDefinitionParserTests {
assertNotNull(wsTransportHandler.getHandshakeHandler()); assertNotNull(wsTransportHandler.getHandshakeHandler());
assertThat(wsTransportHandler.getHandshakeHandler(), Matchers.instanceOf(TestHandshakeHandler.class)); assertThat(wsTransportHandler.getHandshakeHandler(), Matchers.instanceOf(TestHandshakeHandler.class));
ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) defaultSockJsService.getTaskScheduler();
assertEquals(Runtime.getRuntime().availableProcessors(), scheduler.getScheduledThreadPoolExecutor().getCorePoolSize());
UserSessionRegistry userSessionRegistry = this.appContext.getBean(UserSessionRegistry.class); UserSessionRegistry userSessionRegistry = this.appContext.getBean(UserSessionRegistry.class);
assertNotNull(userSessionRegistry); assertNotNull(userSessionRegistry);

10
spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java

@ -37,6 +37,7 @@ import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.simp.annotation.SubscribeMapping; import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.messaging.simp.stomp.StompCommand; import org.springframework.messaging.simp.stomp.StompCommand;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
@ -122,6 +123,15 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
} }
} }
@Test
public void messageBrokerSockJsTaskScheduler() {
ThreadPoolTaskScheduler taskScheduler =
this.config.getBean("messageBrokerSockJsTaskScheduler", ThreadPoolTaskScheduler.class);
assertEquals(Runtime.getRuntime().availableProcessors(),
taskScheduler.getScheduledThreadPoolExecutor().getCorePoolSize());
}
@Controller @Controller
static class TestController { static class TestController {

2
spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java

@ -85,7 +85,7 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
SimpleController controller = this.wac.getBean(SimpleController.class); SimpleController controller = this.wac.getBean(SimpleController.class);
try { try {
assertTrue(controller.latch.await(2, TimeUnit.SECONDS)); assertTrue(controller.latch.await(10, TimeUnit.SECONDS));
} }
finally { finally {
session.close(); session.close();

Loading…
Cancel
Save