From 2245f487ed41ded15392d76c1bae3ae3f1e90782 Mon Sep 17 00:00:00 2001 From: Marcel Rieser Date: Thu, 18 Jan 2024 20:51:52 +0100 Subject: [PATCH] provide more information in the exception when events are not properly ordered --- .../SimStepParallelEventsManagerImpl.java | 4 +++- .../SimStepParallelEventsManagerImplTest.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/matsim/src/main/java/org/matsim/core/events/SimStepParallelEventsManagerImpl.java b/matsim/src/main/java/org/matsim/core/events/SimStepParallelEventsManagerImpl.java index 726c62b96e8..14524bedd6e 100644 --- a/matsim/src/main/java/org/matsim/core/events/SimStepParallelEventsManagerImpl.java +++ b/matsim/src/main/java/org/matsim/core/events/SimStepParallelEventsManagerImpl.java @@ -291,7 +291,9 @@ public void run() { if (event.getTime() < this.lastEventTime) { throw new RuntimeException("Events in the queue are not ordered chronologically. " + "This should never happen. Is the SimTimeStepParallelEventsManager registered " + - "as a MobsimAfterSimStepListener?"); + "as a MobsimAfterSimStepListener? LastEventTime = " + this.lastEventTime + + " currentEvent.time = " + event.getTime() + " currentEvent.type = " + event.getEventType() + + " full event: " + event.toString()); } else { this.lastEventTime = event.getTime(); } diff --git a/matsim/src/test/java/org/matsim/core/events/SimStepParallelEventsManagerImplTest.java b/matsim/src/test/java/org/matsim/core/events/SimStepParallelEventsManagerImplTest.java index 894bc9661b1..cbf74b294c6 100644 --- a/matsim/src/test/java/org/matsim/core/events/SimStepParallelEventsManagerImplTest.java +++ b/matsim/src/test/java/org/matsim/core/events/SimStepParallelEventsManagerImplTest.java @@ -69,4 +69,21 @@ public void reset(int iteration) {} new PersonStuckEvent(1.0, Id.createPersonId(0), Id.createLinkId(0), "car")); } + @Test + void testEventsAreChronologicallyOrdered() { + SimStepParallelEventsManagerImpl events = new SimStepParallelEventsManagerImpl(2); + EventsCollector collector = new EventsCollector(); + events.addHandler(collector); + try { + events.initProcessing(); + events.processEvent(new LinkEnterEvent(10.0, Id.createVehicleId(0), Id.createLinkId(0))); + events.processEvent(new LinkLeaveEvent(50.0, Id.createVehicleId(0), Id.createLinkId(0))); + events.processEvent(new LinkEnterEvent(49.0, Id.createVehicleId(0), Id.createLinkId(0))); + events.processEvent(new LinkLeaveEvent(69.0, Id.createVehicleId(0), Id.createLinkId(0))); + events.finishProcessing(); + Assertions.fail("Expected exception about order of events"); + } catch (Exception expected) { + } + } + }