@Override protected void checkMoveValidity(Point objLoc, Point nextHop) { super.checkMoveValidity(objLoc, nextHop); // check if there is a vehicle driving in the opposite direction if (!objLoc.equals(nextHop)) { final Connection<?> conn = getConnection(objLoc, nextHop); if (graph.hasConnection(conn.to(), conn.from()) && registry() .hasObjectOn(Connection.create(conn.to(), conn.from()))) { throw new DeadlockException(conn); } } }
/** * Test for detection of a dead lock situation between two AGVs. The AGVs * drive on the same connection from opposite ends. An * {@link IllegalArgumentException} should be thrown at the moment the second * AGV tries to enter the connection. */ @Test public void testDetectDeadLock() { final MovingRoadUser agv1 = new TestRoadUser(); final MovingRoadUser agv2 = new TestRoadUser(); model.addObjectAt(agv1, NW); model.addObjectAt(agv2, SW); model.moveTo(agv1, SW, meter(5)); boolean fail = false; try { model.moveTo(agv2, NW, meter(1)); } catch (final DeadlockException e) { assertEquals(SW, e.getConnection().from()); assertEquals(NW, e.getConnection().to()); fail = true; } assertTrue(fail); }