Class FaultyTransport
java.lang.Object
org.mqtt4j.hato.testkit.FaultyTransport
- All Implemented Interfaces:
AutoCloseable, Transport
A wrapper that adds ordered receive delays, send delays, and disconnection to a transport.
Neither direction is delayed until a delay is set. The scheduler measures the delays, so
with
ManualTimerScheduler, delayed data moves on when the test advances it. Use a long
delay in either direction to simulate stopped traffic. A delay must fit in nanoseconds, and
the scheduler must accept the resulting deadline. At most one send is outstanding; admission
retains its array until onSent or the final
onClosed. The input that a receive delay holds back
is bounded: beyond the bound, the wrapper ends the connection with MqttCapacityException, so
a long delay on a connection whose peer keeps sending can end it before the client's own
deadlines. The wrapper owns and closes the delegate, but borrows the scheduler.-
Nested Class Summary
Nested classes/interfaces inherited from interface Transport
Transport.Factory, Transport.Listener, Transport.SendResult -
Constructor Summary
ConstructorsConstructorDescriptionFaultyTransport(Transport delegate, TimerScheduler scheduler) Wrapsdelegate, timing the delays withscheduler. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voiddisconnect(Throwable cause) Ends the connection withcause: later sends are rejected, delayed and later input is discarded, and the delegate is closed.receiveDelay(Duration value) Changes the delay of subsequently received chunks.send(long ticket, byte[] bytes) Changes the delay of subsequently admitted sends.voidstart(URI endpoint, Duration timeout, Transport.Listener receiver)
-
Constructor Details
-
FaultyTransport
Wrapsdelegate, timing the delays withscheduler.- Parameters:
delegate- the transport to wrap, which the wrapper owns and closesscheduler- the scheduler of the delays, which the wrapper borrows
-
-
Method Details
-
receiveDelay
Changes the delay of subsequently received chunks. Earlier chunks keep their deadlines; later chunks never overtake them even when the delay is reduced.- Parameters:
value- the receive delay- Returns:
this transport- Throws:
IllegalArgumentException-if `value` is negativeArithmeticException-if `value` does not fit in nanoseconds, about 292 years
-
sendDelay
Changes the delay of subsequently admitted sends. An admitted send keeps its deadline. Zero delegates immediately; a positive delay postpones delegation, not write completion. Closing before delegation discards the send; the final onClosed releases its array.- Parameters:
value- the send delay- Returns:
this transport- Throws:
IllegalArgumentException-if `value` is negativeArithmeticException-if `value` does not fit in nanoseconds, about 292 years
-
start
-
send
-
disconnect
Ends the connection withcause: later sends are rejected, delayed and later input is discarded, and the delegate is closed. A write the delegate has already completed is still reported through onSent before the final onClosed, which carriescause. No MQTT packet is sent, so the peer sees the connection fail, as on a network failure.- Parameters:
cause- the cause of the disconnection
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTransport
-