From a72e478a78d4718ba149b9bc7f9a4d4f387db8fb Mon Sep 17 00:00:00 2001 From: pranav-super Date: Mon, 21 Oct 2024 13:57:10 -0700 Subject: [PATCH] rearrage derivation tests --- .../aerie/database/ExternalEventTests.java | 632 +++++++++--------- 1 file changed, 317 insertions(+), 315 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 7b8f269325..acf31a03ee 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 @@ -897,77 +897,6 @@ void testAmalgamation() throws SQLException { assertEquals(expectedResults.size(), results.size()); assertTrue(results.containsAll(expectedResults)); } - - /** - * An event that overlaps another event in the same source does not supersede the first event. - */ - @Test - void nEventsAtSameTime() throws SQLException { - // construct the sources and events - ExternalSource A = new ExternalSource( - "A", - SOURCE_TYPE, - DERIVATION_GROUP, - "2024-01-01T00:00:00Z", - "2024-01-01T00:00:00Z", - "2024-01-01T01:30:00Z", - CREATED_AT - ); - - ExternalEvent e1 = new ExternalEvent("a", "2024-01-01T00:00:00Z", "00:10:00", A); - ExternalEvent e2 = new ExternalEvent("b", "2024-01-01T00:00:00Z", "00:05:00", A); - ExternalEvent e3 = new ExternalEvent("c", "2024-01-01T00:00:00Z", "00:15:00", A); - - // insert generic external event type, source type, and derivation group - insertStandardTypes(); - - // insert sources - insertExternalSource(A); - - // insert events - insertExternalEvent(e1); - insertExternalEvent(e2); - insertExternalEvent(e3); - - // all 3 keys should be present! - var results = getDerivedEvents(); - - // all ranges should only have a single element and be fully present - final List expectedResults = List.of( - new DerivedEvent( - "a", - SOURCE_TYPE, - "A", - DERIVATION_GROUP, - "2024-01-01 00:00:00+00", - "00:10:00", - "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 01:30:00+00\")}", - "2024-01-01 00:00:00+00" - ), - new DerivedEvent( - "b", - SOURCE_TYPE, - "A", - DERIVATION_GROUP, - "2024-01-01 00:00:00+00", - "00:05:00", - "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 01:30:00+00\")}", - "2024-01-01 00:00:00+00" - ), - new DerivedEvent( - "c", - SOURCE_TYPE, - "A", - DERIVATION_GROUP, - "2024-01-01 00:00:00+00", - "00:15:00", - "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 01:30:00+00\")}", - "2024-01-01 00:00:00+00" - ) - ); - assertEquals(expectedResults.size(), results.size()); - assertTrue(results.containsAll(expectedResults)); - } } /** @@ -1462,6 +1391,323 @@ void rule4() throws SQLException { assertEquals(expectedResults.size(), results.size()); assertTrue(results.containsAll(expectedResults)); } + + // GENERAL + /** + * An event that overlaps another event in the same source does not supersede the first event. + */ + @Test + void nEventsAtSameTime() throws SQLException { + // construct the sources and events + ExternalSource A = new ExternalSource( + "A", + SOURCE_TYPE, + DERIVATION_GROUP, + "2024-01-01T00:00:00Z", + "2024-01-01T00:00:00Z", + "2024-01-01T01:30:00Z", + CREATED_AT + ); + + ExternalEvent e1 = new ExternalEvent("a", "2024-01-01T00:00:00Z", "00:10:00", A); + ExternalEvent e2 = new ExternalEvent("b", "2024-01-01T00:00:00Z", "00:05:00", A); + ExternalEvent e3 = new ExternalEvent("c", "2024-01-01T00:00:00Z", "00:15:00", A); + + // insert generic external event type, source type, and derivation group + insertStandardTypes(); + + // insert sources + insertExternalSource(A); + + // insert events + insertExternalEvent(e1); + insertExternalEvent(e2); + insertExternalEvent(e3); + + // all 3 keys should be present! + var results = getDerivedEvents(); + + // all ranges should only have a single element and be fully present + final List expectedResults = List.of( + new DerivedEvent( + "a", + SOURCE_TYPE, + "A", + DERIVATION_GROUP, + "2024-01-01 00:00:00+00", + "00:10:00", + "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 01:30:00+00\")}", + "2024-01-01 00:00:00+00" + ), + new DerivedEvent( + "b", + SOURCE_TYPE, + "A", + DERIVATION_GROUP, + "2024-01-01 00:00:00+00", + "00:05:00", + "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 01:30:00+00\")}", + "2024-01-01 00:00:00+00" + ), + new DerivedEvent( + "c", + SOURCE_TYPE, + "A", + DERIVATION_GROUP, + "2024-01-01 00:00:00+00", + "00:15:00", + "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 01:30:00+00\")}", + "2024-01-01 00:00:00+00" + ) + ); + assertEquals(expectedResults.size(), results.size()); + assertTrue(results.containsAll(expectedResults)); + } + + + /** + * 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.). + */ + @Test + void superDerivedEvents() throws SQLException { + // upload all source data, but twice (using different dgs, to prove non overlap in derivation) + String dg2 = DERIVATION_GROUP + "_2"; + + // upload the data once for the first derivation group + upload_source(DERIVATION_GROUP, false); + + // repeat with the second derivation group + upload_source(dg2, true); + + // check that derived events in our prewritten case has the correct keys + // verify everything is present + var results = getDerivedEvents(); + + List expectedResults = List.of( + new DerivedEvent( + "8", + "DerivationB", + "Derivation_Test_00.json", // note - the same source name can be used across different derivation groups + DERIVATION_GROUP + "_2", + "2024-01-10 11:00:00+00", + "01:05:00", + "{[\"2024-01-10 00:00:00+00\",\"2024-01-11 00:00:00+00\")}", + "2024-01-18 00:00:00+00" + ), + new DerivedEvent( + "8", + "DerivationB", + "Derivation_Test_00.json", + DERIVATION_GROUP, + "2024-01-10 11:00:00+00", + "01:05:00", + "{[\"2024-01-10 00:00:00+00\",\"2024-01-11 00:00:00+00\")}", + "2024-01-18 00:00:00+00" + ), + new DerivedEvent( + "3", + "DerivationB", + "Derivation_Test_01.json", + DERIVATION_GROUP + "_2", + "2024-01-02 23:00:00+00", + "03:00:00", + "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", + "2024-01-19 00:00:00+00" + ), + new DerivedEvent( + "1", + "DerivationA", + "Derivation_Test_01.json", + DERIVATION_GROUP + "_2", + "2024-01-01 00:00:00+00", + "02:10:00", + "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", + "2024-01-19 00:00:00+00" + ), + new DerivedEvent( + "1", + "DerivationA", + "Derivation_Test_01.json", + DERIVATION_GROUP, + "2024-01-01 00:00:00+00", + "02:10:00", + "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", + "2024-01-19 00:00:00+00" + ), + new DerivedEvent( + "3", + "DerivationB", + "Derivation_Test_01.json", + DERIVATION_GROUP, + "2024-01-02 23:00:00+00", + "03:00:00", + "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", + "2024-01-19 00:00:00+00" + ), + new DerivedEvent( + "5", + "DerivationC", + "Derivation_Test_02.json", + DERIVATION_GROUP + "_2", + "2024-01-05 23:00:00+00", + "01:10:00", + "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", + "2024-01-20 00:00:00+00" + ), + new DerivedEvent( + "6", + "DerivationC", + "Derivation_Test_02.json", + DERIVATION_GROUP + "_2", + "2024-01-06 12:00:00+00", + "02:00:00", + "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", + "2024-01-20 00:00:00+00" + ), + new DerivedEvent( + "2", + "DerivationB", + "Derivation_Test_02.json", + DERIVATION_GROUP + "_2", + "2024-01-09 11:00:00+00", + "01:05:00", + "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", + "2024-01-20 00:00:00+00" + ), + new DerivedEvent( + "5", + "DerivationC", + "Derivation_Test_02.json", + DERIVATION_GROUP, + "2024-01-05 23:00:00+00", + "01:10:00", + "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", + "2024-01-20 00:00:00+00" + ), + new DerivedEvent( + "6", + "DerivationC", + "Derivation_Test_02.json", + DERIVATION_GROUP, + "2024-01-06 12:00:00+00", + "02:00:00", + "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", + "2024-01-20 00:00:00+00" + ), + new DerivedEvent( + "2", + "DerivationB", + "Derivation_Test_02.json", + DERIVATION_GROUP, + "2024-01-09 11:00:00+00", + "01:05:00", + "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", + "2024-01-20 00:00:00+00" + ), + new DerivedEvent( + "9", + "DerivationC", + "Derivation_Test_03.json", + DERIVATION_GROUP + "_2", + "2024-01-02 00:00:00+00", + "01:00:00", + "{[\"2024-01-01 12:00:00+00\",\"2024-01-02 12:00:00+00\")}", + "2024-01-21 00:00:00+00" + ), + new DerivedEvent( + "9", + "DerivationC", + "Derivation_Test_03.json", + DERIVATION_GROUP, + "2024-01-02 00:00:00+00", + "01:00:00", + "{[\"2024-01-01 12:00:00+00\",\"2024-01-02 12:00:00+00\")}", + "2024-01-21 00:00:00+00" + ) + ); + assertEquals(expectedResults.size(), results.size()); + assertTrue(results.containsAll(expectedResults)); + + // verify for a given DERIVATION_GROUP expected keys are correct, no overlap inside DERIVATION_GROUP + results = getDerivedEvents("WHERE derivation_group_name = '%s' ORDER BY start_time;".formatted(dg2)); + + expectedResults = List.of( + new DerivedEvent( + "1", + "DerivationA", + "Derivation_Test_01.json", + DERIVATION_GROUP + "_2", + "2024-01-01 00:00:00+00", + "02:10:00", + "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", + "2024-01-19 00:00:00+00" + ), + new DerivedEvent( + "9", + "DerivationC", + "Derivation_Test_03.json", + DERIVATION_GROUP + "_2", + "2024-01-02 00:00:00+00", + "01:00:00", + "{[\"2024-01-01 12:00:00+00\",\"2024-01-02 12:00:00+00\")}", + "2024-01-21 00:00:00+00" + ), + new DerivedEvent( + "3", + "DerivationB", + "Derivation_Test_01.json", + DERIVATION_GROUP + "_2", + "2024-01-02 23:00:00+00", + "03:00:00", + "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", + "2024-01-19 00:00:00+00" + ), + new DerivedEvent( + "5", + "DerivationC", + "Derivation_Test_02.json", + DERIVATION_GROUP + "_2", + "2024-01-05 23:00:00+00", + "01:10:00", + "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", + "2024-01-20 00:00:00+00" + ), + new DerivedEvent( + "6", + "DerivationC", + "Derivation_Test_02.json", + DERIVATION_GROUP + "_2", + "2024-01-06 12:00:00+00", + "02:00:00", + "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", + "2024-01-20 00:00:00+00" + ), + new DerivedEvent( + "2", + "DerivationB", + "Derivation_Test_02.json", + DERIVATION_GROUP + "_2", + "2024-01-09 11:00:00+00", + "01:05:00", + "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", + "2024-01-20 00:00:00+00" + ), + new DerivedEvent( + "8", + "DerivationB", + "Derivation_Test_00.json", + DERIVATION_GROUP + "_2", + "2024-01-10 11:00:00+00", + "01:05:00", + "{[\"2024-01-10 00:00:00+00\",\"2024-01-11 00:00:00+00\")}", + "2024-01-18 00:00:00+00" + ) + ); + assertEquals(expectedResults.size(), results.size()); + assertTrue(results.containsAll(expectedResults)); + } } } //endregion @@ -1840,250 +2086,6 @@ void deleteEventTypeWithRemainingEvent() throws SQLException { //region Miscellaneous - /** - * 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.). - */ - @Test - void superDerivedEvents() throws SQLException { - // upload all source data, but twice (using different dgs, to prove non overlap in derivation) - String dg2 = DERIVATION_GROUP + "_2"; - - // upload the data once for the first derivation group - upload_source(DERIVATION_GROUP, false); - - // repeat with the second derivation group - upload_source(dg2, true); - - // check that derived events in our prewritten case has the correct keys - // verify everything is present - var results = getDerivedEvents(); - - List expectedResults = List.of( - new DerivedEvent( - "8", - "DerivationB", - "Derivation_Test_00.json", // note - the same source name can be used across different derivation groups - DERIVATION_GROUP + "_2", - "2024-01-10 11:00:00+00", - "01:05:00", - "{[\"2024-01-10 00:00:00+00\",\"2024-01-11 00:00:00+00\")}", - "2024-01-18 00:00:00+00" - ), - new DerivedEvent( - "8", - "DerivationB", - "Derivation_Test_00.json", - DERIVATION_GROUP, - "2024-01-10 11:00:00+00", - "01:05:00", - "{[\"2024-01-10 00:00:00+00\",\"2024-01-11 00:00:00+00\")}", - "2024-01-18 00:00:00+00" - ), - new DerivedEvent( - "3", - "DerivationB", - "Derivation_Test_01.json", - DERIVATION_GROUP + "_2", - "2024-01-02 23:00:00+00", - "03:00:00", - "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", - "2024-01-19 00:00:00+00" - ), - new DerivedEvent( - "1", - "DerivationA", - "Derivation_Test_01.json", - DERIVATION_GROUP + "_2", - "2024-01-01 00:00:00+00", - "02:10:00", - "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", - "2024-01-19 00:00:00+00" - ), - new DerivedEvent( - "1", - "DerivationA", - "Derivation_Test_01.json", - DERIVATION_GROUP, - "2024-01-01 00:00:00+00", - "02:10:00", - "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", - "2024-01-19 00:00:00+00" - ), - new DerivedEvent( - "3", - "DerivationB", - "Derivation_Test_01.json", - DERIVATION_GROUP, - "2024-01-02 23:00:00+00", - "03:00:00", - "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", - "2024-01-19 00:00:00+00" - ), - new DerivedEvent( - "5", - "DerivationC", - "Derivation_Test_02.json", - DERIVATION_GROUP + "_2", - "2024-01-05 23:00:00+00", - "01:10:00", - "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", - "2024-01-20 00:00:00+00" - ), - new DerivedEvent( - "6", - "DerivationC", - "Derivation_Test_02.json", - DERIVATION_GROUP + "_2", - "2024-01-06 12:00:00+00", - "02:00:00", - "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", - "2024-01-20 00:00:00+00" - ), - new DerivedEvent( - "2", - "DerivationB", - "Derivation_Test_02.json", - DERIVATION_GROUP + "_2", - "2024-01-09 11:00:00+00", - "01:05:00", - "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", - "2024-01-20 00:00:00+00" - ), - new DerivedEvent( - "5", - "DerivationC", - "Derivation_Test_02.json", - DERIVATION_GROUP, - "2024-01-05 23:00:00+00", - "01:10:00", - "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", - "2024-01-20 00:00:00+00" - ), - new DerivedEvent( - "6", - "DerivationC", - "Derivation_Test_02.json", - DERIVATION_GROUP, - "2024-01-06 12:00:00+00", - "02:00:00", - "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", - "2024-01-20 00:00:00+00" - ), - new DerivedEvent( - "2", - "DerivationB", - "Derivation_Test_02.json", - DERIVATION_GROUP, - "2024-01-09 11:00:00+00", - "01:05:00", - "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", - "2024-01-20 00:00:00+00" - ), - new DerivedEvent( - "9", - "DerivationC", - "Derivation_Test_03.json", - DERIVATION_GROUP + "_2", - "2024-01-02 00:00:00+00", - "01:00:00", - "{[\"2024-01-01 12:00:00+00\",\"2024-01-02 12:00:00+00\")}", - "2024-01-21 00:00:00+00" - ), - new DerivedEvent( - "9", - "DerivationC", - "Derivation_Test_03.json", - DERIVATION_GROUP, - "2024-01-02 00:00:00+00", - "01:00:00", - "{[\"2024-01-01 12:00:00+00\",\"2024-01-02 12:00:00+00\")}", - "2024-01-21 00:00:00+00" - ) - ); - assertEquals(expectedResults.size(), results.size()); - assertTrue(results.containsAll(expectedResults)); - - // verify for a given DERIVATION_GROUP expected keys are correct, no overlap inside DERIVATION_GROUP - results = getDerivedEvents("WHERE derivation_group_name = '%s' ORDER BY start_time;".formatted(dg2)); - - expectedResults = List.of( - new DerivedEvent( - "1", - "DerivationA", - "Derivation_Test_01.json", - DERIVATION_GROUP + "_2", - "2024-01-01 00:00:00+00", - "02:10:00", - "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", - "2024-01-19 00:00:00+00" - ), - new DerivedEvent( - "9", - "DerivationC", - "Derivation_Test_03.json", - DERIVATION_GROUP + "_2", - "2024-01-02 00:00:00+00", - "01:00:00", - "{[\"2024-01-01 12:00:00+00\",\"2024-01-02 12:00:00+00\")}", - "2024-01-21 00:00:00+00" - ), - new DerivedEvent( - "3", - "DerivationB", - "Derivation_Test_01.json", - DERIVATION_GROUP + "_2", - "2024-01-02 23:00:00+00", - "03:00:00", - "{[\"2024-01-01 00:00:00+00\",\"2024-01-01 12:00:00+00\"),[\"2024-01-02 12:00:00+00\",\"2024-01-03 00:00:00+00\")}", - "2024-01-19 00:00:00+00" - ), - new DerivedEvent( - "5", - "DerivationC", - "Derivation_Test_02.json", - DERIVATION_GROUP + "_2", - "2024-01-05 23:00:00+00", - "01:10:00", - "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", - "2024-01-20 00:00:00+00" - ), - new DerivedEvent( - "6", - "DerivationC", - "Derivation_Test_02.json", - DERIVATION_GROUP + "_2", - "2024-01-06 12:00:00+00", - "02:00:00", - "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", - "2024-01-20 00:00:00+00" - ), - new DerivedEvent( - "2", - "DerivationB", - "Derivation_Test_02.json", - DERIVATION_GROUP + "_2", - "2024-01-09 11:00:00+00", - "01:05:00", - "{[\"2024-01-03 00:00:00+00\",\"2024-01-10 00:00:00+00\")}", - "2024-01-20 00:00:00+00" - ), - new DerivedEvent( - "8", - "DerivationB", - "Derivation_Test_00.json", - DERIVATION_GROUP + "_2", - "2024-01-10 11:00:00+00", - "01:05:00", - "{[\"2024-01-10 00:00:00+00\",\"2024-01-11 00:00:00+00\")}", - "2024-01-18 00:00:00+00" - ) - ); - assertEquals(expectedResults.size(), results.size()); - assertTrue(results.containsAll(expectedResults)); - } - /** * This test ensures that a derivation group can be associated with a plan. This behavior is very simple and doesn't * have many derivative cases besides merging of plans, and that behavior is handled in a test in