Issue #6601 - add proper JPMS testing for websocket-core

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2021-08-30 11:11:20 +10:00
parent f10ae7c955
commit e64b390fd6
7 changed files with 201 additions and 0 deletions

View File

@ -153,6 +153,7 @@
<module>documentation</module>
<module>jetty-keystore</module>
<module>jetty-unixdomain-server</module>
<module>test-websocket-core</module>
</modules>
<build>

View File

@ -56,5 +56,6 @@
<module>test-http-client-transport</module>
<module>test-distribution</module>
<module>test-cdi</module>
<module>test-jpms</module>
</modules>
</project>

33
tests/test-jpms/pom.xml Normal file
View File

@ -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>

View File

@ -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>

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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);
}
}