Skip to content

Commit

Permalink
rearrage derivation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-super committed Oct 21, 2024
1 parent a72e478 commit 17c2cd5
Showing 1 changed file with 78 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 17c2cd5

Please sign in to comment.