Changes from review.
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
ead1f6b160
commit
59a5b7c9ef
|
@ -10,7 +10,7 @@
|
|||
<packaging>pom</packaging>
|
||||
<name>Jetty Tests :: JPMS Parent</name>
|
||||
<modules>
|
||||
<module>test-websocket-core</module>
|
||||
<module>test-jpms-websocket-core</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<version>10.0.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-websocket-core</artifactId>
|
||||
<artifactId>test-jpms-websocket-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Jetty Tests :: JPMS :: WebSocket Core Tests</name>
|
||||
|
||||
|
@ -22,4 +22,4 @@
|
|||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
</project>
|
|
@ -11,10 +11,12 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
/**
|
||||
* This module-info.java exists so that the tests can be run in JPMS mode,
|
||||
* therefore testing the JPMS module descriptors of the dependencies involved.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -17,18 +17,21 @@ 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.CloseStatus;
|
||||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
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;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class WebSocketCoreJpmsTest
|
||||
public class WebSocketCoreJPMSTest
|
||||
{
|
||||
private Server _server;
|
||||
private ServerConnector _serverConnector;
|
||||
|
@ -42,7 +45,7 @@ public class WebSocketCoreJpmsTest
|
|||
_server.addConnector(_serverConnector);
|
||||
|
||||
WebSocketUpgradeHandler webSocketUpgradeHandler = new WebSocketUpgradeHandler();
|
||||
FrameHandler myFrameHandler = new MyFrameHandler("Server");
|
||||
FrameHandler myFrameHandler = new TestFrameHandler("Server");
|
||||
webSocketUpgradeHandler.addMapping("/ws", WebSocketNegotiator.from(negotiation -> myFrameHandler));
|
||||
|
||||
_server.setHandler(webSocketUpgradeHandler);
|
||||
|
@ -62,11 +65,51 @@ public class WebSocketCoreJpmsTest
|
|||
@Test
|
||||
public void testSimpleEcho() throws Exception
|
||||
{
|
||||
MyFrameHandler frameHandler = new MyFrameHandler("Client");
|
||||
TestFrameHandler frameHandler = new TestFrameHandler("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);
|
||||
}
|
||||
|
||||
public static class TestFrameHandler implements FrameHandler
|
||||
{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TestFrameHandler.class);
|
||||
|
||||
private final String _id;
|
||||
|
||||
public TestFrameHandler(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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue