Skip to content

Commit

Permalink
Add performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienmaillard committed Feb 6, 2024
1 parent b5a4e74 commit 28e9789
Showing 1 changed file with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,36 @@ export default () => Goal.CoexistenceGoal({
assertEquals(Duration.of(5, Duration.HOUR), peelBanana.startOffset());
}

@Test
void testSingleActivityPlanSimpleRecurrenceGoalPerf() {
final var activityDirective = new ActivityDirective(
Duration.ZERO,
"BiteBanana",
Map.of("biteSize", SerializedValue.of(1)),
null,
true);
final var goal = new SchedulingGoal(new GoalId(0L), """
export default () => Goal.ActivityRecurrenceGoal({
activityTemplate: ActivityTemplates.PeelBanana({peelDirection: "fromStem"}),
interval: Temporal.Duration.from({days: 1})
})
""", true);
final var results1 = runScheduler(
BANANANATION,
List.of(activityDirective),
List.of(goal),
PLANNING_HORIZON,
30);
final var results2 = runScheduler(
BANANANATION,
List.of(activityDirective),
List.of(goal),
PLANNING_HORIZON,
0);
assertEquals(Duration.of(432, HOURS), results1.savedSimulationTime);
assertEquals(Duration.of(0, HOURS), results2.savedSimulationTime);
assertEquals(results1.idToAct.values().stream().toList(), results2.idToAct.values().stream().toList());
}

@Test
void testSingleActivityPlanSimpleRecurrenceGoal() {
Expand Down Expand Up @@ -1945,15 +1975,24 @@ private SchedulingRunResults runScheduler(
final MissionModelDescription desc,
final List<ActivityDirective> plannedActivities,
final Iterable<SchedulingGoal> goals,
final PlanningHorizon planningHorizon
final PlanningHorizon planningHorizon){
return runScheduler(desc, plannedActivities, goals, planningHorizon, 30);
}

private SchedulingRunResults runScheduler(
final MissionModelDescription desc,
final List<ActivityDirective> plannedActivities,
final Iterable<SchedulingGoal> goals,
final PlanningHorizon planningHorizon,
final int cachedEngineStoreCapacity
)
{
final var activities = new HashMap<ActivityDirectiveId, ActivityDirective>();
long id = 1;
for (final var activityDirective : plannedActivities) {
activities.put(new ActivityDirectiveId(id++), activityDirective);
}
return runScheduler(desc, activities, goals, List.of(), planningHorizon, Optional.empty());
return runScheduler(desc, activities, goals, List.of(), planningHorizon, Optional.empty(), cachedEngineStoreCapacity);
}

private SchedulingRunResults runScheduler(
Expand All @@ -1963,7 +2002,7 @@ private SchedulingRunResults runScheduler(
final PlanningHorizon planningHorizon
)
{
return runScheduler(desc, plannedActivities, goals, List.of(), planningHorizon, Optional.empty());
return runScheduler(desc, plannedActivities, goals, List.of(), planningHorizon, Optional.empty(), 30);
}

private SchedulingRunResults runScheduler(
Expand All @@ -1989,7 +2028,7 @@ private SchedulingRunResults runScheduler(
for (final var activityDirective : plannedActivities) {
activities.put(new ActivityDirectiveId(id++), activityDirective);
}
return runScheduler(desc, activities, goals, globalSchedulingConditions, planningHorizon, externalProfiles);
return runScheduler(desc, activities, goals, globalSchedulingConditions, planningHorizon, externalProfiles, 30);
}

private SchedulingRunResults runScheduler(
Expand All @@ -1998,7 +2037,8 @@ private SchedulingRunResults runScheduler(
final Iterable<SchedulingGoal> goals,
final List<GlobalSchedulingConditionRecord> globalSchedulingConditions,
final PlanningHorizon planningHorizon,
final Optional<ExternalProfiles> externalProfiles
final Optional<ExternalProfiles> externalProfiles,
final int cachedEngineStoreCapacity
) {
final var mockMerlinService = new MockMerlinService();
mockMerlinService.setMissionModel(getMissionModelInfo(desc));
Expand All @@ -2020,7 +2060,7 @@ private SchedulingRunResults runScheduler(
Map.of(),
false,
globalSchedulingConditions)));
final var cachedSimulationEngineStore = new InMemoryCachedEngineStore(30);
final var cachedSimulationEngineStore = new InMemoryCachedEngineStore(cachedEngineStoreCapacity);
final var agent = new SynchronousSchedulerAgent(
specificationService,
mockMerlinService,
Expand All @@ -2039,10 +2079,20 @@ private SchedulingRunResults runScheduler(
System.err.println(serializedReason);
fail(serializedReason);
}
return new SchedulingRunResults(((MockResultsProtocolWriter.Result.Success) result).results(), mockMerlinService.updatedPlan, mockMerlinService.plan, plannedActivities);
return new SchedulingRunResults(
((MockResultsProtocolWriter.Result.Success) result).results(),
mockMerlinService.updatedPlan,
mockMerlinService.plan,
plannedActivities,
cachedSimulationEngineStore.getTotalSavedSimulationTime());
}

record SchedulingRunResults(ScheduleResults scheduleResults, Collection<ActivityDirective> updatedPlan, Plan plan, Map<ActivityDirectiveId, ActivityDirective> idToAct) {}
record SchedulingRunResults(
ScheduleResults scheduleResults,
Collection<ActivityDirective> updatedPlan,
Plan plan,
Map<ActivityDirectiveId, ActivityDirective> idToAct,
Duration savedSimulationTime) {}

static MerlinService.MissionModelTypes loadMissionModelTypesFromJar(
final String jarPath,
Expand Down

0 comments on commit 28e9789

Please sign in to comment.