|
9 | 9 |
|
10 | 10 | public interface AppendTests extends ConnectionAware {
|
11 | 11 | @Test
|
12 |
| - default void testAppendSingleEventNoStream() throws Throwable { |
| 12 | + default void testAppendAndTraceMultipleEvents() throws Throwable { |
13 | 13 | EventStoreDBClient client = getDatabase().defaultClient();
|
14 | 14 |
|
15 | 15 | final String streamName = generateName();
|
16 | 16 | final String eventType = "TestEvent";
|
17 |
| - final String eventId = "38fffbc2-339e-11ea-8c7b-784f43837872"; |
| 17 | + final String eventId1 = UUID.randomUUID().toString(); |
| 18 | + final String eventId2 = UUID.randomUUID().toString(); |
18 | 19 | final byte[] eventMetaData = new byte[]{0xd, 0xe, 0xa, 0xd};
|
19 | 20 | final JsonMapper jsonMapper = new JsonMapper();
|
20 | 21 |
|
21 |
| - EventData event = EventData.builderAsJson(eventType, jsonMapper.writeValueAsBytes(new Foo())) |
| 22 | + // Create first event data with metadata bytes |
| 23 | + EventData event1 = EventData.builderAsJson(eventType, jsonMapper.writeValueAsBytes(new Foo())) |
22 | 24 | .metadataAsBytes(eventMetaData)
|
23 |
| - .eventId(UUID.fromString(eventId)) |
| 25 | + .eventId(UUID.fromString(eventId1)) |
| 26 | + .build(); |
| 27 | + |
| 28 | + // Create second event data with JSON metadata |
| 29 | + EventData event2 = EventData.builderAsJson(eventType, jsonMapper.writeValueAsBytes(new Foo())) |
| 30 | + .metadataAsBytes(jsonMapper.writeValueAsBytes(new Foo())) |
| 31 | + .eventId(UUID.fromString(eventId2)) |
24 | 32 | .build();
|
25 | 33 |
|
26 | 34 | AppendToStreamOptions appendOptions = AppendToStreamOptions.get()
|
27 | 35 | .expectedRevision(ExpectedRevision.noStream());
|
28 | 36 |
|
29 |
| - WriteResult appendResult = client.appendToStream(streamName, appendOptions, event) |
| 37 | + // Append both events to stream |
| 38 | + WriteResult appendResult = client.appendToStream(streamName, appendOptions, event1, event2) |
30 | 39 | .get();
|
31 | 40 |
|
32 |
| - Assertions.assertEquals(ExpectedRevision.expectedRevision(0), appendResult.getNextExpectedRevision()); |
| 41 | + // Validate the append operation |
| 42 | + Assertions.assertEquals(ExpectedRevision.expectedRevision(1), appendResult.getNextExpectedRevision()); |
33 | 43 |
|
34 | 44 | ReadStreamOptions readStreamOptions = ReadStreamOptions.get()
|
35 | 45 | .fromEnd()
|
36 | 46 | .backwards()
|
37 |
| - .maxCount(1); |
| 47 | + .maxCount(2); |
38 | 48 |
|
39 |
| - // Ensure appended event is readable |
| 49 | + // Ensure both appended events are readable |
40 | 50 | ReadResult result = client.readStream(streamName, readStreamOptions)
|
41 | 51 | .get();
|
42 | 52 |
|
43 |
| - Assertions.assertEquals(1, result.getEvents().size()); |
44 |
| - RecordedEvent first = result.getEvents().get(0).getEvent(); |
| 53 | + Assertions.assertEquals(2, result.getEvents().size()); |
| 54 | + RecordedEvent first = result.getEvents().get(1).getEvent(); |
| 55 | + RecordedEvent second = result.getEvents().get(0).getEvent(); |
45 | 56 | JsonMapper mapper = new JsonMapper();
|
46 | 57 |
|
| 58 | + // Verify first event details |
47 | 59 | Assertions.assertEquals(streamName, first.getStreamId());
|
48 | 60 | Assertions.assertEquals(eventType, first.getEventType());
|
49 |
| - Assertions.assertEquals(eventId, first.getEventId().toString()); |
| 61 | + Assertions.assertEquals(eventId1, first.getEventId().toString()); |
50 | 62 | Assertions.assertArrayEquals(eventMetaData, first.getUserMetadata());
|
51 | 63 | Assertions.assertEquals(new Foo(), mapper.readValue(first.getEventData(), Foo.class));
|
| 64 | + |
| 65 | + // Verify second event details |
| 66 | + Assertions.assertEquals(streamName, second.getStreamId()); |
| 67 | + Assertions.assertEquals(eventType, second.getEventType()); |
| 68 | + Assertions.assertEquals(eventId2, second.getEventId().toString()); |
| 69 | + Assertions.assertEquals(new Foo(), mapper.readValue(second.getEventData(), Foo.class)); |
52 | 70 | }
|
53 | 71 | }
|
| 72 | + |
0 commit comments