Search in sources :

Example 16 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl 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());
}
Also used : BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Example 17 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl 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());
}
Also used : BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Example 18 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class BlockLocationRecordCacheImplTest method testConcurrentOperations.

@Test
public void testConcurrentOperations() {
    BlockLocationRecordCacheImpl cache = new BlockLocationRecordCacheImpl();
    cache.setBlockLocationRecordCacheWindowSize(2);
    long serviceDate = System.currentTimeMillis();
    int vid = 0;
    for (int i = 0; i < 20; i++) {
        BlockEntryImpl block = block(Integer.toString(i));
        TripEntryImpl trip = trip(Integer.toString(i), "serviceId");
        stopTime(0, null, trip, time(9, 00), 0);
        BlockConfigurationEntry blockConfig = linkBlockTrips(block, trip);
        BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);
        for (int j = 0; j < 5; j++) {
            AgencyAndId vehicleId = new AgencyAndId("1", Integer.toString(vid++));
            RecordSource source = new RecordSource(blockInstance, vehicleId, cache);
            Thread thread = new Thread(source);
            thread.run();
        }
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Example 19 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class BlockLocationServiceImplTest method testWithShapeInfo.

@Test
public void testWithShapeInfo() {
    StopEntryImpl stopA = stop("a", 47.5, -122.5);
    StopEntryImpl stopB = stop("b", 47.6, -122.4);
    StopEntryImpl stopC = stop("c", 47.5, -122.3);
    BlockEntryImpl block = block("block");
    TripEntryImpl tripA = trip("tripA", "serviceId");
    TripEntryImpl tripB = trip("tripB", "serviceId");
    stopTime(0, stopA, tripA, 30, 90, 0);
    stopTime(1, stopB, tripA, 120, 120, 100);
    stopTime(2, stopC, tripA, 180, 210, 200);
    stopTime(3, stopC, tripB, 240, 240, 300);
    stopTime(4, stopB, tripB, 270, 270, 400);
    stopTime(5, stopA, tripB, 300, 300, 500);
    BlockConfigurationEntry blockConfig = linkBlockTrips(block, tripA, tripB);
    long serviceDate = 1000 * 1000;
    double epsilon = 0.001;
    TargetTime target = new TargetTime(t(serviceDate, 0, 0), System.currentTimeMillis());
    BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);
    BlockLocation location = _service.getLocationForBlockInstance(blockInstance, target);
    assertNull(location);
    ScheduledBlockLocation p = new ScheduledBlockLocation();
    p.setActiveTrip(blockConfig.getTrips().get(0));
    p.setClosestStop(blockConfig.getStopTimes().get(0));
    p.setClosestStopTimeOffset(0);
    p.setDistanceAlongBlock(0);
    p.setLocation(new CoordinatePoint(stopA.getStopLat(), stopA.getStopLon()));
    p.setInService(true);
    Mockito.when(_blockLocationService.getScheduledBlockLocationFromScheduledTime(blockConfig, 1800)).thenReturn(p);
    target = new TargetTime(t(serviceDate, 0, 30), System.currentTimeMillis());
    location = _service.getLocationForBlockInstance(blockInstance, target);
    assertTrue(location.isInService());
    assertEquals(blockConfig.getStopTimes().get(0), location.getClosestStop());
    assertEquals(0, location.getClosestStopTimeOffset());
    assertEquals(stopA.getStopLocation(), location.getLocation());
    assertFalse(location.isScheduleDeviationSet());
    assertTrue(Double.isNaN(location.getScheduleDeviation()));
    assertFalse(location.isDistanceAlongBlockSet());
    assertTrue(Double.isNaN(location.getDistanceAlongBlock()));
    assertEquals(blockInstance, location.getBlockInstance());
    assertEquals(0, location.getLastUpdateTime());
    assertEquals(blockConfig.getTrips().get(0), location.getActiveTrip());
    assertNull(location.getVehicleId());
    assertEquals(47.5, location.getLocation().getLat(), epsilon);
    assertEquals(-122.5, location.getLocation().getLon(), epsilon);
    assertEquals(blockConfig.getStopTimes().get(0), location.getClosestStop());
    assertEquals(0, location.getClosestStopTimeOffset());
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 20 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class VehicleLocationRecordCacheImplTest 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);
    VehicleLocationRecordCacheImpl cache = new VehicleLocationRecordCacheImpl();
    cache.setBlockLocationRecordCacheWindowSize(20);
    List<VehicleLocationCacheElements> records = cache.getRecordsForBlockInstance(blockInstance);
    assertEquals(0, records.size());
    VehicleLocationCacheElements cacheRecord = cache.getRecordForVehicleId(aid("vehicleA"));
    assertNull(cacheRecord);
    cache.addRecord(blockInstance, record(20, "blockA", serviceDate, "vehicleA", 10.0), null, null);
    records = cache.getRecordsForBlockInstance(blockInstance);
    assertEquals(1, records.size());
    cacheRecord = records.get(0);
    VehicleLocationRecord record = cacheRecord.getLastElement().getRecord();
    assertEquals(20, record.getTimeOfRecord());
    assertEquals(blockInstance, cacheRecord.getBlockInstance());
    assertEquals(aid("vehicleA"), record.getVehicleId());
    VehicleLocationCacheElements cacheRecord2 = cache.getRecordForVehicleId(aid("vehicleA"));
    assertSame(cacheRecord, cacheRecord2);
    cache.addRecord(blockInstance, record(30, "blockA", serviceDate, "vehicleA", 20.0), null, null);
    records = cache.getRecordsForBlockInstance(blockInstance);
    assertEquals(1, records.size());
    cacheRecord = records.get(0);
    record = cacheRecord.getLastElement().getRecord();
    assertEquals(30, record.getTimeOfRecord());
    assertEquals(blockInstance, cacheRecord.getBlockInstance());
    assertEquals(aid("vehicleA"), record.getVehicleId());
    cacheRecord2 = cache.getRecordForVehicleId(aid("vehicleA"));
    assertSame(cacheRecord, cacheRecord2);
    cache.addRecord(blockInstance, record(40, "blockA", serviceDate, "vehicleB", 5.0), null, null);
    records = cache.getRecordsForBlockInstance(blockInstance);
    assertEquals(2, records.size());
    cacheRecord = cache.getRecordForVehicleId(aid("vehicleA"));
    record = cacheRecord.getLastElement().getRecord();
    assertEquals(30, record.getTimeOfRecord());
    assertEquals(blockInstance, cacheRecord.getBlockInstance());
    assertEquals(aid("vehicleA"), record.getVehicleId());
    cacheRecord = cache.getRecordForVehicleId(aid("vehicleB"));
    record = cacheRecord.getLastElement().getRecord();
    assertEquals(40, record.getTimeOfRecord());
    assertEquals(blockInstance, cacheRecord.getBlockInstance());
    assertEquals(aid("vehicleB"), record.getVehicleId());
    cache.clearRecordsForVehicleId(aid("vehicleA"));
    records = cache.getRecordsForBlockInstance(blockInstance);
    assertEquals(1, records.size());
    cacheRecord = cache.getRecordForVehicleId(aid("vehicleA"));
    assertNull(cacheRecord);
    cacheRecord = cache.getRecordForVehicleId(aid("vehicleB"));
    assertEquals(aid("vehicleB"), cacheRecord.getLastElement().getRecord().getVehicleId());
}
Also used : VehicleLocationCacheElements(org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheElements) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Aggregations

BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)43 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)34 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)34 Test (org.junit.Test)33 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)25 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)16 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)8 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)7 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)7 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)7 Date (java.util.Date)6 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)6 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)6 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)6 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)5 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)5 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)5