Class FaultRule

java.lang.Object
org.apache.kafka.test.faultproxy.FaultRule

public final class FaultRule extends Object
A single fault to apply to responses of one ApiKeys. Built through the fluent DSL on KafkaProtocolFaultProxy (injectError(...) / disconnectOn(...) then a trigger), and returned to the caller as a handle so a test can inspect timesTriggered() or remove() it.

A rule counts each response offered to it ("matches"); the IntPredicate trigger decides, from the 1-based match count, whether the fault fires on that match — e.g. n -> n == 1 is once(), n -> n <= 3 is times(3). Responses are offered in registration order and consumed by the first rule that fires, so a later rule is not offered a response an earlier rule already acted on.

  • Method Details

    • timesTriggered

      public int timesTriggered()
      How many times this fault actually fired — for test assertions.
    • timesMatched

      public int timesMatched()
      How many responses of this API the rule has observed (whether or not it fired).
    • remove

      public void remove()
      Deregister this rule from the proxy.
    • toString

      public String toString()
      Overrides:
      toString in class Object