Class DirectSocket
java.lang.Object
io.helidon.webserver.testing.junit5.DirectSocket
- All Implemented Interfaces:
HelidonSocket
,SocketContext
,Supplier<byte[]>
A socket not backed by any network, used for unit testing.
-
Method Summary
Modifier and TypeMethodDescriptionChild socket id.void
close()
Close the underlying socket.static DirectSocket
Create a new socket with explicit peer information.byte[]
get()
void
idle()
Sets the socket to idle mode.boolean
Check if socket is connected.boolean
isSecure()
Whether the request is secure.Local peer information.int
read
(BufferData buffer) Read bytes from the socket.Remote peer information.socketId()
Main socket id.void
write
(BufferData buffer) Write teh buffer to the underlying socket.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.helidon.common.socket.HelidonSocket
protocol, protocolNegotiated
Methods inherited from interface io.helidon.common.socket.SocketContext
log, log
-
Method Details
-
create
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
Description copied from interface:SocketContext
Remote peer information.- Specified by:
remotePeer
in interfaceSocketContext
- Returns:
- peer info
-
localPeer
Description copied from interface:SocketContext
Local peer information.- Specified by:
localPeer
in interfaceSocketContext
- Returns:
- peer info
-
isSecure
public boolean isSecure()Description copied from interface:SocketContext
Whether the request is secure.- Specified by:
isSecure
in interfaceSocketContext
- Returns:
- whether secure
-
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 interfaceSocketContext
- Returns:
- socket id
-
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 interfaceSocketContext
- Returns:
- child socket id, never null
-
close
public void close()Description copied from interface:HelidonSocket
Close the underlying socket.- Specified by:
close
in interfaceHelidonSocket
-
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 interfaceHelidonSocket
-
isConnected
public boolean isConnected()Description copied from interface:HelidonSocket
Check if socket is connected.- Specified by:
isConnected
in interfaceHelidonSocket
- Returns:
- true if connected
-
read
Description copied from interface:HelidonSocket
Read bytes from the socket. This method blocks until at least 1 byte is available.- Specified by:
read
in interfaceHelidonSocket
- Parameters:
buffer
- buffer to read to- Returns:
- number of bytes read
-
write
Description copied from interface:HelidonSocket
Write teh buffer to the underlying socket. This method blocks until all bytes are written.- Specified by:
write
in interfaceHelidonSocket
- Parameters:
buffer
- buffer to write
-
get
public byte[] get()
-