Vertex stop_a = graph.getVertex("agency:A");
Vertex stop_c = graph.getVertex("agency:C");
RoutingRequest options = new RoutingRequest();
ShortestPathTree spt;
GraphPath path;
// non-existing trip
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("b");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.CANCELED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
tripUpdate = tripUpdateBuilder.build();
assertFalse(timetable.update(tripUpdate, timeZone, serviceDate));
// update trip with bad data
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(
TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopSequence(0);
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SKIPPED);
tripUpdate = tripUpdateBuilder.build();
assertFalse(timetable.update(tripUpdate, timeZone, serviceDate));
// update trip with non-increasing data
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopSequence(2);
stopTimeUpdateBuilder.setScheduleRelationship(
StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeEventBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
stopTimeEventBuilder.setTime(TestUtils.dateInSeconds(
"America/New_York", 2009, AUGUST, 7, 0, 10, 1));
stopTimeEventBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
stopTimeEventBuilder.setTime(TestUtils.dateInSeconds(
"America/New_York", 2009, AUGUST, 7, 0, 10, 0));
tripUpdate = tripUpdateBuilder.build();
assertFalse(timetable.update(tripUpdate, timeZone, serviceDate));
//---
long startTime = TestUtils.dateInSeconds("America/New_York", 2009, AUGUST, 7, 0, 0, 0);
long endTime;
options.dateTime = startTime;
//---
options.setRoutingContext(graph, stop_a, stop_c);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_c, false);
assertNotNull(path);
endTime = startTime + 20 * 60;
assertEquals(endTime, path.getEndTime());
// update trip
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(
TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0);
stopTimeUpdateBuilder.setStopSequence(1);
stopTimeUpdateBuilder.setScheduleRelationship(
StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeEventBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
stopTimeEventBuilder.setTime(TestUtils.dateInSeconds(
"America/New_York", 2009, AUGUST, 7, 0, 2, 0));
stopTimeEventBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
stopTimeEventBuilder.setTime(TestUtils.dateInSeconds(
"America/New_York", 2009, AUGUST, 7, 0, 2, 0));
tripUpdate = tripUpdateBuilder.build();
assertEquals(20*60, timetable.getTripTimes(trip_1_1_index).getArrivalTime(2));
assertTrue(timetable.update(tripUpdate, timeZone, serviceDate));
assertEquals(20*60 + 120, timetable.getTripTimes(trip_1_1_index).getArrivalTime(2));
//---
options.setRoutingContext(graph, stop_a, stop_c);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_c, false);
assertNotNull(path);
endTime = startTime + 20 * 60 + 120;
assertEquals(endTime, path.getEndTime());
// cancel trip
tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.CANCELED);
tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
tripUpdate = tripUpdateBuilder.build();
assertTrue(timetable.update(tripUpdate, timeZone, serviceDate));
TripTimes tripTimes = timetable.getTripTimes(trip_1_1_index);
for (int i = 0; i < tripTimes.getNumStops(); i++) {
assertEquals(TripTimes.UNAVAILABLE, tripTimes.getDepartureTime(i));
assertEquals(TripTimes.UNAVAILABLE, tripTimes.getArrivalTime(i));
}
//---
options.setRoutingContext(graph, stop_a, stop_c);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_c, false);
assertNotNull(path);
endTime = startTime + 40 * 60;
assertEquals(endTime, path.getEndTime());
// update trip arrival time incorrectly