Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Oct 13, 2024
1 parent f91086e commit a129131
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,36 @@
import com.google.transit.realtime.GtfsRealtime.TripUpdate;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.opentripplanner.ConstantsForTests;
import org.opentripplanner.TestOtpModel;
import org.opentripplanner._support.time.ZoneIds;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.TransitLayer;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers.TransitLayerUpdater;
import org.opentripplanner.transit.model.framework.Deduplicator;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.framework.Result;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.timetable.Trip;
import org.opentripplanner.transit.model.timetable.TripIdAndServiceDate;
import org.opentripplanner.transit.model.timetable.TripOnServiceDate;
import org.opentripplanner.transit.model.timetable.TripTimes;
import org.opentripplanner.transit.model.timetable.TripTimesFactory;
import org.opentripplanner.transit.service.TransitModel;
import org.opentripplanner.updater.spi.UpdateError;
import org.opentripplanner.updater.trip.BackwardsDelayPropagationType;

public class TimetableSnapshotTest {

private static final ZoneId timeZone = ZoneIds.GMT;
public static final LocalDate SERVICE_DATE = LocalDate.of(2024, 1, 1);
private static Map<FeedScopedId, TripPattern> patternIndex;
static String feedId;

Expand Down Expand Up @@ -261,6 +272,44 @@ public void testPurge() {
assertFalse(resolver.isDirty());
}

@Test
void testUniqueDirtyTimetablesAfterMultipleUpdates() {
TimetableSnapshot snapshot = new TimetableSnapshot();
TripPattern pattern = patternIndex.get(new FeedScopedId(feedId, "1.1"));
Trip trip = pattern.scheduledTripsAsStream().findFirst().orElseThrow();

TripTimes updatedTriptimes = TripTimesFactory.tripTimes(
trip,
List.of(new StopTime()),
new Deduplicator()
);
RealTimeTripUpdate realTimeTripUpdate = new RealTimeTripUpdate(
pattern,
updatedTriptimes,
SERVICE_DATE,
TripOnServiceDate.of(trip.getId()).withTrip(trip).withServiceDate(SERVICE_DATE).build(),
true,
true
);

snapshot.update(realTimeTripUpdate);
snapshot.update(realTimeTripUpdate);
assertTrue(snapshot.isDirty());

TransitLayerUpdater transitLayer = new TransitLayerUpdater(null) {
@Override
public void update(
Collection<Timetable> updatedTimetables,
Map<TripPattern, SortedSet<Timetable>> timetables
) {
assertEquals(1, updatedTimetables.size());
assertEquals(1, timetables.size());
}
};

snapshot.commit(transitLayer, true);
}

@Test
void testCannotUpdateReadOnlyTimetableSnapshot() {
TimetableSnapshot committedSnapshot = createCommittedSnapshot();
Expand Down

0 comments on commit a129131

Please sign in to comment.