Search in sources :

Example 1 with FakeScheduledExecutor

use of net.morimekta.testing.concurrent.FakeScheduledExecutor in project providence by morimekta.

the class QueuedFileMessageWriterTest method testFailedWrite.

@Test
public void testFailedWrite() throws IOException {
    MessageWriter target = mock(MessageWriter.class);
    FakeClock clock = new FakeClock();
    long start = clock.millis();
    FakeScheduledExecutor executor = new FakeScheduledExecutor(clock);
    QueuedMessageWriter writer = new FakeQueuedMessageWriter(target, executor, clock);
    writer.write(new CompactFields("foo", 42, "bar"));
    writer.write(new CompactFields("foo", 42, "bar"));
    when(target.write(any(CompactFields.class))).thenThrow(new IOException());
    when(target.write(any(CompactFields.class))).thenAnswer(i -> {
        executor.shutdown();
        throw new IOException();
    });
    clock.tick(1);
    assertThat(clock.millis() - start, is(138L));
    verify(target).write(any(CompactFields.class));
    verify(target).write(any(CompactFields.class));
    verifyNoMoreInteractions(target);
}
Also used : FakeScheduledExecutor(net.morimekta.testing.concurrent.FakeScheduledExecutor) FakeClock(net.morimekta.testing.time.FakeClock) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) CompactFields(net.morimekta.test.providence.core.CompactFields) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 CompactFields (net.morimekta.test.providence.core.CompactFields)1 FakeScheduledExecutor (net.morimekta.testing.concurrent.FakeScheduledExecutor)1 FakeClock (net.morimekta.testing.time.FakeClock)1 Test (org.junit.Test)1