From d351c571addc4f2098c0fabe487e79f186c312f3 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Wed, 17 Apr 2024 15:51:02 -0400 Subject: [PATCH] Add deployment test data job --- .../service/DeploymentTestDataService.java | 2 +- .../support/jobs/DeploymentTestDataJob.java | 53 +++++++++++++++++++ .../src/main/resources/application.properties | 4 ++ .../service/DeploymentTestDataServiceIT.java | 2 +- .../support/jobs/ScheduledJobsTest.java | 16 +++++- 5 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/jobs/DeploymentTestDataJob.java diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java index fb4875e9b..563b6494b 100644 --- a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Johns Hopkins University + * Copyright 2024 Johns Hopkins University * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/jobs/DeploymentTestDataJob.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/jobs/DeploymentTestDataJob.java new file mode 100644 index 000000000..d5eeb0c09 --- /dev/null +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/jobs/DeploymentTestDataJob.java @@ -0,0 +1,53 @@ +/* + * Copyright 2024 Johns Hopkins University + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.eclipse.pass.deposit.support.jobs; + +import org.eclipse.pass.deposit.service.DeploymentTestDataService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@ConditionalOnExpression( + "'${pass.test.data.job.enabled}'=='true' and '${pass.deposit.jobs.disabled}'=='false'" +) +@Component +public class DeploymentTestDataJob { + + private static final Logger LOG = LoggerFactory.getLogger(DeploymentTestDataJob.class); + + private final DeploymentTestDataService deploymentTestDataService; + + public DeploymentTestDataJob(DeploymentTestDataService deploymentTestDataService) { + this.deploymentTestDataService = deploymentTestDataService; + } + + @Scheduled( + fixedDelayString = "${pass.test.data.job.interval-ms}", + initialDelayString = "${pass.deposit.jobs.3.init.delay}" + ) + public void processDeploymentTestData() { + LOG.warn("Starting {}", this.getClass().getSimpleName()); + try { + deploymentTestDataService.processTestData(); + } catch (Exception e) { + LOG.error("DeploymentTestDataJob execution failed: {}", e.getMessage(), e); + } + LOG.warn("Finished {}", this.getClass().getSimpleName()); + } + +} diff --git a/pass-deposit-services/deposit-core/src/main/resources/application.properties b/pass-deposit-services/deposit-core/src/main/resources/application.properties index cdddd1c18..b5c19de7d 100644 --- a/pass-deposit-services/deposit-core/src/main/resources/application.properties +++ b/pass-deposit-services/deposit-core/src/main/resources/application.properties @@ -48,6 +48,7 @@ pass.deposit.jobs.disabled=false pass.deposit.jobs.default-interval-ms=600000 pass.deposit.jobs.1.init.delay=5000 pass.deposit.jobs.2.init.delay=10000 +pass.deposit.jobs.3.init.delay=20000 jscholarship.hack.sword.statement.uri-prefix=http://dspace-prod.mse.jhu.edu:8080/swordv2/ jscholarship.hack.sword.statement.uri-replacement=https://jscholarship.library.jhu.edu/swordv2/ @@ -67,5 +68,8 @@ pass.deposit.nihms.email.delay=720000 pass.deposit.nihms.email.auth=${NIHMS_MAIL_AUTH:LOGIN} pass.deposit.nihms.email.from=${PASS_DEPOSIT_NIHMS_EMAIL_FROM:nihms-help@ncbi.nlm.nih.gov} +pass.test.data.job.enabled=false +# Run every 12 hours +pass.test.data.job.interval-ms=43200000 pass.test.data.policy.title=${TEST_DATA_POLICY_TITLE:} pass.test.data.user.email=${TEST_DATA_USER_EMAIL:} diff --git a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java index a400d3f32..9fb0bf6d7 100644 --- a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java +++ b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Johns Hopkins University + * Copyright 2024 Johns Hopkins University * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/support/jobs/ScheduledJobsTest.java b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/support/jobs/ScheduledJobsTest.java index 3aef6df91..8e583a374 100644 --- a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/support/jobs/ScheduledJobsTest.java +++ b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/support/jobs/ScheduledJobsTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.verify; import org.eclipse.pass.deposit.DepositApp; +import org.eclipse.pass.deposit.service.DeploymentTestDataService; import org.eclipse.pass.deposit.service.DepositUpdater; import org.eclipse.pass.deposit.service.SubmissionStatusUpdater; import org.junit.jupiter.api.Test; @@ -34,14 +35,18 @@ @TestPropertySource("classpath:test-application.properties") @TestPropertySource(properties = { "pass.deposit.jobs.disabled=false", + "pass.test.data.job.enabled=true", "pass.deposit.jobs.default-interval-ms=1500", + "pass.test.data.job.interval-ms=1500", "pass.deposit.jobs.1.init.delay=50", - "pass.deposit.jobs.2.init.delay=100" + "pass.deposit.jobs.2.init.delay=100", + "pass.deposit.jobs.3.init.delay=120" }) public class ScheduledJobsTest { @MockBean private SubmissionStatusUpdater submissionStatusUpdater; @MockBean private DepositUpdater depositUpdater; + @MockBean private DeploymentTestDataService deploymentTestDataService; @Test void testDepositUpdaterJob() { @@ -61,4 +66,13 @@ void testSubmissionStatusUpdaterJob() { }); } + @Test + void testDeploymentTestDataJob() { + // GIVEN/WHEN + // deploymentTestDataService.processTestData() will be called from Scheduled method in job + await().atMost(3, SECONDS).untilAsserted(() -> { + verify(deploymentTestDataService).processTestData(); + }); + } + }