Issue #4800 - Reproduce LinkageError in WebSocket unit test
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
7c2d804ce9
commit
f5b0dc56d2
|
@ -29,6 +29,12 @@
|
|||
<artifactId>websocket-javax-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-bad-websocket-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-http-tools</artifactId>
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.javax.tests;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
|
||||
|
@ -28,6 +29,7 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.IO;
|
||||
import org.eclipse.jetty.toolchain.test.JAR;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.TypeUtil;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
|
@ -37,6 +39,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
/**
|
||||
|
@ -70,8 +73,9 @@ public class WSServer extends LocalServer implements LocalFuzzer.Provider
|
|||
{
|
||||
private final WebAppContext context;
|
||||
private final Path contextDir;
|
||||
private Path classesDir;
|
||||
private final Path webInf;
|
||||
private final Path classesDir;
|
||||
private final Path libDir;
|
||||
|
||||
private WebApp(String contextName)
|
||||
{
|
||||
|
@ -79,11 +83,13 @@ public class WSServer extends LocalServer implements LocalFuzzer.Provider
|
|||
contextDir = testDir.resolve(contextName);
|
||||
FS.ensureEmpty(contextDir);
|
||||
|
||||
// Ensure WEB-INF.
|
||||
// Ensure WEB-INF directories.
|
||||
webInf = contextDir.resolve("WEB-INF");
|
||||
FS.ensureDirExists(webInf);
|
||||
classesDir = webInf.resolve("classes");
|
||||
FS.ensureDirExists(classesDir);
|
||||
libDir = webInf.resolve("lib");
|
||||
FS.ensureDirExists(libDir);
|
||||
|
||||
// Configure the WebAppContext.
|
||||
context = new WebAppContext();
|
||||
|
@ -132,6 +138,26 @@ public class WSServer extends LocalServer implements LocalFuzzer.Provider
|
|||
IO.copy(srcFile, destFile.toFile());
|
||||
}
|
||||
|
||||
public void copyLib(Class<?> clazz, String jarFileName) throws URISyntaxException, IOException
|
||||
{
|
||||
Path jarFile = libDir.resolve(jarFileName);
|
||||
|
||||
URL codeSourceURL = clazz.getProtectionDomain().getCodeSource().getLocation();
|
||||
assertThat("Class CodeSource URL is file scheme", codeSourceURL.getProtocol(), is("file"));
|
||||
|
||||
File sourceCodeSourceFile = new File(codeSourceURL.toURI());
|
||||
if (sourceCodeSourceFile.isDirectory())
|
||||
{
|
||||
LOG.info("Creating " + jarFile + " from " + sourceCodeSourceFile);
|
||||
JAR.create(sourceCodeSourceFile, jarFile.toFile());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.info("Copying " + sourceCodeSourceFile + " to " + jarFile);
|
||||
IO.copy(sourceCodeSourceFile, jarFile.toFile());
|
||||
}
|
||||
}
|
||||
|
||||
public void deploy()
|
||||
{
|
||||
contexts.addHandler(context);
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
|
||||
//
|
||||
// This program and the accompanying materials are made available under
|
||||
// the terms of the Eclipse Public License 2.0 which is available at
|
||||
// https://www.eclipse.org/legal/epl-2.0
|
||||
//
|
||||
// This Source Code may also be made available under the following
|
||||
// Secondary Licenses when the conditions for such availability set
|
||||
// forth in the Eclipse Public License, v. 2.0 are satisfied:
|
||||
// the Apache License v2.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.eclipse.jetty.websocket.javax.tests;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import org.eclipse.jetty.tests.webapp.websocket.bad.BadOnCloseServerEndpoint;
|
||||
import org.eclipse.jetty.tests.webapp.websocket.bad.BadOnOpenServerEndpoint;
|
||||
import org.eclipse.jetty.tests.webapp.websocket.bad.StringSequence;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class DoubleDeployTest
|
||||
{
|
||||
private WSServer server;
|
||||
private WSServer.WebApp app1;
|
||||
private WSServer.WebApp app2;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
Path testdir = MavenTestingUtils.getTargetTestingPath(DoubleDeployTest.class.getName());
|
||||
server = new WSServer(testdir);
|
||||
|
||||
app1 = server.createWebApp("test1");
|
||||
app1.createWebInf();
|
||||
app1.copyClass(BadOnOpenServerEndpoint.class);
|
||||
app1.copyClass(BadOnCloseServerEndpoint.class);
|
||||
app1.copyClass(StringSequence.class);
|
||||
app1.deploy();
|
||||
|
||||
app2 = server.createWebApp("test2");
|
||||
app2.createWebInf();
|
||||
app2.copyClass(BadOnOpenServerEndpoint.class);
|
||||
app2.copyClass(BadOnCloseServerEndpoint.class);
|
||||
app2.copyClass(StringSequence.class);
|
||||
app2.deploy();
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception
|
||||
{
|
||||
// Initially just test deployment. (We should fail at deployment anyway).
|
||||
if (true) return;
|
||||
|
||||
WebSocketContainer client = ContainerProvider.getWebSocketContainer();
|
||||
EventSocket clientSocket = new EventSocket();
|
||||
Session session = client.connectToServer(clientSocket, server.getWsUri().resolve(app1.getContextPath() + "/badonclose/a"));
|
||||
session.getBasicRemote().sendText("test");
|
||||
session.close();
|
||||
assertTrue(clientSocket.closeLatch.await(5, TimeUnit.SECONDS));
|
||||
|
||||
clientSocket = new EventSocket();
|
||||
session = client.connectToServer(clientSocket, server.getWsUri().resolve(app2.getContextPath() + "/badonopen/b"));
|
||||
session.getBasicRemote().sendText("test");
|
||||
session.close();
|
||||
assertTrue(clientSocket.closeLatch.await(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue