Skip to content

Commit

Permalink
updates to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-super committed Oct 23, 2024
1 parent aede544 commit cea3b09
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ public record ExternalEventsSourceQueryGoal() implements Goal {
@Override
public void run(@NotNull final EditablePlan plan) {

// demonstrate more complicated query functionality
// extract events belonging to the second source
EventQuery eventQuery = new EventQuery(
null,
null,
List.of(new ExternalSource("NewTest.json", "TestGroup_2"))
);

for (final var e: plan.events(eventQuery)) {
plan.create("BiteBanana", new DirectiveStart.Absolute(e.getInterval().start), Map.of("biteSize", SerializedValue.of(1)));
// filter events that we schedule off of by key
if (e.key.contains("01")) {
plan.create(
"BiteBanana",
// place the directive such that it is coincident with the event's start
new DirectiveStart.Absolute(e.getInterval().start),
Map.of("biteSize", SerializedValue.of(1)));
}
}
plan.commit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@ public class ExternalEventsTests extends ProceduralSchedulingSetup {
externalSource.key(),
externalSource.derivation_group_name(),
"2023-01-01T01:00:00Z",
"00:10:00"
"01:00:00"
),
new HasuraRequests.ExternalEvent(
"Event_02",
EVENT_TYPE,
externalSource.key(),
externalSource.derivation_group_name(),
"2023-01-01T03:00:00Z",
"00:10:00"
"01:00:00"
),
new HasuraRequests.ExternalEvent(
"Event_03",
EVENT_TYPE,
externalSource.key(),
externalSource.derivation_group_name(),
"2023-01-01T05:00:00Z",
"00:10:00"
"01:00:00"
)
);

private final HasuraRequests.ExternalSource additionalExternalSource = new HasuraRequests.ExternalSource(
"NewTest.json",
SOURCE_TYPE,
ADDITIONAL_DERIVATION_GROUP,
"2024-01-02T00:00:00Z",
"2024-01-01T00:00:00Z",
"2023-01-01T00:00:00Z",
"2023-01-08T00:00:00Z",
"2024-10-01T00:00:00Z"
Expand All @@ -78,23 +78,23 @@ public class ExternalEventsTests extends ProceduralSchedulingSetup {
additionalExternalSource.key(),
additionalExternalSource.derivation_group_name(),
"2023-01-02T01:00:00Z",
"00:10:00"
"01:00:00"
),
new HasuraRequests.ExternalEvent(
"Event_02",
ADDITIONAL_EVENT_TYPE,
additionalExternalSource.key(),
additionalExternalSource.derivation_group_name(),
"2023-01-02T03:00:00Z",
"00:10:00"
"01:00:00"
),
new HasuraRequests.ExternalEvent(
"Event_03",
ADDITIONAL_EVENT_TYPE,
additionalExternalSource.key(),
additionalExternalSource.derivation_group_name(),
"2023-01-02T05:00:00Z",
"00:10:00"
"01:00:00"
)
);

Expand Down Expand Up @@ -223,17 +223,12 @@ void testExternalEventSourceQuery() throws IOException {
final var plan = hasura.getPlan(planId);
final var activities = plan.activityDirectives();

// ensure the orderings line up
activities.sort(Comparator.comparing(Plan.ActivityDirective::startOffset));

// compare arrays
assertEquals(additionalExternalEvents.size(), activities.size());
for (int i = 0; i < activities.size(); i++) {
Instant activityStartTime = Duration.addToInstant(
Instant.parse(planStartTimestamp),
Duration.fromString(activities.get(i).startOffset())
);
assertEquals(activityStartTime.toString(), additionalExternalEvents.get(i).start_time());
}
// only 1 activity this time
assertEquals(1, activities.size());
Instant activityStartTime = Duration.addToInstant(
Instant.parse(planStartTimestamp),
Duration.fromString(activities.get(0).startOffset())
);
assertEquals(activityStartTime.toString(), additionalExternalEvents.get(0).start_time());
}
}

0 comments on commit cea3b09

Please sign in to comment.