-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract separate test for transfer cache
- Loading branch information
1 parent
041d1bb
commit 0363fc8
Showing
3 changed files
with
79 additions
and
24 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
application/src/test/java/org/opentripplanner/transit/speed_test/LoadModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.opentripplanner.transit.speed_test; | ||
|
||
import org.opentripplanner.routing.graph.Graph; | ||
import org.opentripplanner.standalone.config.BuildConfig; | ||
import org.opentripplanner.transit.service.TimetableRepository; | ||
|
||
record LoadModel(Graph graph, TimetableRepository timetableRepository, BuildConfig buildConfig) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
application/src/test/java/org/opentripplanner/transit/speed_test/TransferCacheTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.opentripplanner.transit.speed_test; | ||
|
||
import static org.opentripplanner.standalone.configure.ConstructApplication.creatTransitLayerForRaptor; | ||
import static org.opentripplanner.transit.speed_test.support.AssertSpeedTestSetup.assertTestDateHasData; | ||
|
||
import java.util.stream.IntStream; | ||
import org.opentripplanner.framework.application.OtpAppException; | ||
import org.opentripplanner.routing.api.request.RouteRequest; | ||
import org.opentripplanner.standalone.OtpStartupInfo; | ||
import org.opentripplanner.transit.service.TimetableRepository; | ||
import org.opentripplanner.transit.speed_test.model.timer.SpeedTestTimer; | ||
import org.opentripplanner.transit.speed_test.options.SpeedTestCmdLineOpts; | ||
import org.opentripplanner.transit.speed_test.options.SpeedTestConfig; | ||
|
||
/** | ||
* Test how long it takes to compute the transfer cache. | ||
*/ | ||
public class TransferCacheTest { | ||
|
||
|
||
public static void main(String[] args) { | ||
try { | ||
OtpStartupInfo.logInfo("Run transfer cache test"); | ||
// Given the following setup | ||
SpeedTestCmdLineOpts opts = new SpeedTestCmdLineOpts(args); | ||
var config = SpeedTestConfig.config(opts.rootDir()); | ||
SetupHelper.loadOtpFeatures(opts); | ||
var model = SetupHelper.loadGraph(opts.rootDir(), config.graph); | ||
var timetableRepository = model.timetableRepository(); | ||
var buildConfig = model.buildConfig(); | ||
|
||
var timer = new SpeedTestTimer(); | ||
|
||
assertTestDateHasData(timetableRepository, config, buildConfig); | ||
|
||
// Creating transitLayerForRaptor should be integrated into the TimetableRepository, but for now | ||
// we do it manually here | ||
creatTransitLayerForRaptor(timetableRepository, config.transitRoutingParams); | ||
|
||
measureTransferCacheComputation(timer, timetableRepository); | ||
|
||
timer.setUp(false); | ||
timer.finishUp(); | ||
|
||
} catch (OtpAppException ae) { | ||
System.err.println(ae.getMessage()); | ||
System.exit(1); | ||
} catch (Exception e) { | ||
System.err.println(e.getMessage()); | ||
e.printStackTrace(System.err); | ||
System.exit(1); | ||
} | ||
} | ||
|
||
/** | ||
* Measure how long it takes to compute the transfer cache. | ||
*/ | ||
private static void measureTransferCacheComputation(SpeedTestTimer timer, TimetableRepository timetableRepository) { | ||
IntStream.range(1,7) | ||
.forEach(reluctance -> { | ||
RouteRequest routeRequest = new RouteRequest(); | ||
routeRequest.withPreferences(b -> b.withWalk(c -> c.withReluctance(reluctance))); | ||
timer.recordTimer( | ||
"transfer_cache_computation", | ||
() -> timetableRepository.getTransitLayer().initTransferCacheForRequest(routeRequest) | ||
); | ||
}); | ||
} | ||
|
||
|
||
} |