|
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; |
46 | 51 | import org.springframework.messaging.converter.CompositeMessageConverter;
|
47 | 52 | import org.springframework.messaging.converter.MessageConverter;
|
48 | 53 | import org.springframework.messaging.converter.SimpleMessageConverter;
|
49 | 54 | import org.springframework.messaging.simp.annotation.SubscribeMapping;
|
| 55 | +import org.springframework.messaging.simp.config.ChannelRegistration; |
50 | 56 | import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
51 | 57 | import org.springframework.messaging.simp.stomp.StompCommand;
|
52 | 58 | import org.springframework.messaging.simp.stomp.StompFrameHandler;
|
53 | 59 | import org.springframework.messaging.simp.stomp.StompHeaders;
|
54 | 60 | import org.springframework.messaging.simp.stomp.StompSession;
|
55 | 61 | import org.springframework.messaging.simp.stomp.StompSessionHandler;
|
56 | 62 | import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter;
|
| 63 | +import org.springframework.security.util.FieldUtils; |
57 | 64 | import org.springframework.stereotype.Controller;
|
58 | 65 | import org.springframework.web.client.RestTemplate;
|
59 | 66 | import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
|
75 | 82 | * Tests for {@link WebSocketMessagingAutoConfiguration}.
|
76 | 83 | *
|
77 | 84 | * @author Andy Wilkinson
|
| 85 | + * @author Lasse Wulff |
78 | 86 | */
|
79 | 87 | class WebSocketMessagingAutoConfigurationTests {
|
80 | 88 |
|
@@ -129,10 +137,38 @@ void customizedConverterTypesMatchDefaultConverterTypes() {
|
129 | 137 | }
|
130 | 138 | }
|
131 | 139 |
|
| 140 | + @Test |
| 141 | + void predefinedThreadExecutorIsSelectedForInboundChannel() throws Throwable { |
| 142 | + AsyncTaskExecutor expectedExecutor = new SimpleAsyncTaskExecutor(); |
| 143 | + ChannelRegistration registration = new ChannelRegistration(); |
| 144 | + WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( |
| 145 | + new ObjectMapper(), |
| 146 | + Map.of(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, expectedExecutor)); |
| 147 | + |
| 148 | + configuration.configureClientInboundChannel(registration); |
| 149 | + |
| 150 | + AsyncTaskExecutor mappedExecutor = (AsyncTaskExecutor) FieldUtils.getFieldValue(registration, "executor"); |
| 151 | + assertThat(mappedExecutor).isEqualTo(expectedExecutor); |
| 152 | + } |
| 153 | + |
| 154 | + @Test |
| 155 | + void predefinedThreadExecutorIsSelectedForOutboundChannel() throws Throwable { |
| 156 | + AsyncTaskExecutor expectedExecutor = new SimpleAsyncTaskExecutor(); |
| 157 | + ChannelRegistration registration = new ChannelRegistration(); |
| 158 | + WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( |
| 159 | + new ObjectMapper(), |
| 160 | + Map.of(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, expectedExecutor)); |
| 161 | + |
| 162 | + configuration.configureClientOutboundChannel(registration); |
| 163 | + |
| 164 | + AsyncTaskExecutor mappedExecutor = (AsyncTaskExecutor) FieldUtils.getFieldValue(registration, "executor"); |
| 165 | + assertThat(mappedExecutor).isEqualTo(expectedExecutor); |
| 166 | + } |
| 167 | + |
132 | 168 | private List<MessageConverter> getCustomizedConverters() {
|
133 | 169 | List<MessageConverter> customizedConverters = new ArrayList<>();
|
134 | 170 | WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration(
|
135 |
| - new ObjectMapper()); |
| 171 | + new ObjectMapper(), Collections.emptyMap()); |
136 | 172 | configuration.configureMessageConverters(customizedConverters);
|
137 | 173 | return customizedConverters;
|
138 | 174 | }
|
|
0 commit comments