Skip to content

Commit

Permalink
Adding both WebSocket tests to /test-integration/ to verify behavior
Browse files Browse the repository at this point in the history
that is causing problems from within OSGi.

+ Renamed TestableJettyServer to XmlBasedJettyServer to avoid
  it being picked up as a Test class (due it starting with the
  name "Test")
+ Renamed .addConfiguration() to .addXmlConfiguration() to
  reflect true nature, and also to avoid naming confusion
  with new Configuration infrastructure in Jetty.

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Mar 21, 2019
1 parent f51968b commit b351631
Show file tree
Hide file tree
Showing 16 changed files with 583 additions and 84 deletions.
40 changes: 37 additions & 3 deletions tests/test-integration/pom.xml
Expand Up @@ -30,11 +30,8 @@
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupId>org.eclipse.jetty.tests</includeGroupId>
<includeScope>test</includeScope>
<includeTypes>war</includeTypes>
<overwriteSnapshots>true</overwriteSnapshots>
<overwriteReleases>true</overwriteReleases>
<stripVersion>true</stripVersion>
<outputDirectory>${project.build.directory}/webapps</outputDirectory>
</configuration>
Expand Down Expand Up @@ -123,13 +120,50 @@
<artifactId>http2-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-annotations</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-websocket-server</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-websocket-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.tests</groupId>
<artifactId>test-webapp-rfc2616</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>test-jetty-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-server</artifactId>
Expand Down
Expand Up @@ -29,7 +29,7 @@
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.tools.HttpTester;
import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.XmlBasedJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpSocketImpl;
import org.eclipse.jetty.test.support.rawhttp.HttpTesting;
import org.eclipse.jetty.util.IO;
Expand All @@ -50,16 +50,16 @@
*/
public class DefaultHandlerTest
{
private static TestableJettyServer server;
private static XmlBasedJettyServer server;
private int serverPort;

@BeforeAll
public static void setUpServer() throws Exception
{
server = new TestableJettyServer();
server = new XmlBasedJettyServer();
server.setScheme(HttpScheme.HTTP.asString());
server.addConfiguration("DefaultHandler.xml");
server.addConfiguration("NIOHttp.xml");
server.addXmlConfiguration("DefaultHandler.xml");
server.addXmlConfiguration("NIOHttp.xml");

server.load();
server.start();
Expand Down
Expand Up @@ -33,7 +33,7 @@
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.tools.HttpTester;
import org.eclipse.jetty.test.support.StringUtil;
import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.XmlBasedJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.test.support.rawhttp.HttpTesting;
import org.eclipse.jetty.toolchain.test.FS;
Expand Down Expand Up @@ -62,7 +62,7 @@ public abstract class RFC2616BaseTest
private static final String ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
/** STRICT RFC TESTS */
private static final boolean STRICT = false;
private static TestableJettyServer server;
private static XmlBasedJettyServer server;
private HttpTesting http;

class TestFile
Expand All @@ -88,7 +88,7 @@ public void setData(String data)
}
}

