Package dev.relism.flash.testing
Class FlashWebSocket
java.lang.Object
dev.relism.flash.testing.FlashWebSocket
- All Implemented Interfaces:
AutoCloseable
A WebSocket connected to a
FlashTest server, for asserting on what a Flash endpoint
pushes back.
try (FlashWebSocket socket = app.ws("/live")) {
socket.sendText("hello");
assertEquals("echo:hello", socket.awaitText(Duration.ofSeconds(2)));
}
Backed by WebSocket, so the RFC 6455 handshake, masking and
fragmentation are the JDK's, not hand-rolled. Incoming text is queued as it arrives, so a
message that lands before awaitText(java.time.Duration) is called is not lost.-
Method Summary
Modifier and TypeMethodDescriptionintawaitClose(Duration timeout) Waits for the server to close the connection and returns its close status code.Waits for the next text message.voidclose()Sends a normal close and gives the server a moment to answer it.Sends a whole text message.
-
Method Details
-
sendText
Sends a whole text message. -
awaitText
Waits for the next text message.- Throws:
AssertionError- if none arrives withintimeout
-
awaitClose
Waits for the server to close the connection and returns its close status code.- Throws:
AssertionError- if the server does not close withintimeout
-
close
public void close()Sends a normal close and gives the server a moment to answer it.Never throws: this is cleanup, usually in a try-with-resources, and a connection the server already dropped must not mask the failure the test was actually reporting. Use
awaitClose(java.time.Duration)when the close itself is what you are asserting on.- Specified by:
closein interfaceAutoCloseable
-