diff options
author | 2023-07-24 14:37:16 +0200 | |
---|---|---|
committer | 2023-07-24 14:37:16 +0200 | |
commit | 8789304690384d19ad829286560aec5ed0917976 (patch) | |
tree | b157e78e8b6a3f2fb3d0eee6e1aa10d2c16e0204 /subprojects/language-web/src/test/java/tools | |
parent | decreasing steps in fast fuzz tests (diff) | |
parent | Merge pull request #27 from kris7t/ordered-result-set (diff) | |
download | refinery-8789304690384d19ad829286560aec5ed0917976.tar.gz refinery-8789304690384d19ad829286560aec5ed0917976.tar.zst refinery-8789304690384d19ad829286560aec5ed0917976.zip |
Merge branch 'graphs4value:main' into datastructure
Diffstat (limited to 'subprojects/language-web/src/test/java/tools')
6 files changed, 77 insertions, 31 deletions
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java index ecbefc4f..927eeab1 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java | |||
@@ -1,20 +1,30 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
1 | package tools.refinery.language.web; | 6 | package tools.refinery.language.web; |
2 | 7 | ||
3 | import org.eclipse.jetty.ee10.servlet.ServletContextHandler; | 8 | import org.eclipse.jetty.ee10.servlet.ServletContextHandler; |
4 | import org.eclipse.jetty.ee10.servlet.ServletHolder; | 9 | import org.eclipse.jetty.ee10.servlet.ServletHolder; |
5 | import org.eclipse.jetty.ee10.websocket.api.Session; | ||
6 | import org.eclipse.jetty.ee10.websocket.api.StatusCode; | ||
7 | import org.eclipse.jetty.ee10.websocket.api.annotations.WebSocket; | ||
8 | import org.eclipse.jetty.ee10.websocket.api.exceptions.UpgradeException; | ||
9 | import org.eclipse.jetty.ee10.websocket.client.ClientUpgradeRequest; | ||
10 | import org.eclipse.jetty.ee10.websocket.client.WebSocketClient; | ||
11 | import org.eclipse.jetty.ee10.websocket.server.config.JettyWebSocketServletContainerInitializer; | 10 | import org.eclipse.jetty.ee10.websocket.server.config.JettyWebSocketServletContainerInitializer; |
12 | import org.eclipse.jetty.http.HttpHeader; | 11 | import org.eclipse.jetty.http.HttpHeader; |
13 | import org.eclipse.jetty.http.HttpStatus; | 12 | import org.eclipse.jetty.http.HttpStatus; |
14 | import org.eclipse.jetty.server.Server; | 13 | import org.eclipse.jetty.server.Server; |
14 | import org.eclipse.jetty.util.thread.QueuedThreadPool; | ||
15 | import org.eclipse.jetty.websocket.api.Callback; | ||
16 | import org.eclipse.jetty.websocket.api.Session; | ||
17 | import org.eclipse.jetty.websocket.api.StatusCode; | ||
18 | import org.eclipse.jetty.websocket.api.annotations.WebSocket; | ||
19 | import org.eclipse.jetty.websocket.api.exceptions.UpgradeException; | ||
20 | import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; | ||
21 | import org.eclipse.jetty.websocket.client.WebSocketClient; | ||
15 | import org.eclipse.xtext.testing.GlobalRegistries; | 22 | import org.eclipse.xtext.testing.GlobalRegistries; |
16 | import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; | 23 | import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; |
17 | import org.junit.jupiter.api.*; | 24 | import org.junit.jupiter.api.AfterEach; |
25 | import org.junit.jupiter.api.BeforeEach; | ||
26 | import org.junit.jupiter.api.Test; | ||
27 | import org.junit.jupiter.api.TestInfo; | ||
18 | import org.junit.jupiter.params.ParameterizedTest; | 28 | import org.junit.jupiter.params.ParameterizedTest; |
19 | import org.junit.jupiter.params.provider.ValueSource; | 29 | import org.junit.jupiter.params.provider.ValueSource; |
20 | import tools.refinery.language.web.tests.WebSocketIntegrationTestClient; | 30 | import tools.refinery.language.web.tests.WebSocketIntegrationTestClient; |
@@ -86,23 +96,34 @@ class ProblemWebSocketServletIntegrationTest { | |||
86 | assertThat(responses, hasSize(5)); | 96 | assertThat(responses, hasSize(5)); |
87 | assertThat(responses.get(0), equalTo("{\"id\":\"foo\",\"response\":{\"stateId\":\"-80000000\"}}")); | 97 | assertThat(responses.get(0), equalTo("{\"id\":\"foo\",\"response\":{\"stateId\":\"-80000000\"}}")); |
88 | assertThat(responses.get(1), startsWith( | 98 | assertThat(responses.get(1), startsWith( |
89 | "{\"resource\":\"test.problem\",\"stateId\":\"-80000000\",\"service\":\"highlight\",\"push\":{\"regions\":[")); | 99 | "{\"resource\":\"test.problem\",\"stateId\":\"-80000000\",\"service\":\"highlight\"," + |
100 | "\"push\":{\"regions\":[")); | ||
90 | assertThat(responses.get(2), equalTo( | 101 | assertThat(responses.get(2), equalTo( |
91 | "{\"resource\":\"test.problem\",\"stateId\":\"-80000000\",\"service\":\"validate\",\"push\":{\"issues\":[]}}")); | 102 | "{\"resource\":\"test.problem\",\"stateId\":\"-80000000\",\"service\":\"validate\"," + |
103 | "\"push\":{\"issues\":[]}}")); | ||
92 | assertThat(responses.get(3), equalTo("{\"id\":\"bar\",\"response\":{\"stateId\":\"-7fffffff\"}}")); | 104 | assertThat(responses.get(3), equalTo("{\"id\":\"bar\",\"response\":{\"stateId\":\"-7fffffff\"}}")); |
93 | assertThat(responses.get(4), startsWith( | 105 | assertThat(responses.get(4), startsWith( |
94 | "{\"resource\":\"test.problem\",\"stateId\":\"-7fffffff\",\"service\":\"highlight\",\"push\":{\"regions\":[")); | 106 | "{\"resource\":\"test.problem\",\"stateId\":\"-7fffffff\",\"service\":\"highlight\"," + |
107 | "\"push\":{\"regions\":[")); | ||
95 | } | 108 | } |
96 | 109 | ||
97 | @WebSocket | 110 | @WebSocket |
98 | public static class UpdateTestClient extends WebSocketIntegrationTestClient { | 111 | public static class UpdateTestClient extends WebSocketIntegrationTestClient { |
99 | @Override | 112 | @Override |
100 | protected void arrange(Session session, int responsesReceived) throws IOException { | 113 | protected void arrange(Session session, int responsesReceived) { |
101 | switch (responsesReceived) { | 114 | switch (responsesReceived) { |
102 | case 0 -> session.getRemote().sendString( | 115 | case 0 -> session.sendText( |
103 | "{\"id\":\"foo\",\"request\":{\"resource\":\"test.problem\",\"serviceType\":\"update\",\"fullText\":\"class Person.\n\"}}"); | 116 | "{\"id\":\"foo\",\"request\":{\"resource\":\"test.problem\",\"serviceType\":\"update\"," + |
104 | case 3 -> session.getRemote().sendString( | 117 | "\"fullText\":\"class Person.\n\"}}", |
105 | "{\"id\":\"bar\",\"request\":{\"resource\":\"test.problem\",\"serviceType\":\"update\",\"requiredStateId\":\"-80000000\",\"deltaText\":\"indiv q.\nnode(q).\n\",\"deltaOffset\":\"0\",\"deltaReplaceLength\":\"0\"}}"); | 118 | Callback.NOOP |
119 | ); | ||
120 | case 3 -> //noinspection TextBlockMigration | ||
121 | session.sendText( | ||
122 | "{\"id\":\"bar\",\"request\":{\"resource\":\"test.problem\",\"serviceType\":\"update\"," + | ||
123 | "\"requiredStateId\":\"-80000000\",\"deltaText\":\"indiv q.\nnode(q).\n\"," + | ||
124 | "\"deltaOffset\":\"0\",\"deltaReplaceLength\":\"0\"}}", | ||
125 | Callback.NOOP | ||
126 | ); | ||
106 | case 5 -> session.close(); | 127 | case 5 -> session.close(); |
107 | } | 128 | } |
108 | } | 129 | } |
@@ -152,13 +173,13 @@ class ProblemWebSocketServletIntegrationTest { | |||
152 | @WebSocket | 173 | @WebSocket |
153 | public static class InvalidJsonTestClient extends WebSocketIntegrationTestClient { | 174 | public static class InvalidJsonTestClient extends WebSocketIntegrationTestClient { |
154 | @Override | 175 | @Override |
155 | protected void arrange(Session session, int responsesReceived) throws IOException { | 176 | protected void arrange(Session session, int responsesReceived) { |
156 | session.getRemote().sendString("<invalid json>"); | 177 | session.sendText("<invalid json>", Callback.NOOP); |
157 | } | 178 | } |
158 | } | 179 | } |
159 | 180 | ||
160 | @ParameterizedTest(name = "validOriginTest(\"{0}\")") | 181 | @ParameterizedTest(name = "validOriginTest(\"{0}\")") |
161 | @ValueSource(strings = { "https://refinery.example", "https://refinery.example:443", "HTTPS://REFINERY.EXAMPLE" }) | 182 | @ValueSource(strings = {"https://refinery.example", "https://refinery.example:443", "HTTPS://REFINERY.EXAMPLE"}) |
162 | void validOriginTest(String origin) { | 183 | void validOriginTest(String origin) { |
163 | startServer("https://refinery.example,https://refinery.example:443"); | 184 | startServer("https://refinery.example,https://refinery.example:443"); |
164 | var clientSocket = new CloseImmediatelyTestClient(); | 185 | var clientSocket = new CloseImmediatelyTestClient(); |
@@ -188,7 +209,8 @@ class ProblemWebSocketServletIntegrationTest { | |||
188 | private void startServer(String allowedOrigins) { | 209 | private void startServer(String allowedOrigins) { |
189 | var testName = getClass().getSimpleName() + "-" + testInfo.getDisplayName(); | 210 | var testName = getClass().getSimpleName() + "-" + testInfo.getDisplayName(); |
190 | var listenAddress = new InetSocketAddress(HOSTNAME, serverPort); | 211 | var listenAddress = new InetSocketAddress(HOSTNAME, serverPort); |
191 | server = VirtualThreadUtils.newServerWithVirtualThreadsThreadPool(testName, listenAddress); | 212 | server = new Server(listenAddress); |
213 | ((QueuedThreadPool) server.getThreadPool()).setName(testName); | ||
192 | var handler = new ServletContextHandler(); | 214 | var handler = new ServletContextHandler(); |
193 | var holder = new ServletHolder(ProblemWebSocketServlet.class); | 215 | var holder = new ServletHolder(ProblemWebSocketServlet.class); |
194 | if (allowedOrigins != null) { | 216 | if (allowedOrigins != null) { |
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java index c634e8fc..52acee6d 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java | |||
@@ -1,14 +1,19 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
1 | package tools.refinery.language.web.tests; | 6 | package tools.refinery.language.web.tests; |
2 | 7 | ||
3 | import com.google.inject.Singleton; | 8 | import com.google.inject.Singleton; |
4 | import tools.refinery.language.web.xtext.VirtualThreadExecutorServiceProvider; | 9 | import org.eclipse.xtext.ide.ExecutorServiceProvider; |
5 | 10 | ||
6 | import java.util.ArrayList; | 11 | import java.util.ArrayList; |
7 | import java.util.List; | 12 | import java.util.List; |
8 | import java.util.concurrent.ExecutorService; | 13 | import java.util.concurrent.ExecutorService; |
9 | 14 | ||
10 | @Singleton | 15 | @Singleton |
11 | public class AwaitTerminationExecutorServiceProvider extends VirtualThreadExecutorServiceProvider { | 16 | public class AwaitTerminationExecutorServiceProvider extends ExecutorServiceProvider { |
12 | private final List<RestartableCachedThreadPool> servicesToShutDown = new ArrayList<>(); | 17 | private final List<RestartableCachedThreadPool> servicesToShutDown = new ArrayList<>(); |
13 | 18 | ||
14 | @Override | 19 | @Override |
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/ProblemWebInjectorProvider.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/ProblemWebInjectorProvider.java index 43c12faa..4a5eed95 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/ProblemWebInjectorProvider.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/ProblemWebInjectorProvider.java | |||
@@ -1,3 +1,8 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
1 | package tools.refinery.language.web.tests; | 6 | package tools.refinery.language.web.tests; |
2 | 7 | ||
3 | import org.eclipse.xtext.ide.ExecutorServiceProvider; | 8 | import org.eclipse.xtext.ide.ExecutorServiceProvider; |
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/RestartableCachedThreadPool.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/RestartableCachedThreadPool.java index cf805eda..09079aa8 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/RestartableCachedThreadPool.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/RestartableCachedThreadPool.java | |||
@@ -1,3 +1,8 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
1 | package tools.refinery.language.web.tests; | 6 | package tools.refinery.language.web.tests; |
2 | 7 | ||
3 | import com.google.inject.Provider; | 8 | import com.google.inject.Provider; |
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java index f19c10ca..6ccf1760 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java | |||
@@ -1,12 +1,16 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
1 | package tools.refinery.language.web.tests; | 6 | package tools.refinery.language.web.tests; |
2 | 7 | ||
3 | import org.eclipse.jetty.ee10.websocket.api.Session; | 8 | import org.eclipse.jetty.websocket.api.Session; |
4 | import org.eclipse.jetty.ee10.websocket.api.annotations.OnWebSocketClose; | 9 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; |
5 | import org.eclipse.jetty.ee10.websocket.api.annotations.OnWebSocketConnect; | 10 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError; |
6 | import org.eclipse.jetty.ee10.websocket.api.annotations.OnWebSocketError; | 11 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; |
7 | import org.eclipse.jetty.ee10.websocket.api.annotations.OnWebSocketMessage; | 12 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketOpen; |
8 | 13 | ||
9 | import java.io.IOException; | ||
10 | import java.time.Duration; | 14 | import java.time.Duration; |
11 | import java.util.ArrayList; | 15 | import java.util.ArrayList; |
12 | import java.util.List; | 16 | import java.util.List; |
@@ -14,7 +18,7 @@ import java.util.List; | |||
14 | import static org.junit.jupiter.api.Assertions.fail; | 18 | import static org.junit.jupiter.api.Assertions.fail; |
15 | 19 | ||
16 | public abstract class WebSocketIntegrationTestClient { | 20 | public abstract class WebSocketIntegrationTestClient { |
17 | private static final long TIMEOUT_MILLIS = Duration.ofSeconds(1).toMillis(); | 21 | private static final long TIMEOUT_MILLIS = Duration.ofSeconds(10).toMillis(); |
18 | 22 | ||
19 | private boolean finished = false; | 23 | private boolean finished = false; |
20 | 24 | ||
@@ -34,8 +38,8 @@ public abstract class WebSocketIntegrationTestClient { | |||
34 | return responses; | 38 | return responses; |
35 | } | 39 | } |
36 | 40 | ||
37 | @OnWebSocketConnect | 41 | @OnWebSocketOpen |
38 | public void onConnect(Session session) { | 42 | public void onOpen(Session session) { |
39 | arrangeAndCatchErrors(session); | 43 | arrangeAndCatchErrors(session); |
40 | } | 44 | } |
41 | 45 | ||
@@ -47,7 +51,7 @@ public abstract class WebSocketIntegrationTestClient { | |||
47 | } | 51 | } |
48 | } | 52 | } |
49 | 53 | ||
50 | protected abstract void arrange(Session session, int responsesReceived) throws IOException; | 54 | protected abstract void arrange(Session session, int responsesReceived); |
51 | 55 | ||
52 | @OnWebSocketClose | 56 | @OnWebSocketClose |
53 | public void onClose(int statusCode, String reason) { | 57 | public void onClose(int statusCode, String reason) { |
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/xtext/servlet/TransactionExecutorTest.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/xtext/servlet/TransactionExecutorTest.java index 17f1ff5c..841bacd3 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/xtext/servlet/TransactionExecutorTest.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/xtext/servlet/TransactionExecutorTest.java | |||
@@ -1,3 +1,8 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
1 | package tools.refinery.language.web.xtext.servlet; | 6 | package tools.refinery.language.web.xtext.servlet; |
2 | 7 | ||
3 | import com.google.inject.Inject; | 8 | import com.google.inject.Inject; |