Skip to content

Commit

Permalink
Add deployment test data job
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Apr 17, 2024
1 parent c5b7f24 commit d351c57
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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:[email protected]}

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:}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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();
});
}

}

0 comments on commit d351c57

Please sign in to comment.