From 17c2cd501960aff5889dfdbfbc57779c60334ae9 Mon Sep 17 00:00:00 2001 From: pranav-super Date: Mon, 21 Oct 2024 14:09:04 -0700 Subject: [PATCH] rearrage derivation tests --- .../aerie/database/ExternalEventTests.java | 101 ++++++++++++++---- 1 file changed, 78 insertions(+), 23 deletions(-) diff --git a/db-tests/src/test/java/gov/nasa/jpl/aerie/database/ExternalEventTests.java b/db-tests/src/test/java/gov/nasa/jpl/aerie/database/ExternalEventTests.java index acf31a03ee..95671fa740 100644 --- a/db-tests/src/test/java/gov/nasa/jpl/aerie/database/ExternalEventTests.java +++ b/db-tests/src/test/java/gov/nasa/jpl/aerie/database/ExternalEventTests.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -924,10 +925,11 @@ void beforeEach() throws SQLException { } ////////////////////////// RULE 1 ////////////////////////// + /** * A solitary event shouldn't be superseded by anything. * - * A: aa + * A: aa */ @Test void rule1_solitary() throws SQLException { @@ -973,11 +975,11 @@ void rule1_solitary() throws SQLException { /** * An event that is in a partially overlapped source but outside of the overlap is not superseded, even if - * the other source "bookends" it (i.e. the end of that source meets the event's start time). + * the other source "bookends" it (i.e. the end of that source meets the event's start time). * - * A: +++++aa++++++ - * B: bb+++ - * C: +cc++++ + * A: +++++aa++++++ + * B: bb+++ + * C: +cc++++ */ @Test void rule1_bookended() throws SQLException { @@ -1066,13 +1068,14 @@ void rule1_bookended() throws SQLException { } ////////////////////////// RULE 2 ////////////////////////// + /** * An event that starts before a source that partially overlaps it is not superseded by the overlapping - * source. + * source. * - * A: +++aaaaa - * B: b+bb++++ - * (a and both b's should be in result) + * A: +++aaaaa + * B: b+bb++++ + * (a and both b's should be in result) */ @Test void rule2() throws SQLException { @@ -1152,13 +1155,14 @@ void rule2() throws SQLException { } ////////////////////////// RULE 3 ////////////////////////// + /** * An event whose start time is overlapped by a newer source will be superseded by the newer source. * This holds even if the new source is empty at the overlapped event's start time. * - * A: +a+aaaaa - * B: b+bb++++ - * (only b's should be in result) + * A: +a+aaaaa + * B: b+bb++++ + * (only b's should be in result) */ @Test void rule3_basic() throws SQLException { @@ -1242,9 +1246,9 @@ void rule3_basic() throws SQLException { /** * A completely empty source will still supercede earlier sources. * - * A: +a+aaaaa - * B: ++++++++ - * (empty result) + * A: +a+aaaaa + * B: ++++++++ + * (empty result) */ @Test void rule3_empty() throws SQLException { @@ -1301,13 +1305,15 @@ void rule3_empty() throws SQLException { } ////////////////////////// RULE 4 ////////////////////////// + /** - * An event that appears in a later source will replace its occurrence in an earlier source, even if the sources don't overlap. + * An event that appears in a later source will replace its occurrence in an earlier source, even if the sources + * don't overlap. * - * A: ++++aaa+++++ - * B: +++++aaaaa+ - * C: +++++aaaa+++++ - * (one A, of specific DURATION) + * A: ++++aaa+++++ + * B: +++++aaaaa+ + * C: +++++aaaa+++++ + * (one A, of specific DURATION) */ @Test void rule4() throws SQLException { @@ -1391,7 +1397,15 @@ void rule4() throws SQLException { assertEquals(expectedResults.size(), results.size()); assertTrue(results.containsAll(expectedResults)); } + } + /** + * This class separates a few tests that don't test a particular rule, but rather general properties of the derivation + * process. + */ + @Nested + @TestInstance(TestInstance.Lifecycle.PER_CLASS) + class GeneralDerivationTests { // GENERAL /** * An event that overlaps another event in the same source does not supersede the first event. @@ -1466,9 +1480,9 @@ void nEventsAtSameTime() throws SQLException { /** - * Finally, we include an extra test. This is a comprehensive test for derived events that manages several derivation - * groups (which entails repeating basicDerivedEvents twice but the second round bears a new DG name. Then, we - * verify that there is no overlap! Note that this test is effectively vacuous but is a good sanity check.). + * This is a comprehensive test for derived events that manages several derivation groups (which entails + * repeating basicDerivedEvents twice but the second round bears a new DG name. Then, we verify that there is + * no overlap! Note that this test is effectively vacuous but is a good sanity check.). */ @Test void superDerivedEvents() throws SQLException { @@ -2106,6 +2120,47 @@ void associateDerivationGroupWithBasePlan() throws SQLException { // associate the derivation group with it assertDoesNotThrow(() -> associateDerivationGroupWithPlan(parentPlanId, derivationGroupName)); + + // check that acknowledged is true + try(final var statement = connection.createStatement()) { + // create the event type + var res = statement.executeQuery( + // language=sql + """ + SELECT * FROM merlin.plan_derivation_group; + """ + ); + + assertTrue(res.next()); + assertTrue(res.getBoolean("acknowledged")); + } + + // insert a source + insertExternalSource( + new ExternalSource( + "A.json", + SOURCE_TYPE, + derivationGroupName, + "2024-01-19 00:00:01+00", + "2024-01-01 00:00:00+00", + "2024-01-07 00:00:00+00", + CREATED_AT + ) + ); + + // check that acknowledged is now false + try(final var statement = connection.createStatement()) { + // create the event type + var res = statement.executeQuery( + // language=sql + """ + SELECT * FROM merlin.plan_derivation_group; + """ + ); + + assertTrue(res.next()); + assertFalse(res.getBoolean("acknowledged")); + } } //endregion }