Package com.jsgalactic.axiom.test
Record Class StreamBuffering
java.lang.Object
java.lang.Record
com.jsgalactic.axiom.test.StreamBuffering
- Record Components:
highWaterBytes- unread bytes at which writers start to wait; positivelowWaterBytes- unread bytes below which waiting writers continue; positive, at most the high water markpieceBytes- largest chunk queued by one step of a write; positivestallTimeout- how long a writer waits for the reader to take anything before the client counts as gone; positive, or null for none (only the request deadline then ends the wait)
public record StreamBuffering(int highWaterBytes, int lowWaterBytes, int pieceBytes, Duration stallTimeout)
extends Record
How
TestClient.stream(com.jsgalactic.axiom.http.Request) models the buffering between a handler's writes and the client's
reads. The queue holds unread chunks. A writer waits before queuing a piece while the channel is
unwritable: it becomes unwritable when the unread bytes reach highWaterBytes and
writable again when the reader brings them below lowWaterBytes. A write larger than
pieceBytes is queued as several chunks of at most that size, which the reader receives
one by one. A wait ends with a StreamAbortedException when the reader takes nothing for
stallTimeout (CLIENT_DISCONNECTED) or at the request deadline (TIMEOUT).
HAND_OFF is the default: a writer is never more than one write ahead of the reader
and writes are never split, which makes tests that read chunk by chunk fully deterministic.
listener() uses the HTTP listener's numbers (32 and 128 KiB water marks, 16 KiB pieces,
a 30 second stall bound), so that a test sees the same blocking points as a real socket would
give, apart from the socket buffers of the operating system, which hold more.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StreamBufferingOne chunk in flight, no splitting and no stall bound. -
Constructor Summary
ConstructorsConstructorDescriptionStreamBuffering(int highWaterBytes, int lowWaterBytes, int pieceBytes, Duration stallTimeout) Creates a buffering model. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intReturns the value of thehighWaterBytesrecord component.static StreamBufferinglistener()The numbers of the HTTP listener: 128 KiB high and 32 KiB low water marks, 16 KiB pieces and a 30 second stall bound.intReturns the value of thelowWaterBytesrecord component.static StreamBufferingofBytes(int highWaterBytes) A buffer of the given size: the low water mark is a quarter of it, pieces are at most 16 KiB and there is no stall bound.intReturns the value of thepieceBytesrecord component.Returns the value of thestallTimeoutrecord component.toString()Returns a string representation of this record class.withStallTimeout(Duration timeout) Returns a copy with another stall bound.
-
Field Details
-
HAND_OFF
One chunk in flight, no splitting and no stall bound.
-
-
Constructor Details
-
StreamBuffering
public StreamBuffering(int highWaterBytes, int lowWaterBytes, int pieceBytes, Duration stallTimeout) Creates a buffering model.- Parameters:
highWaterBytes- unread bytes at which writers start to wait; positivelowWaterBytes- unread bytes below which waiting writers continue; positive, at most the high water markpieceBytes- largest chunk queued by one step of a write; positivestallTimeout- how long a writer waits for the reader before the client counts as gone, or null
-
-
Method Details
-
listener
The numbers of the HTTP listener: 128 KiB high and 32 KiB low water marks, 16 KiB pieces and a 30 second stall bound.- Returns:
- the listener's buffering
-
ofBytes
A buffer of the given size: the low water mark is a quarter of it, pieces are at most 16 KiB and there is no stall bound.- Parameters:
highWaterBytes- unread bytes at which writers start to wait; positive- Returns:
- the buffering
-
withStallTimeout
Returns a copy with another stall bound.- Parameters:
timeout- how long a writer waits for the reader before the client counts as gone, or null for none- Returns:
- the buffering
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
highWaterBytes
public int highWaterBytes()Returns the value of thehighWaterBytesrecord component.- Returns:
- the value of the
highWaterBytesrecord component
-
lowWaterBytes
public int lowWaterBytes()Returns the value of thelowWaterBytesrecord component.- Returns:
- the value of the
lowWaterBytesrecord component
-
pieceBytes
public int pieceBytes()Returns the value of thepieceBytesrecord component.- Returns:
- the value of the
pieceBytesrecord component
-
stallTimeout
Returns the value of thestallTimeoutrecord component.- Returns:
- the value of the
stallTimeoutrecord component
-