-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d013722
commit 62049ea
Showing
6 changed files
with
283 additions
and
8 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...in/java/gov/nasa/jpl/aerie/e2e/procedural/scheduling/procedures/ActivityDeletionGoal.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,47 @@ | ||
package gov.nasa.jpl.aerie.e2e.procedural.scheduling.procedures; | ||
|
||
import gov.nasa.ammos.aerie.procedural.scheduling.Goal; | ||
import gov.nasa.ammos.aerie.procedural.scheduling.annotations.SchedulingProcedure; | ||
import gov.nasa.ammos.aerie.procedural.scheduling.plan.DeletedAnchorStrategy; | ||
import gov.nasa.ammos.aerie.procedural.scheduling.plan.EditablePlan; | ||
import gov.nasa.ammos.aerie.procedural.timeline.payloads.activities.DirectiveStart; | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; | ||
import gov.nasa.jpl.aerie.types.ActivityDirectiveId; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Creates three activities in a chain of anchors, then deletes one. | ||
*/ | ||
@SchedulingProcedure | ||
public record ActivityDeletionGoal(int whichToDelete, DeletedAnchorStrategy anchorStrategy) implements Goal { | ||
@Override | ||
public void run(@NotNull final EditablePlan plan) { | ||
final var ids = new ActivityDirectiveId[3]; | ||
|
||
ids[0] = plan.create( | ||
"BiteBanana", | ||
new DirectiveStart.Absolute(Duration.HOUR), | ||
Map.of("biteSize", SerializedValue.of(0)) | ||
); | ||
ids[1] = plan.create( | ||
"BiteBanana", | ||
new DirectiveStart.Anchor(ids[0], Duration.HOUR, DirectiveStart.Anchor.AnchorPoint.End), | ||
Map.of("biteSize", SerializedValue.of(1)) | ||
); | ||
ids[2] = plan.create( | ||
"BiteBanana", | ||
new DirectiveStart.Anchor(ids[1], Duration.HOUR, DirectiveStart.Anchor.AnchorPoint.Start), | ||
Map.of("biteSize", SerializedValue.of(2)) | ||
); | ||
|
||
if (whichToDelete >= 0) { | ||
plan.delete(ids[whichToDelete], anchorStrategy); | ||
} | ||
|
||
plan.commit(); | ||
} | ||
} |
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
215 changes: 215 additions & 0 deletions
215
e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/procedural/scheduling/DeletionTests.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,215 @@ | ||
package gov.nasa.jpl.aerie.e2e.procedural.scheduling; | ||
|
||
import gov.nasa.jpl.aerie.e2e.types.GoalInvocationId; | ||
import gov.nasa.jpl.aerie.e2e.utils.GatewayRequests; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.json.Json; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class DeletionTests extends ProceduralSchedulingSetup { | ||
private GoalInvocationId procedureId; | ||
|
||
@BeforeEach | ||
void localBeforeEach() throws IOException { | ||
try (final var gateway = new GatewayRequests(playwright)) { | ||
int procedureJarId = gateway.uploadJarFile("build/libs/ActivityDeletionGoal.jar"); | ||
// Add Scheduling Procedure | ||
procedureId = hasura.createSchedulingSpecProcedure( | ||
"Test Scheduling Procedure", | ||
procedureJarId, | ||
specId, | ||
0 | ||
); | ||
} | ||
} | ||
|
||
@AfterEach | ||
void localAfterEach() throws IOException { | ||
hasura.deleteSchedulingGoal(procedureId.goalId()); | ||
} | ||
|
||
@Test | ||
void createsThreeActivities() throws IOException { | ||
final var args = Json | ||
.createObjectBuilder() | ||
.add("whichToDelete", -1) | ||
.add("anchorStrategy", "Error") | ||
.build(); | ||
|
||
hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
final var plan = hasura.getPlan(planId); | ||
final var activities = plan.activityDirectives(); | ||
|
||
assertEquals(3, activities.size()); | ||
|
||
final AtomicReference<Integer> id1 = new AtomicReference<>(); | ||
final AtomicReference<Integer> id2 = new AtomicReference<>(); | ||
assertTrue(activities.stream().anyMatch( | ||
it -> { | ||
final var result = Objects.equals(it.type(), "BiteBanana") && Objects.equals(it.anchorId(), null); | ||
if (result) id1.set(it.id()); | ||
return result; | ||
} | ||
)); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> { | ||
final var result = Objects.equals(it.type(), "BiteBanana") && Objects.equals(it.anchorId(), id1.get()); | ||
if (result) id2.set(it.id()); | ||
return result; | ||
} | ||
)); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "BiteBanana") && Objects.equals(it.anchorId(), id2.get()) | ||
)); | ||
} | ||
|
||
@Test | ||
void deletesLast() throws IOException { | ||
final var args = Json | ||
.createObjectBuilder() | ||
.add("whichToDelete", 2) | ||
.add("anchorStrategy", "Error") | ||
.build(); | ||
|
||
hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
final var plan = hasura.getPlan(planId); | ||
final var activities = plan.activityDirectives(); | ||
|
||
assertEquals(2, activities.size()); | ||
|
||
final AtomicReference<Integer> id1 = new AtomicReference<>(); | ||
assertTrue(activities.stream().anyMatch( | ||
it -> { | ||
final var result = Objects.equals(it.type(), "BiteBanana") && Objects.equals(it.anchorId(), null); | ||
if (result) id1.set(it.id()); | ||
return result; | ||
} | ||
)); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "BiteBanana") && Objects.equals(it.anchorId(), id1.get()) | ||
)); | ||
} | ||
|
||
@Test | ||
void deletesMiddleCascade() throws IOException { | ||
final var args = Json | ||
.createObjectBuilder() | ||
.add("whichToDelete", 1) | ||
.add("anchorStrategy", "Cascade") | ||
.build(); | ||
|
||
hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
final var plan = hasura.getPlan(planId); | ||
final var activities = plan.activityDirectives(); | ||
|
||
assertEquals(1, activities.size()); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "BiteBanana") && Objects.equals(it.anchorId(), null) | ||
)); | ||
} | ||
|
||
@Test | ||
void deletesMiddleAnchorToParent() throws IOException { | ||
final var args = Json | ||
.createObjectBuilder() | ||
.add("whichToDelete", 1) | ||
.add("anchorStrategy", "ReAnchor") | ||
.build(); | ||
|
||
hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
final var plan = hasura.getPlan(planId); | ||
final var activities = plan.activityDirectives(); | ||
|
||
assertEquals(2, activities.size()); | ||
|
||
final AtomicReference<Integer> id1 = new AtomicReference<>(); | ||
assertTrue(activities.stream().anyMatch( | ||
it -> { | ||
final var result = Objects.equals(it.type(), "BiteBanana") && Objects.equals(it.anchorId(), null); | ||
if (result) id1.set(it.id()); | ||
return result; | ||
} | ||
)); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "BiteBanana") | ||
&& Objects.equals(it.anchorId(), id1.get()) | ||
&& Objects.equals(it.startOffset(), "02:00:00") | ||
)); | ||
} | ||
|
||
@Test | ||
void deletesFirstCascade() throws IOException { | ||
final var args = Json | ||
.createObjectBuilder() | ||
.add("whichToDelete", 0) | ||
.add("anchorStrategy", "Cascade") | ||
.build(); | ||
|
||
hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
final var plan = hasura.getPlan(planId); | ||
final var activities = plan.activityDirectives(); | ||
|
||
assertEquals(0, activities.size()); | ||
} | ||
|
||
@Test | ||
void deletesFirstReAnchorToPlan() throws IOException { | ||
final var args = Json | ||
.createObjectBuilder() | ||
.add("whichToDelete", 0) | ||
.add("anchorStrategy", "ReAnchor") | ||
.build(); | ||
|
||
hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
final var plan = hasura.getPlan(planId); | ||
final var activities = plan.activityDirectives(); | ||
|
||
assertEquals(2, activities.size()); | ||
|
||
final AtomicReference<Integer> id2 = new AtomicReference<>(); | ||
assertTrue(activities.stream().anyMatch( | ||
it -> { | ||
final var result = Objects.equals(it.type(), "BiteBanana") | ||
&& Objects.equals(it.anchorId(), null) | ||
&& Objects.equals(it.startOffset(), "02:00:00"); | ||
if (result) id2.set(it.id()); | ||
return result; | ||
} | ||
)); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "BiteBanana") && Objects.equals(it.anchorId(), id2.get()) | ||
)); | ||
} | ||
} |
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
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
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