java.lang.Object
io.helidon.webserver.testing.junit5.DirectSocket
All Implemented Interfaces:
HelidonSocket, SocketContext, Supplier<byte[]>

public class DirectSocket extends Object implements HelidonSocket
A socket not backed by any network, used for unit testing.
  • Method Details

    • create

      public static DirectSocket create(PeerInfo localPeer, PeerInfo remotePeer, boolean isSecure)
      Create a new socket with explicit peer information.
      Parameters:
      localPeer - local peer (local host and port)
      remotePeer - remote peer (remote party host and port)
      isSecure - whether the socket is secured (TLS)
      Returns:
      a new direct socket
    • remotePeer

      public PeerInfo remotePeer()
      Description copied from interface: SocketContext
      Remote peer information.
      Specified by:
      remotePeer in interface SocketContext
      Returns:
      peer info
    • localPeer

      public PeerInfo localPeer()
      Description copied from interface: SocketContext
      Local peer information.
      Specified by:
      localPeer in interface SocketContext
      Returns:
      peer info
    • isSecure

      public boolean isSecure()
      Description copied from interface: SocketContext
      Whether the request is secure.
      Specified by:
      isSecure in interface SocketContext
      Returns:
      whether secure
    • socketId

      public String socketId()
      Description copied from interface: SocketContext
      Main socket id. This is the server socket id for server side, connection id for client side.
      Specified by:
      socketId in interface SocketContext
      Returns:
      socket id
    • childSocketId

      public String childSocketId()
      Description copied from interface: SocketContext
      Child socket id. This is the connection socket id for server side. For client side, this may be additional identification of a request (pipeline id, stream id).
      Specified by:
      childSocketId in interface SocketContext
      Returns:
      child socket id, never null
    • close

      public void close()
      Description copied from interface: HelidonSocket
      Close the underlying socket.
      Specified by:
      close in interface HelidonSocket
    • idle

      public void idle()
      Description copied from interface: HelidonSocket
      Sets the socket to idle mode. Idle mode expects no bytes coming over the socket but keeps reading exactly one byte in case connection is severed. Idle mode should be used in case of client side connection caching.
      Specified by:
      idle in interface HelidonSocket
    • isConnected

      public boolean isConnected()
      Description copied from interface: HelidonSocket
      Check if socket is connected.
      Specified by:
      isConnected in interface HelidonSocket
      Returns:
      true if connected
    • read

      public int read(BufferData buffer)
      Description copied from interface: HelidonSocket
      Read bytes from the socket. This method blocks until at least 1 byte is available.
      Specified by:
      read in interface HelidonSocket
      Parameters:
      buffer - buffer to read to
      Returns:
      number of bytes read
    • write

      public void write(BufferData buffer)
      Description copied from interface: HelidonSocket
      Write teh buffer to the underlying socket. This method blocks until all bytes are written.
      Specified by:
      write in interface HelidonSocket
      Parameters:
      buffer - buffer to write
    • get

      public byte[] get()
      Specified by:
      get in interface Supplier<byte[]>