Skip to content

Commit

Permalink
fixed review recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
mynecker committed Oct 21, 2024
1 parent 8b8a77e commit 9f1a5b3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion service/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<spring-kafka.version>3.2.4</spring-kafka.version>
<kafka-clients.version>3.5.0</kafka-clients.version>
<jackson.version>2.16.1</jackson.version>
<awaitility.version>4.2.0</awaitility.version>
<dockerfile-maven.version>1.4.13</dockerfile-maven.version>
</properties>
<repositories>
Expand Down Expand Up @@ -293,7 +294,6 @@
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.0</version>
</dependency>

<!-- for testing -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class EventPortalProperties {
private Boolean managed = false;
private String incomingRequestQueueName;

private int waitAckScanCompleteTimeout = 300;
private int waitAckScanCompletePollInterval = 10;
private int waitAckScanCompleteTimeoutSec = 300;
private int waitAckScanCompletePollIntervalSec = 10;

private GatewayProperties gateway
= new GatewayProperties("standalone", "standalone", new GatewayMessagingProperties(true, false, List.of()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void processMessage(ScanCommandMessage message) {

scanManager.scan(scanRequestBO);
//if managed, wait for scan to complete
if (eventPortalProperties.getManaged()) {
if (Boolean.TRUE.equals(eventPortalProperties.getManaged())) {
log.debug("Waiting for scan to complete for scanId: {}", scanId);
waitForScanCompletion(scanId);
}
Expand All @@ -94,8 +94,8 @@ public void processMessage(ScanCommandMessage message) {
public void waitForScanCompletion(String scanId) {
try {
await()
.atMost(eventPortalProperties.getWaitAckScanCompleteTimeout(), SECONDS)
.pollInterval(eventPortalProperties.getWaitAckScanCompletePollInterval(), SECONDS)
.atMost(eventPortalProperties.getWaitAckScanCompleteTimeoutSec(), SECONDS)
.pollInterval(eventPortalProperties.getWaitAckScanCompletePollIntervalSec(), SECONDS)
.pollInSameThread()
.until(() -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void testFindById() {
@ParameterizedTest
@ValueSource(strings = {"COMPLETE", "FAILED", "TIMED_OUT"})
@SneakyThrows
public void testIsScanCompleteIsComplete(String scanStatus) {
public void testScanStatusCompletionWithSingleScan(String scanStatus) {
ScanStatusEntity scanStatusA = scanServiceHelper.buildScanStatusEntity("status1", scanStatus);
ScanTypeEntity scanTypeA = scanServiceHelper.buildScanTypeEntity("123", "queueListing", null, scanStatusA);

Expand All @@ -360,7 +360,7 @@ public void testIsScanCompleteIsComplete(String scanStatus) {
@ParameterizedTest
@ValueSource(strings = {"IN_PROGRESS", "INITIATED"})
@SneakyThrows
public void testIsScanCompleteIsNotComplete(String scanStatus) {
public void testScanStatusIncompleteWithSingleScan(String scanStatus) {
ScanStatusEntity scanStatusA = scanServiceHelper.buildScanStatusEntity("status1", scanStatus);
ScanTypeEntity scanTypeA = scanServiceHelper.buildScanTypeEntity("123", "queueListing", null, scanStatusA);

Expand All @@ -372,22 +372,11 @@ public void testIsScanCompleteIsNotComplete(String scanStatus) {
Assertions.assertFalse(scanService.isScanComplete("scan1"));
}

@Test
@SneakyThrows
public void testIsScanCompleteIsNotCompleteEmptyScanTypeList() {
ScanStatusEntity scanStatusA = scanServiceHelper.buildScanStatusEntity("status1", "COMPLETE");

when(scanTypeRepository.findAllByScanId(any(String.class)))
.thenReturn(List.of());
when(scanStatusRepository.findByScanType(any(ScanTypeEntity.class)))
.thenReturn(scanStatusA);

Assertions.assertFalse(scanService.isScanComplete("scan1"));
}

@Test
@SneakyThrows
public void testIsScanCompleteIsCompleteScans() {
@Test
@SneakyThrows
public void testScanStatusCompletedWithMultipleScans(){
ScanStatusEntity scanStatusA = scanServiceHelper.buildScanStatusEntity("status1", "COMPLETE");
ScanTypeEntity scanTypeA = scanServiceHelper.buildScanTypeEntity("123", "queueListing", null, scanStatusA);

Expand All @@ -406,7 +395,7 @@ public void testIsScanCompleteIsCompleteScans() {

@Test
@SneakyThrows
public void testIsScanCompleteIsNotCompleteScans() {
public void testScanStatusNotCompleteWithMultipleScans() {
ScanStatusEntity scanStatusA = scanServiceHelper.buildScanStatusEntity("status1", "COMPLETE");
ScanTypeEntity scanTypeA = scanServiceHelper.buildScanTypeEntity("123", "queueListing", null, scanStatusA);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

})
@Slf4j
public class ScanJobPersistentMessageHandlerTests {
class ScanJobPersistentMessageHandlerTests {

@MockBean
private ScanManager scanManager;
Expand Down Expand Up @@ -105,7 +105,7 @@ void testPersistentMessageHandlerScanCommandMsgAcked() {
waitForScanCompletePolling(2);
// the scan command message processor should be called once by the persistent message handler
verify(scanCommandMessageProcessor, times(1)).processMessage(any());
// if the scan is managed, the waitForScanCompletion method should be called
// if the EMA is managed, the waitForScanCompletion method should be called
verify(scanCommandMessageProcessor, atLeastOnce()).waitForScanCompletion(any());
// the message should be acked after the scan is complete
verify(solacePersistentMessageHandler.getPersistentMessageReceiver(), times(1)).ack(inboundMessage);
Expand All @@ -131,7 +131,7 @@ void testPersistentMessageHandlerScanCommandTimeoutMsgAcked() {

// the scan command message processor should be called once by the persistent message handler
verify(scanCommandMessageProcessor, times(1)).processMessage(any());
// if the scan is managed, the waitForScanCompletion method should be called
// if the EMA is managed, the waitForScanCompletion method should be called
verify(scanCommandMessageProcessor, atLeastOnce()).waitForScanCompletion(any());
// the message should be acked after the scan is complete, even though it is timed out
verify(solacePersistentMessageHandler.getPersistentMessageReceiver(), times(1)).ack(inboundMessage);
Expand Down Expand Up @@ -166,7 +166,7 @@ void testPersistentMessageHandlerScanCommandExceptionThrownMsgAcked() {

private void waitForScanCompletePolling(Integer additionalSeconds) {
try {
int timeout =eventPortalProperties.getWaitAckScanCompleteTimeout() + additionalSeconds;
int timeout =eventPortalProperties.getWaitAckScanCompleteTimeoutSec() + additionalSeconds;
Thread.sleep(timeout* 1000L );
} catch (InterruptedException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 9f1a5b3

Please sign in to comment.