public static void setUpServer(TestableJettyServer testableserver, Class<?> testclazz) throws Exception
public static void setUpServer(XmlBasedJettyServer testableserver, Class<?> testclazz) throws Exception
{
File testWorkDir = MavenTestingUtils.getTargetTestingDir(testclazz.getName());
FS.ensureDirExists(testWorkDir);
Expand Down
Expand Up @@ -19,7 +19,7 @@
package org.eclipse.jetty.test.rfcs;

import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.XmlBasedJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.test.support.rawhttp.HttpSocketImpl;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -32,12 +32,12 @@ public class RFC2616NIOHttpTest extends RFC2616BaseTest
@BeforeAll
public static void setupServer() throws Exception
{
TestableJettyServer server = new TestableJettyServer();
XmlBasedJettyServer server = new XmlBasedJettyServer();
server.setScheme(HttpScheme.HTTP.asString());
server.addConfiguration("RFC2616Base.xml");
server.addConfiguration("RFC2616_Redirects.xml");
server.addConfiguration("RFC2616_Filters.xml");
server.addConfiguration("NIOHttp.xml");
server.addXmlConfiguration("RFC2616Base.xml");
server.addXmlConfiguration("RFC2616_Redirects.xml");
server.addXmlConfiguration("RFC2616_Filters.xml");
server.addXmlConfiguration("NIOHttp.xml");
setUpServer(server, RFC2616NIOHttpTest.class);
}

Expand Down
Expand Up @@ -19,7 +19,7 @@
package org.eclipse.jetty.test.rfcs;

import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.XmlBasedJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.test.support.rawhttp.HttpsSocketImpl;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -35,12 +35,12 @@ public class RFC2616NIOHttpsTest extends RFC2616BaseTest
@BeforeAll
public static void setupServer() throws Exception
{
TestableJettyServer server = new TestableJettyServer();
XmlBasedJettyServer server = new XmlBasedJettyServer();
server.setScheme(HttpScheme.HTTPS.asString());
server.addConfiguration("RFC2616Base.xml");
server.addConfiguration("RFC2616_Redirects.xml");
server.addConfiguration("RFC2616_Filters.xml");
server.addConfiguration("NIOHttps.xml");
server.addXmlConfiguration("RFC2616Base.xml");
server.addXmlConfiguration("RFC2616_Redirects.xml");
server.addXmlConfiguration("RFC2616_Filters.xml");
server.addXmlConfiguration("NIOHttps.xml");
setUpServer(server, RFC2616NIOHttpsTest.class);
}

Expand Down
Expand Up @@ -39,15 +39,16 @@
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.junit.jupiter.api.Disabled;

/**
* Allows for setting up a Jetty server for testing based on XML configuration files.
*/
@Disabled
public class TestableJettyServer
public class XmlBasedJettyServer
{
private static final Logger LOG = Log.getLogger(XmlBasedJettyServer.class);
private List<URL> _xmlConfigurations;
private final Map<String,String> _properties = new HashMap<>();
private Server _server;
Expand All @@ -58,7 +59,7 @@ public class TestableJettyServer
private File baseDir;
private File testResourcesDir;

public TestableJettyServer() throws IOException
public XmlBasedJettyServer() throws IOException
{
_xmlConfigurations = new ArrayList<>();
Properties properties = new Properties();
Expand Down Expand Up @@ -87,25 +88,25 @@ public TestableJettyServer() throws IOException
// Write out configuration for use by ConfigurationManager.
File testConfig = new File(targetDir,"testable-jetty-server-config.properties");
FileOutputStream out = new FileOutputStream(testConfig);
properties.store(out,"Generated by " + TestableJettyServer.class.getName());
properties.store(out,"Generated by " + XmlBasedJettyServer.class.getName());

for (Object key:properties.keySet())
_properties.put(String.valueOf(key),String.valueOf(properties.get(key)));
}

public void addConfiguration(URL xmlConfig)
public void addXmlConfiguration(URL xmlConfig)
{
_xmlConfigurations.add(xmlConfig);
}

public void addConfiguration(File xmlConfigFile) throws MalformedURLException
public void addXmlConfiguration(File xmlConfigFile) throws MalformedURLException
{
_xmlConfigurations.add(xmlConfigFile.toURI().toURL());
}

public void addConfiguration(String testConfigName) throws MalformedURLException
public void addXmlConfiguration(String testConfigName) throws MalformedURLException
{
addConfiguration(new File(testResourcesDir,testConfigName));
addXmlConfiguration(new File(testResourcesDir,testConfigName));
}

public void setProperty(String key, String value)
Expand All @@ -122,7 +123,7 @@ public void load() throws Exception
for (int i = 0; i < this._xmlConfigurations.size(); i++)
{
URL configURL = this._xmlConfigurations.get(i);
System.err.println("configuring: "+configURL);
LOG.debug("configuring: "+configURL);
XmlConfiguration configuration = new XmlConfiguration(configURL);
if (last != null)
{
Expand Down
@@ -0,0 +1,72 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package org.eclipse.jetty.test.websocket;

import static org.junit.jupiter.api.Assertions.fail;

import java.util.concurrent.CountDownLatch;

import javax.websocket.ClientEndpoint;
import javax.websocket.CloseReason;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;

import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

@ClientEndpoint(
subprotocols = {"chat"})
public class JavaxSimpleEchoSocket
{
private static final Logger LOG = Log.getLogger(JavaxSimpleEchoSocket.class);
private Session session;
public CountDownLatch messageLatch = new CountDownLatch(1);
public CountDownLatch closeLatch = new CountDownLatch(1);

@OnError
public void onError(Throwable t)
{
LOG.warn(t);
fail(t.getMessage());
}

@OnClose
public void onClose(CloseReason close)
{
LOG.debug("Closed: {}, {}", close.getCloseCode().getCode(), close.getReasonPhrase());
closeLatch.countDown();
}

@OnMessage
public void onMessage(String message)
{
LOG.debug("Received: {}", message);
messageLatch.countDown();
}

@OnOpen
public void onOpen(Session session)
{
LOG.debug("Opened");
this.session = session;
}
}

0 comments on commit b351631

Please sign in to comment.