|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import java.lang.reflect.Type;
|
20 | 20 | import java.util.ArrayList;
|
21 | 21 | import java.util.Arrays;
|
| 22 | +import java.util.Collections; |
22 | 23 | import java.util.Iterator;
|
23 | 24 | import java.util.List;
|
| 25 | +import java.util.Map; |
24 | 26 | import java.util.concurrent.CountDownLatch;
|
25 | 27 | import java.util.concurrent.TimeUnit;
|
26 | 28 | import java.util.concurrent.atomic.AtomicReference;
|
|
35 | 37 | import org.springframework.boot.LazyInitializationBeanFactoryPostProcessor;
|
36 | 38 | import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
37 | 39 | import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
| 40 | +import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; |
38 | 41 | import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
39 | 42 | import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
|
40 | 43 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
43 | 46 | import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
44 | 47 | import org.springframework.context.annotation.Bean;
|
45 | 48 | import org.springframework.context.annotation.Configuration;
|
| 49 | +import org.springframework.core.task.AsyncTaskExecutor; |
| 50 | +import org.springframework.core.task.SimpleAsyncTaskExecutor; |
| 51 | +import org.springframework.core.task.TaskExecutor; |
46 | 52 | import org.springframework.messaging.converter.CompositeMessageConverter;
|
47 | 53 | import org.springframework.messaging.converter.MessageConverter;
|
48 | 54 | import org.springframework.messaging.converter.SimpleMessageConverter;
|
49 | 55 | import org.springframework.messaging.simp.annotation.SubscribeMapping;
|
| 56 | +import org.springframework.messaging.simp.config.ChannelRegistration; |
50 | 57 | import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
51 | 58 | import org.springframework.messaging.simp.stomp.StompCommand;
|
52 | 59 | import org.springframework.messaging.simp.stomp.StompFrameHandler;
|
53 | 60 | import org.springframework.messaging.simp.stomp.StompHeaders;
|
54 | 61 | import org.springframework.messaging.simp.stomp.StompSession;
|
55 | 62 | import org.springframework.messaging.simp.stomp.StompSessionHandler;
|
56 | 63 | import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter;
|
| 64 | +import org.springframework.security.util.FieldUtils; |
57 | 65 | import org.springframework.stereotype.Controller;
|
58 | 66 | import org.springframework.web.client.RestTemplate;
|
59 | 67 | import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
|
75 | 83 | * Tests for {@link WebSocketMessagingAutoConfiguration}.
|
76 | 84 | *
|
77 | 85 | * @author Andy Wilkinson
|
| 86 | + * @author Lasse Wulff |
78 | 87 | */
|
79 | 88 | class WebSocketMessagingAutoConfigurationTests {
|
80 | 89 |
|
@@ -129,10 +138,34 @@ void customizedConverterTypesMatchDefaultConverterTypes() {
|
129 | 138 | }
|
130 | 139 | }
|
131 | 140 |
|
| 141 | + @Test |
| 142 | + void predefinedThreadExecutorIsSelectedForInboundChannel() throws Throwable { |
| 143 | + AsyncTaskExecutor expectedExecutor = new SimpleAsyncTaskExecutor(); |
| 144 | + ChannelRegistration registration = new ChannelRegistration(); |
| 145 | + WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( |
| 146 | + new ObjectMapper(), |
| 147 | + Map.of(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, expectedExecutor)); |
| 148 | + configuration.configureClientInboundChannel(registration); |
| 149 | + TaskExecutor executor = (TaskExecutor) FieldUtils.getFieldValue(registration, "executor"); |
| 150 | + assertThat(executor).isEqualTo(expectedExecutor); |
| 151 | + } |
| 152 | + |
| 153 | + @Test |
| 154 | + void predefinedThreadExecutorIsSelectedForOutboundChannel() throws Throwable { |
| 155 | + AsyncTaskExecutor expectedExecutor = new SimpleAsyncTaskExecutor(); |
| 156 | + ChannelRegistration registration = new ChannelRegistration(); |
| 157 | + WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( |
| 158 | + new ObjectMapper(), |
| 159 | + Map.of(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, expectedExecutor)); |
| 160 | + configuration.configureClientOutboundChannel(registration); |
| 161 | + TaskExecutor executor = (TaskExecutor) FieldUtils.getFieldValue(registration, "executor"); |
| 162 | + assertThat(executor).isEqualTo(expectedExecutor); |
| 163 | + } |
| 164 | + |
132 | 165 | private List<MessageConverter> getCustomizedConverters() {
|
133 | 166 | List<MessageConverter> customizedConverters = new ArrayList<>();
|
134 | 167 | WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration(
|
135 |
| - new ObjectMapper()); |
| 168 | + new ObjectMapper(), Collections.emptyMap()); |
136 | 169 | configuration.configureMessageConverters(customizedConverters);
|
137 | 170 | return customizedConverters;
|
138 | 171 | }
|
|
0 commit comments