Class FlashWebSocket

java.lang.Object
dev.relism.flash.testing.FlashWebSocket
All Implemented Interfaces:
AutoCloseable

public final class FlashWebSocket extends Object implements 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 Details

    • sendText

      public FlashWebSocket sendText(String message)
      Sends a whole text message.
    • awaitText

      public String awaitText(Duration timeout)
      Waits for the next text message.
      Throws:
      AssertionError - if none arrives within timeout
    • awaitClose

      public int awaitClose(Duration timeout)
      Waits for the server to close the connection and returns its close status code.
      Throws:
      AssertionError - if the server does not close within timeout
    • 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:
      close in interface AutoCloseable