@Test public void if_times_out_before_initial_message_then_sends_timeout_messages_and_drops_all_future_messages() { MessageReceiver<Event<DummyListener>> timeoutMessages = onBar123(); InitialMessageTimeout<Event<DummyListener>> timeout = new InitialMessageTimeout<>(target, timeoutMessages, NEVER, TimeUnit.MILLISECONDS); timeout.timedOut(); sendTo(timeout).onFoo(1); sendTo(timeout).onFoo(2); sendTo(timeout).onFoo(3); expect.onBar(1); expect.onBar(2); expect.onBar(3); verifyExpected(target); }
public void timedOut() { State prev; do { prev = state.get(); if (prev != State.NO_MESSAGES_YET) { return; } } while (!state.compareAndSet(prev, State.TIMED_OUT)); copy(timeoutMessages, target); }
InitialMessageTimeout implements MessageSender<T> { public void timedOut() { State prev; do { prev = state.get(); if (prev != State.NO_MESSAGES_YET) { return; } } while (!state.compareAndSet(prev, State.TIMED_OUT)); copy(timeoutMessages, target); } }
InitialMessageTimeout implements MessageSender<T> { public void timedOut() { State prev; do { prev = state.get(); if (prev != State.NO_MESSAGES_YET) { return; } } while (!state.compareAndSet(prev, State.TIMED_OUT)); copy(timeoutMessages, target); } InitialMessageTimeout(MessageSender<T> target, MessageReceiver<T> timeoutMessages, long timeout, TimeUnit unit); }
InitialMessageTimeout implements MessageSender<T> { public void timedOut() { State prev; do { prev = state.get(); if (prev != State.NO_MESSAGES_YET) { return; } } while (!state.compareAndSet(prev, State.TIMED_OUT)); copy(timeoutMessages, target); } InitialMessageTimeout(MessageSender<T> target, MessageReceiver<T> timeoutMessages, long timeout, TimeUnit unit); @Override void send(T message); void timedOut(); }
InitialMessageTimeout implements MessageSender<T> { public void timedOut() { State prev; do { prev = state.get(); if (prev != State.NO_MESSAGES_YET) { return; } } while (!state.compareAndSet(prev, State.TIMED_OUT)); copy(timeoutMessages, target); } InitialMessageTimeout(MessageSender<T> target, MessageReceiver<T> timeoutMessages, long timeout, TimeUnit unit); @Override void send(T message); void timedOut();  }