use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecordWithMultipleTrips.
/**
* Set up the BlockLocationServiceImpl for the test, using the given
* timepointPredictions
*
* This method creates a loop route with a three trips and two stops in a block
* Stop A is visited twice in a trip
*
* stop_id trip_id stop_sequence
* A 1 0
* B 1 1
* A 1 3
*
* A 2 0
* B 2 1
* A 2 3
*
* A 3 0
* B 3 1
* A 3 3
*
* @param timepointPredictions real-time predictions to apply to the
* BlockLocationServiceImpl
* @param stop stop_id for this stop is used to call getArrivalsAndDeparturesForStopInTimeRange()
* @return a list of ArrivalAndDepartureInstances which is used to access
* predicted arrival/departure times for a stop, for comparison
* against the expected values
*/
private List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecordWithMultipleTrips(List<TimepointPredictionRecord> timepointPredictions, StopEntryImpl stop) {
TargetTime target = new TargetTime(mCurrentTime, mCurrentTime);
// Setup block
BlockEntryImpl block = block("blockA");
stopTime(0, mStopA, mTrip1, time(13, 30), time(13, 35), 1000);
stopTime(1, mStopB, mTrip1, time(13, 45), time(13, 50), 2000);
stopTime(2, mStopA, mTrip1, time(13, 55), time(13, 55), 2000);
stopTime(0, mStopA, mTrip2, time(14, 05), time(14, 10), 1000);
stopTime(1, mStopB, mTrip2, time(14, 15), time(14, 20), 2000);
stopTime(2, mStopA, mTrip2, time(14, 25), time(14, 25), 2000);
stopTime(0, mStopA, mTrip3, time(14, 30), time(14, 35), 1000);
stopTime(1, mStopB, mTrip3, time(14, 45), time(14, 50), 2000);
stopTime(2, mStopA, mTrip3, time(14, 55), time(14, 55), 2000);
BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("sA", "sB", "sC"), lsids()), mTrip1, mTrip2, mTrip3);
BlockStopTimeEntry bstAA = blockConfig.getStopTimes().get(0);
BlockStopTimeEntry bstAB = blockConfig.getStopTimes().get(1);
BlockStopTimeEntry bstAC = blockConfig.getStopTimes().get(2);
BlockStopTimeEntry bstBA = blockConfig.getStopTimes().get(3);
BlockStopTimeEntry bstBB = blockConfig.getStopTimes().get(4);
BlockStopTimeEntry bstBC = blockConfig.getStopTimes().get(5);
BlockStopTimeEntry bstCA = blockConfig.getStopTimes().get(6);
BlockStopTimeEntry bstCB = blockConfig.getStopTimes().get(7);
BlockStopTimeEntry bstCC = blockConfig.getStopTimes().get(8);
// Setup block location instance for trip B
BlockInstance blockInstance = new BlockInstance(blockConfig, mServiceDate);
BlockLocation blockLocationB = new BlockLocation();
blockLocationB.setActiveTrip(bstBB.getTrip());
blockLocationB.setBlockInstance(blockInstance);
blockLocationB.setClosestStop(bstBC);
blockLocationB.setDistanceAlongBlock(400);
blockLocationB.setInService(true);
blockLocationB.setNextStop(bstBC);
blockLocationB.setPredicted(false);
blockLocationB.setScheduledDistanceAlongBlock(400);
blockLocationB.setTimepointPredictions(timepointPredictions);
// Mock StopTimeInstance with time frame
long stopTimeFrom = dateAsLong("2015-07-23 00:00");
long stopTimeTo = dateAsLong("2015-07-24 00:00");
StopTimeInstance sti1 = new StopTimeInstance(bstAA, blockInstance.getState());
ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
in1.setBlockLocation(blockLocationB);
in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime()));
in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
StopTimeInstance sti2 = new StopTimeInstance(bstAB, blockInstance.getState());
ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
in2.setBlockLocation(blockLocationB);
StopTimeInstance sti3 = new StopTimeInstance(bstAC, blockInstance.getState());
ArrivalAndDepartureInstance in3 = new ArrivalAndDepartureInstance(sti3);
in3.setBlockLocation(blockLocationB);
in3.setPredictedArrivalTime((long) (in3.getScheduledArrivalTime()));
in3.setPredictedDepartureTime((long) (in3.getScheduledDepartureTime()));
StopTimeInstance sti4 = new StopTimeInstance(bstBA, blockInstance.getState());
ArrivalAndDepartureInstance in4 = new ArrivalAndDepartureInstance(sti4);
in4.setBlockLocation(blockLocationB);
StopTimeInstance sti5 = new StopTimeInstance(bstBB, blockInstance.getState());
ArrivalAndDepartureInstance in5 = new ArrivalAndDepartureInstance(sti5);
in5.setBlockLocation(blockLocationB);
StopTimeInstance sti6 = new StopTimeInstance(bstBC, blockInstance.getState());
ArrivalAndDepartureInstance in6 = new ArrivalAndDepartureInstance(sti6);
in6.setBlockLocation(blockLocationB);
StopTimeInstance sti7 = new StopTimeInstance(bstCA, blockInstance.getState());
ArrivalAndDepartureInstance in7 = new ArrivalAndDepartureInstance(sti7);
in7.setBlockLocation(blockLocationB);
StopTimeInstance sti8 = new StopTimeInstance(bstCB, blockInstance.getState());
ArrivalAndDepartureInstance in8 = new ArrivalAndDepartureInstance(sti8);
in8.setBlockLocation(blockLocationB);
StopTimeInstance sti9 = new StopTimeInstance(bstCC, blockInstance.getState());
ArrivalAndDepartureInstance in9 = new ArrivalAndDepartureInstance(sti9);
in9.setBlockLocation(blockLocationB);
Date fromTimeBuffered = new Date(stopTimeFrom - _blockStatusService.getRunningLateWindow() * 1000);
Date toTimeBuffered = new Date(stopTimeTo + _blockStatusService.getRunningEarlyWindow() * 1000);
Mockito.when(_stopTimeService.getStopTimeInstancesInTimeRange(stop, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED)).thenReturn(Arrays.asList(sti1, sti2, sti3, sti4, sti5, sti6, sti7, sti8, sti9));
// Create and add vehicle location record cache
VehicleLocationRecordCacheImpl _cache = new VehicleLocationRecordCacheImpl();
VehicleLocationRecord vlr = new VehicleLocationRecord();
vlr.setBlockId(blockLocationB.getBlockInstance().getBlock().getBlock().getId());
vlr.setTripId(mTrip2.getId());
vlr.setTimepointPredictions(blockLocationB.getTimepointPredictions());
vlr.setTimeOfRecord(mCurrentTime);
vlr.setVehicleId(new AgencyAndId("1", "123"));
// Create ScheduledBlockLocation for cache
ScheduledBlockLocation sbl = new ScheduledBlockLocation();
sbl.setActiveTrip(blockLocationB.getActiveTrip());
// Add data to cache
_cache.addRecord(blockInstance, vlr, sbl, null);
_blockLocationService.setVehicleLocationRecordCache(_cache);
ScheduledBlockLocationServiceImpl scheduledBlockLocationServiceImpl = new ScheduledBlockLocationServiceImpl();
_blockLocationService.setScheduledBlockLocationService(scheduledBlockLocationServiceImpl);
// Call ArrivalAndDepartureService
return _service.getArrivalsAndDeparturesForStopInTimeRange(stop, target, stopTimeFrom, stopTimeTo);
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord.
/**
* Set up the BlockLocationServiceImpl for the test, using the given
* timepointPredictions
*
* This method creates a normal route with a single trip and two stops in a block
*
* stop_id trip_id stop_sequence
* A 1 0
* B 1 1
*
* @param timepointPredictions real-time predictions to apply to the
* BlockLocationServiceImpl
* @return a list of ArrivalAndDepartureInstances which is used to access
* predicted arrival/departure times for a stop, for comparison
* against the expected values
*/
private List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord(List<TimepointPredictionRecord> timepointPredictions) {
TargetTime target = new TargetTime(mCurrentTime, mCurrentTime);
// Setup block
BlockEntryImpl block = block("blockA");
stopTime(0, mStopA, mTrip1, time(13, 30), time(13, 35), 1000);
stopTime(1, mStopB, mTrip1, time(13, 45), time(13, 50), 2000);
BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("sA"), lsids()), mTrip1);
BlockStopTimeEntry bstAA = blockConfig.getStopTimes().get(0);
BlockStopTimeEntry bstAB = blockConfig.getStopTimes().get(1);
BlockStopTimeEntry bstBA = blockConfig.getStopTimes().get(0);
// Setup block location instance for trip B
BlockInstance blockInstance = new BlockInstance(blockConfig, mServiceDate);
BlockLocation blockLocationB = new BlockLocation();
blockLocationB.setActiveTrip(bstBA.getTrip());
blockLocationB.setBlockInstance(blockInstance);
blockLocationB.setClosestStop(bstBA);
blockLocationB.setDistanceAlongBlock(400);
blockLocationB.setInService(true);
blockLocationB.setNextStop(bstAA);
blockLocationB.setPredicted(false);
blockLocationB.setScheduledDistanceAlongBlock(400);
blockLocationB.setTimepointPredictions(timepointPredictions);
// Mock StopTimeInstance with time frame
long stopTimeFrom = dateAsLong("2015-07-23 00:00");
long stopTimeTo = dateAsLong("2015-07-24 00:00");
StopTimeInstance sti1 = new StopTimeInstance(bstAB, blockInstance.getState());
ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
in1.setBlockLocation(blockLocationB);
in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime()));
in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
StopTimeInstance sti2 = new StopTimeInstance(bstBA, blockInstance.getState());
ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
in2.setBlockLocation(blockLocationB);
Date fromTimeBuffered = new Date(stopTimeFrom - _blockStatusService.getRunningLateWindow() * 1000);
Date toTimeBuffered = new Date(stopTimeTo + _blockStatusService.getRunningEarlyWindow() * 1000);
Mockito.when(_stopTimeService.getStopTimeInstancesInTimeRange(mStopB, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED)).thenReturn(Arrays.asList(sti1, sti2));
// Create and add vehicle location record cache
VehicleLocationRecordCacheImpl _cache = new VehicleLocationRecordCacheImpl();
VehicleLocationRecord vlr = new VehicleLocationRecord();
vlr.setBlockId(blockLocationB.getBlockInstance().getBlock().getBlock().getId());
vlr.setTripId(mTrip1.getId());
vlr.setTimepointPredictions(blockLocationB.getTimepointPredictions());
vlr.setTimeOfRecord(mCurrentTime);
vlr.setVehicleId(new AgencyAndId("1", "123"));
// Create ScheduledBlockLocation for cache
ScheduledBlockLocation sbl = new ScheduledBlockLocation();
sbl.setActiveTrip(blockLocationB.getActiveTrip());
// Add data to cache
_cache.addRecord(blockInstance, vlr, sbl, null);
_blockLocationService.setVehicleLocationRecordCache(_cache);
ScheduledBlockLocationServiceImpl scheduledBlockLocationServiceImpl = new ScheduledBlockLocationServiceImpl();
_blockLocationService.setScheduledBlockLocationService(scheduledBlockLocationServiceImpl);
// Call ArrivalAndDepartureService
return _service.getArrivalsAndDeparturesForStopInTimeRange(mStopB, target, stopTimeFrom, stopTimeTo);
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImplTest method testGetActiveBlocksInTimeRange.
@Test
public void testGetActiveBlocksInTimeRange() {
Date serviceDateA = UnitTestingSupport.date("2010-09-07 00:00");
Date serviceDateB = UnitTestingSupport.date("2010-09-08 00:00");
Date serviceDateC = UnitTestingSupport.date("2010-09-09 00:00");
UnitTestingSupport.addDates(_calendarData, "sidA", serviceDateA, serviceDateB);
UnitTestingSupport.addDates(_calendarData, "sidB", serviceDateB, serviceDateC);
ServiceIdActivation ids_A_not_B = serviceIds(lsids("sidA"), lsids("sidB"));
ServiceIdActivation ids_B_not_A = serviceIds(lsids("sidB"), lsids("sidA"));
ServiceIdActivation ids_A_and_B = serviceIds(lsids("sidA", "sidB"), lsids());
StopEntryImpl stopA = stop("stopA", 0.0, 0.0);
StopEntryImpl stopB = stop("stopB", 0.0, 0.0);
BlockEntryImpl blockA = block("blockA");
TripEntryImpl tripA = trip("tripA", "sidA");
TripEntryImpl tripB = trip("tripB", "sidB");
stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
stopTime(2, stopB, tripB, time(10, 00), time(10, 00), 200);
stopTime(3, stopA, tripB, time(10, 30), time(10, 30), 300);
linkBlockTrips(ids_A_not_B, blockA, tripA);
linkBlockTrips(ids_A_and_B, blockA, tripA, tripB);
linkBlockTrips(ids_B_not_A, blockA, tripB);
BlockConfigurationEntry bcA_A_B = findBlockConfig(blockA, ids_A_not_B);
BlockConfigurationEntry bcA_B_A = findBlockConfig(blockA, ids_B_not_A);
BlockConfigurationEntry bcA_AB = findBlockConfig(blockA, ids_A_and_B);
BlockEntryImpl blockB = block("blockB");
TripEntryImpl tripC = trip("tripC", "sidA");
TripEntryImpl tripD = trip("tripD", "sidB");
TripEntryImpl tripE = trip("tripE", "sidA");
stopTime(4, stopA, tripC, time(10, 00), time(10, 00), 0);
stopTime(5, stopB, tripC, time(10, 30), time(10, 30), 0);
stopTime(6, stopB, tripD, time(11, 00), time(11, 00), 0);
stopTime(7, stopA, tripD, time(11, 30), time(11, 30), 0);
stopTime(8, stopA, tripE, time(12, 00), time(12, 00), 0);
stopTime(9, stopB, tripE, time(12, 30), time(12, 30), 0);
linkBlockTrips(ids_A_not_B, blockB, tripC, tripE);
linkBlockTrips(ids_A_and_B, blockB, tripC, tripD, tripE);
linkBlockTrips(ids_B_not_A, blockB, tripD);
BlockConfigurationEntry bcB_A_B = findBlockConfig(blockB, ids_A_not_B);
BlockConfigurationEntry bcB_B_A = findBlockConfig(blockB, ids_B_not_A);
BlockConfigurationEntry bcB_AB = findBlockConfig(blockB, ids_A_and_B);
List<BlockTripIndex> blocks = blockTripIndices(blockA, blockB);
List<BlockLayoverIndex> layoverIndices = Collections.emptyList();
List<FrequencyBlockTripIndex> frequencyIndices = Collections.emptyList();
/**
**
*
***
*/
long time = timeFromString("2010-09-07 09:15");
List<BlockInstance> instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
BlockInstance instance = instances.get(0);
assertEquals(bcA_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-07 010:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
/*
* time = timeFromString("2010-09-07 011:15");
*
* instances = _service.getActiveBlocksInTimeRange(blocks, frequencyIndices,
* time, time);
*
* assertEquals(1, instances.size());
*
* instance = instances.get(0); assertEquals(bcB_A_B, instance.getBlock());
* assertEquals(serviceDateA.getTime(), instance.getServiceDate());
*/
/**
**
*
***
*/
time = timeFromString("2010-09-07 012:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 09:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcA_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 10:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
Collections.sort(instances, new BlockInstanceComparator());
assertEquals(2, instances.size());
instance = instances.get(0);
assertEquals(bcA_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
instance = instances.get(1);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 11:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 12:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-09 09:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(0, instances.size());
/**
**
*
***
*/
time = timeFromString("2010-09-09 10:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcA_B_A, instance.getBlock());
assertEquals(serviceDateC.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-09 11:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_B_A, instance.getBlock());
assertEquals(serviceDateC.getTime(), instance.getServiceDate());
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.
the class BlockLocationRecordCacheImplTest method testSimpleOperations.
@Test
public void testSimpleOperations() {
long serviceDate = System.currentTimeMillis();
BlockEntryImpl block = block("blockA");
TripEntryImpl trip = trip("tripA", "serviceId");
stopTime(0, null, trip, time(9, 00), 0);
BlockConfigurationEntry blockConfig = linkBlockTrips(block, trip);
BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);
BlockLocationRecordCacheImpl cache = new BlockLocationRecordCacheImpl();
cache.setBlockLocationRecordCacheWindowSize(20);
List<BlockLocationRecordCollection> records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(0, records.size());
records = cache.getRecordsForVehicleId(aid("vehicleA"));
assertEquals(0, records.size());
cache.addRecord(blockInstance, record(20, "blockA", serviceDate, "vehicleA", 10.0));
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(1, records.size());
BlockLocationRecordCollection collection = records.get(0);
assertEquals(20, collection.getFromTime());
assertEquals(20, collection.getToTime());
assertEquals(blockInstance, collection.getBlockInstance());
assertEquals(aid("vehicleA"), collection.getVehicleId());
records = cache.getRecordsForVehicleId(aid("vehicleA"));
assertEquals(1, records.size());
cache.addRecord(blockInstance, record(30, "blockA", serviceDate, "vehicleA", 20.0));
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(1, records.size());
collection = records.get(0);
assertEquals(20, collection.getFromTime());
assertEquals(30, collection.getToTime());
assertEquals(blockInstance, collection.getBlockInstance());
assertEquals(aid("vehicleA"), collection.getVehicleId());
records = cache.getRecordsForVehicleId(aid("vehicleA"));
assertEquals(1, records.size());
cache.addRecord(blockInstance, record(40, "blockA", serviceDate, "vehicleB", 5.0));
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(2, records.size());
records = cache.getRecordsForVehicleId(aid("vehicleA"));
assertEquals(1, records.size());
collection = records.get(0);
assertEquals(20, collection.getFromTime());
assertEquals(30, collection.getToTime());
assertEquals(blockInstance, collection.getBlockInstance());
assertEquals(aid("vehicleA"), collection.getVehicleId());
records = cache.getRecordsForVehicleId(aid("vehicleB"));
assertEquals(1, records.size());
collection = records.get(0);
assertEquals(40, collection.getFromTime());
assertEquals(40, collection.getToTime());
assertEquals(blockInstance, collection.getBlockInstance());
assertEquals(aid("vehicleB"), collection.getVehicleId());
cache.clearRecordsForVehicleId(aid("vehicleA"));
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(1, records.size());
records = cache.getRecordsForVehicleId(aid("vehicleA"));
assertEquals(0, records.size());
records = cache.getRecordsForVehicleId(aid("vehicleB"));
assertEquals(1, records.size());
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.
the class BlockLocationRecordCacheImplTest method testClearCache.
@Test
public void testClearCache() throws InterruptedException {
long serviceDate = System.currentTimeMillis();
BlockEntryImpl blockA = block("blockA");
TripEntryImpl tripA = trip("tripA", "serviceId");
stopTime(0, null, tripA, time(9, 00), 0);
BlockConfigurationEntry blockConfigA = linkBlockTrips(blockA, tripA);
BlockInstance instanceA = new BlockInstance(blockConfigA, serviceDate);
BlockEntryImpl blockB = block("blockB");
TripEntryImpl tripB = trip("tripB", "serviceId");
stopTime(0, null, tripB, time(9, 00), 0);
BlockConfigurationEntry blockConfigB = linkBlockTrips(blockB, tripB);
BlockInstance instanceB = new BlockInstance(blockConfigB, serviceDate);
BlockLocationRecordCacheImpl cache = new BlockLocationRecordCacheImpl();
cache.setBlockLocationRecordCacheWindowSize(20);
cache.addRecord(instanceA, record(20, "blockA", serviceDate, "vehicleA", 10.0));
Thread.sleep(100);
cache.addRecord(instanceB, record(30, "blockB", serviceDate, "vehicleB", 20.0));
Thread.sleep(100);
cache.addRecord(instanceA, record(40, "blockA", serviceDate, "vehicleC", 20.0));
Thread.sleep(100);
cache.addRecord(instanceB, record(50, "blockB", serviceDate, "vehicleD", 20.0));
cache.clearStaleRecords(System.currentTimeMillis() - 150);
List<BlockLocationRecordCollection> records = cache.getRecordsForVehicleId(aid("vehicleA"));
assertEquals(0, records.size());
records = cache.getRecordsForVehicleId(aid("vehicleB"));
assertEquals(0, records.size());
records = cache.getRecordsForVehicleId(aid("vehicleC"));
assertEquals(1, records.size());
records = cache.getRecordsForVehicleId(aid("vehicleD"));
assertEquals(1, records.size());
records = cache.getRecordsForBlockInstance(instanceA);
assertEquals(1, records.size());
records = cache.getRecordsForBlockInstance(instanceB);
assertEquals(1, records.size());
}
Aggregations