Merge pull request #3259 from lachlan-roberts/jetty-10.0.x-websocket-tests

Issue #3246 - javax-websocket-tests exception stacktraces
This commit is contained in:
Greg Wilkins 2019-01-15 17:56:08 +11:00 committed by GitHub
commit 5307f49bbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 52 deletions

View File

@ -100,7 +100,7 @@ abstract public class WriteFlusher
* @param previous the expected current state
* @param next the desired new state
* @return the previous state or null if the state transition failed
* @throws WritePendingException if currentState is WRITING and new state is WRITING (api usage error)
* @throws IllegalStateException if previous to next is not a legal state transition (api usage error)
*/
private boolean updateState(State previous, State next)
{

View File

@ -45,7 +45,7 @@ import org.eclipse.jetty.websocket.core.internal.Generator;
public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseable
{
private final LocalServer server;
private final RawWebSocketClient rawClient;
private final WebSocketCoreClient client;
private final RawUpgradeRequest upgradeRequest;
private final UnitGenerator generator;
private final FrameCapture frameCapture;
@ -65,9 +65,9 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
{
super();
this.server = server;
this.rawClient = new RawWebSocketClient();
this.client = new WebSocketCoreClient();
CompletableFuture<FrameCapture> futureOnCapture = new CompletableFuture<>();
this.upgradeRequest = new RawUpgradeRequest(rawClient, wsURI, futureOnCapture);
this.upgradeRequest = new RawUpgradeRequest(client, wsURI, futureOnCapture);
if (requestHeaders != null)
{
HttpFields fields = this.upgradeRequest.getHeaders();
@ -77,10 +77,10 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
fields.put(name, value);
});
}
this.rawClient.start();
this.client.start();
this.generator = new UnitGenerator(Behavior.CLIENT);
CompletableFuture<FrameHandler.CoreSession> futureHandler = this.rawClient.connect(upgradeRequest);
CompletableFuture<FrameHandler.CoreSession> futureHandler = this.client.connect(upgradeRequest);
CompletableFuture<FrameCapture> futureCapture = futureHandler.thenCombine(futureOnCapture, (channel, capture) -> capture);
this.frameCapture = futureCapture.get(10, TimeUnit.SECONDS);
}
@ -102,7 +102,7 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
@Override
public void close() throws Exception
{
this.rawClient.stop();
this.client.stop();
}
@Override
@ -156,7 +156,7 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
{
try (SharedBlockingCallback.Blocker blocker = sharedBlockingCallback.acquire())
{
frameCapture.channel.sendFrame(f, blocker, false);
frameCapture.session.sendFrame(f, blocker, false);
}
}
}
@ -168,7 +168,7 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
{
try (SharedBlockingCallback.Blocker blocker = sharedBlockingCallback.acquire())
{
frameCapture.channel.sendFrame(f, blocker, false);
frameCapture.session.sendFrame(f, blocker, false);
}
}
}
@ -184,10 +184,6 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
}
}
public static class RawWebSocketClient extends WebSocketCoreClient
{
}
public static class RawUpgradeRequest extends UpgradeRequest
{
private final CompletableFuture<FrameCapture> futureCapture;
@ -226,7 +222,7 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
private final BlockingQueue<Frame> receivedFrames = new LinkedBlockingQueue<>();
private final EndPoint endPoint;
private final SharedBlockingCallback blockingCallback = new SharedBlockingCallback();
private CoreSession channel;
private CoreSession session;
public FrameCapture(EndPoint endPoint)
{
@ -247,20 +243,26 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
public void onFrame(Frame frame, Callback callback)
{
receivedFrames.offer(Frame.copy(frame));
callback.succeeded();
synchronized(this)
{
callback.succeeded();
}
}
@Override
public void onOpen(CoreSession coreSession) throws Exception
{
this.channel = coreSession;
this.session = coreSession;
}
public void writeRaw(ByteBuffer buffer) throws IOException
{
try (SharedBlockingCallback.Blocker blocker = blockingCallback.acquire())
synchronized (this)
{
this.endPoint.write(blocker, buffer);
try (SharedBlockingCallback.Blocker blocker = blockingCallback.acquire())
{
this.endPoint.write(blocker, buffer);
}
}
}
}

View File

@ -18,6 +18,24 @@
package org.eclipse.jetty.websocket.javax.tests.client;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.MessageHandler;
@ -29,24 +47,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -90,12 +90,14 @@ public class DecoderReaderManySmallTest
{
URI wsUri = server.getWsUri().resolve("/eventids");
EventIdSocket clientSocket = new EventIdSocket(testInfo.getTestMethod().toString());
Session clientSession = client.connectToServer(clientSocket, wsUri);
final int from = 1000;
final int to = 2000;
clientSession.getAsyncRemote().sendText("seq|" + from + "|" + to);
try(Session clientSession = client.connectToServer(clientSocket, wsUri))
{
clientSession.getAsyncRemote().sendText("seq|" + from + "|" + to);
}
// collect seen ids
List<Integer> seen = new ArrayList<>();
@ -181,6 +183,8 @@ public class DecoderReaderManySmallTest
sendText(Integer.toString(id), Callback.NOOP, false);
}
}
getCoreSession().flush(callback);
}
}
}

View File

@ -18,7 +18,11 @@
package org.eclipse.jetty.websocket.javax.tests.server;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.log.StacklessLogging;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.core.CloseStatus;
import org.eclipse.jetty.websocket.core.Frame;
@ -31,9 +35,6 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
@ -69,7 +70,8 @@ public class IdleTimeoutTest
private void assertConnectionTimeout(String requestPath) throws Exception
{
try (Fuzzer session = server.newNetworkFuzzer(requestPath))
try (Fuzzer session = server.newNetworkFuzzer(requestPath);
StacklessLogging stacklessLogging = new StacklessLogging(IdleTimeoutOnOpenSocket.class))
{
// wait 1 second to allow timeout to fire off
TimeUnit.SECONDS.sleep(1);

View File

@ -18,6 +18,15 @@
package org.eclipse.jetty.websocket.core.internal;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Queue;
import java.util.stream.Collectors;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.DecoratedObjectFactory;
@ -34,15 +43,6 @@ import org.eclipse.jetty.websocket.core.IncomingFrames;
import org.eclipse.jetty.websocket.core.OutgoingFrames;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Queue;
import java.util.stream.Collectors;
/**
* Represents the stack of Extensions.
*/
@ -359,7 +359,7 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable
// and the failure of a frame may not mean that the whole
// connection is now invalid.
notifyCallbackFailure(current.callback, cause);
super.failed(cause);
super.succeeded();
}
private void notifyCallbackSuccess(Callback callback)