Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #6601 - add proper JPMS testing for websocket-core
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
- Loading branch information
1 parent
f10ae7c
commit e64b390
Showing
7 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>org.eclipse.jetty.tests</groupId> | ||
<artifactId>tests-parent</artifactId> | ||
<version>10.0.7-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>test-jpms</artifactId> | ||
<packaging>pom</packaging> | ||
<name>Jetty Tests :: JPMS Parent</name> | ||
<modules> | ||
<module>test-websocket-core</module> | ||
</modules> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-slf4j-impl</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.toolchain</groupId> | ||
<artifactId>jetty-test-helper</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>test-jpms</artifactId> | ||
<groupId>org.eclipse.jetty.tests</groupId> | ||
<version>10.0.7-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>test-websocket-core</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Jetty Tests :: JPMS :: WebSocket Core Tests</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.websocket</groupId> | ||
<artifactId>websocket-core-server</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.websocket</groupId> | ||
<artifactId>websocket-core-client</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
7 changes: 7 additions & 0 deletions
7
tests/test-jpms/test-websocket-core/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module org.eclipse.jetty.websocket.core.tests | ||
{ | ||
exports org.example.websocket; | ||
|
||
requires org.eclipse.jetty.websocket.core.server; | ||
requires org.eclipse.jetty.websocket.core.client; | ||
} |
62 changes: 62 additions & 0 deletions
62
tests/test-jpms/test-websocket-core/src/main/java/org/example/websocket/MyFrameHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.example.websocket; | ||
|
||
import org.eclipse.jetty.util.Callback; | ||
import org.eclipse.jetty.websocket.core.CloseStatus; | ||
import org.eclipse.jetty.websocket.core.CoreSession; | ||
import org.eclipse.jetty.websocket.core.Frame; | ||
import org.eclipse.jetty.websocket.core.FrameHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class MyFrameHandler implements FrameHandler | ||
{ | ||
private static final Logger LOG = LoggerFactory.getLogger(MyFrameHandler.class); | ||
|
||
private final String _id; | ||
|
||
public MyFrameHandler(String id) | ||
{ | ||
_id = id; | ||
} | ||
|
||
@Override | ||
public void onOpen(CoreSession coreSession, Callback callback) | ||
{ | ||
LOG.info(_id + " onOpen"); | ||
callback.succeeded(); | ||
} | ||
|
||
@Override | ||
public void onFrame(Frame frame, Callback callback) | ||
{ | ||
LOG.info(_id + " onFrame"); | ||
callback.succeeded(); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable cause, Callback callback) | ||
{ | ||
LOG.info(_id + " onError"); | ||
callback.succeeded(); | ||
} | ||
|
||
@Override | ||
public void onClosed(CloseStatus closeStatus, Callback callback) | ||
{ | ||
LOG.info(_id + " onClosed"); | ||
callback.succeeded(); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
tests/test-jpms/test-websocket-core/src/test/java/WebSocketCoreJpmsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.ServerConnector; | ||
import org.eclipse.jetty.util.Callback; | ||
import org.eclipse.jetty.websocket.core.CoreSession; | ||
import org.eclipse.jetty.websocket.core.FrameHandler; | ||
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest; | ||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; | ||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; | ||
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler; | ||
import org.example.websocket.MyFrameHandler; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class WebSocketCoreJpmsTest | ||
{ | ||
private Server _server; | ||
private ServerConnector _serverConnector; | ||
private WebSocketCoreClient _client; | ||
|
||
@BeforeEach | ||
public void before() throws Exception | ||
{ | ||
_server = new Server(); | ||
_serverConnector = new ServerConnector(_server); | ||
_server.addConnector(_serverConnector); | ||
|
||
WebSocketUpgradeHandler webSocketUpgradeHandler = new WebSocketUpgradeHandler(); | ||
FrameHandler myFrameHandler = new MyFrameHandler("Server"); | ||
webSocketUpgradeHandler.addMapping("/ws", WebSocketNegotiator.from(negotiation -> myFrameHandler)); | ||
|
||
_server.setHandler(webSocketUpgradeHandler); | ||
_server.start(); | ||
|
||
_client = new WebSocketCoreClient(); | ||
_client.start(); | ||
} | ||
|
||
@AfterEach | ||
public void after() throws Exception | ||
{ | ||
_client.stop(); | ||
_server.stop(); | ||
} | ||
|
||
@Test | ||
public void testSimpleEcho() throws Exception | ||
{ | ||
MyFrameHandler frameHandler = new MyFrameHandler("Client"); | ||
URI uri = URI.create("ws://localhost:" + _serverConnector.getLocalPort() + "/ws"); | ||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, uri, frameHandler); | ||
upgradeRequest.addExtensions("permessage-deflate"); | ||
CoreSession coreSession = _client.connect(upgradeRequest).get(5, TimeUnit.SECONDS); | ||
coreSession.close(Callback.NOOP); | ||
} | ||
} |