From 28bce49057fc544016ccaa9ee2d37a9c13e454db Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 26 Nov 2021 17:33:40 +0000 Subject: [PATCH] Remove Jetty 10 smoke tests to prepare for Jetty 11 upgrade Closes gh-28825 --- .../build.gradle | 23 -- .../ExampleServletContextListener.java | 40 --- .../jetty10/SampleJetty10Application.java | 29 -- .../jetty10/service/HelloWorldService.java | 32 --- .../jetty10/web/SampleController.java | 38 --- .../src/main/resources/application.properties | 3 - .../src/main/resources/sample.jks | Bin 2264 -> 0 bytes .../jetty10/Jetty10Http2OverTlsTests.java | 86 ------ .../SampleJetty10ApplicationTests.java | 72 ----- .../build.gradle | 22 -- .../SampleJetty10WebSocketsApplication.java | 90 ------- .../jetty10/client/GreetingService.java | 23 -- .../client/SimpleClientWebSocketHandler.java | 60 ----- .../jetty10/client/SimpleGreetingService.java | 26 -- .../jetty10/echo/DefaultEchoService.java | 32 --- .../websocket/jetty10/echo/EchoService.java | 23 -- .../jetty10/echo/EchoWebSocketHandler.java | 58 ---- .../reverse/ReverseWebSocketEndpoint.java | 33 --- .../websocket/jetty10/snake/Direction.java | 23 -- .../websocket/jetty10/snake/Location.java | 78 ------ .../websocket/jetty10/snake/Snake.java | 156 ----------- .../websocket/jetty10/snake/SnakeTimer.java | 117 -------- .../websocket/jetty10/snake/SnakeUtils.java | 66 ----- .../jetty10/snake/SnakeWebSocketHandler.java | 103 -------- .../src/main/resources/static/echo.html | 134 ---------- .../src/main/resources/static/index.html | 33 --- .../src/main/resources/static/reverse.html | 141 ---------- .../src/main/resources/static/snake.html | 250 ------------------ ...mpleJetty10WebSocketsApplicationTests.java | 127 --------- ...omContainerWebSocketsApplicationTests.java | 142 ---------- .../jetty10/snake/SnakeTimerTests.java | 40 --- 31 files changed, 2100 deletions(-) delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/build.gradle delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/ExampleServletContextListener.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/SampleJetty10Application.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/service/HelloWorldService.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/web/SampleController.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/resources/application.properties delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/resources/sample.jks delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/test/java/smoketest/jetty10/Jetty10Http2OverTlsTests.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/test/java/smoketest/jetty10/SampleJetty10ApplicationTests.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/build.gradle delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/SampleJetty10WebSocketsApplication.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/GreetingService.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/SimpleClientWebSocketHandler.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/SimpleGreetingService.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/DefaultEchoService.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/EchoService.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/EchoWebSocketHandler.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/reverse/ReverseWebSocketEndpoint.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Direction.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Location.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Snake.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeTimer.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeUtils.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeWebSocketHandler.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/echo.html delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/index.html delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/reverse.html delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/snake.html delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/SampleJetty10WebSocketsApplicationTests.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/echo/CustomContainerWebSocketsApplicationTests.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/snake/SnakeTimerTests.java diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/build.gradle deleted file mode 100644 index d0fef13649..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -plugins { - id "java" - id "org.springframework.boot.conventions" -} - -description = "Spring Boot Jetty 10 smoke test" - -dependencies { - implementation(enforcedPlatform("org.eclipse.jetty:jetty-bom:10.0.5")) - implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jetty")) { - exclude group: "org.eclipse.jetty.websocket", module: "websocket-server" - exclude group: "org.eclipse.jetty.websocket", module: "javax-websocket-server-impl" - } - implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) { - exclude module: "spring-boot-starter-tomcat" - } - - runtimeOnly("org.eclipse.jetty:jetty-alpn-java-server") - runtimeOnly("org.eclipse.jetty.http2:http2-server") - - testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - testImplementation("org.apache.httpcomponents.client5:httpclient5") -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/ExampleServletContextListener.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/ExampleServletContextListener.java deleted file mode 100644 index 2b408390f8..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/ExampleServletContextListener.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.jetty10; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.springframework.stereotype.Component; - -/** - * Simple {@link ServletContextListener} to test gh-2058. - */ -@Component -public class ExampleServletContextListener implements ServletContextListener { - - @Override - public void contextInitialized(ServletContextEvent sce) { - System.out.println("*** contextInitialized"); - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - System.out.println("*** contextDestroyed"); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/SampleJetty10Application.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/SampleJetty10Application.java deleted file mode 100644 index 4cee564618..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/SampleJetty10Application.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.jetty10; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJetty10Application { - - public static void main(String[] args) { - SpringApplication.run(SampleJetty10Application.class, args); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/service/HelloWorldService.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/service/HelloWorldService.java deleted file mode 100644 index 732de935ba..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/service/HelloWorldService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.jetty10.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - @Value("${name:World}") - private String name; - - public String getHelloMessage() { - return "Hello " + this.name; - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/web/SampleController.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/web/SampleController.java deleted file mode 100644 index d089c836d4..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/java/smoketest/jetty10/web/SampleController.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.jetty10.web; - -import smoketest.jetty10.service.HelloWorldService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class SampleController { - - @Autowired - private HelloWorldService helloWorldService; - - @GetMapping("/") - @ResponseBody - public String helloWorld() { - return this.helloWorldService.getHelloMessage(); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/resources/application.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/resources/application.properties deleted file mode 100644 index eab83fbdfd..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -server.compression.enabled: true -server.compression.min-response-size: 1 -server.jetty.threads.acceptors=2 diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/resources/sample.jks b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/main/resources/sample.jks deleted file mode 100644 index 6aa9a28053a591e41453e665e5024e8a8cb78b3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2264 zcmchYX*3iJ7sqE|hQS!q5Mv)4GM2$i#uAFqC`%7x7baWA*i&dRX>3`uq(XS?3XSYp z%38`&ib7E$8j~$cF^}gt?|I+noW8#w?uYxk=iGD8|K9Vzd#pVc0002(2k@T|2@MMI zqxqr2AhQO*TVi`j@((S;e;g;l$#dAA{>vf0kX$R(Qn4oKgGEYjZ5zti2dw?Z6A zh%LuFCNI?9o+Z1duJL-++e#cjO`zlK?u9s030=k_*wD1#-$FbIDRDnA^vo@fm( zzjt(3VJrGOr0iHXSTM|rYN#>RZ@Dp`PwB2zrDQffLvuoR2~V3ReYa0&vU^dXd8isV zsAf*@!8s%xBvHLseXn6f?1kefe(8uAmAbaF$x{Ykzb6c6jdUwY1$y4tFzsj7 zIghr!T#ODfu@Po!a29@kXQ8kY#(LE<0o7?7PQ|eMeY@Equ?R-6*f@Na3o&stDQ=6( zQzDSQhCnS(9Bu9W_~giknP0vECqUsr4_9y_}nEU`cy z4}dApnAip92wMwgzciAFpc3i}+-#Zlq+iF7d1y}d4Qsp8=%l1N8NIs161I`HmkcpQ zY4*CUCFJJf(2!M{`&qQ}3($KeTQ=)mMrBs`DOb;%Of0tC)9he_p~w&CO#DfCgx(%s z{@|D(brX_Gb}ZDLmGej*JgEl0Et>q~kgTXuJg-PwvRjNx8sBbIShxD=xOySzw{;^X zAvrh5HTg>Xq@<{#^!Kg}B?qz@b<{ebD)yaSf&RChBIJQo-?Ahzw@qopSe^e&>^IuU zydM4Y1_C&>k7u|}=; z63R7$H6zat=hNExxEwXu1fQ*ytuEkP!{w{|#6TIEq1#*ck=6_NM*ILF65tmD-O5&R zMI!-MT<3U~t@}(CN4@RlZ~1I>C=!ywF)dNI{VvH;5Y3(Z4jY^%_c&fsm4Q`<1g|qX z&!h29jXjVE3nJnet*L)XL?-8<>qDbVGP%i^NwOZfwWO7?Mr!X7 zl}sG@9S_5}}td}$xrWIYY=e(VVBiv%A+M-{M z!3_^Tc=pV?niT!{D`!{e@W;MvrZ(OER{x7itVAtwE~spPtPtma|J=5dv&_oE!5H#` zdgXJ;+gJ4hI}*9QX9jpL`Gb)yCe%1}t!&O-^sihyZys%%5uF~WhsR_w(q7;vV5d4P zr%ZUA2}kO+L^2ePTgGT9Ua71w<+)poSyjTdLq&xbUn`<6&SpwFp(HRHUyU6J3WZ_! zfztko79+94Tq%mTYj53(RYcL&1~5`I#+w3`(Q|r+P(aT z%?r(^?IWw~19CB&uvXf(f7&BnEE{zwK4piVU`I4j1j?v5d4N<7VUJ8nM`$7S*mfKR z#9-JzPRZ?{M!@L+0N^V)IyeeP2T|^UK|m0QD+Ibs!wEoml^N!YO#vW~j~jraX(0A3 z6Kux?IRLez`O^X;{!4g%BhcRn>^H*qKZ3*|{_YGuz)KCJcu;)DSES5D2tDE`C02YR0R%Vy1T7k|RQ;3g<0icA$AuP0pOvc~jGl zz+NeKv_FT_;GWK&8XlDUv&hv9kxg?@c!bu?83i=YQ$S!K09Y)Glg3Hz?@|)ZCBlVz zP8i}#XZkMoje3I=h&I!!s_m?Qi@1MR`yv7X*yEs47qOs^t^?&=;*IQ!q&)gq_Sx5* z?fhU8Q*PSe*w7y)FH#P!9R^Xw!lTT+zI39L<&8cViaj$A(Z2Cg7!{V?uuyi#vlNCg z40i}2ivw&y&1-&Nh&WMG`&aIt>)(#tKTJ}^@696Kw1-{IzSOTnFF+0@k$o3%ZHS;Q#;t diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/test/java/smoketest/jetty10/Jetty10Http2OverTlsTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/test/java/smoketest/jetty10/Jetty10Http2OverTlsTests.java deleted file mode 100644 index 54a152c462..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/test/java/smoketest/jetty10/Jetty10Http2OverTlsTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.jetty10; - -import javax.net.ssl.SSLContext; - -import org.apache.hc.client5.http.async.methods.SimpleHttpRequest; -import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; -import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder; -import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; -import org.apache.hc.client5.http.impl.async.HttpAsyncClients; -import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder; -import org.apache.hc.client5.http.ssl.TrustAllStrategy; -import org.apache.hc.core5.concurrent.FutureCallback; -import org.apache.hc.core5.http.ContentType; -import org.apache.hc.core5.http.nio.ssl.TlsStrategy; -import org.apache.hc.core5.ssl.SSLContexts; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; - -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for HTTP/2 over TLS (h2) with Jetty 10. - * - * @author Andy Wilkinson - */ -@EnabledForJreRange(min = JRE.JAVA_11) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = { "server.http2.enabled=true", "server.ssl.enabled=true", - "server.ssl.keystore=classpath:sample.jks", "server.ssl.key-store-password=secret", - "server.ssl.key-password=password" }) -class Jetty10Http2OverTlsTests { - - @LocalServerPort - private int port; - - @Test - void httpOverTlsGetWhenHttp2AndSslAreEnabledSucceeds() throws Exception { - SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(new TrustAllStrategy()).build(); - TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create().setSslContext(sslContext).build(); - try (CloseableHttpAsyncClient http2Client = HttpAsyncClients.customHttp2().setTlsStrategy(tlsStrategy) - .build()) { - http2Client.start(); - SimpleHttpRequest request = SimpleRequestBuilder.get("https://localhost:" + this.port).build(); - request.setBody("Hello World", ContentType.TEXT_PLAIN); - SimpleHttpResponse response = http2Client.execute(request, new FutureCallback() { - - @Override - public void failed(Exception ex) { - } - - @Override - public void completed(SimpleHttpResponse result) { - } - - @Override - public void cancelled() { - } - - }).get(); - assertThat(response.getCode()).isEqualTo(200); - assertThat(response.getBodyText()).isEqualTo("Hello World"); - } - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/test/java/smoketest/jetty10/SampleJetty10ApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/test/java/smoketest/jetty10/SampleJetty10ApplicationTests.java deleted file mode 100644 index dafc112154..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/test/java/smoketest/jetty10/SampleJetty10ApplicationTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.jetty10; - -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; -import java.util.zip.GZIPInputStream; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.util.StreamUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - * @author Andy Wilkinson - */ -@EnabledForJreRange(min = JRE.JAVA_11) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleJetty10ApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() { - ResponseEntity entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - - @Test - void testCompression() throws Exception { - HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.set("Accept-Encoding", "gzip"); - HttpEntity requestEntity = new HttpEntity<>(requestHeaders); - ResponseEntity entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - try (GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()))) { - assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)).isEqualTo("Hello World"); - } - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/build.gradle deleted file mode 100644 index ea3d1b7b68..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/build.gradle +++ /dev/null @@ -1,22 +0,0 @@ -plugins { - id "java" - id "org.springframework.boot.conventions" -} - -description = "Spring Boot WebSocket Jetty 10 smoke test" - -dependencies { - implementation(enforcedPlatform("org.eclipse.jetty:jetty-bom:10.0.5")) - implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jetty")) { - exclude group: "org.eclipse.jetty.websocket", module: "websocket-server" - exclude group: "org.eclipse.jetty.websocket", module: "javax-websocket-server-impl" - } - implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-websocket")) { - exclude module: "spring-boot-starter-tomcat" - } - - runtimeOnly ("org.eclipse.jetty.websocket:websocket-javax-server") - runtimeOnly ("org.eclipse.jetty.websocket:websocket-jetty-server") - - testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/SampleJetty10WebSocketsApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/SampleJetty10WebSocketsApplication.java deleted file mode 100644 index e2711206b2..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/SampleJetty10WebSocketsApplication.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10; - -import smoketest.websocket.jetty10.client.GreetingService; -import smoketest.websocket.jetty10.client.SimpleGreetingService; -import smoketest.websocket.jetty10.echo.DefaultEchoService; -import smoketest.websocket.jetty10.echo.EchoService; -import smoketest.websocket.jetty10.echo.EchoWebSocketHandler; -import smoketest.websocket.jetty10.reverse.ReverseWebSocketEndpoint; -import smoketest.websocket.jetty10.snake.SnakeWebSocketHandler; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.WebSocketHandler; -import org.springframework.web.socket.config.annotation.EnableWebSocket; -import org.springframework.web.socket.config.annotation.WebSocketConfigurer; -import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; -import org.springframework.web.socket.handler.PerConnectionWebSocketHandler; -import org.springframework.web.socket.server.standard.ServerEndpointExporter; - -@Configuration(proxyBeanMethods = false) -@EnableAutoConfiguration -@EnableWebSocket -public class SampleJetty10WebSocketsApplication extends SpringBootServletInitializer implements WebSocketConfigurer { - - @Override - public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS(); - registry.addHandler(snakeWebSocketHandler(), "/snake").withSockJS(); - } - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleJetty10WebSocketsApplication.class); - } - - @Bean - public EchoService echoService() { - return new DefaultEchoService("Did you say \"%s\"?"); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - @Bean - public WebSocketHandler echoWebSocketHandler() { - return new EchoWebSocketHandler(echoService()); - } - - @Bean - public WebSocketHandler snakeWebSocketHandler() { - return new PerConnectionWebSocketHandler(SnakeWebSocketHandler.class); - } - - @Bean - public ReverseWebSocketEndpoint reverseWebSocketEndpoint() { - return new ReverseWebSocketEndpoint(); - } - - @Bean - public ServerEndpointExporter serverEndpointExporter() { - return new ServerEndpointExporter(); - } - - public static void main(String[] args) { - SpringApplication.run(SampleJetty10WebSocketsApplication.class, args); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/GreetingService.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/GreetingService.java deleted file mode 100644 index f0a8ff30da..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/GreetingService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.client; - -public interface GreetingService { - - String getGreeting(); - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/SimpleClientWebSocketHandler.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/SimpleClientWebSocketHandler.java deleted file mode 100644 index 5e628fb651..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/SimpleClientWebSocketHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.client; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -public class SimpleClientWebSocketHandler extends TextWebSocketHandler { - - protected Log logger = LogFactory.getLog(SimpleClientWebSocketHandler.class); - - private final GreetingService greetingService; - - private final CountDownLatch latch; - - private final AtomicReference messagePayload; - - public SimpleClientWebSocketHandler(GreetingService greetingService, CountDownLatch latch, - AtomicReference message) { - this.greetingService = greetingService; - this.latch = latch; - this.messagePayload = message; - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - TextMessage message = new TextMessage(this.greetingService.getGreeting()); - session.sendMessage(message); - } - - @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); - session.close(); - this.messagePayload.set(message.getPayload()); - this.latch.countDown(); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/SimpleGreetingService.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/SimpleGreetingService.java deleted file mode 100644 index 5b5669db00..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/client/SimpleGreetingService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.client; - -public class SimpleGreetingService implements GreetingService { - - @Override - public String getGreeting() { - return "Hello world!"; - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/DefaultEchoService.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/DefaultEchoService.java deleted file mode 100644 index d5df9473e3..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/DefaultEchoService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.echo; - -public class DefaultEchoService implements EchoService { - - private final String echoFormat; - - public DefaultEchoService(String echoFormat) { - this.echoFormat = (echoFormat != null) ? echoFormat : "%s"; - } - - @Override - public String getMessage(String message) { - return String.format(this.echoFormat, message); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/EchoService.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/EchoService.java deleted file mode 100644 index b0d83dcd9f..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/EchoService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.echo; - -public interface EchoService { - - String getMessage(String message); - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/EchoWebSocketHandler.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/EchoWebSocketHandler.java deleted file mode 100644 index c7cd9186c2..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/echo/EchoWebSocketHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.echo; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketHandler; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -/** - * Echo messages by implementing a Spring {@link WebSocketHandler} abstraction. - */ -public class EchoWebSocketHandler extends TextWebSocketHandler { - - private static Log logger = LogFactory.getLog(EchoWebSocketHandler.class); - - private final EchoService echoService; - - public EchoWebSocketHandler(EchoService echoService) { - this.echoService = echoService; - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) { - logger.debug("Opened new session in instance " + this); - } - - @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - String echoMessage = this.echoService.getMessage(message.getPayload()); - logger.debug(echoMessage); - session.sendMessage(new TextMessage(echoMessage)); - } - - @Override - public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { - session.close(CloseStatus.SERVER_ERROR); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/reverse/ReverseWebSocketEndpoint.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/reverse/ReverseWebSocketEndpoint.java deleted file mode 100644 index c971981a4c..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/reverse/ReverseWebSocketEndpoint.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.reverse; - -import java.io.IOException; - -import javax.websocket.OnMessage; -import javax.websocket.Session; -import javax.websocket.server.ServerEndpoint; - -@ServerEndpoint("/reverse") -public class ReverseWebSocketEndpoint { - - @OnMessage - public void handleMessage(Session session, String message) throws IOException { - session.getBasicRemote().sendText("Reversed: " + new StringBuilder(message).reverse()); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Direction.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Direction.java deleted file mode 100644 index 76c1378ab5..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Direction.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.snake; - -public enum Direction { - - NONE, NORTH, SOUTH, EAST, WEST - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Location.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Location.java deleted file mode 100644 index 8121a754ad..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Location.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.snake; - -public class Location { - - /** - * The X location. - */ - public int x; - - /** - * The Y location. - */ - public int y; - - public Location(int x, int y) { - this.x = x; - this.y = y; - } - - public Location getAdjacentLocation(Direction direction) { - switch (direction) { - case NORTH: - return new Location(this.x, this.y - SnakeUtils.GRID_SIZE); - case SOUTH: - return new Location(this.x, this.y + SnakeUtils.GRID_SIZE); - case EAST: - return new Location(this.x + SnakeUtils.GRID_SIZE, this.y); - case WEST: - return new Location(this.x - SnakeUtils.GRID_SIZE, this.y); - case NONE: - // fall through - default: - return this; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Location location = (Location) o; - if (this.x != location.x) { - return false; - } - if (this.y != location.y) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int result = this.x; - result = 31 * result + this.y; - return result; - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Snake.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Snake.java deleted file mode 100644 index 8f4cc363ea..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/Snake.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.snake; - -import java.util.ArrayDeque; -import java.util.Collection; -import java.util.Deque; - -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; - -public class Snake { - - private static final int DEFAULT_LENGTH = 5; - - private final Deque tail = new ArrayDeque<>(); - - private final Object monitor = new Object(); - - private final int id; - - private final WebSocketSession session; - - private final String hexColor; - - private Direction direction; - - private int length = DEFAULT_LENGTH; - - private Location head; - - public Snake(int id, WebSocketSession session) { - this.id = id; - this.session = session; - this.hexColor = SnakeUtils.getRandomHexColor(); - resetState(); - } - - private void resetState() { - this.direction = Direction.NONE; - this.head = SnakeUtils.getRandomLocation(); - this.tail.clear(); - this.length = DEFAULT_LENGTH; - } - - private void kill() throws Exception { - synchronized (this.monitor) { - resetState(); - sendMessage("{'type': 'dead'}"); - } - } - - private void reward() throws Exception { - synchronized (this.monitor) { - this.length++; - sendMessage("{'type': 'kill'}"); - } - } - - protected void sendMessage(String msg) throws Exception { - this.session.sendMessage(new TextMessage(msg)); - } - - public void update(Collection snakes) throws Exception { - synchronized (this.monitor) { - Location nextLocation = this.head.getAdjacentLocation(this.direction); - if (nextLocation.x >= SnakeUtils.PLAYFIELD_WIDTH) { - nextLocation.x = 0; - } - if (nextLocation.y >= SnakeUtils.PLAYFIELD_HEIGHT) { - nextLocation.y = 0; - } - if (nextLocation.x < 0) { - nextLocation.x = SnakeUtils.PLAYFIELD_WIDTH; - } - if (nextLocation.y < 0) { - nextLocation.y = SnakeUtils.PLAYFIELD_HEIGHT; - } - if (this.direction != Direction.NONE) { - this.tail.addFirst(this.head); - if (this.tail.size() > this.length) { - this.tail.removeLast(); - } - this.head = nextLocation; - } - - handleCollisions(snakes); - } - } - - private void handleCollisions(Collection snakes) throws Exception { - for (Snake snake : snakes) { - boolean headCollision = this.id != snake.id && snake.getHead().equals(this.head); - boolean tailCollision = snake.getTail().contains(this.head); - if (headCollision || tailCollision) { - kill(); - if (this.id != snake.id) { - snake.reward(); - } - } - } - } - - public Location getHead() { - synchronized (this.monitor) { - return this.head; - } - } - - public Collection getTail() { - synchronized (this.monitor) { - return this.tail; - } - } - - public void setDirection(Direction direction) { - synchronized (this.monitor) { - this.direction = direction; - } - } - - public String getLocationsJson() { - synchronized (this.monitor) { - StringBuilder sb = new StringBuilder(); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y))); - for (Location location : this.tail) { - sb.append(','); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y))); - } - return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb.toString()); - } - } - - public int getId() { - return this.id; - } - - public String getHexColor() { - return this.hexColor; - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeTimer.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeTimer.java deleted file mode 100644 index c140a4703b..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeTimer.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.snake; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Sets up the timer for the multi-player snake game WebSocket example. - */ -public final class SnakeTimer { - - private static final long TICK_DELAY = 100; - - private static final Object MONITOR = new Object(); - - private static final Log logger = LogFactory.getLog(SnakeTimer.class); - - private static final ConcurrentHashMap snakes = new ConcurrentHashMap<>(); - - private static Timer gameTimer = null; - - private SnakeTimer() { - } - - public static void addSnake(Snake snake) { - synchronized (MONITOR) { - if (snakes.isEmpty()) { - startTimer(); - } - snakes.put(Integer.valueOf(snake.getId()), snake); - } - } - - public static Collection getSnakes() { - return Collections.unmodifiableCollection(snakes.values()); - } - - public static void removeSnake(Snake snake) { - synchronized (MONITOR) { - snakes.remove(Integer.valueOf(snake.getId())); - if (snakes.isEmpty()) { - stopTimer(); - } - } - } - - public static void tick() throws Exception { - StringBuilder sb = new StringBuilder(); - for (Iterator iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { - Snake snake = iterator.next(); - snake.update(SnakeTimer.getSnakes()); - sb.append(snake.getLocationsJson()); - if (iterator.hasNext()) { - sb.append(','); - } - } - broadcast(String.format("{'type': 'update', 'data' : [%s]}", sb.toString())); - } - - public static void broadcast(String message) throws Exception { - Collection snakes = new CopyOnWriteArrayList<>(SnakeTimer.getSnakes()); - for (Snake snake : snakes) { - try { - snake.sendMessage(message); - } - catch (Throwable ex) { - // if Snake#sendMessage fails the client is removed - removeSnake(snake); - } - } - } - - public static void startTimer() { - gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer"); - gameTimer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - try { - tick(); - } - catch (Throwable ex) { - logger.error("Caught to prevent timer from shutting down", ex); - } - } - }, TICK_DELAY, TICK_DELAY); - } - - public static void stopTimer() { - if (gameTimer != null) { - gameTimer.cancel(); - } - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeUtils.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeUtils.java deleted file mode 100644 index 081e1a6d75..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeUtils.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.snake; - -import java.awt.Color; -import java.util.Random; - -public final class SnakeUtils { - - /** - * The width of the playfield. - */ - public static final int PLAYFIELD_WIDTH = 640; - - /** - * The height of the playfield. - */ - public static final int PLAYFIELD_HEIGHT = 480; - - /** - * The grid size. - */ - public static final int GRID_SIZE = 10; - - private static final Random random = new Random(); - - private SnakeUtils() { - } - - public static String getRandomHexColor() { - float hue = random.nextFloat(); - // sat between 0.1 and 0.3 - float saturation = (random.nextInt(2000) + 1000) / 10000f; - float luminance = 0.9f; - Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); - } - - public static Location getRandomLocation() { - int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH)); - int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT)); - return new Location(x, y); - } - - private static int roundByGridSize(int value) { - value = value + (GRID_SIZE / 2); - value = value / GRID_SIZE; - value = value * GRID_SIZE; - return value; - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeWebSocketHandler.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeWebSocketHandler.java deleted file mode 100644 index b7d4476550..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/java/smoketest/websocket/jetty10/snake/SnakeWebSocketHandler.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.snake; - -import java.awt.Color; -import java.util.Iterator; -import java.util.Random; -import java.util.concurrent.atomic.AtomicInteger; - -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -public class SnakeWebSocketHandler extends TextWebSocketHandler { - - private static final AtomicInteger snakeIds = new AtomicInteger(); - - private static final Random random = new Random(); - - private final int id; - - private Snake snake; - - public static String getRandomHexColor() { - float hue = random.nextFloat(); - // sat between 0.1 and 0.3 - float saturation = (random.nextInt(2000) + 1000) / 10000f; - float luminance = 0.9f; - Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); - } - - public static Location getRandomLocation() { - int x = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_WIDTH)); - int y = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_HEIGHT)); - return new Location(x, y); - } - - private static int roundByGridSize(int value) { - value = value + (SnakeUtils.GRID_SIZE / 2); - value = value / SnakeUtils.GRID_SIZE; - value = value * SnakeUtils.GRID_SIZE; - return value; - } - - public SnakeWebSocketHandler() { - this.id = snakeIds.getAndIncrement(); - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - this.snake = new Snake(this.id, session); - SnakeTimer.addSnake(this.snake); - StringBuilder sb = new StringBuilder(); - for (Iterator iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { - Snake snake = iterator.next(); - sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor())); - if (iterator.hasNext()) { - sb.append(','); - } - } - SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); - } - - @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - String payload = message.getPayload(); - if ("west".equals(payload)) { - this.snake.setDirection(Direction.WEST); - } - else if ("north".equals(payload)) { - this.snake.setDirection(Direction.NORTH); - } - else if ("east".equals(payload)) { - this.snake.setDirection(Direction.EAST); - } - else if ("south".equals(payload)) { - this.snake.setDirection(Direction.SOUTH); - } - } - - @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { - SnakeTimer.removeSnake(this.snake); - SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/echo.html b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/echo.html deleted file mode 100644 index 54d33f55bd..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/echo.html +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - Apache Tomcat WebSocket Examples: Echo - - - - - - -
-
-
- -
-
- - -
-
- -
-
- -
-
-
-
-
-
- - diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/index.html b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/index.html deleted file mode 100644 index 6bab9d6237..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/index.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - Apache Tomcat WebSocket Examples: Index - - - -

Please select the sample you would like to try.

-
- - diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/reverse.html b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/reverse.html deleted file mode 100644 index 60d7ee4978..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/reverse.html +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - WebSocket Examples: Reverse - - - - - -
-
-
- -
-
- - -
-
- -
-
- -
-
-
-
-
-
- - diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/snake.html b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/snake.html deleted file mode 100644 index fe0a2ea88e..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/main/resources/static/snake.html +++ /dev/null @@ -1,250 +0,0 @@ - - - - - - - Apache Tomcat WebSocket Examples: Multiplayer Snake - - - - - - -
- -
-
-
-
- - - diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/SampleJetty10WebSocketsApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/SampleJetty10WebSocketsApplicationTests.java deleted file mode 100644 index dec1463448..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/SampleJetty10WebSocketsApplicationTests.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; -import smoketest.websocket.jetty10.client.GreetingService; -import smoketest.websocket.jetty10.client.SimpleClientWebSocketHandler; -import smoketest.websocket.jetty10.client.SimpleGreetingService; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@EnabledForJreRange(min = JRE.JAVA_11) -@SpringBootTest(classes = SampleJetty10WebSocketsApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleJetty10WebSocketsApplicationTests { - - private static Log logger = LogFactory.getLog(SampleJetty10WebSocketsApplicationTests.class); - - @LocalServerPort - private int port = 1234; - - @Test - void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); - } - - @Test - void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); - } - - @Configuration(proxyBeanMethods = false) - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference messagePayload = new AtomicReference<>(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - WebSocketConnectionManager wsConnectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); - manager.setAutoStartup(true); - return manager; - } - - @Bean - StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); - } - - @Bean - GreetingService greetingService() { - return new SimpleGreetingService(); - } - - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/echo/CustomContainerWebSocketsApplicationTests.java deleted file mode 100644 index 7f581051c9..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/echo/CustomContainerWebSocketsApplicationTests.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.echo; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; -import smoketest.websocket.jetty10.SampleJetty10WebSocketsApplication; -import smoketest.websocket.jetty10.client.GreetingService; -import smoketest.websocket.jetty10.client.SimpleClientWebSocketHandler; -import smoketest.websocket.jetty10.client.SimpleGreetingService; -import smoketest.websocket.jetty10.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.boot.web.servlet.server.ServletWebServerFactory; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@EnabledForJreRange(min = JRE.JAVA_11) -@SpringBootTest(classes = { SampleJetty10WebSocketsApplication.class, CustomContainerConfiguration.class }, - webEnvironment = WebEnvironment.RANDOM_PORT) -class CustomContainerWebSocketsApplicationTests { - - private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); - - @LocalServerPort - private int port; - - @Test - void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); - } - - @Test - void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); - } - - @Configuration(proxyBeanMethods = false) - protected static class CustomContainerConfiguration { - - @Bean - public ServletWebServerFactory webServerFactory() { - return new JettyServletWebServerFactory("/ws", 0); - } - - } - - @Configuration(proxyBeanMethods = false) - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference messagePayload = new AtomicReference<>(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - WebSocketConnectionManager wsConnectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); - manager.setAutoStartup(true); - return manager; - } - - @Bean - StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); - } - - @Bean - GreetingService greetingService() { - return new SimpleGreetingService(); - } - - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/snake/SnakeTimerTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/snake/SnakeTimerTests.java deleted file mode 100644 index c45ef584a2..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty10/src/test/java/smoketest/websocket/jetty10/snake/SnakeTimerTests.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.websocket.jetty10.snake; - -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Mockito.mock; - -class SnakeTimerTests { - - @Test - void removeDysfunctionalSnakes() throws Exception { - Snake snake = mock(Snake.class); - willThrow(new IOException()).given(snake).sendMessage(anyString()); - SnakeTimer.addSnake(snake); - - SnakeTimer.broadcast(""); - assertThat(SnakeTimer.getSnakes()).hasSize(0); - } - -}