Class TcpChaosProfile


public class TcpChaosProfile extends ObjectWithJsonToString
Declarative TCP-layer fault/chaos injection profile, applied at the raw byte level before HTTP decoding. Each fault type mirrors one of Toxiproxy's named toxics:
  • latency — delay all inbound data by latencyMs milliseconds
  • down — silently drop all inbound data (service appears down)
  • bandwidth — throttle inbound data to bandwidthBytesPerSec
  • slow_close — delay the TCP FIN by 2 seconds
  • timeout — never send FIN; connection hangs on close
  • reset_peer — send TCP RST and close immediately
  • slicer — fragment inbound data into chunks of slicerChunkSize bytes
  • limit_data — close the connection after limitDataBytes bytes received

Profiles are registered in the TcpChaosRegistry and applied by the TcpChaosHandler Netty handler. When multiple faults are configured on the same profile, they are evaluated in priority order: down, resetPeer, limitData, slicer, bandwidth, latency.

Follows the model field/withX/getter convention so it round-trips through Jackson without a bespoke (de)serializer.

  • Constructor Details

    • TcpChaosProfile

      public TcpChaosProfile()
  • Method Details

    • tcpChaosProfile

      public static TcpChaosProfile tcpChaosProfile()
    • getLatencyMs

      public Long getLatencyMs()
    • withLatencyMs

      public TcpChaosProfile withLatencyMs(Long latencyMs)
    • getDown

      public Boolean getDown()
    • withDown

      public TcpChaosProfile withDown(Boolean down)
    • getBandwidthBytesPerSec

      public Long getBandwidthBytesPerSec()
    • withBandwidthBytesPerSec

      public TcpChaosProfile withBandwidthBytesPerSec(Long bandwidthBytesPerSec)
    • getSlowClose

      public Boolean getSlowClose()
    • withSlowClose

      public TcpChaosProfile withSlowClose(Boolean slowClose)
    • getTimeout

      public Boolean getTimeout()
    • withTimeout

      public TcpChaosProfile withTimeout(Boolean timeout)
    • getResetPeer

      public Boolean getResetPeer()
    • withResetPeer

      public TcpChaosProfile withResetPeer(Boolean resetPeer)
    • getSlicerChunkSize

      public Integer getSlicerChunkSize()
    • withSlicerChunkSize

      public TcpChaosProfile withSlicerChunkSize(Integer slicerChunkSize)
    • getLimitDataBytes

      public Long getLimitDataBytes()
    • withLimitDataBytes

      public TcpChaosProfile withLimitDataBytes(Long limitDataBytes)
    • getResetMidResponse

      public Boolean getResetMidResponse()
    • withResetMidResponse

      public TcpChaosProfile withResetMidResponse(Boolean resetMidResponse)
      When true, after the response head is written the socket is forced to RST (SO_LINGER 0 + forced close) instead of a clean FIN, so the client sees the connection reset mid-stream — the "server crashed while replying" fault. Applied in the response writer, not at connect time.
    • getResetAfterResponseChunks

      public Integer getResetAfterResponseChunks()
    • withResetAfterResponseChunks

      public TcpChaosProfile withResetAfterResponseChunks(Integer resetAfterResponseChunks)
      Number of response body chunks to write before the mid-response RST. null (or 0) means "reset after the head". v1 only honours the "after head" semantics precisely; values > 0 for non-chunked bodies are deferred and treated as "after head".
    • getSlowCloseDelay

      public Delay getSlowCloseDelay()
    • withSlowCloseDelay

      public TcpChaosProfile withSlowCloseDelay(Delay slowCloseDelay)
      Host-scoped (optionally jittered) delay applied before the socket FIN on the response path, even when ConnectionOptions.closeSocketDelay is null. Lets a host be made to linger on close without a per-expectation connection option.
    • getHttp2GoAway

      public Boolean getHttp2GoAway()
    • withHttp2GoAway

      public TcpChaosProfile withHttp2GoAway(Boolean http2GoAway)
      When true and the connection is HTTP/2, a GOAWAY frame is emitted on the response path so the client stops opening new streams and drains — the graceful "this connection is going away" signal. HTTP/1.1 has no GOAWAY and degrades to Connection: close + 503 elsewhere.
    • getHttp2GoAwayErrorCode

      public Long getHttp2GoAwayErrorCode()
    • withHttp2GoAwayErrorCode

      public TcpChaosProfile withHttp2GoAwayErrorCode(Long http2GoAwayErrorCode)
      HTTP/2 error code carried on the GOAWAY frame. null defaults to 0 (NO_ERROR), the graceful-shutdown code.
    • getHttp2GoAwayLastStreamId

      public Long getHttp2GoAwayLastStreamId()
    • withHttp2GoAwayLastStreamId

      public TcpChaosProfile withHttp2GoAwayLastStreamId(Long http2GoAwayLastStreamId)
      The lastStreamId carried on the GOAWAY frame. null means "use the current / last-processed stream id" (resolved at emit time by the connection handler).
    • hasAnyFault

      public boolean hasAnyFault()
      Returns true when at least one fault is configured (non-null and meaningful).
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class ObjectWithReflectiveEqualsHashCodeToString
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class ObjectWithReflectiveEqualsHashCodeToString