diff --git a/eventsourcingdb/src/test/java/io/eventsourcingdb/CancellationTest.java b/eventsourcingdb/src/test/java/io/eventsourcingdb/CancellationTest.java index bf8204f..08ce0a2 100644 --- a/eventsourcingdb/src/test/java/io/eventsourcingdb/CancellationTest.java +++ b/eventsourcingdb/src/test/java/io/eventsourcingdb/CancellationTest.java @@ -9,7 +9,6 @@ import java.time.Duration; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.concurrent.CancellationException; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -24,6 +23,12 @@ // the thread that makes it, and a stream by closing it. Either way, the // request then ends with a CancellationException, so that an aborted read can // be told apart from a complete one. +// +// The timeout of this class must not cover starting a container: if it +// interrupts Testcontainers while it looks for Docker, Testcontainers never +// tries again, and every later test that needs a container fails. Tests that +// need EventSourcingDB itself start it in @BeforeEach elsewhere, e.g. in +// WriteEventsTest, which this timeout does not cover. @Timeout(10) class CancellationTest { static List all() { @@ -124,29 +129,6 @@ void aStreamThatIsClosedBeforeItStartsDoesNotSendTheRequest(Operation operation) } } - @Test - void aWriteOfAnInterruptedThreadWritesNothing() { - var container = Database.start(); - try { - var client = container.getClient(); - var candidate = new EventCandidate( - "https://www.eventsourcingdb.io", "/test", "io.eventsourcingdb.test", Map.of("value", 23)); - - Thread.currentThread().interrupt(); - try { - assertThrows(CancellationException.class, () -> client.writeEvents(List.of(candidate))); - } finally { - assertTrue(Thread.interrupted()); - } - - try (var events = client.readEvents("/", new ReadEventsOptions(true))) { - assertEquals(0, events.count()); - } - } finally { - container.stop(); - } - } - @Test void anInterruptEndsAWriteWhoseResponseStopsInTheMiddle() throws InterruptedException { try (var server = FakeServer.start((exchange, fakeServer) -> { diff --git a/eventsourcingdb/src/test/java/io/eventsourcingdb/WriteEventsTest.java b/eventsourcingdb/src/test/java/io/eventsourcingdb/WriteEventsTest.java index 9072ac5..e8a3550 100644 --- a/eventsourcingdb/src/test/java/io/eventsourcingdb/WriteEventsTest.java +++ b/eventsourcingdb/src/test/java/io/eventsourcingdb/WriteEventsTest.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.concurrent.CancellationException; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -70,6 +71,20 @@ void writesMultipleEvents() { assertEquals(new EventData(42), writtenEvents.get(1).data(EventData.class)); } + @Test + void writesNothingIfTheThreadIsInterrupted() { + Thread.currentThread().interrupt(); + try { + assertThrows(CancellationException.class, () -> client.writeEvents(List.of(candidate(23)))); + } finally { + assertTrue(Thread.interrupted()); + } + + try (var events = client.readEvents("/", new ReadEventsOptions(true))) { + assertEquals(0, events.count()); + } + } + @Test void writesTheTraceContextOfAnEvent() { var traceParent = "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01";