From a22e73d06e51205e0caca24d1c78b6ea4e693e49 Mon Sep 17 00:00:00 2001 From: bischoffz Date: Tue, 18 Jun 2024 09:18:05 -0400 Subject: [PATCH 01/15] bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 90872b938..cf454ea6a 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ - 4.2.2 + 4.3.0-SNAPSHOT UTF-8 From 028643db91a69104a924157d6522531483e38ff9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:02:20 -0400 Subject: [PATCH 02/15] Bump org.sonatype.central:central-publishing-maven-plugin (#241) Bumps [org.sonatype.central:central-publishing-maven-plugin](https://github.com/sonatype/central-publishing-maven-plugin) from 0.4.0 to 0.5.0. - [Commits](https://github.com/sonatype/central-publishing-maven-plugin/commits) --- updated-dependencies: - dependency-name: org.sonatype.central:central-publishing-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cf454ea6a..08e788ba9 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ 3.1.2 3.7.0 3.2.4 - 0.4.0 + 0.5.0 4.2.0 From d0b07f11bfc4dd8b2ef6ed063a5996294a0ded6e Mon Sep 17 00:00:00 2001 From: bischoffz Date: Thu, 20 Jun 2024 15:03:58 -0400 Subject: [PATCH 03/15] update pom --- pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index ae322b661..0161e32ce 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ 0.5.0 - 4.2.1 + 4.2.0-SNAPSHOT 0.8.12 5.10.2 @@ -78,9 +78,9 @@ - gov.hhs.aspr.ms - util - ${util.version} + gov.hhs.aspr.ms.taskit + protobuf + ${taskit.version} org.jacoco @@ -105,8 +105,8 @@ - gov.hhs.aspr.ms - util + gov.hhs.aspr.ms.taskit + protobuf org.jacoco From 543ffce1b66c6dc062d67d271688470b840ed368 Mon Sep 17 00:00:00 2001 From: bischoffz Date: Thu, 20 Jun 2024 15:20:00 -0400 Subject: [PATCH 04/15] update workflow --- .github/workflows/release_build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml index ae0c5fd33..9e2037938 100644 --- a/.github/workflows/release_build.yml +++ b/.github/workflows/release_build.yml @@ -61,6 +61,7 @@ jobs: update-gcm-taskit: + if: ${{ !endsWith(needs.release.outputs.gcm_version, '0') }} needs: release runs-on: ubuntu-latest permissions: From 598937e81cfd0bdc52dbad9d4b2370a04cd36aed Mon Sep 17 00:00:00 2001 From: bischoffz Date: Thu, 20 Jun 2024 15:25:35 -0400 Subject: [PATCH 05/15] update workflow --- .github/workflows/dev_build.yml | 19 ++++++++++++++++++- .github/workflows/dev_pr_build.yml | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev_build.yml b/.github/workflows/dev_build.yml index d5b3dff77..948c65330 100644 --- a/.github/workflows/dev_build.yml +++ b/.github/workflows/dev_build.yml @@ -26,9 +26,22 @@ jobs: distribution: 'temurin' cache: maven + - name: Get Taskit Version + run: | + echo "taskit_version=v$(mvn help:evaluate -Dexpression=taskit.version -q -DforceStdout --file pom.xml)" >> "$GITHUB_ENV" + + - name: Checkout Taskit + if: ${{ endsWith(env.taskit_version, 'SNAPSHOT') }} + uses: actions/checkout@v4 + with: + repository: HHS/ASPR-ms-taskit + path: taskit + ref: dev + - name: Get Util Version + if: ${{ endsWith(env.taskit_version, 'SNAPSHOT') }} run: | - echo "util_version=v$(mvn help:evaluate -Dexpression=util.version -q -DforceStdout --file pom.xml)" >> "$GITHUB_ENV" + echo "util_version=v$(mvn help:evaluate -Dexpression=util.version -q -DforceStdout --file taskit/pom.xml)" >> "$GITHUB_ENV" - name: Checkout Util if: ${{ endsWith(env.util_version, 'SNAPSHOT') }} @@ -42,6 +55,10 @@ jobs: if: ${{ endsWith(env.util_version, 'SNAPSHOT') }} run: mvn clean install -DskipTests --file util/pom.xml + - name: Build Taskit + if: ${{ endsWith(env.taskit_version, 'SNAPSHOT') }} + run: mvn clean install -DskipTests --file taskit/pom.xml + - name: Build GCM run: mvn clean install --file pom.xml diff --git a/.github/workflows/dev_pr_build.yml b/.github/workflows/dev_pr_build.yml index 50153c4ce..b38e5f9b9 100644 --- a/.github/workflows/dev_pr_build.yml +++ b/.github/workflows/dev_pr_build.yml @@ -26,9 +26,22 @@ jobs: distribution: 'temurin' cache: maven + - name: Get Taskit Version + run: | + echo "taskit_version=v$(mvn help:evaluate -Dexpression=taskit.version -q -DforceStdout --file pom.xml)" >> "$GITHUB_ENV" + + - name: Checkout Taskit + if: ${{ endsWith(env.taskit_version, 'SNAPSHOT') }} + uses: actions/checkout@v4 + with: + repository: HHS/ASPR-ms-taskit + path: taskit + ref: dev + - name: Get Util Version + if: ${{ endsWith(env.taskit_version, 'SNAPSHOT') }} run: | - echo "util_version=v$(mvn help:evaluate -Dexpression=util.version -q -DforceStdout --file pom.xml)" >> "$GITHUB_ENV" + echo "util_version=v$(mvn help:evaluate -Dexpression=util.version -q -DforceStdout --file taskit/pom.xml)" >> "$GITHUB_ENV" - name: Checkout Util if: ${{ endsWith(env.util_version, 'SNAPSHOT') }} @@ -42,6 +55,10 @@ jobs: if: ${{ endsWith(env.util_version, 'SNAPSHOT') }} run: mvn clean install -DskipTests --file util/pom.xml + - name: Build Taskit + if: ${{ endsWith(env.taskit_version, 'SNAPSHOT') }} + run: mvn clean install -DskipTests --file taskit/pom.xml + - name: Build GCM run: mvn clean install --file pom.xml From 3c6c9dc36e4abfe96963369cdaeb4f3ea35c0211 Mon Sep 17 00:00:00 2001 From: shawnhatch <30730734+shawnhatch@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:52:48 -0400 Subject: [PATCH 06/15] Planning refactor (#243) * Moved simulation time update from plan time to stop cancelled plans from moving time forward. This was leading to the time when data managers and actors to execute end of sim activities to not agree with the time of the last action taken by an agent or data manager. * Minor refactoring of plan classes to tighten up on package access and inheritance pattern. * more refinements to the plan classes * Changed descendancy pattern for ActorPlan * More plan class refinements and adaptation of those changes to the lesson classes --- .../plugins/model/actors/Vaccinator.java | 5 +- .../plugins/model/actors/SchoolManager.java | 3 +- .../plugins/model/actors/TeleworkManager.java | 3 +- .../plugins/model/actors/EventVaccinator.java | 3 +- .../gcm/simulation/nucleus/ActorContext.java | 5 +- .../ms/gcm/simulation/nucleus/ActorPlan.java | 57 +- .../simulation/nucleus/ConsumerActorPlan.java | 74 + .../nucleus/ConsumerDataManagerPlan.java | 76 + .../nucleus/ConsumerReportPlan.java | 54 + .../nucleus/DataManagerContext.java | 16 +- .../simulation/nucleus/DataManagerPlan.java | 62 +- .../aspr/ms/gcm/simulation/nucleus/Plan.java | 15 +- .../gcm/simulation/nucleus/ReportContext.java | 9 +- .../ms/gcm/simulation/nucleus/ReportPlan.java | 36 +- .../ms/gcm/simulation/nucleus/Simulation.java | 158 +-- .../RunContinuityActor.java | 3 +- .../testsupport/testplugin/TestActorPlan.java | 19 +- .../simulation/nucleus/AT_ActorContext.java | 137 +- .../nucleus/AT_ActorContextPlanRecovery.java | 24 +- .../gcm/simulation/nucleus/AT_ActorPlan.java | 33 +- .../nucleus/AT_ConsumerActorPlan.java | 44 + .../nucleus/AT_ConsumerDataManagerPlan.java | 45 + .../nucleus/AT_ConsumerReportPlan.java | 34 + .../nucleus/AT_DataManagerContext.java | 134 +- .../nucleus/AT_DataManagerPlan.java | 54 +- .../simulation/nucleus/AT_ReportContext.java | 1221 +++++++++-------- .../gcm/simulation/nucleus/AT_ReportPlan.java | 22 +- .../testplugin/AT_TestActorPlan.java | 9 +- 28 files changed, 1409 insertions(+), 946 deletions(-) create mode 100644 simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java create mode 100644 simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java create mode 100644 simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java create mode 100644 simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerActorPlan.java create mode 100644 simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerDataManagerPlan.java create mode 100644 simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerReportPlan.java diff --git a/lessons/lesson-16/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/Vaccinator.java b/lessons/lesson-16/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/Vaccinator.java index 1bbb8f7de..97937ab7d 100644 --- a/lessons/lesson-16/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/Vaccinator.java +++ b/lessons/lesson-16/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/Vaccinator.java @@ -10,6 +10,7 @@ import gov.hhs.aspr.ms.gcm.lessons.plugins.model.PersonProperty; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan; +import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan; import gov.hhs.aspr.ms.gcm.simulation.nucleus.EventFilter; import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager; @@ -46,7 +47,7 @@ private void vaccinatePerson(PersonId personId) { if (refusesVaccine) { double planTime = actorContext.getTime() + randomGenerator.nextDouble() * vaccineAttemptInterval; - ActorPlan plan = new ActorPlan(planTime, (c) -> vaccinatePerson(personId)); + ActorPlan plan = new ConsumerActorPlan(planTime, (c) -> vaccinatePerson(personId)); actorContext.addPlan(plan); //record the plan for possible cancellation actorPlans.put(personId, plan); @@ -80,7 +81,7 @@ private void handleVaccineAcceptance(ActorContext actorContext, /* start code_ref= person_properties_vaccinator_plan_vaccination|code_cap= Each unvaccinated person has a planned vaccination based on the VACCINE_ATTEMPT_INTERVAL global property. */ private void planVaccination(PersonId personId) { double planTime = actorContext.getTime() + randomGenerator.nextDouble() * vaccineAttemptInterval; - ActorPlan plan = new ActorPlan(planTime, (c) -> vaccinatePerson(personId)); + ActorPlan plan = new ConsumerActorPlan(planTime, (c) -> vaccinatePerson(personId)); actorContext.addPlan(plan); //record the plan for possible cancellation actorPlans.put(personId, plan); diff --git a/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/SchoolManager.java b/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/SchoolManager.java index d1c66b158..c54a543c3 100644 --- a/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/SchoolManager.java +++ b/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/SchoolManager.java @@ -10,6 +10,7 @@ import gov.hhs.aspr.ms.gcm.lessons.plugins.model.support.SchoolStatus; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan; +import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan; import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.datamanagers.GroupsDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.support.GroupConstructionInfo; @@ -41,7 +42,7 @@ public void init(ActorContext actorContext) { private void planNextReview() { double planTime = actorContext.getTime() + reviewInterval; - ActorPlan plan = new ActorPlan(planTime,false,this::reviewSchools); + ActorPlan plan = new ConsumerActorPlan(planTime,false,this::reviewSchools); actorContext.addPlan(plan); } diff --git a/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/TeleworkManager.java b/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/TeleworkManager.java index 9bfacde4c..e2f77ca42 100644 --- a/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/TeleworkManager.java +++ b/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/TeleworkManager.java @@ -11,6 +11,7 @@ import gov.hhs.aspr.ms.gcm.lessons.plugins.model.support.PersonProperty; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan; +import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan; import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.datamanagers.GroupsDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.support.GroupId; @@ -31,7 +32,7 @@ public void init(ActorContext actorContext) { private void scheduleNextReview() { double planTime = actorContext.getTime() + reviewInterval; - ActorPlan plan = new ActorPlan(planTime,false,this::reviewTeleworkStatus); + ActorPlan plan = new ConsumerActorPlan(planTime,false,this::reviewTeleworkStatus); actorContext.addPlan(plan); } diff --git a/lessons/lesson-20/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/EventVaccinator.java b/lessons/lesson-20/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/EventVaccinator.java index 3fce46054..4a4ff40fd 100644 --- a/lessons/lesson-20/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/EventVaccinator.java +++ b/lessons/lesson-20/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/EventVaccinator.java @@ -11,6 +11,7 @@ import gov.hhs.aspr.ms.gcm.lessons.plugins.model.support.PersonProperty; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan; +import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan; import gov.hhs.aspr.ms.gcm.simulation.nucleus.EventFilter; import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager; @@ -215,7 +216,7 @@ private void intializeCandidatesAndWeights() { * vaccinator selects from maintained sub-populations. */ private void planNextVaccination() { - futurePlan = new ActorPlan(interVaccinationTime + actorContext.getTime(), this::vaccinatePerson); + futurePlan = new ConsumerActorPlan(interVaccinationTime + actorContext.getTime(), this::vaccinatePerson); actorContext.addPlan(futurePlan); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ActorContext.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ActorContext.java index 5ab6f57de..5a52de5b7 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ActorContext.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ActorContext.java @@ -51,7 +51,7 @@ public void subscribeToSimulationClose(Consumer consumer) { * */ public void addPlan(final Consumer consumer, final double planTime) { - simulation.addActorPlan(new ActorPlan(planTime, consumer)); + simulation.addActorPlan(new ConsumerActorPlan(planTime, consumer)); } /** @@ -74,9 +74,6 @@ public void addPlan(final Consumer consumer, final double planTime * */ public void addPlan(final ActorPlan plan) { - if (plan == null) { - throw new ContractException(NucleusError.NULL_PLAN); - } simulation.addActorPlan(plan); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ActorPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ActorPlan.java index 36f9ac3db..a4db68a9e 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ActorPlan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ActorPlan.java @@ -1,28 +1,45 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; -import java.util.function.Consumer; +public abstract class ActorPlan extends Plan { -public class ActorPlan extends Plan { - ActorId actorId; - protected final Consumer consumer; + // The actor id is used by the simulation via package access + ActorId actorId; - public ActorPlan(double time, boolean active, long arrivalId, Consumer consumer) { - super(time, active, arrivalId, Planner.ACTOR); - this.consumer = consumer; - } + - public ActorPlan(double time, Consumer consumer) { - super(time, true, -1L, Planner.ACTOR); - this.consumer = consumer; - } + /** + * Constructs the plan scheduled for the given time, active status and arrivalId. + * + * + */ + public ActorPlan(double time, boolean active, long arrivalId) { + super(time, active, arrivalId, Planner.ACTOR); + } - public ActorPlan(double time, boolean active, Consumer consumer) { - super(time, active, -1L, Planner.ACTOR); - this.consumer = consumer; - } + /** + * Constructs the plan scheduled for the given time. The plan will + * be active.The arrival id is set to -1L indicating that this is a new, + * non-deserialized plan. + * + * + */ + public ActorPlan(double time) { + super(time, true, -1L, Planner.ACTOR); + } - protected void execute(ActorContext context) { - this.consumer.accept(context); - } - + /** + * Constructs the plan scheduled for the given time and active status. + * The arrival id is set to -1L indicating that this is a new, non-deserialized + * plan. + * + * + */ + public ActorPlan(double time, boolean active) { + super(time, active, -1L, Planner.ACTOR); + } + + /** + * Executes the actor logic associated with the plan. + */ + protected abstract void execute(ActorContext context); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java new file mode 100644 index 000000000..82dbb58b6 --- /dev/null +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java @@ -0,0 +1,74 @@ +package gov.hhs.aspr.ms.gcm.simulation.nucleus; + +import java.util.function.Consumer; + +import gov.hhs.aspr.ms.util.errors.ContractException; + +public final class ConsumerActorPlan extends ActorPlan { + + private final Consumer consumer; + + /** + * Constructs the plan scheduled for the given time active status arrivalId and + * consumer + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerActorPlan(double time, boolean active, long arrivalId, Consumer consumer) { + super(time, active, arrivalId); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + this.consumer = consumer; + } + + /** + * Constructs the plan scheduled for the given time and consumer. The plan will + * be active.The arrival id is set to -1L indicating that this is a new, + * non-deserialized plan. + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerActorPlan(double time, Consumer consumer) { + super(time); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + this.consumer = consumer; + } + + /** + * Constructs the plan scheduled for the given time, active status and consumer. + * The arrival id is set to -1L indicating that this is a new, non-deserialized + * plan. + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerActorPlan(double time, boolean active, Consumer consumer) { + super(time, active); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + this.consumer = consumer; + } + + @Override + protected final void execute(ActorContext context) { + this.consumer.accept(context); + } +} diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java new file mode 100644 index 000000000..d342e68fb --- /dev/null +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java @@ -0,0 +1,76 @@ +package gov.hhs.aspr.ms.gcm.simulation.nucleus; + +import java.util.function.Consumer; + +import gov.hhs.aspr.ms.util.errors.ContractException; + +public class ConsumerDataManagerPlan extends DataManagerPlan { + + private final Consumer consumer; + + /** + * Constructs the plan scheduled for the given time active status arrivalId and + * consumer + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerDataManagerPlan(double time, boolean active, long arrivalId, Consumer consumer) { + super(time, active, arrivalId); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + + this.consumer = consumer; + } + + /** + * Constructs the plan scheduled for the given time, active status and consumer. + * The arrival id is set to -1L indicating that this is a new, non-deserialized + * plan. + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerDataManagerPlan(double time, boolean active, Consumer consumer) { + super(time, active); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + this.consumer = consumer; + } + + /** + * Constructs the plan scheduled for the given time and consumer. The plan will + * be active.The arrival id is set to -1L indicating that this is a new, + * non-deserialized plan. + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerDataManagerPlan(double time, Consumer consumer) { + super(time); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + + this.consumer = consumer; + } + + @Override + protected void execute(DataManagerContext context) { + this.consumer.accept(context); + } +} diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java new file mode 100644 index 000000000..1487cbe2f --- /dev/null +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java @@ -0,0 +1,54 @@ +package gov.hhs.aspr.ms.gcm.simulation.nucleus; + +import java.util.function.Consumer; + +import gov.hhs.aspr.ms.util.errors.ContractException; + +public class ConsumerReportPlan extends ReportPlan { + + private final Consumer consumer; + + /** + * Constructs the plan scheduled for the given time, arrivalId and consumer. + * Report plans are always passive. + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerReportPlan(double time, long arrivalId, Consumer consumer) { + super(time, arrivalId); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + this.consumer = consumer; + } + + /** + * Constructs the plan scheduled for the given time and consumer. Report plans + * are always passive.The arrival id is set to -1L indicating that this is a + * new, non-deserialized plan. + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerReportPlan(double time, Consumer consumer) { + super(time); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + this.consumer = consumer; + } + + @Override + protected void execute(ReportContext context) { + this.consumer.accept(context); + } +} diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java index 1cfe64d79..0dfce12e8 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java @@ -27,9 +27,7 @@ protected DataManagerContext(DataManagerId dataManagerId, Simulation simulation) * executed at the given time. * * @throws ContractException - *
    - *
  • {@link NucleusError#NULL_PLAN} if the plan is - * null
  • + *
      *
    • {@link NucleusError#NULL_PLAN_CONSUMER} if the * consumer is null
    • *
    • {@link NucleusError#PAST_PLANNING_TIME} if the @@ -38,9 +36,10 @@ protected DataManagerContext(DataManagerId dataManagerId, Simulation simulation) * the plan is added to the simulation after event * processing is finished
    • *
    + * */ public void addPlan(final Consumer consumer, final double planTime) { - simulation.addDataManagerPlan(dataManagerId, new DataManagerPlan(planTime, consumer)); + simulation.addDataManagerPlan(dataManagerId, new ConsumerDataManagerPlan(planTime, consumer)); } /** @@ -56,8 +55,8 @@ public void addPlan(final Consumer consumer, final double pl *
      *
    • {@link NucleusError#NULL_PLAN} if the plan is * null
    • - *
    • {@link NucleusError#NULL_PLAN_CONSUMER} if the - * plan consumer is null
    • + *
    • {@link NucleusError#INVALID_PLAN_ARRIVAL_ID} if the + * arrival id is less than -1
    • *
    • {@link NucleusError#PAST_PLANNING_TIME} if the * plan is scheduled for a time in the past *
    • *
    • {@link NucleusError#PLANNING_QUEUE_CLOSED} if @@ -65,10 +64,7 @@ public void addPlan(final Consumer consumer, final double pl * processing is finished
    • *
    */ - public void addPlan(DataManagerPlan plan) { - if (plan == null) { - throw new ContractException(NucleusError.NULL_PLAN); - } + public void addPlan(DataManagerPlan plan) { simulation.addDataManagerPlan(dataManagerId, plan); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerPlan.java index 7f12ec515..692112b3b 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerPlan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerPlan.java @@ -1,27 +1,49 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; -import java.util.function.Consumer; +public abstract class DataManagerPlan extends Plan { + // The data manager id is used by the simulation via package access + DataManagerId dataManagerId; -public class DataManagerPlan extends Plan { - DataManagerId dataManagerId; - final Consumer consumer; + - public DataManagerPlan(double time, boolean active, long arrivalId, Consumer consumer) { - super(time, active, arrivalId, Planner.DATA_MANAGER); - this.consumer = consumer; - } + /** + * Constructs the plan scheduled for the given time active status and arrivalId. + * + + */ + public DataManagerPlan(double time, boolean active, long arrivalId) { + super(time, active, arrivalId, Planner.DATA_MANAGER); + + } - public DataManagerPlan(double time, boolean active, Consumer consumer) { - super(time, active, -1L, Planner.DATA_MANAGER); - this.consumer = consumer; - } + /** + * Constructs the plan scheduled for the given time and active status. + * The arrival id is set to -1L indicating that this is a new, non-deserialized + * plan. + + * + */ + public DataManagerPlan(double time, boolean active) { + super(time, active, -1L, Planner.DATA_MANAGER); + + } - public DataManagerPlan(double time, Consumer consumer) { - super(time, true, -1L, Planner.DATA_MANAGER); - this.consumer = consumer; - } - - void execute(DataManagerContext context) { - this.consumer.accept(context); - } + /** + * Constructs the plan scheduled for the given time. The plan will + * be active.The arrival id is set to -1L indicating that this is a new, + * non-deserialized plan. + * + + * + */ + public DataManagerPlan(double time) { + super(time, true, -1L, Planner.DATA_MANAGER); + + } + + /** + * Executes the data manager logic associated with the plan. + */ + protected abstract void execute(DataManagerContext context); + } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Plan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Plan.java index 5b1df8be5..b0dda7195 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Plan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Plan.java @@ -1,13 +1,20 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; +/** + * Base class for plans. It is purposely kept as a package access only class. + */ abstract class Plan { - protected final double time; - protected final Planner planner; - protected final boolean isActive; - + + //internal state of the plan is package access to make the sim slightly faster + final double time; + final Planner planner; + final boolean isActive; boolean canceled = false; long arrivalId = -1; + /** + * Package access constructor + */ Plan(double time, boolean active, long arrivalId, Planner planner) { /* * Do we throw an execption here if the arrival id is < -1? Or do we detect this diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportContext.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportContext.java index 7384aad90..c21c533c4 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportContext.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportContext.java @@ -33,7 +33,7 @@ protected ReportContext(Simulation simulation) { * * @throws ContractException *
      - *
    • {@link NucleusError#NULL_PLAN} if the plan is + *
    • {@link NucleusError#NULL_PLAN_CONSUMER} if the consumer is * null
    • *
    • {@link NucleusError#PAST_PLANNING_TIME} if the * plan is scheduled for a time in the past *
    • @@ -43,7 +43,7 @@ protected ReportContext(Simulation simulation) { *
    */ public void addPlan(final Consumer consumer, final double planTime) { - simulation.addReportPlan(new ReportPlan(planTime, consumer)); + simulation.addReportPlan(new ConsumerReportPlan(planTime, consumer)); } /** @@ -63,12 +63,11 @@ public void addPlan(final Consumer consumer, final double planTim *
  • {@link NucleusError#PLANNING_QUEUE_CLOSED} if * the plan is added to the simulation after event * processing is finished
  • + *
  • {@link NucleusError#INVALID_PLAN_ARRIVAL_ID} if + * the arrival id is less than -1
  • *
*/ public void addPlan(ReportPlan plan) { - if (plan == null) { - throw new ContractException(NucleusError.NULL_PLAN); - } simulation.addReportPlan(plan); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportPlan.java index 541dcea6a..2ea59e185 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportPlan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportPlan.java @@ -1,22 +1,26 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; -import java.util.function.Consumer; +public abstract class ReportPlan extends Plan { + ReportId reportId; + -public class ReportPlan extends Plan { - ReportId reportId; - final Consumer consumer; + /** + * Constructs the plan scheduled for the given time and arrivalId. + * Report plans are always passive. + * + */ + public ReportPlan(double time, long arrivalId) { + super(time, false, arrivalId, Planner.REPORT); + } - public ReportPlan(double time, long arrivalId, Consumer consumer) { - super(time, false, arrivalId, Planner.REPORT); - this.consumer = consumer; - } + /** + * Constructs the plan scheduled for the given time. Report plans + * are always passive.The arrival id is set to -1L indicating that this is a + * new, non-deserialized plan. + */ + public ReportPlan(double time) { + super(time, false, -1L, Planner.REPORT); + } - public ReportPlan(double time, Consumer consumer) { - super(time, false, -1L, Planner.REPORT); - this.consumer = consumer; - } - - void execute(ReportContext context) { - this.consumer.accept(context); - } + protected abstract void execute(ReportContext context); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Simulation.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Simulation.java index 08cf33456..739916cf5 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Simulation.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Simulation.java @@ -322,13 +322,12 @@ protected void addDataManagerForPlugin(DataManager dataManager) { } protected void addActorPlan(ActorPlan plan) { - if (planningQueueMode == PlanningQueueMode.CLOSED) { throw new ContractException(NucleusError.PLANNING_QUEUE_CLOSED); } - if (plan.consumer == null) { - throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + if (plan == null) { + throw new ContractException(NucleusError.NULL_PLAN); } if (plan.time < time) { @@ -359,7 +358,8 @@ protected void addActorPlan(ActorPlan plan) { plan.arrivalId = initialArrivalId--; } } - // If we aren't in CLOSED or READY, we are in RUNNING, and therefore just set the + // If we aren't in CLOSED or READY, we are in RUNNING, and therefore just set + // the // arrivalId to the current masterPlanningArrivalId and increment it. else { plan.arrivalId = masterPlanningArrivalId++; @@ -380,8 +380,8 @@ protected void addReportPlan(ReportPlan plan) { throw new ContractException(NucleusError.PLANNING_QUEUE_CLOSED); } - if (plan.consumer == null) { - throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + if (plan == null) { + throw new ContractException(NucleusError.NULL_PLAN); } if (plan.time < time) { @@ -412,7 +412,8 @@ protected void addReportPlan(ReportPlan plan) { plan.arrivalId = initialArrivalId--; } } - // If we aren't in CLOSED or READY, we are in RUNNING, and therefore just set the + // If we aren't in CLOSED or READY, we are in RUNNING, and therefore just set + // the // arrivalId to the current masterPlanningArrivalId and increment it. else { plan.arrivalId = masterPlanningArrivalId++; @@ -429,8 +430,8 @@ protected void addDataManagerPlan(DataManagerId dataManagerId, DataManagerPlan p throw new ContractException(NucleusError.PLANNING_QUEUE_CLOSED); } - if (plan.consumer == null) { - throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + if (plan == null) { + throw new ContractException(NucleusError.NULL_PLAN); } if (plan.time < time) { @@ -461,7 +462,8 @@ protected void addDataManagerPlan(DataManagerId dataManagerId, DataManagerPlan p plan.arrivalId = initialArrivalId--; } } - // If we aren't in CLOSED or READY, we are in RUNNING, and therefore just set the + // If we aren't in CLOSED or READY, we are in RUNNING, and therefore just set + // the // arrivalId to the current masterPlanningArrivalId and increment it. else { plan.arrivalId = masterPlanningArrivalId++; @@ -670,12 +672,10 @@ public void execute() { started = true; time = data.simulationState.getStartTime(); - + LocalDateTime dateTime = LocalDateTime.of(data.simulationState.getBaseDate(), LocalTime.of(0, 0)); - - + simulationTimeConverter = new SimulationTimeConverter(dateTime); - forcedHaltPresent = false; if (data.simulationHaltTime != null) { @@ -768,7 +768,6 @@ public void execute() { final Plan plan = planningQueue.poll(); // System.out.println(plan); - time = plan.time; if (plan.isActive) { activePlanCount--; } @@ -778,43 +777,44 @@ public void execute() { continue; } + time = plan.time; + switch (plan.planner) { - case ACTOR: - ActorPlan actorPlan = (ActorPlan) plan; - if (actorPlan.consumer != null) { - ActorContentRec actorContentRec = new ActorContentRec(); - actorContentRec.actorId = actorPlan.actorId; - actorContentRec.actorPlan = actorPlan::execute; - actorQueue.add(actorContentRec); - executeActorQueue(); - } - break; - case DATA_MANAGER: - DataManagerPlan dmPlan = (DataManagerPlan) plan; - if (dmPlan.consumer != null) { - DataManagerContentRec dataManagerContentRec = new DataManagerContentRec(); - dataManagerContentRec.dataManagerId = dmPlan.dataManagerId; - dataManagerContentRec.dmPlan = dmPlan::execute; - dataManagerQueue.add(dataManagerContentRec); - executeDataManagerQueue(); - executeActorQueue(); - } - break; + case ACTOR: + ActorPlan actorPlan = (ActorPlan) plan; - case REPORT: - ReportPlan reportPlan = (ReportPlan) plan; - if (reportPlan.consumer != null) { - ReportContentRec reportContentRec = new ReportContentRec(); - reportContentRec.reportId = reportPlan.reportId; - reportContentRec.reportPlan = reportPlan::execute; - reportQueue.add(reportContentRec); - executeReportQueue(); - } + ActorContentRec actorContentRec = new ActorContentRec(); + actorContentRec.actorId = actorPlan.actorId; + actorContentRec.actorPlan = actorPlan::execute; + actorQueue.add(actorContentRec); + executeActorQueue(); - break; + break; + case DATA_MANAGER: + DataManagerPlan dmPlan = (DataManagerPlan) plan; - default: - throw new RuntimeException("unhandled planner type " + plan.planner); + DataManagerContentRec dataManagerContentRec = new DataManagerContentRec(); + dataManagerContentRec.dataManagerId = dmPlan.dataManagerId; + dataManagerContentRec.dmPlan = dmPlan::execute; + dataManagerQueue.add(dataManagerContentRec); + executeDataManagerQueue(); + executeActorQueue(); + + break; + + case REPORT: + ReportPlan reportPlan = (ReportPlan) plan; + + ReportContentRec reportContentRec = new ReportContentRec(); + reportContentRec.reportId = reportPlan.reportId; + reportContentRec.reportPlan = reportPlan::execute; + reportQueue.add(reportContentRec); + executeReportQueue(); + + break; + + default: + throw new RuntimeException("unhandled planner type " + plan.planner); } } @@ -1705,35 +1705,35 @@ private void dumpPlanningQueue() { if (!plan.canceled) { switch (plan.planner) { - case ACTOR: - ActorPlan actorPlan = (ActorPlan) plan; - List actorPlans = actorPlanDump.get(actorPlan.actorId); - if (actorPlans == null) { - actorPlans = new ArrayList<>(); - actorPlanDump.put(actorPlan.actorId, actorPlans); - } - actorPlans.add(actorPlan); - break; - case DATA_MANAGER: - DataManagerPlan dataManagerPlan = (DataManagerPlan) plan; - List dataManagerPlans = dataManagerPlanDump.get(dataManagerPlan.dataManagerId); - if (dataManagerPlans == null) { - dataManagerPlans = new ArrayList<>(); - dataManagerPlanDump.put(dataManagerPlan.dataManagerId, dataManagerPlans); - } - dataManagerPlans.add(dataManagerPlan); - break; - case REPORT: - ReportPlan reportPlan = (ReportPlan) plan; - List reportPlans = reportPlanDump.get(reportPlan.reportId); - if (reportPlans == null) { - reportPlans = new ArrayList<>(); - reportPlanDump.put(reportPlan.reportId, reportPlans); - } - reportPlans.add(reportPlan); - break; - default: - throw new RuntimeException("unhandled planner type " + plan.planner); + case ACTOR: + ActorPlan actorPlan = (ActorPlan) plan; + List actorPlans = actorPlanDump.get(actorPlan.actorId); + if (actorPlans == null) { + actorPlans = new ArrayList<>(); + actorPlanDump.put(actorPlan.actorId, actorPlans); + } + actorPlans.add(actorPlan); + break; + case DATA_MANAGER: + DataManagerPlan dataManagerPlan = (DataManagerPlan) plan; + List dataManagerPlans = dataManagerPlanDump.get(dataManagerPlan.dataManagerId); + if (dataManagerPlans == null) { + dataManagerPlans = new ArrayList<>(); + dataManagerPlanDump.put(dataManagerPlan.dataManagerId, dataManagerPlans); + } + dataManagerPlans.add(dataManagerPlan); + break; + case REPORT: + ReportPlan reportPlan = (ReportPlan) plan; + List reportPlans = reportPlanDump.get(reportPlan.reportId); + if (reportPlans == null) { + reportPlans = new ArrayList<>(); + reportPlanDump.put(reportPlan.reportId, reportPlans); + } + reportPlans.add(reportPlan); + break; + default: + throw new RuntimeException("unhandled planner type " + plan.planner); } } } @@ -1783,14 +1783,14 @@ protected List retrievePlansForDataManager(DataManagerId dataMa } return result; } - + /* * Registers the given consumer to be executed at the end of the simulation. * Activity associated with the consumer should be limited to querying data * state and releasing output. * * @throws ContractException {@link NucleusError#NULL_ACTOR_CONTEXT_CONSUMER} if - * the consumer is null + * the consumer is null */ protected double getSimulationTime(LocalDateTime localDateTime) { return simulationTimeConverter.getSimulationTime(localDateTime); diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/runcontinuityplugin/RunContinuityActor.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/runcontinuityplugin/RunContinuityActor.java index 6be09e1cf..0a1ede75e 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/runcontinuityplugin/RunContinuityActor.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/runcontinuityplugin/RunContinuityActor.java @@ -10,6 +10,7 @@ import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan; +import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan; public class RunContinuityActor implements Consumer { private final RunContinuityPluginData runContinuityPluginData; @@ -29,7 +30,7 @@ public void accept(ActorContext actorContext) { double time = pair.getFirst(); Consumer consumer = pair.getSecond(); - ActorPlan actorPlan = new ActorPlan(time, (c) -> { + ActorPlan actorPlan = new ConsumerActorPlan(time, (c) -> { planMap.remove(i); consumer.accept(actorContext); }); diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/testplugin/TestActorPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/testplugin/TestActorPlan.java index 759b9138a..e414ea73c 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/testplugin/TestActorPlan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/testplugin/TestActorPlan.java @@ -12,6 +12,7 @@ */ public class TestActorPlan extends ActorPlan { private boolean executed; + private Consumer consumer; /** * Constructs an actor action plan. If assignKey is false, then this actor @@ -20,11 +21,12 @@ public class TestActorPlan extends ActorPlan { * @throws ContractException {@linkplain TestError#NULL_PLAN} if the plan is * null */ - public TestActorPlan(final double scheduledTime, Consumer plan) { - super(scheduledTime, plan); - if (plan == null) { + public TestActorPlan(final double scheduledTime, Consumer consumer) { + super(scheduledTime); + if (consumer == null) { throw new ContractException(TestError.NULL_PLAN); } + this.consumer = consumer; } /** @@ -36,7 +38,7 @@ public int hashCode() { int result = 1; result = prime * result + (executed ? 1231 : 1237); long temp; - temp = Double.doubleToLongBits(time); + temp = Double.doubleToLongBits(getTime()); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; } @@ -60,18 +62,19 @@ public boolean equals(Object obj) { return false; } - if (Double.doubleToLongBits(time) != Double.doubleToLongBits(other.time)) { + if (Double.doubleToLongBits(getTime()) != Double.doubleToLongBits(other.getTime())) { return false; } return true; } /** - * Constructs an test actor plan from another test actor plan. + * Constructs a test actor plan from another test actor plan. */ public TestActorPlan(TestActorPlan testActorPlan) { - super(testActorPlan.time, testActorPlan.consumer); + super(testActorPlan.getTime()); executed = testActorPlan.executed; + consumer = testActorPlan.consumer; } /** @@ -84,7 +87,7 @@ public boolean executed() { @Override protected void execute(final ActorContext actorContext) { try { - consumer.accept(actorContext); + consumer.accept(actorContext); } finally { executed = true; } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorContext.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorContext.java index 31b1db1b0..acba88e96 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorContext.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorContext.java @@ -192,20 +192,6 @@ public void testAddPlan_Consumer() { TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - // test preconditions - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(1, (context) -> { - double scheduledTime = context.getTime() + 1; - - ContractException contractException = assertThrows(ContractException.class, - () -> context.addPlan(null, scheduledTime)); - assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> context.addPlan((c) -> { - }, 0)); - assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); - - })); - /* * Have the actor add a plan and show that that plan executes */ @@ -233,6 +219,48 @@ public void testAddPlan_Consumer() { // show that the last two passive plans did not execute assertTrue(planExecuted.getValue()); + + // precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin( + TestPluginData.builder().addTestActorPlan("actor", new TestActorPlan(0, (c) -> { + c.addPlan(null,0); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + + // precondition test: if the plan is scheduled for a time in the past + contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin( + TestPluginData.builder().addTestActorPlan("actor", new TestActorPlan(0, (c) -> { + c.addPlan((c2)->{},-10); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); + + // precondition test: if the plan is added to the simulation after event + // processing is finished + contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin( + TestPluginData.builder().addTestActorPlan("actor", new TestActorPlan(0, (c) -> { + c.subscribeToSimulationClose((c2)->{ + c2.addPlan((c3)->{},0); + }); + + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.PLANNING_QUEUE_CLOSED, contractException.getErrorType()); + + } @Test @@ -241,28 +269,12 @@ public void testAddPlan_Plan() { TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - // test preconditions - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(1, (context) -> { - - ContractException contractException = assertThrows(ContractException.class, () -> context.addPlan(null)); - assertEquals(NucleusError.NULL_PLAN, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, - () -> context.addPlan(new ActorPlan(2, true, null))); - assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, - () -> context.addPlan(new ActorPlan(0, true, (c) -> { - }))); - assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); - })); - /* * Have the actor add a plan and show that that plan executes */ MutableBoolean planExecuted = new MutableBoolean(); - ActorPlan actorPlan = new ActorPlan(5, (c) -> { + ActorPlan actorPlan = new ConsumerActorPlan(5, (c) -> { planExecuted.setValue(true); }); @@ -285,6 +297,48 @@ public void testAddPlan_Plan() { // show that the last two passive plans did not execute assertTrue(planExecuted.getValue()); + + // precondition test: if the plan is null + ContractException contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin( + TestPluginData.builder().addTestActorPlan("actor", new TestActorPlan(0, (c) -> { + c.addPlan(null); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.NULL_PLAN, contractException.getErrorType()); + + // precondition test: if the plan is scheduled for a time in the past + contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin( + TestPluginData.builder().addTestActorPlan("actor", new TestActorPlan(0, (c) -> { + c.addPlan(new ConsumerActorPlan(-10, (c3)->{})); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); + + // precondition test: if the plan is added to the simulation after event + // processing is finished + contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin( + TestPluginData.builder().addTestActorPlan("actor", new TestActorPlan(0, (c) -> { + c.subscribeToSimulationClose((c2)->{ + c2.addPlan(new ConsumerActorPlan(0, (c3)->{})); + }); + + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.PLANNING_QUEUE_CLOSED, contractException.getErrorType()); + + } @Test @@ -866,20 +920,20 @@ public void testGetSimulationTime() { localDateTimes.add(LocalDateTime.of(2020, 3, 15, 22, 13, 18)); localDateTimes.add(LocalDateTime.of(2023, 12, 25, 15, 38, 19)); - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(0, (c) -> { - SimulationTimeConverter simulationTimeConverter = new SimulationTimeConverter( LocalDateTime.of(localDate, LocalTime.of(0, 0))); - for(LocalDateTime localDateTime : localDateTimes) { - assertEquals(simulationTimeConverter.getSimulationTime(localDateTime), c.getSimulationTime(localDateTime)); + SimulationTimeConverter simulationTimeConverter = new SimulationTimeConverter( + LocalDateTime.of(localDate, LocalTime.of(0, 0))); + for (LocalDateTime localDateTime : localDateTimes) { + assertEquals(simulationTimeConverter.getSimulationTime(localDateTime), + c.getSimulationTime(localDateTime)); } - + })); TestPluginData testPluginData = pluginDataBuilder.build(); Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - SimulationState simulationState = SimulationState.builder().setBaseDate(localDate).build(); TestSimulation.builder().setSimulationState(simulationState).addPlugin(testPlugin).build().execute(); @@ -889,8 +943,6 @@ public void testGetSimulationTime() { @UnitTestMethod(target = ActorContext.class, name = "getLocalDateTime", args = { double.class }) public void testGetLocalDateTime() { - - LocalDate localDate = LocalDate.of(2020, 4, 1); List times = new ArrayList<>(); times.add(-5.7); @@ -900,10 +952,10 @@ public void testGetLocalDateTime() { times.add(137.765); times.add(4000.5437); - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(0, (c) -> { - SimulationTimeConverter simulationTimeConverter = new SimulationTimeConverter(LocalDateTime.of(localDate, LocalTime.of(0, 0))); + SimulationTimeConverter simulationTimeConverter = new SimulationTimeConverter( + LocalDateTime.of(localDate, LocalTime.of(0, 0))); for (Double time : times) { assertEquals(simulationTimeConverter.getLocalDateTime(time), c.getLocalDateTime(time)); } @@ -911,7 +963,6 @@ public void testGetLocalDateTime() { TestPluginData testPluginData = pluginDataBuilder.build(); Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - SimulationState simulationState = SimulationState.builder().setBaseDate(localDate).build(); TestSimulation.builder().setSimulationState(simulationState).addPlugin(testPlugin).build().execute(); @@ -934,7 +985,7 @@ public void testRetrievePlans() { double haltTime = 50; for (int i = 1; i <= 100; i++) { - ActorPlan actorPlan = new ActorPlan(i, (c) -> { + ActorPlan actorPlan = new ConsumerActorPlan(i, (c) -> { }); if (i > 50) { expectedPlans.add(actorPlan); diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorContextPlanRecovery.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorContextPlanRecovery.java index baba73b60..416f0bdf9 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorContextPlanRecovery.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorContextPlanRecovery.java @@ -28,21 +28,21 @@ public SpecialActor(int id) { public void accept(ActorContext actorContext) { switch (id) { case 0: - actorContext.addPlan(new ActorPlan(2, true, 5L, c -> c.releaseOutput(1))); - actorContext.addPlan(new ActorPlan(7, true, 14L, c -> c.releaseOutput(4))); - actorContext.addPlan(new ActorPlan(14, true, 12L, c -> c.releaseOutput(9))); - actorContext.addPlan(new ActorPlan(2, true, -1L, c -> c.releaseOutput(2))); - actorContext.addPlan(new ActorPlan(7, true, -1L, c -> c.releaseOutput(6))); - actorContext.addPlan(new ActorPlan(14, true, -1L, c -> c.releaseOutput(10))); + actorContext.addPlan(new ConsumerActorPlan(2, true, 5L, c -> c.releaseOutput(1))); + actorContext.addPlan(new ConsumerActorPlan(7, true, 14L, c -> c.releaseOutput(4))); + actorContext.addPlan(new ConsumerActorPlan(14, true, 12L, c -> c.releaseOutput(9))); + actorContext.addPlan(new ConsumerActorPlan(2, true, -1L, c -> c.releaseOutput(2))); + actorContext.addPlan(new ConsumerActorPlan(7, true, -1L, c -> c.releaseOutput(6))); + actorContext.addPlan(new ConsumerActorPlan(14, true, -1L, c -> c.releaseOutput(10))); break; case 1: - actorContext.addPlan(new ActorPlan(2, true, 4L, c -> c.releaseOutput(0))); - actorContext.addPlan(new ActorPlan(7, true, 16L, c -> c.releaseOutput(5))); - actorContext.addPlan(new ActorPlan(14, true, 11L, c -> c.releaseOutput(8))); - actorContext.addPlan(new ActorPlan(2, true, -1L, c -> c.releaseOutput(3))); - actorContext.addPlan(new ActorPlan(7, true, -1L, c -> c.releaseOutput(7))); - actorContext.addPlan(new ActorPlan(14, true, -1L, c -> c.releaseOutput(11))); + actorContext.addPlan(new ConsumerActorPlan(2, true, 4L, c -> c.releaseOutput(0))); + actorContext.addPlan(new ConsumerActorPlan(7, true, 16L, c -> c.releaseOutput(5))); + actorContext.addPlan(new ConsumerActorPlan(14, true, 11L, c -> c.releaseOutput(8))); + actorContext.addPlan(new ConsumerActorPlan(2, true, -1L, c -> c.releaseOutput(3))); + actorContext.addPlan(new ConsumerActorPlan(7, true, -1L, c -> c.releaseOutput(7))); + actorContext.addPlan(new ConsumerActorPlan(14, true, -1L, c -> c.releaseOutput(11))); break; default: diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorPlan.java index 7709076b8..c2ea2d23b 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorPlan.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ActorPlan.java @@ -1,9 +1,5 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.util.function.Consumer; - import org.junit.jupiter.api.Test; import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; @@ -11,35 +7,20 @@ public class AT_ActorPlan { @Test - @UnitTestConstructor(target = ActorPlan.class, args = { double.class, Consumer.class }) - public void testConstructor() { - for (int i = 0; i < 10; i++) { - ActorPlan actorPlan = new ActorPlan(i, (c) -> { - }); - - assertNotNull(actorPlan); - } + @UnitTestConstructor(target = ActorPlan.class, args = { double.class }) + public void testActorPlan() { + //nothing to test } @Test - @UnitTestConstructor(target = ActorPlan.class, args = { double.class, boolean.class, Consumer.class }) + @UnitTestConstructor(target = ActorPlan.class, args = { double.class, boolean.class}) public void testConstructor_Active() { - for (int i = 0; i < 10; i++) { - ActorPlan actorPlan = new ActorPlan(i, i % 2 == 0, (c) -> { - }); - - assertNotNull(actorPlan); - } + //nothing to test } @Test - @UnitTestConstructor(target = ActorPlan.class, args = { double.class, boolean.class, long.class, Consumer.class }) + @UnitTestConstructor(target = ActorPlan.class, args = { double.class, boolean.class, long.class}) public void testConstructor_Active_Arrival() { - for (int i = 0; i < 10; i++) { - ActorPlan actorPlan = new ActorPlan(i, i % 2 == 0, (long) i, (c) -> { - }); - - assertNotNull(actorPlan); - } + //nothing to test } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerActorPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerActorPlan.java new file mode 100644 index 000000000..a25da1f5c --- /dev/null +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerActorPlan.java @@ -0,0 +1,44 @@ +package gov.hhs.aspr.ms.gcm.simulation.nucleus; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.function.Consumer; + +import org.junit.jupiter.api.Test; + +import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; +import gov.hhs.aspr.ms.util.errors.ContractException; + +public class AT_ConsumerActorPlan { + + @Test + @UnitTestConstructor(target = ConsumerActorPlan.class, args = { double.class, Consumer.class }) + public void testActorPlan() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, ()->{ + new ConsumerActorPlan(0, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } + + @Test + @UnitTestConstructor(target = ConsumerActorPlan.class, args = { double.class, boolean.class, Consumer.class }) + public void testConstructor_Active() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, ()->{ + new ConsumerActorPlan(0,true, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } + + @Test + @UnitTestConstructor(target = ConsumerActorPlan.class, args = { double.class, boolean.class, long.class, Consumer.class }) + public void testConstructor_Active_Arrival() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, ()->{ + new ConsumerActorPlan(0,true,2345345L, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } +} diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerDataManagerPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerDataManagerPlan.java new file mode 100644 index 000000000..1a145677f --- /dev/null +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerDataManagerPlan.java @@ -0,0 +1,45 @@ +package gov.hhs.aspr.ms.gcm.simulation.nucleus; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.function.Consumer; + +import org.junit.jupiter.api.Test; + +import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; +import gov.hhs.aspr.ms.util.errors.ContractException; + +public class AT_ConsumerDataManagerPlan { + + @Test + @UnitTestConstructor(target = ConsumerDataManagerPlan.class, args = { double.class, Consumer.class }) + public void testConstructor() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + new ConsumerDataManagerPlan(0, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } + + @Test + @UnitTestConstructor(target = ConsumerDataManagerPlan.class, args = { double.class, boolean.class, Consumer.class }) + public void testConstructor_Active() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + new ConsumerDataManagerPlan(0, true, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } + + @Test + @UnitTestConstructor(target = ConsumerDataManagerPlan.class, args = { double.class, boolean.class, long.class, + Consumer.class }) + public void testConstructor_Active_Arrival() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + new ConsumerDataManagerPlan(0, true,34534L, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } +} diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerReportPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerReportPlan.java new file mode 100644 index 000000000..8cea57156 --- /dev/null +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerReportPlan.java @@ -0,0 +1,34 @@ +package gov.hhs.aspr.ms.gcm.simulation.nucleus; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.function.Consumer; + +import org.junit.jupiter.api.Test; + +import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; +import gov.hhs.aspr.ms.util.errors.ContractException; + +public class AT_ConsumerReportPlan { + + @Test + @UnitTestConstructor(target = ConsumerReportPlan.class, args = { double.class, Consumer.class }) + public void testConstructor() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + new ConsumerReportPlan(0, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } + + @Test + @UnitTestConstructor(target = ConsumerReportPlan.class, args = { double.class, long.class, Consumer.class }) + public void testConstructor_Arrival() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + new ConsumerReportPlan(0,3453L, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } +} diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerContext.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerContext.java index 9ff0d44a4..1f6c824f4 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerContext.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerContext.java @@ -232,18 +232,7 @@ public void testAddPlan_Consumer() { // test preconditions pluginDataBuilder.addTestDataManager("dm", () -> new TestDataManager1()); - pluginDataBuilder.addTestDataManagerPlan("dm", new TestDataManagerPlan(1, (context) -> { - double scheduledTime = context.getTime() + 1; - - ContractException contractException = assertThrows(ContractException.class, - () -> context.addPlan(null, scheduledTime)); - assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); - contractException = assertThrows(ContractException.class, () -> context.addPlan((c) -> { - }, 0)); - assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); - - })); /* * Have the actor add a plan and show that that plan executes @@ -273,6 +262,49 @@ public void testAddPlan_Consumer() { // show that the last two passive plans did not execute assertTrue(planExecuted.getValue()); + // precondition test: if the plan is null + ContractException contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin(TestPluginData.builder()// + .addTestDataManager("dm", () -> new TestDataManager1()) + .addTestDataManagerPlan("dm", new TestDataManagerPlan(0, (c) -> { + c.addPlan(null,0); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + + // precondition test: if the plan is scheduled for a time in the past + contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin(TestPluginData.builder()// + .addTestDataManager("dm", () -> new TestDataManager1()) + .addTestDataManagerPlan("dm", new TestDataManagerPlan(0, (c) -> { + c.addPlan((c2) -> {},-10); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); + + // precondition test: if the plan is added to the simulation after event + // processing is finished + contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin(TestPluginData.builder()// + .addTestDataManager("dm", () -> new TestDataManager1()) + .addTestDataManagerPlan("dm", new TestDataManagerPlan(0, (c) -> { + c.subscribeToSimulationClose(c2 -> { + c2.addPlan((c3) -> {},0); + }); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.PLANNING_QUEUE_CLOSED, contractException.getErrorType()); + + } @Test @@ -283,22 +315,6 @@ public void testAddPlan_Plan() { // test preconditions pluginDataBuilder.addTestDataManager("dm", () -> new TestDataManager1()); - pluginDataBuilder.addTestDataManagerPlan("dm", new TestDataManagerPlan(1, (context) -> { - double scheduledTime = context.getTime() + 1; - - ContractException contractException = assertThrows(ContractException.class, - () -> context.addPlan(new DataManagerPlan(scheduledTime, null))); - assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> context.addPlan(null)); - assertEquals(NucleusError.NULL_PLAN, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, - () -> context.addPlan(new DataManagerPlan(-1, (c) -> { - }))); - assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); - - })); /* * Have the actor add a plan and show that that plan executes @@ -308,7 +324,7 @@ public void testAddPlan_Plan() { pluginDataBuilder.addTestDataManagerPlan("dm", new TestDataManagerPlan(4, (context) -> { // schedule two passive plans - context.addPlan(new DataManagerPlan(5, (c) -> { + context.addPlan(new ConsumerDataManagerPlan(5, (c) -> { planExecuted.setValue(true); })); })); @@ -328,6 +344,64 @@ public void testAddPlan_Plan() { // show that the last two passive plans did not execute assertTrue(planExecuted.getValue()); + // precondition test: if the plan is null + ContractException contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin(TestPluginData.builder()// + .addTestDataManager("dm", () -> new TestDataManager1()) + .addTestDataManagerPlan("dm", new TestDataManagerPlan(0, (c) -> { + c.addPlan(null); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.NULL_PLAN, contractException.getErrorType()); + + // precondition test: if the arrival id is less than -1 + contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin(TestPluginData.builder()// + .addTestDataManager("dm", () -> new TestDataManager1()) + .addTestDataManagerPlan("dm", new TestDataManagerPlan(0, (c) -> { + c.addPlan(new ConsumerDataManagerPlan(0, true, -2, (c2) -> { + })); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.INVALID_PLAN_ARRIVAL_ID, contractException.getErrorType()); + + // precondition test: if the plan is scheduled for a time in the past + contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin(TestPluginData.builder()// + .addTestDataManager("dm", () -> new TestDataManager1()) + .addTestDataManagerPlan("dm", new TestDataManagerPlan(0, (c) -> { + c.addPlan(new ConsumerDataManagerPlan(-10, true, -1, (c2) -> { + })); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); + + // precondition test: if the plan is added to the simulation after event + // processing is finished + contractException = assertThrows(ContractException.class, () -> { + Simulation.builder()// + .addPlugin(TestPlugin.getTestPlugin(TestPluginData.builder()// + .addTestDataManager("dm", () -> new TestDataManager1()) + .addTestDataManagerPlan("dm", new TestDataManagerPlan(0, (c) -> { + c.subscribeToSimulationClose(c2 -> { + c2.addPlan(new ConsumerDataManagerPlan(0, true, -1, (c3) -> { + })); + }); + })).build()))// + .build()// + .execute();// + }); + assertEquals(NucleusError.PLANNING_QUEUE_CLOSED, contractException.getErrorType()); + } @Test @@ -1036,7 +1110,7 @@ public void testRetrievePlans() { double haltTime = 50; for (int i = 1; i <= 100; i++) { - DataManagerPlan actorPlan = new DataManagerPlan(i, (c) -> { + DataManagerPlan actorPlan = new ConsumerDataManagerPlan(i, (c) -> { }); if (i > 50) { expectedPlans.add(actorPlan); @@ -1088,7 +1162,7 @@ public void testGetDataManagerId() { * The TestPlugin already contains a data manager that will be added to the * simulation ahead of the ones above, so the numbering will start with 1. */ - + pluginDataBuilder.addTestDataManagerPlan("dm1", new TestDataManagerPlan(0, (context) -> { assertEquals(new DataManagerId(1), context.getDataManagerId()); })); diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerPlan.java index 3ec9258cc..285a6aa10 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerPlan.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerPlan.java @@ -1,46 +1,26 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.util.function.Consumer; - import org.junit.jupiter.api.Test; import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; public class AT_DataManagerPlan { - - @Test - @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class, Consumer.class }) - public void testConstructor() { - for (int i = 0; i < 10; i++) { - DataManagerPlan dataManagerPlan = new DataManagerPlan(i, (c) -> { - }); - - assertNotNull(dataManagerPlan); - } - } - - @Test - @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class, boolean.class, Consumer.class }) - public void testConstructor_Active() { - for (int i = 0; i < 10; i++) { - DataManagerPlan dataManagerPlan = new DataManagerPlan(i, i % 2 == 0, (c) -> { - }); - - assertNotNull(dataManagerPlan); - } - } - - @Test - @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class, boolean.class, long.class, - Consumer.class }) - public void testConstructor_Active_Arrival() { - for (int i = 0; i < 10; i++) { - DataManagerPlan dataManagerPlan = new DataManagerPlan(i, i % 2 == 0, (long) i, (c) -> { - }); - assertNotNull(dataManagerPlan); - } - } + @Test + @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class }) + public void testConstructor() { + // nothing to test + } + + @Test + @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class, boolean.class }) + public void testConstructor_Active() { + // nothing to test + } + + @Test + @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class, boolean.class, long.class }) + public void testConstructor_Active_Arrival() { + // nothing to test + } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportContext.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportContext.java index 1498f4e0a..6551a2ae2 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportContext.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportContext.java @@ -33,615 +33,628 @@ public class AT_ReportContext { - private static class TestDataManager1 extends TestDataManager { - } + private static class TestDataManager1 extends TestDataManager { + } - private static class TestDataManager3 extends TestDataManager { + private static class TestDataManager3 extends TestDataManager { - } + } - private static class TestDataManager3A extends TestDataManager3 { + private static class TestDataManager3A extends TestDataManager3 { - } + } - private static class TestDataManager3B extends TestDataManager3 { + private static class TestDataManager3B extends TestDataManager3 { - } + } - private static class TestDataManager4 extends TestDataManager { + private static class TestDataManager4 extends TestDataManager { - } + } - private static class TestDataManager4A extends TestDataManager4 { + private static class TestDataManager4A extends TestDataManager4 { - } + } - /* - * Executes the simulation by adding TestReport that executes the give - * consumer in a task planned at time zero. Also adds a TestActor with a - * task scheduled at positive infinity to guarantee the execution of the - * report's task. - */ - private void testConsumer(Consumer consumer) { - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); + /* + * Executes the simulation by adding TestReport that executes the give consumer + * in a task planned at time zero. Also adds a TestActor with a task scheduled + * at positive infinity to guarantee the execution of the report's task. + */ + private void testConsumer(Consumer consumer) { + TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, consumer)); - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { - })); + pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, consumer)); + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { + })); - TestPluginData testPluginData = pluginDataBuilder.build(); - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); + TestPluginData testPluginData = pluginDataBuilder.build(); + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - TestSimulation.builder().addPlugin(testPlugin).build().execute(); + TestSimulation.builder().addPlugin(testPlugin).build().execute(); - } + } - @Test - @UnitTestMethod(target = ReportContext.class, name = "addPlan", args = { Consumer.class, double.class }) - public void testAddPlan_Consumer() { - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); + @Test + @UnitTestMethod(target = ReportContext.class, name = "addPlan", args = { Consumer.class, double.class }) + public void testAddPlan_Consumer() { + TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - /* - * Show that passive plans do not execute if there are no remaining - * active plans. To do this, we will schedule a few passive plans, one - * active plan and then a few more passive plans. We will then show that - * the passive plans that come after the last active plan never execute - */ + /* + * Show that passive plans do not execute if there are no remaining active + * plans. To do this, we will schedule a few passive plans, one active plan and + * then a few more passive plans. We will then show that the passive plans that + * come after the last active plan never execute + */ - // create some containers for passive keys - Set expectedOutput = new LinkedHashSet<>(); - expectedOutput.add("A"); - expectedOutput.add("B"); - Set actualOuput = new LinkedHashSet<>(); + // create some containers for passive keys + Set expectedOutput = new LinkedHashSet<>(); + expectedOutput.add("A"); + expectedOutput.add("B"); + Set actualOuput = new LinkedHashSet<>(); + + pluginDataBuilder.addTestReportPlan("actor", new TestReportPlan(4, (context) -> { + + // schedule two passive plans + context.addPlan((c) -> { + actualOuput.add("A"); + }, 5); + context.addPlan((c) -> { + actualOuput.add("B"); + }, 6); + + // schedule two more passive plans + context.addPlan((c) -> { + actualOuput.add("C"); + }, 8); + context.addPlan((c) -> { + actualOuput.add("D"); + }, 9); - pluginDataBuilder.addTestReportPlan("actor", new TestReportPlan(4, (context) -> { + })); - // schedule two passive plans - context.addPlan((c) -> { - actualOuput.add("A"); - }, 5); - context.addPlan((c) -> { - actualOuput.add("B"); - }, 6); + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(7, (context) -> { + // place holder active plan that drives time to 7.0 + })); - // schedule two more passive plans - context.addPlan((c) -> { - actualOuput.add("C"); - }, 8); - context.addPlan((c) -> { - actualOuput.add("D"); - }, 9); + // build the plugin + TestPluginData testPluginData = pluginDataBuilder.build(); + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - })); - - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(7, (context) -> { - // place holder active plan that drives time to 7.0 - })); - - // build the plugin - TestPluginData testPluginData = pluginDataBuilder.build(); - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - - // run the simulation -- we do not need to show that all plans executed - Simulation.builder()// - .addPlugin(testPlugin)// - .build()// - .execute();// - - // show that the last two passive plans did not execute - assertEquals(expectedOutput, actualOuput); + // run the simulation -- we do not need to show that all plans executed + Simulation.builder()// + .addPlugin(testPlugin)// + .build()// + .execute();// - // precondition test : if the plan is null - ContractException contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.addPlan(null, 0); - })); - assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); - - // precondition test : if the plan is scheduled for the past - contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.addPlan((c2) -> { - }, -1); - })); - assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "addPlan", args = { ReportPlan.class }) - public void testAddPlan_Plan() { - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - - /* - * Show that passive plans do not execute if there are no remaining - * active plans. To do this, we will schedule a few passive plans, one - * active plan and then a few more passive plans. We will then show that - * the passive plans that come after the last active plan never execute - */ - - // create some containers for passive keys - Set expectedOutput = new LinkedHashSet<>(); - expectedOutput.add("A"); - expectedOutput.add("B"); - Set actualOuput = new LinkedHashSet<>(); - - pluginDataBuilder.addTestReportPlan("actor", new TestReportPlan(4, (context) -> { - - // schedule two passive plans - context.addPlan(new ReportPlan(5, (c) -> { - actualOuput.add("A"); - })); - - context.addPlan(new ReportPlan(6, (c) -> { - actualOuput.add("B"); - })); - - // schedule two more passive plans - context.addPlan(new ReportPlan(8, (c) -> { - actualOuput.add("C"); - }));// - - context.addPlan(new ReportPlan(9, (c) -> { - actualOuput.add("D"); - })); - })); - - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(7, (context) -> - - { - // place holder active plan that drives time to 7.0 - })); - - // build the plugin - TestPluginData testPluginData = pluginDataBuilder.build(); - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - - // run the simulation -- we do not need to show that all plans executed - Simulation.builder()// - .addPlugin(testPlugin)// - .build()// - .execute();// - - // show that the last two passive plans did not execute - assertEquals(expectedOutput, actualOuput); - - // precondition test : if the plan is null - ContractException contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.addPlan(new ReportPlan(9, null)); - })); - assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.addPlan(null); - })); - assertEquals(NucleusError.NULL_PLAN, contractException.getErrorType()); - - // precondition test : if the plan is scheduled for the past - contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.addPlan(new ReportPlan(-1, (c1) -> {})); - })); - assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "getDataManager", args = { Class.class }) - public void testGetDataManager() { - // create the test plugin data builder - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - - // create a data manager for the report to find - - pluginDataBuilder.addTestDataManager("dm1", () -> new TestDataManager1()); - pluginDataBuilder.addTestDataManager("dm3A", () -> new TestDataManager3A()); - pluginDataBuilder.addTestDataManager("dm3B", () -> new TestDataManager3B()); - pluginDataBuilder.addTestDataManager("dm4A", () -> new TestDataManager4A()); - - pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { - c.getDataManager(TestDataManager1.class); - c.getDataManager(TestDataManager3A.class); - c.getDataManager(TestDataManager3B.class); - c.getDataManager(TestDataManager4A.class); - })); - - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { - })); - - // build the action plugin - TestPluginData testPluginData = pluginDataBuilder.build(); - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - - TestSimulation.builder().addPlugin(testPlugin).build().execute(); - - // precondition test : if the class reference is ambiguous - pluginDataBuilder.addTestDataManager("dm3A", () -> new TestDataManager3A()); - pluginDataBuilder.addTestDataManager("dm3B", () -> new TestDataManager3B()); - - // show that ambiguous class matching throws an exception - pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { - ContractException contractException = assertThrows(ContractException.class, - () -> c.getDataManager(TestDataManager3.class)); - assertEquals(NucleusError.AMBIGUOUS_DATA_MANAGER_CLASS, contractException.getErrorType()); - })); - - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { - })); - - // build the action plugin - testPluginData = pluginDataBuilder.build(); - testPlugin = TestPlugin.getTestPlugin(testPluginData); - - TestSimulation.builder().addPlugin(testPlugin).build().execute(); - - // Precondition test 2 - pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { - ContractException contractException = assertThrows(ContractException.class, () -> c.getDataManager(null)); - assertEquals(NucleusError.NULL_DATA_MANAGER_CLASS, contractException.getErrorType()); - })); - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { - })); - // build the action plugin - testPluginData = pluginDataBuilder.build(); - testPlugin = TestPlugin.getTestPlugin(testPluginData); - - TestSimulation.builder().addPlugin(testPlugin).build().execute(); - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "getReportId", args = {}) - public void testGetReportId() { - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - - double testTime = 1; - // there are no precondition tests - - Set observedReportIds = new LinkedHashSet<>(); - Set expectedReportIds = new LinkedHashSet<>(); - for (int i = 0; i < 3; i++) { - expectedReportIds.add(new ReportId(i)); - } - - /* - * Have actors get their own actor ids and show that these ids match the - * expected values established during the initialization of the - * TestReports. - */ - pluginDataBuilder.addTestReportPlan("Alpha", new TestReportPlan(testTime++, (c) -> { - ReportId reportId = c.getReportId(); - observedReportIds.add(reportId); - assertNotNull(reportId); - - })); - - pluginDataBuilder.addTestReportPlan("Beta", new TestReportPlan(testTime++, (c) -> { - ReportId reportId = c.getReportId(); - observedReportIds.add(reportId); - assertNotNull(reportId); - - })); - - pluginDataBuilder.addTestReportPlan("Gamma", new TestReportPlan(testTime++, (c) -> { - ReportId reportId = c.getReportId(); - observedReportIds.add(reportId); - assertNotNull(reportId); - - })); - - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { - assertEquals(expectedReportIds, observedReportIds); - })); - - // build the plugin - TestPluginData testPluginData = pluginDataBuilder.build(); - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - - TestSimulation.builder().addPlugin(testPlugin).build().execute(); - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "getScheduledSimulationHaltTime", args = {}) - public void testGetScheduledSimulationHaltTime() { - Set stopTimes = new LinkedHashSet<>(); - - stopTimes.add(4.6); - stopTimes.add(13.0); - stopTimes.add(554.3); - stopTimes.add(7.9); - stopTimes.add(400.2); - stopTimes.add(3000.1); - - for (Double stopTime : stopTimes) { - TestPluginData testPluginData = TestPluginData - .builder() - .addTestReportPlan("report plan", new TestReportPlan(0, (context) -> { - assertEquals(stopTime, context.getScheduledSimulationHaltTime()); - })) - .addTestActorPlan("actor", new TestActorPlan(1, (c) -> { - })) - .build(); - - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - - TestSimulation.builder().setSimulationHaltTime(stopTime).addPlugin(testPlugin).build().execute(); - } - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "getTime", args = {}) - public void testGetTime() { - Set planTimes = new LinkedHashSet<>(); - - planTimes.add(4.6); - planTimes.add(13.8764); - planTimes.add(554.345); - planTimes.add(7.95346); - planTimes.add(400.234234); - planTimes.add(3000.12422346); - - /* - * Have a report build plans to check the time in the simulation against - * the planning time - */ - testConsumer((context1) -> { - for (Double planTime : planTimes) { - context1.addPlan((context2) -> { - assertEquals(planTime.doubleValue(), context2.getTime(), 0); - }, planTime); - } - }); - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "releaseOutput", args = { Object.class }) - public void testReleaseOutput() { - // begin building the action plugin - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - - // set up the expected output - Set expectedOutput = new LinkedHashSet<>(); - expectedOutput.add("the sly fox"); - expectedOutput.add(15); - expectedOutput.add("the lazy, brown dog"); - expectedOutput.add(45.34513453); - - // have the agent release the output - pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(1, (c) -> { - for (Object outputValue : expectedOutput) { - c.releaseOutput(outputValue); - } - })); - - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { - })); - - // build the plugin - TestPluginData testPluginData = pluginDataBuilder.build(); - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - - /* - * Add an output consumer that will place the output into the - * actualOutput set above and then execute the simulation - */ - TestOutputConsumer testOutputConsumer = TestSimulation.builder().addPlugin(testPlugin).build().execute(); - - Map outputItems = testOutputConsumer.getOutputItemMap(Object.class); - for (Object key : outputItems.keySet()) { - Integer count = outputItems.get(key); - assertEquals(1, count.intValue()); - } - - // show that the output matches expectations - assertTrue(outputItems.keySet().containsAll(expectedOutput)); - } - - private static class TestEvent1 implements Event { - - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "subscribe", args = { Class.class, BiConsumer.class }) - public void testSubscribe() { - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - - MutableBoolean observed = new MutableBoolean(); - - // have the report subscribe for test events. - pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { - c.subscribe(TestEvent1.class, (c2, e) -> { - observed.setValue(true); - }); - })); - - // create a data manager that will generate a test event - - pluginDataBuilder.addTestDataManager("generator", () -> new TestDataManager()); - pluginDataBuilder.addTestDataManagerPlan("generator", new TestDataManagerPlan(1, (c) -> { - c.releaseObservationEvent(new TestEvent1()); - })); - - /* - * show that report received the event - */ - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { - assertTrue(observed.getValue()); - })); - - // build the plugin - TestPluginData testPluginData = pluginDataBuilder.build(); - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - - // build and execute the engine - TestSimulation.builder().addPlugin(testPlugin).build().execute(); - - // precondition test: if the event class is null - ContractException contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.subscribe(null, (c2, e) -> { - }); - })); - assertEquals(NucleusError.NULL_EVENT_CLASS, contractException.getErrorType()); - - // precondition test: if the event consumer is null - contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.subscribe(TestEvent1.class, null); - })); - assertEquals(NucleusError.NULL_EVENT_CONSUMER, contractException.getErrorType()); - - // precondition test: if the subsciption duplicates another subscription - contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.subscribe(TestEvent1.class, (c2, e) -> { - }); - c.subscribe(TestEvent1.class, (c2, e) -> { - }); - })); - assertEquals(NucleusError.DUPLICATE_EVENT_SUBSCRIPTION, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "subscribeToSimulationClose", args = { Consumer.class }) - public void testSubscribeToSimulationClose() { - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - - MutableBoolean simCloseEventHandled = new MutableBoolean(); - - // have a report schedule a few plans and subscribe to simulation close - pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { - c.addPlan((c2) -> { - }, 1); - c.addPlan((c2) -> { - }, 2); - c.addPlan((c2) -> { - }, 3); - c.subscribeToSimulationClose((c2) -> { - simCloseEventHandled.setValue(true); - }); - })); - - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { - })); - - TestPluginData testPluginData = pluginDataBuilder.build(); - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - - TestSimulation.builder().addPlugin(testPlugin).build().execute(); - - // show that the subscription to simulation close was successful - assertTrue(simCloseEventHandled.getValue()); - - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "stateRecordingIsScheduled", args = {}) - public void testStateRecordingIsScheduled() { - Set stateRecordingList = new LinkedHashSet<>(); - - stateRecordingList.add(false); - stateRecordingList.add(false); - stateRecordingList.add(true); - stateRecordingList.add(false); - stateRecordingList.add(true); - stateRecordingList.add(true); - - for (Boolean stateRecording : stateRecordingList) { - TestPluginData testPluginData = TestPluginData - .builder() - .addTestReportPlan("actor 1", new TestReportPlan(0, (context) -> { - assertEquals(stateRecording, context.stateRecordingIsScheduled()); - })) - .addTestActorPlan("actor", new TestActorPlan(1, (c) -> { - })) - .build(); - - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - - TestSimulation.builder().setSimulationHaltTime(2).setProduceSimulationStateOnHalt(stateRecording) - .addPlugin(testPlugin).build().execute(); - } - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "unsubscribe", args = { Class.class }) - public void testUnsubscribe() { - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); - - /* - * Create a container to count the number of times a subscription - * execution occurred - */ - MutableInteger observationCount = new MutableInteger(); - - /* - * have the resolver subscribe to the test event and have it handle each - * type of event handling by incrementing a counter - */ - - int taskTime = 0; - - pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(taskTime++, (c) -> { - c.subscribe(TestEvent1.class, (c2, e) -> { - observationCount.increment(); - }); - })); - - // create a data manager that will produce a test event - pluginDataBuilder.addTestDataManager("generator", () -> new TestDataManager()); - pluginDataBuilder.addTestDataManagerPlan("generator", new TestDataManagerPlan(taskTime++, (c) -> { - c.releaseObservationEvent(new TestEvent1()); - })); - - pluginDataBuilder.addTestDataManagerPlan("generator", new TestDataManagerPlan(taskTime++, (c) -> { - c.releaseObservationEvent(new TestEvent1()); - })); - - pluginDataBuilder.addTestDataManagerPlan("generator", new TestDataManagerPlan(taskTime++, (c) -> { - c.releaseObservationEvent(new TestEvent1()); - })); - - /* - * Show that the phaseExecutionCount is three after the the agent is - * done - */ - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(taskTime++, (c) -> { - assertEquals(3, observationCount.getValue()); - })); - - // have the report unsubscribe - pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(taskTime++, (c) -> { - c.unsubscribe(TestEvent1.class); - })); - - // have the data manager generate another test event - pluginDataBuilder.addTestDataManagerPlan("generator", new TestDataManagerPlan(taskTime++, (c) -> { - c.releaseObservationEvent(new TestEvent1()); - })); - - /* - * Show that the observation count is still three - */ - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(taskTime++, (c) -> { - assertEquals(3, observationCount.getValue()); - })); - - // build the plugin - TestPluginData testPluginData = pluginDataBuilder.build(); - Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); - - // build and execute the engine - TestSimulation.builder().addPlugin(testPlugin).build().execute(); - - // precondition test: if the event class reference is null - ContractException contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.unsubscribe(null); - })); - assertEquals(NucleusError.NULL_EVENT_CLASS, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = ReportContext.class, name = "getSimulationTime", args = { LocalDateTime.class }) - public void testGetSimulationTime() { + // show that the last two passive plans did not execute + assertEquals(expectedOutput, actualOuput); + + // precondition test : if the plan is null + ContractException contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.addPlan(null, 0); + })); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + + // precondition test : if the plan is scheduled for the past + contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.addPlan((c2) -> { + }, -1); + })); + assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); + + // precondition test : if the plan is added to the simulation after event processing is finished + contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.addPlan(new ConsumerReportPlan(0, (c1) -> { + c1.subscribeToSimulationClose((c2->{ + c2.addPlan(c3->{},0); + })); + })); + })); + assertEquals(NucleusError.PLANNING_QUEUE_CLOSED, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "addPlan", args = { ReportPlan.class }) + public void testAddPlan_Plan() { + TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); + + /* + * Show that passive plans do not execute if there are no remaining active + * plans. To do this, we will schedule a few passive plans, one active plan and + * then a few more passive plans. We will then show that the passive plans that + * come after the last active plan never execute + */ + + // create some containers for passive keys + Set expectedOutput = new LinkedHashSet<>(); + expectedOutput.add("A"); + expectedOutput.add("B"); + Set actualOuput = new LinkedHashSet<>(); + + pluginDataBuilder.addTestReportPlan("actor", new TestReportPlan(4, (context) -> { + + // schedule two passive plans + context.addPlan(new ConsumerReportPlan(5, (c) -> { + actualOuput.add("A"); + })); + + context.addPlan(new ConsumerReportPlan(6, (c) -> { + actualOuput.add("B"); + })); + + // schedule two more passive plans + context.addPlan(new ConsumerReportPlan(8, (c) -> { + actualOuput.add("C"); + }));// + + context.addPlan(new ConsumerReportPlan(9, (c) -> { + actualOuput.add("D"); + })); + })); + + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(7, (context) -> + + { + // place holder active plan that drives time to 7.0 + })); + + // build the plugin + TestPluginData testPluginData = pluginDataBuilder.build(); + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); + + // run the simulation -- we do not need to show that all plans executed + Simulation.builder()// + .addPlugin(testPlugin)// + .build()// + .execute();// + + // show that the last two passive plans did not execute + assertEquals(expectedOutput, actualOuput); + + + ContractException contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.addPlan(null); + })); + assertEquals(NucleusError.NULL_PLAN, contractException.getErrorType()); + + // precondition test : if the plan is scheduled for the past + contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.addPlan(new ConsumerReportPlan(-1, (c1) -> { + })); + })); + assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); + + // precondition test : if the arrival id is less than -1 + contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.addPlan(new ConsumerReportPlan(0, -2, (c1) -> { + })); + })); + assertEquals(NucleusError.INVALID_PLAN_ARRIVAL_ID, contractException.getErrorType()); + + // precondition test : if the plan is added to the simulation after event processing is finished + contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.addPlan(new ConsumerReportPlan(0, (c1) -> { + c1.subscribeToSimulationClose((c2->{ + c2.addPlan(new ConsumerReportPlan(0,(c3->{}))); + })); + })); + })); + assertEquals(NucleusError.PLANNING_QUEUE_CLOSED, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "getDataManager", args = { Class.class }) + public void testGetDataManager() { + // create the test plugin data builder + TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); + + // create a data manager for the report to find + + pluginDataBuilder.addTestDataManager("dm1", () -> new TestDataManager1()); + pluginDataBuilder.addTestDataManager("dm3A", () -> new TestDataManager3A()); + pluginDataBuilder.addTestDataManager("dm3B", () -> new TestDataManager3B()); + pluginDataBuilder.addTestDataManager("dm4A", () -> new TestDataManager4A()); + + pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { + c.getDataManager(TestDataManager1.class); + c.getDataManager(TestDataManager3A.class); + c.getDataManager(TestDataManager3B.class); + c.getDataManager(TestDataManager4A.class); + })); + + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { + })); + + // build the action plugin + TestPluginData testPluginData = pluginDataBuilder.build(); + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); + + TestSimulation.builder().addPlugin(testPlugin).build().execute(); + + // precondition test : if the class reference is ambiguous + pluginDataBuilder.addTestDataManager("dm3A", () -> new TestDataManager3A()); + pluginDataBuilder.addTestDataManager("dm3B", () -> new TestDataManager3B()); + + // show that ambiguous class matching throws an exception + pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { + ContractException contractException = assertThrows(ContractException.class, + () -> c.getDataManager(TestDataManager3.class)); + assertEquals(NucleusError.AMBIGUOUS_DATA_MANAGER_CLASS, contractException.getErrorType()); + })); + + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { + })); + + // build the action plugin + testPluginData = pluginDataBuilder.build(); + testPlugin = TestPlugin.getTestPlugin(testPluginData); + + TestSimulation.builder().addPlugin(testPlugin).build().execute(); + + // Precondition test 2 + pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { + ContractException contractException = assertThrows(ContractException.class, () -> c.getDataManager(null)); + assertEquals(NucleusError.NULL_DATA_MANAGER_CLASS, contractException.getErrorType()); + })); + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { + })); + // build the action plugin + testPluginData = pluginDataBuilder.build(); + testPlugin = TestPlugin.getTestPlugin(testPluginData); + + TestSimulation.builder().addPlugin(testPlugin).build().execute(); + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "getReportId", args = {}) + public void testGetReportId() { + TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); + + double testTime = 1; + // there are no precondition tests + + Set observedReportIds = new LinkedHashSet<>(); + Set expectedReportIds = new LinkedHashSet<>(); + for (int i = 0; i < 3; i++) { + expectedReportIds.add(new ReportId(i)); + } + + /* + * Have actors get their own actor ids and show that these ids match the + * expected values established during the initialization of the TestReports. + */ + pluginDataBuilder.addTestReportPlan("Alpha", new TestReportPlan(testTime++, (c) -> { + ReportId reportId = c.getReportId(); + observedReportIds.add(reportId); + assertNotNull(reportId); + + })); + + pluginDataBuilder.addTestReportPlan("Beta", new TestReportPlan(testTime++, (c) -> { + ReportId reportId = c.getReportId(); + observedReportIds.add(reportId); + assertNotNull(reportId); + + })); + + pluginDataBuilder.addTestReportPlan("Gamma", new TestReportPlan(testTime++, (c) -> { + ReportId reportId = c.getReportId(); + observedReportIds.add(reportId); + assertNotNull(reportId); + + })); + + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { + assertEquals(expectedReportIds, observedReportIds); + })); + + // build the plugin + TestPluginData testPluginData = pluginDataBuilder.build(); + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); + + TestSimulation.builder().addPlugin(testPlugin).build().execute(); + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "getScheduledSimulationHaltTime", args = {}) + public void testGetScheduledSimulationHaltTime() { + Set stopTimes = new LinkedHashSet<>(); + + stopTimes.add(4.6); + stopTimes.add(13.0); + stopTimes.add(554.3); + stopTimes.add(7.9); + stopTimes.add(400.2); + stopTimes.add(3000.1); + + for (Double stopTime : stopTimes) { + TestPluginData testPluginData = TestPluginData.builder() + .addTestReportPlan("report plan", new TestReportPlan(0, (context) -> { + assertEquals(stopTime, context.getScheduledSimulationHaltTime()); + })).addTestActorPlan("actor", new TestActorPlan(1, (c) -> { + })).build(); + + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); + + TestSimulation.builder().setSimulationHaltTime(stopTime).addPlugin(testPlugin).build().execute(); + } + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "getTime", args = {}) + public void testGetTime() { + Set planTimes = new LinkedHashSet<>(); + + planTimes.add(4.6); + planTimes.add(13.8764); + planTimes.add(554.345); + planTimes.add(7.95346); + planTimes.add(400.234234); + planTimes.add(3000.12422346); + + /* + * Have a report build plans to check the time in the simulation against the + * planning time + */ + testConsumer((context1) -> { + for (Double planTime : planTimes) { + context1.addPlan((context2) -> { + assertEquals(planTime.doubleValue(), context2.getTime(), 0); + }, planTime); + } + }); + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "releaseOutput", args = { Object.class }) + public void testReleaseOutput() { + // begin building the action plugin + TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); + + // set up the expected output + Set expectedOutput = new LinkedHashSet<>(); + expectedOutput.add("the sly fox"); + expectedOutput.add(15); + expectedOutput.add("the lazy, brown dog"); + expectedOutput.add(45.34513453); + + // have the agent release the output + pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(1, (c) -> { + for (Object outputValue : expectedOutput) { + c.releaseOutput(outputValue); + } + })); + + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { + })); + + // build the plugin + TestPluginData testPluginData = pluginDataBuilder.build(); + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); + + /* + * Add an output consumer that will place the output into the actualOutput set + * above and then execute the simulation + */ + TestOutputConsumer testOutputConsumer = TestSimulation.builder().addPlugin(testPlugin).build().execute(); + + Map outputItems = testOutputConsumer.getOutputItemMap(Object.class); + for (Object key : outputItems.keySet()) { + Integer count = outputItems.get(key); + assertEquals(1, count.intValue()); + } + + // show that the output matches expectations + assertTrue(outputItems.keySet().containsAll(expectedOutput)); + } + + private static class TestEvent1 implements Event { + + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "subscribe", args = { Class.class, BiConsumer.class }) + public void testSubscribe() { + TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); + + MutableBoolean observed = new MutableBoolean(); + + // have the report subscribe for test events. + pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { + c.subscribe(TestEvent1.class, (c2, e) -> { + observed.setValue(true); + }); + })); + + // create a data manager that will generate a test event + + pluginDataBuilder.addTestDataManager("generator", () -> new TestDataManager()); + pluginDataBuilder.addTestDataManagerPlan("generator", new TestDataManagerPlan(1, (c) -> { + c.releaseObservationEvent(new TestEvent1()); + })); + + /* + * show that report received the event + */ + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { + assertTrue(observed.getValue()); + })); + + // build the plugin + TestPluginData testPluginData = pluginDataBuilder.build(); + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); + + // build and execute the engine + TestSimulation.builder().addPlugin(testPlugin).build().execute(); + + // precondition test: if the event class is null + ContractException contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.subscribe(null, (c2, e) -> { + }); + })); + assertEquals(NucleusError.NULL_EVENT_CLASS, contractException.getErrorType()); + + // precondition test: if the event consumer is null + contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.subscribe(TestEvent1.class, null); + })); + assertEquals(NucleusError.NULL_EVENT_CONSUMER, contractException.getErrorType()); + + // precondition test: if the subsciption duplicates another subscription + contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.subscribe(TestEvent1.class, (c2, e) -> { + }); + c.subscribe(TestEvent1.class, (c2, e) -> { + }); + })); + assertEquals(NucleusError.DUPLICATE_EVENT_SUBSCRIPTION, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "subscribeToSimulationClose", args = { Consumer.class }) + public void testSubscribeToSimulationClose() { + TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); + + MutableBoolean simCloseEventHandled = new MutableBoolean(); + + // have a report schedule a few plans and subscribe to simulation close + pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { + c.addPlan((c2) -> { + }, 1); + c.addPlan((c2) -> { + }, 2); + c.addPlan((c2) -> { + }, 3); + c.subscribeToSimulationClose((c2) -> { + simCloseEventHandled.setValue(true); + }); + })); + + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(Double.POSITIVE_INFINITY, (c) -> { + })); + + TestPluginData testPluginData = pluginDataBuilder.build(); + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); + + TestSimulation.builder().addPlugin(testPlugin).build().execute(); + + // show that the subscription to simulation close was successful + assertTrue(simCloseEventHandled.getValue()); + + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "stateRecordingIsScheduled", args = {}) + public void testStateRecordingIsScheduled() { + Set stateRecordingList = new LinkedHashSet<>(); + + stateRecordingList.add(false); + stateRecordingList.add(false); + stateRecordingList.add(true); + stateRecordingList.add(false); + stateRecordingList.add(true); + stateRecordingList.add(true); + + for (Boolean stateRecording : stateRecordingList) { + TestPluginData testPluginData = TestPluginData.builder() + .addTestReportPlan("actor 1", new TestReportPlan(0, (context) -> { + assertEquals(stateRecording, context.stateRecordingIsScheduled()); + })).addTestActorPlan("actor", new TestActorPlan(1, (c) -> { + })).build(); + + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); + + TestSimulation.builder().setSimulationHaltTime(2).setProduceSimulationStateOnHalt(stateRecording) + .addPlugin(testPlugin).build().execute(); + } + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "unsubscribe", args = { Class.class }) + public void testUnsubscribe() { + TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); + + /* + * Create a container to count the number of times a subscription execution + * occurred + */ + MutableInteger observationCount = new MutableInteger(); + + /* + * have the resolver subscribe to the test event and have it handle each type of + * event handling by incrementing a counter + */ + + int taskTime = 0; + + pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(taskTime++, (c) -> { + c.subscribe(TestEvent1.class, (c2, e) -> { + observationCount.increment(); + }); + })); + + // create a data manager that will produce a test event + pluginDataBuilder.addTestDataManager("generator", () -> new TestDataManager()); + pluginDataBuilder.addTestDataManagerPlan("generator", new TestDataManagerPlan(taskTime++, (c) -> { + c.releaseObservationEvent(new TestEvent1()); + })); + + pluginDataBuilder.addTestDataManagerPlan("generator", new TestDataManagerPlan(taskTime++, (c) -> { + c.releaseObservationEvent(new TestEvent1()); + })); + + pluginDataBuilder.addTestDataManagerPlan("generator", new TestDataManagerPlan(taskTime++, (c) -> { + c.releaseObservationEvent(new TestEvent1()); + })); + + /* + * Show that the phaseExecutionCount is three after the the agent is done + */ + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(taskTime++, (c) -> { + assertEquals(3, observationCount.getValue()); + })); + + // have the report unsubscribe + pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(taskTime++, (c) -> { + c.unsubscribe(TestEvent1.class); + })); + + // have the data manager generate another test event + pluginDataBuilder.addTestDataManagerPlan("generator", new TestDataManagerPlan(taskTime++, (c) -> { + c.releaseObservationEvent(new TestEvent1()); + })); + + /* + * Show that the observation count is still three + */ + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(taskTime++, (c) -> { + assertEquals(3, observationCount.getValue()); + })); + + // build the plugin + TestPluginData testPluginData = pluginDataBuilder.build(); + Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); + + // build and execute the engine + TestSimulation.builder().addPlugin(testPlugin).build().execute(); + + // precondition test: if the event class reference is null + ContractException contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { + c.unsubscribe(null); + })); + assertEquals(NucleusError.NULL_EVENT_CLASS, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = ReportContext.class, name = "getSimulationTime", args = { LocalDateTime.class }) + public void testGetSimulationTime() { + LocalDate localDate = LocalDate.of(2020, 4, 1); List localDateTimes = new ArrayList<>(); @@ -651,19 +664,21 @@ public void testGetSimulationTime() { localDateTimes.add(LocalDateTime.of(2020, 3, 15, 22, 13, 18)); localDateTimes.add(LocalDateTime.of(2023, 12, 25, 15, 38, 19)); - TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { - SimulationTimeConverter simulationTimeConverter = new SimulationTimeConverter( LocalDateTime.of(localDate, LocalTime.of(0, 0))); - for(LocalDateTime localDateTime : localDateTimes) { - assertEquals(simulationTimeConverter.getSimulationTime(localDateTime), c.getSimulationTime(localDateTime)); + SimulationTimeConverter simulationTimeConverter = new SimulationTimeConverter( + LocalDateTime.of(localDate, LocalTime.of(0, 0))); + for (LocalDateTime localDateTime : localDateTimes) { + assertEquals(simulationTimeConverter.getSimulationTime(localDateTime), + c.getSimulationTime(localDateTime)); } - + })); - - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(1, (c) -> {})); - + + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(1, (c) -> { + })); + TestPluginData testPluginData = pluginDataBuilder.build(); Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); @@ -677,7 +692,6 @@ public void testGetSimulationTime() { @UnitTestMethod(target = ReportContext.class, name = "getLocalDateTime", args = { double.class }) public void testGetLocalDateTime() { - LocalDate localDate = LocalDate.of(2020, 4, 1); List times = new ArrayList<>(); times.add(-5.7); @@ -689,14 +703,16 @@ public void testGetLocalDateTime() { TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (c) -> { - SimulationTimeConverter simulationTimeConverter = new SimulationTimeConverter(LocalDateTime.of(localDate, LocalTime.of(0, 0))); + SimulationTimeConverter simulationTimeConverter = new SimulationTimeConverter( + LocalDateTime.of(localDate, LocalTime.of(0, 0))); for (Double time : times) { assertEquals(simulationTimeConverter.getLocalDateTime(time), c.getLocalDateTime(time)); } })); - - pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(1, (c) -> {})); - + + pluginDataBuilder.addTestActorPlan("actor", new TestActorPlan(1, (c) -> { + })); + TestPluginData testPluginData = pluginDataBuilder.build(); Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData); @@ -705,8 +721,7 @@ public void testGetLocalDateTime() { } - - @Test + @Test @UnitTestMethod(target = ReportContext.class, name = "retrievePlans", args = {}) public void testRetrievePlans() { TestPluginData.Builder pluginDataBuilder = TestPluginData.builder(); @@ -722,8 +737,9 @@ public void testRetrievePlans() { List expectedPlans = new ArrayList<>(); double haltTime = 50; - for(int i = 1; i <= 100; i++) { - ReportPlan actorPlan = new ReportPlan(i, (c) -> {}); + for (int i = 1; i <= 100; i++) { + ReportPlan actorPlan = new ConsumerReportPlan(i, (c) -> { + }); if (i > 50) { expectedPlans.add(actorPlan); } @@ -734,7 +750,7 @@ public void testRetrievePlans() { */ pluginDataBuilder.addTestReportPlan("report", new TestReportPlan(0, (context) -> { - for(ReportPlan plan : dmPlans) { + for (ReportPlan plan : dmPlans) { context.addPlan(plan); } @@ -748,8 +764,7 @@ public void testRetrievePlans() { // run the simulation Simulation.builder()// .addPlugin(testPlugin)// - .setSimulationHaltTime(haltTime) - .build()// + .setSimulationHaltTime(haltTime).build()// .execute();// } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportPlan.java index cf1d22038..adf446eda 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportPlan.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportPlan.java @@ -1,9 +1,5 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.util.function.Consumer; - import org.junit.jupiter.api.Test; import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; @@ -11,24 +7,14 @@ public class AT_ReportPlan { @Test - @UnitTestConstructor(target = ReportPlan.class, args = { double.class, Consumer.class }) + @UnitTestConstructor(target = ReportPlan.class, args = { double.class}) public void testConstructor() { - for (int i = 0; i < 10; i++) { - ReportPlan reportPlan = new ReportPlan(i, (c) -> { - }); - - assertNotNull(reportPlan); - } + //nothing to test } @Test - @UnitTestConstructor(target = ReportPlan.class, args = { double.class, long.class, Consumer.class }) + @UnitTestConstructor(target = ReportPlan.class, args = { double.class, long.class}) public void testConstructor_Arrival() { - for (int i = 0; i < 10; i++) { - ReportPlan reportPlan = new ReportPlan(i, (long) i, (c) -> { - }); - - assertNotNull(reportPlan); - } + //nothing to test } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/testplugin/AT_TestActorPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/testplugin/AT_TestActorPlan.java index 6e12b0c57..3c958941d 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/testplugin/AT_TestActorPlan.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/testsupport/testplugin/AT_TestActorPlan.java @@ -95,11 +95,10 @@ public void testHashCode() { TestActorPlan plan2 = new TestActorPlan(4.5, (c) -> { }); assertEquals(plan1.hashCode(), plan2.hashCode()); - - // via the copy constructor - plan1 = new TestActorPlan(4.5, (c) -> { - }); - plan2 = new TestActorPlan(plan1); + + + plan1.execute(null); + plan2.execute(null); assertEquals(plan1.hashCode(), plan2.hashCode()); } From b276d682fe243e5f7e0ae9e2a9e8191db85ce21a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:50:04 -0400 Subject: [PATCH 07/15] Bump the test-dependencies group with 2 updates (#244) Bumps the test-dependencies group with 2 updates: [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) and [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5). Updates `org.junit.jupiter:junit-jupiter-api` from 5.10.2 to 5.10.3 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.2...r5.10.3) Updates `org.junit.jupiter:junit-jupiter-engine` from 5.10.2 to 5.10.3 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.2...r5.10.3) Updates `org.junit.jupiter:junit-jupiter-engine` from 5.10.2 to 5.10.3 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.2...r5.10.3) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-patch dependency-group: test-dependencies - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:development update-type: version-update:semver-patch dependency-group: test-dependencies - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:development update-type: version-update:semver-patch dependency-group: test-dependencies ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0161e32ce..ff2c06a22 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ 4.2.0-SNAPSHOT 0.8.12 - 5.10.2 + 5.10.3 From bf2eb050b16900d3a30c7f2277680fde4615f502 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:50:15 -0400 Subject: [PATCH 08/15] Bump the standard-plugins group across 1 directory with 3 updates (#246) Bumps the standard-plugins group with 3 updates in the / directory: [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire), [org.apache.maven.plugins:maven-failsafe-plugin](https://github.com/apache/maven-surefire) and [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin). Updates `org.apache.maven.plugins:maven-surefire-plugin` from 3.2.5 to 3.3.1 - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.3.1) Updates `org.apache.maven.plugins:maven-failsafe-plugin` from 3.2.5 to 3.3.1 - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.3.1) Updates `org.apache.maven.plugins:maven-javadoc-plugin` from 3.7.0 to 3.8.0 - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.7.0...maven-javadoc-plugin-3.8.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor dependency-group: standard-plugins - dependency-name: org.apache.maven.plugins:maven-failsafe-plugin dependency-type: direct:production update-type: version-update:semver-minor dependency-group: standard-plugins - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor dependency-group: standard-plugins ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index ff2c06a22..4ff7fe1ff 100644 --- a/pom.xml +++ b/pom.xml @@ -60,12 +60,12 @@ 1.6.0 - 3.2.5 - 3.2.5 + 3.3.1 + 3.3.1 3.3.1 3.1.2 3.1.2 - 3.7.0 + 3.8.0 3.2.4 0.5.0 From 6e61d7088e07322e3b0187594de69da0c9c4aade Mon Sep 17 00:00:00 2001 From: Zachary Bischoff <116595361+bischoffz@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:52:05 -0400 Subject: [PATCH 09/15] update to taskit 5.0 (#248) --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4ff7fe1ff..255ea4ecc 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ - 4.3.0-SNAPSHOT + 4.3.1-SNAPSHOT UTF-8 @@ -70,7 +70,7 @@ 0.5.0 - 4.2.0-SNAPSHOT + 5.0.0-SNAPSHOT 0.8.12 5.10.3 From da1605cba388404a02bb694a3de509a4b69c5583 Mon Sep 17 00:00:00 2001 From: Zachary Bischoff <116595361+bischoffz@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:48:59 -0400 Subject: [PATCH 10/15] add feature to send a event to a specific actor (#251) * add feature to send a event to a specific actor * addresses issue #247 --- .../vaccine/VaccinationDataManager.java | 2 +- .../nucleus/DataManagerContext.java | 29 +++++++--- .../ms/gcm/simulation/nucleus/Simulation.java | 54 +++++++++++++++++++ 3 files changed, 77 insertions(+), 8 deletions(-) diff --git a/lessons/lesson-07/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/vaccine/VaccinationDataManager.java b/lessons/lesson-07/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/vaccine/VaccinationDataManager.java index 5f45e5964..a8e548671 100644 --- a/lessons/lesson-07/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/vaccine/VaccinationDataManager.java +++ b/lessons/lesson-07/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/vaccine/VaccinationDataManager.java @@ -75,7 +75,7 @@ public List getUnvaccinatedFamilyMembers(PersonId personId) { List familyMembers = familyDataManager.getFamilyMembers(familyId); for (PersonId familyMemeberId : familyMembers) { if (!isPersonVaccinated(familyMemeberId)) { - result.add(personId); + result.add(familyMemeberId); } } } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java index 0dfce12e8..f36786af8 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java @@ -27,7 +27,7 @@ protected DataManagerContext(DataManagerId dataManagerId, Simulation simulation) * executed at the given time. * * @throws ContractException - *
    + *
      *
    • {@link NucleusError#NULL_PLAN_CONSUMER} if the * consumer is null
    • *
    • {@link NucleusError#PAST_PLANNING_TIME} if the @@ -36,7 +36,6 @@ protected DataManagerContext(DataManagerId dataManagerId, Simulation simulation) * the plan is added to the simulation after event * processing is finished
    • *
    - * */ public void addPlan(final Consumer consumer, final double planTime) { simulation.addDataManagerPlan(dataManagerId, new ConsumerDataManagerPlan(planTime, consumer)); @@ -50,13 +49,12 @@ public void addPlan(final Consumer consumer, final double pl * plans (having arrival id = -1) are scheduled in the planning queue with * higher arrival ids than all the serialized plans. * - * * @throws ContractException *
      *
    • {@link NucleusError#NULL_PLAN} if the plan is * null
    • - *
    • {@link NucleusError#INVALID_PLAN_ARRIVAL_ID} if the - * arrival id is less than -1
    • + *
    • {@link NucleusError#INVALID_PLAN_ARRIVAL_ID} if + * the arrival id is less than -1
    • *
    • {@link NucleusError#PAST_PLANNING_TIME} if the * plan is scheduled for a time in the past *
    • *
    • {@link NucleusError#PLANNING_QUEUE_CLOSED} if @@ -64,7 +62,7 @@ public void addPlan(final Consumer consumer, final double pl * processing is finished
    • *
    */ - public void addPlan(DataManagerPlan plan) { + public void addPlan(DataManagerPlan plan) { simulation.addDataManagerPlan(dataManagerId, plan); } @@ -111,6 +109,24 @@ public void releaseObservationEvent(final Event event) { simulation.releaseObservationEventForDataManager(event); } + /** + * Broadcasts the given event to a single actor. This is used + * for OBSERVATION events that are generated by the data managers. MUTATION + * events that are generated by the data managers as a proxy for actors and data + * managers should use releaseMutationEvent() instead. + * + * @throws ContractException + *
      + *
    • {@link NucleusError#NULL_EVENT} if the event is + * null
    • + *
    • {@link NucleusError#NULL_ACTOR_ID} if the + * actorId is null
    • + *
    + */ + public void releaseObservationEventToActor(final Event event, final ActorId actorId) { + simulation.releaseObservationEventForDataManagerToActor(event, actorId); + } + /** * Starts the event handling process for the given event This is used for * MUTATION events. @@ -243,7 +259,6 @@ public LocalDateTime getLocalDateTime(double simulationTime) { * if this method is invoked before the termination of * the simulation *
- * */ public List retrievePlans() { return simulation.retrievePlansForDataManager(dataManagerId); diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Simulation.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Simulation.java index 739916cf5..5095719f3 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Simulation.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/Simulation.java @@ -1116,6 +1116,23 @@ protected void unsubscribeReportFromEvent(Class eventClass) { } + protected void releaseObservationEventForDataManagerToActor(final Event event, final ActorId actorId) { + if (event == null) { + throw new ContractException(NucleusError.NULL_EVENT); + } + + if (actorId == null) { + throw new ContractException(NucleusError.NULL_ACTOR_ID); + } + + if (!dataManagerQueueActive) { + throw new ContractException(NucleusError.OBSERVATION_EVENT_IMPROPER_RELEASE); + } + + // queue the event handling for actors + broadcastEventToFilterNodeAndActor(event, rootNode, actorId); + } + protected void releaseObservationEventForDataManager(final Event event) { if (event == null) { @@ -1474,6 +1491,43 @@ protected boolean subscribersExistForEvent(Class eventClass) { || rootNode.children.containsKey(eventClass) || rootNode.consumers.containsKey(eventClass)); } + /* + * Recursively processes the event through the filter node to the given actor. Events should be + * processed through the root filter node. Each node's consumers have each such + * consumer scheduled onto the actor queue for delayed execution of the + * consumer. + */ + private void broadcastEventToFilterNodeAndActor(final Event event, FilterNode filterNode, ActorId actorId) { + // determine the value of the function for the given event + Object value = filterNode.function.apply(event); + + // use that value to place any consumers that are matched to that value + // on the actor queue + Map> consumerMap = filterNode.consumers.get(value); + if (consumerMap != null) { + if (consumerMap.containsKey(actorId)) { + Consumer consumer = consumerMap.get(actorId); + final ActorContentRec actorContentRec = new ActorContentRec(); + actorContentRec.event = event; + actorContentRec.actorId = actorId; + actorContentRec.eventConsumer = consumer; + actorQueue.add(actorContentRec); + } + } + + // match the value to any child nodes and recursively call this method + // on that node + Map, FilterNode> childMap = filterNode.children.get(value); + if (childMap != null) { + for (Object id : childMap.keySet()) { + FilterNode childNode = childMap.get(id); + if (childNode != null) { + broadcastEventToFilterNodeAndActor(event, childNode, actorId); + } + } + } + } + /* * Recursively processes the event through the filter node . Events should be * processed through the root filter node. Each node's consumers have each such From 7cfc55fec79e5fe922bb7fb856c09de911c6699a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:49:13 -0400 Subject: [PATCH 11/15] Bump the test-dependencies group with 2 updates (#250) Bumps the test-dependencies group with 2 updates: [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) and [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5). Updates `org.junit.jupiter:junit-jupiter-api` from 5.10.3 to 5.11.0 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.3...r5.11.0) Updates `org.junit.jupiter:junit-jupiter-engine` from 5.10.3 to 5.11.0 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.3...r5.11.0) Updates `org.junit.jupiter:junit-jupiter-engine` from 5.10.3 to 5.11.0 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.3...r5.11.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-minor dependency-group: test-dependencies - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:development update-type: version-update:semver-minor dependency-group: test-dependencies - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:development update-type: version-update:semver-minor dependency-group: test-dependencies ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 255ea4ecc..21bbcc7b4 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ 5.0.0-SNAPSHOT 0.8.12 - 5.10.3 + 5.11.0 From 87dc920a09f05d9ac6dc2beaa1b330fc4fa67d60 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:49:22 -0400 Subject: [PATCH 12/15] Bump org.apache.maven.plugins:maven-gpg-plugin (#249) Bumps the standard-plugins group with 1 update: [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin). Updates `org.apache.maven.plugins:maven-gpg-plugin` from 3.2.4 to 3.2.5 - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.4...maven-gpg-plugin-3.2.5) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch dependency-group: standard-plugins ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 21bbcc7b4..1dacc8145 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ 3.1.2 3.1.2 3.8.0 - 3.2.4 + 3.2.5 0.5.0 From 9957b86d1472b5c583acaaaa63dac3a066d5427c Mon Sep 17 00:00:00 2001 From: bischoffz Date: Mon, 19 Aug 2024 19:44:02 -0400 Subject: [PATCH 13/15] change to 4.3.0 proper --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1dacc8145..535fe406a 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ - 4.3.1-SNAPSHOT + 4.3.0 UTF-8 @@ -70,7 +70,7 @@ 0.5.0 - 5.0.0-SNAPSHOT + 5.0.0 0.8.12 5.11.0 From 6518d2f348b34f5d48dea2a61c3545be1c4aaec3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 19:44:26 -0400 Subject: [PATCH 14/15] Bump the standard-plugins group with 2 updates (#252) Bumps the standard-plugins group with 2 updates: [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) and [org.apache.maven.plugins:maven-failsafe-plugin](https://github.com/apache/maven-surefire). Updates `org.apache.maven.plugins:maven-surefire-plugin` from 3.3.1 to 3.4.0 - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.3.1...surefire-3.4.0) Updates `org.apache.maven.plugins:maven-failsafe-plugin` from 3.3.1 to 3.4.0 - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.3.1...surefire-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor dependency-group: standard-plugins - dependency-name: org.apache.maven.plugins:maven-failsafe-plugin dependency-type: direct:production update-type: version-update:semver-minor dependency-group: standard-plugins ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 535fe406a..e00ff3e18 100644 --- a/pom.xml +++ b/pom.xml @@ -60,8 +60,8 @@ 1.6.0 - 3.3.1 - 3.3.1 + 3.4.0 + 3.4.0 3.3.1 3.1.2 3.1.2 From 07c038983599f6545c04a602e41d8daaf14ef284 Mon Sep 17 00:00:00 2001 From: bischoffz Date: Mon, 19 Aug 2024 19:54:08 -0400 Subject: [PATCH 15/15] fix javadoc errors --- simulation/pom.xml | 5 --- .../simulation/nucleus/ConsumerActorPlan.java | 33 ++++++++--------- .../nucleus/ConsumerDataManagerPlan.java | 35 +++++++++---------- .../nucleus/ConsumerReportPlan.java | 26 +++++++------- 4 files changed, 43 insertions(+), 56 deletions(-) diff --git a/simulation/pom.xml b/simulation/pom.xml index 4a12ab589..cae5f6eee 100644 --- a/simulation/pom.xml +++ b/simulation/pom.xml @@ -51,11 +51,6 @@ all,-missing - - gov.hhs.aspr.ms - util - ${util.version} - org.junit.jupiter junit-jupiter-api diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java index 82dbb58b6..d51a15e9c 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java @@ -12,12 +12,11 @@ public final class ConsumerActorPlan extends ActorPlan { * Constructs the plan scheduled for the given time active status arrivalId and * consumer * - * @throw {@link ContractException} - *
    - *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
  • - *
- * + * @throws ContractException + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if + * the consumer is null
  • + *
*/ public ConsumerActorPlan(double time, boolean active, long arrivalId, Consumer consumer) { super(time, active, arrivalId); @@ -32,12 +31,11 @@ public ConsumerActorPlan(double time, boolean active, long arrivalId, Consumer - *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
  • - * - * + * @throws ContractException + *
      + *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if + * the consumer is null
    • + *
    */ public ConsumerActorPlan(double time, Consumer consumer) { super(time); @@ -52,12 +50,11 @@ public ConsumerActorPlan(double time, Consumer consumer) { * The arrival id is set to -1L indicating that this is a new, non-deserialized * plan. * - * @throw {@link ContractException} - *
      - *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
    • - *
    - * + * @throws ContractException + *
      + *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if + * the consumer is null
    • + *
    */ public ConsumerActorPlan(double time, boolean active, Consumer consumer) { super(time, active); diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java index d342e68fb..fa9129342 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java @@ -5,19 +5,18 @@ import gov.hhs.aspr.ms.util.errors.ContractException; public class ConsumerDataManagerPlan extends DataManagerPlan { - + private final Consumer consumer; /** * Constructs the plan scheduled for the given time active status arrivalId and * consumer * - * @throw {@link ContractException} - *
      - *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
    • - *
    - * + * @throws ContractException + *
      + *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if + * the consumer is null
    • + *
    */ public ConsumerDataManagerPlan(double time, boolean active, long arrivalId, Consumer consumer) { super(time, active, arrivalId); @@ -33,12 +32,11 @@ public ConsumerDataManagerPlan(double time, boolean active, long arrivalId, Cons * The arrival id is set to -1L indicating that this is a new, non-deserialized * plan. * - * @throw {@link ContractException} - *
      - *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
    • - *
    - * + * @throws ContractException + *
      + *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if + * the consumer is null
    • + *
    */ public ConsumerDataManagerPlan(double time, boolean active, Consumer consumer) { super(time, active); @@ -53,12 +51,11 @@ public ConsumerDataManagerPlan(double time, boolean active, Consumer - *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
  • - * - * + * @throws ContractException + *
      + *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if + * the consumer is null
    • + *
    */ public ConsumerDataManagerPlan(double time, Consumer consumer) { super(time); diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java index 1487cbe2f..48518bc78 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java @@ -5,19 +5,18 @@ import gov.hhs.aspr.ms.util.errors.ContractException; public class ConsumerReportPlan extends ReportPlan { - + private final Consumer consumer; /** * Constructs the plan scheduled for the given time, arrivalId and consumer. * Report plans are always passive. * - * @throw {@link ContractException} - *
      - *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
    • - *
    - * + * @throws ContractException + *
      + *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if + * the consumer is null
    • + *
    */ public ConsumerReportPlan(double time, long arrivalId, Consumer consumer) { super(time, arrivalId); @@ -32,12 +31,11 @@ public ConsumerReportPlan(double time, long arrivalId, Consumer c * are always passive.The arrival id is set to -1L indicating that this is a * new, non-deserialized plan. * - * @throw {@link ContractException} - *
      - *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
    • - *
    - * + * @throws ContractException + *
      + *
    • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if + * the consumer is null
    • + *
    */ public ConsumerReportPlan(double time, Consumer consumer) { super(time); @@ -48,7 +46,7 @@ public ConsumerReportPlan(double time, Consumer consumer) { } @Override - protected void execute(ReportContext context) { + protected void execute(ReportContext context) { this.consumer.accept(context); } }