-
Notifications
You must be signed in to change notification settings - Fork 22
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
f13b669
commit 1e50c77
Showing
6 changed files
with
217 additions
and
6 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...n/java/gov/nasa/jpl/aerie/e2e/procedural/scheduling/procedures/DeleteBiteBananasGoal.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,26 @@ | ||
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; | ||
|
||
/** | ||
* Deletes all Bite Bananas with extreme prejudice. Used to test that updated | ||
* anchors are saved in the database properly. | ||
*/ | ||
@SchedulingProcedure | ||
public record DeleteBiteBananasGoal() implements Goal { | ||
@Override | ||
public void run(@NotNull final EditablePlan plan) { | ||
plan.directives("BiteBanana").forEach($ -> plan.delete($, DeletedAnchorStrategy.PreserveTree)); | ||
plan.commit(); | ||
} | ||
} |
177 changes: 177 additions & 0 deletions
177
...sts/src/test/java/gov/nasa/jpl/aerie/e2e/procedural/scheduling/DatabaseDeletionTests.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,177 @@ | ||
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 javax.json.JsonValue; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class DatabaseDeletionTests extends ProceduralSchedulingSetup { | ||
private GoalInvocationId procedureId; | ||
|
||
@BeforeEach | ||
void localBeforeEach() throws IOException { | ||
try (final var gateway = new GatewayRequests(playwright)) { | ||
int procedureJarId = gateway.uploadJarFile("build/libs/DeleteBiteBananaGoal.jar"); | ||
// Add Scheduling Procedure | ||
procedureId = hasura.createSchedulingSpecProcedure( | ||
"Test Scheduling Procedure", | ||
procedureJarId, | ||
specId, | ||
0 | ||
); | ||
} | ||
} | ||
|
||
@AfterEach | ||
void localAfterEach() throws IOException { | ||
hasura.deleteSchedulingGoal(procedureId.goalId()); | ||
} | ||
|
||
@Test | ||
void deletesDirectiveAlreadyInDatabase() throws IOException { | ||
hasura.insertActivityDirective( | ||
planId, | ||
"BiteBanana", | ||
"1h", | ||
JsonValue.EMPTY_JSON_OBJECT | ||
); | ||
|
||
var plan = hasura.getPlan(planId); | ||
assertEquals(1, plan.activityDirectives().size()); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
plan = hasura.getPlan(planId); | ||
assertEquals(0, plan.activityDirectives().size()); | ||
} | ||
|
||
@Test | ||
void deletesDirectiveInDatabaseWithAnchor() throws IOException { | ||
final var bite = hasura.insertActivityDirective( | ||
planId, | ||
"BiteBanana", | ||
"1h", | ||
JsonValue.EMPTY_JSON_OBJECT | ||
); | ||
|
||
final var grow = hasura.insertActivityDirective( | ||
planId, | ||
"GrowBanana", | ||
"1h", | ||
JsonValue.EMPTY_JSON_OBJECT, | ||
Json.createObjectBuilder().add("anchor_id", bite) | ||
); | ||
|
||
var plan = hasura.getPlan(planId); | ||
var activities = plan.activityDirectives(); | ||
assertEquals(2, activities.size()); | ||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "GrowBanana") | ||
&& Objects.equals(it.anchorId(), bite) | ||
&& Objects.equals(it.startOffset(), "01:00:00") | ||
)); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
plan = hasura.getPlan(planId); | ||
|
||
activities = plan.activityDirectives(); | ||
assertEquals(1, activities.size()); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "GrowBanana") | ||
&& Objects.equals(it.anchorId(), null) | ||
&& Objects.equals(it.startOffset(), "02:00:00") | ||
)); | ||
} | ||
|
||
@Test | ||
void deletesDirectiveInDatabaseInMiddleOfChain() throws IOException { | ||
|
||
// Creates 5 activities, deletes "Bite". | ||
// grow1 <- bite | ||
// bite <- grow (id lost) | ||
// bite <- grow2 | ||
// grow2 <- grow3 | ||
|
||
// Bite has two children, a grandchild, and a parent. | ||
|
||
final var grow1 = hasura.insertActivityDirective( | ||
planId, | ||
"GrowBanana", | ||
"1h", | ||
JsonValue.EMPTY_JSON_OBJECT | ||
); | ||
|
||
final var bite = hasura.insertActivityDirective( | ||
planId, | ||
"BiteBanana", | ||
"1h", | ||
JsonValue.EMPTY_JSON_OBJECT, | ||
Json.createObjectBuilder().add("anchor_id", grow1) | ||
); | ||
|
||
int grow2 = -1; | ||
for (int i = 0; i < 2; i++) { | ||
grow2 = hasura.insertActivityDirective( | ||
planId, | ||
"GrowBanana", | ||
i + "h", | ||
JsonValue.EMPTY_JSON_OBJECT, | ||
Json.createObjectBuilder().add("anchor_id", bite) | ||
); | ||
} | ||
|
||
final var grow3 = hasura.insertActivityDirective( | ||
planId, | ||
"GrowBanana", | ||
"0h", | ||
JsonValue.EMPTY_JSON_OBJECT, | ||
Json.createObjectBuilder().add("anchor_id", grow2) | ||
); | ||
|
||
var plan = hasura.getPlan(planId); | ||
var activities = plan.activityDirectives(); | ||
assertEquals(5, activities.size()); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
plan = hasura.getPlan(planId); | ||
|
||
activities = plan.activityDirectives(); | ||
assertEquals(4, activities.size()); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "GrowBanana") | ||
&& Objects.equals(it.id(), grow1) | ||
&& Objects.equals(it.anchorId(), null) | ||
)); | ||
final int finalGrow2 = grow2; | ||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "GrowBanana") | ||
&& Objects.equals(it.id(), finalGrow2) | ||
&& Objects.equals(it.anchorId(), grow1) | ||
&& Objects.equals(it.startOffset(), "02:00:00") | ||
)); | ||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "GrowBanana") | ||
&& Objects.equals(it.anchorId(), grow1) | ||
&& Objects.equals(it.startOffset(), "01:00:00") | ||
)); | ||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "GrowBanana") | ||
&& Objects.equals(it.id(), grow3) | ||
&& Objects.equals(it.anchorId(), finalGrow2) | ||
&& Objects.equals(it.startOffset(), "00:00:00") | ||
)); | ||
} | ||
} |
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
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