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.voidclose()Close the underlying socket.static DirectSocketCreate a new socket with explicit peer information.byte[]get()voididle()Sets the socket to idle mode.booleanCheck if socket is connected.booleanisSecure()Whether the request is secure.Local peer information.intread(BufferData buffer) Read bytes from the socket.Remote peer information.socketId()Main socket id.voidwrite(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, waitMethods inherited from interface io.helidon.common.socket.HelidonSocket
protocol, protocolNegotiatedMethods 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:SocketContextRemote peer information.- Specified by:
remotePeerin interfaceSocketContext- Returns:
- peer info
-
localPeer
Description copied from interface:SocketContextLocal peer information.- Specified by:
localPeerin interfaceSocketContext- Returns:
- peer info
-
isSecure
public boolean isSecure()Description copied from interface:SocketContextWhether the request is secure.- Specified by:
isSecurein interfaceSocketContext- Returns:
- whether secure
-
socketId
Description copied from interface:SocketContextMain socket id. This is the server socket id for server side, connection id for client side.- Specified by:
socketIdin interfaceSocketContext- Returns:
- socket id
-
childSocketId
Description copied from interface:SocketContextChild 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:
childSocketIdin interfaceSocketContext- Returns:
- child socket id, never null
-
close
public void close()Description copied from interface:HelidonSocketClose the underlying socket.- Specified by:
closein interfaceHelidonSocket
-
idle
public void idle()Description copied from interface:HelidonSocketSets 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:
idlein interfaceHelidonSocket
-
isConnected
public boolean isConnected()Description copied from interface:HelidonSocketCheck if socket is connected.- Specified by:
isConnectedin interfaceHelidonSocket- Returns:
- true if connected
-
read
Description copied from interface:HelidonSocketRead bytes from the socket. This method blocks until at least 1 byte is available.- Specified by:
readin interfaceHelidonSocket- Parameters:
buffer- buffer to read to- Returns:
- number of bytes read
-
write
Description copied from interface:HelidonSocketWrite teh buffer to the underlying socket. This method blocks until all bytes are written.- Specified by:
writein interfaceHelidonSocket- Parameters:
buffer- buffer to write
-
get
public byte[] get()
-