1
+ /*
2
+ *
3
+ * * Copyright 2019-2020 the original author or authors.
4
+ * *
5
+ * * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * * you may not use this file except in compliance with the License.
7
+ * * You may obtain a copy of the License at
8
+ * *
9
+ * * https://www.apache.org/licenses/LICENSE-2.0
10
+ * *
11
+ * * Unless required by applicable law or agreed to in writing, software
12
+ * * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * * See the License for the specific language governing permissions and
15
+ * * limitations under the License.
16
+ *
17
+ */
18
+
19
+ package test .org .springdoc .ui .app8 ;
20
+
21
+ import org .junit .jupiter .api .Test ;
22
+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
23
+ import org .springframework .test .context .TestPropertySource ;
24
+ import test .org .springdoc .ui .AbstractSpringDocTest ;
25
+
26
+ import java .util .concurrent .CompletableFuture ;
27
+ import java .util .stream .Stream ;
28
+
29
+ import static java .util .concurrent .CompletableFuture .allOf ;
30
+ import static java .util .concurrent .CompletableFuture .runAsync ;
31
+ import static org .hamcrest .CoreMatchers .equalTo ;
32
+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
33
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
34
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
35
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
36
+
37
+ @ TestPropertySource (properties = {
38
+ "springdoc.swagger-ui.urls[0].name=first-user-list" ,
39
+ "springdoc.swagger-ui.urls[0].url=/api-docs.yaml" ,
40
+ "springdoc.swagger-ui.urls[1].name=second-user-list" ,
41
+ "springdoc.swagger-ui.urls[1].url=/api-docs.yaml" ,
42
+ "springdoc.swagger-ui.urls[2].name=third-user-list" ,
43
+ "springdoc.swagger-ui.urls[2].url=/api-docs.yaml"
44
+ })
45
+ public class SpringDocApp8MultipleUrlsSeveralParallelRequestsTest extends AbstractSpringDocTest {
46
+
47
+ private static final int PARALLEL_REQUEST_NUMBER = 100 ;
48
+
49
+ /**
50
+ * Sends {@link SpringDocApp8MultipleUrlsSeveralParallelRequestsTest#PARALLEL_REQUEST_NUMBER} requests
51
+ * simultaneously to make sure no race condition issues are present.
52
+ */
53
+ @ Test
54
+ public void swagger_config_for_multiple_groups_and_many_parallel_requests () {
55
+ assertDoesNotThrow (() -> {
56
+ allOf (Stream .generate (() -> runAsync (() -> {
57
+ try {
58
+ mockMvc .perform (get ("/v3/api-docs/swagger-config" ))
59
+ .andExpect (status ().isOk ())
60
+ .andExpect (jsonPath ("configUrl" , equalTo ("/v3/api-docs/swagger-config" )))
61
+ .andExpect (jsonPath ("url" ).doesNotExist ())
62
+ .andExpect (jsonPath ("urls.length()" , equalTo (3 )))
63
+ .andExpect (jsonPath ("urls[0].url" , equalTo ("/api-docs.yaml" )))
64
+ .andExpect (jsonPath ("urls[0].name" , equalTo ("first-user-list" )))
65
+ .andExpect (jsonPath ("urls[1].url" , equalTo ("/api-docs.yaml" )))
66
+ .andExpect (jsonPath ("urls[1].name" , equalTo ("second-user-list" )))
67
+ .andExpect (jsonPath ("urls[2].url" , equalTo ("/api-docs.yaml" )))
68
+ .andExpect (jsonPath ("urls[2].name" , equalTo ("third-user-list" )));
69
+ } catch (Exception e ) {
70
+ throw new RuntimeException (e );
71
+ }
72
+ }))
73
+ .limit (PARALLEL_REQUEST_NUMBER )
74
+ .toArray (CompletableFuture []::new ))
75
+ .join ();
76
+ }, "Swagger config is supposed to be delivered successfully " +
77
+ "no matter how many parallel requests are sent" );
78
+ }
79
+
80
+ @ SpringBootApplication
81
+ static class SpringDocTestApp {}
82
+
83
+ }
0 commit comments