Add timeout to async test-cases 46/123546/1
authorRenu Kumari <renu.kumari@bell.ca>
Wed, 25 Aug 2021 13:32:35 +0000 (09:32 -0400)
committerRenu Kumari <renu.kumari@bell.ca>
Wed, 25 Aug 2021 13:32:35 +0000 (09:32 -0400)
Issue-ID: CPS-526
Signed-off-by: Renu Kumari <renu.kumari@bell.ca>
Change-Id: Icf46f94090a615bf945eb70b58edf86c0c509155

cps-service/src/main/java/org/onap/cps/config/AsyncConfig.java
cps-service/src/main/java/org/onap/cps/notification/NotificationService.java
cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy

index 3ae675e..4c96159 100644 (file)
@@ -42,7 +42,7 @@ public class AsyncConfig {
     @Min(2)
     private int maxPoolSize = 10;
     @Min(0)
-    private int queueCapacity = 2147483647;
+    private int queueCapacity = Integer.MAX_VALUE;
     private boolean waitForTasksToCompleteOnShutdown = true;
     private String threadNamePrefix = "Async-";
 
index 9ed8b65..4745739 100644 (file)
@@ -79,6 +79,7 @@ public class NotificationService {
      *
      * @param dataspaceName dataspace name
      * @param anchorName    anchor name
+     * @return future
      */
     @Async("notificationExecutor")
     public Future<Void> processDataUpdatedEvent(final String dataspaceName, final String anchorName) {
index 0a2d3d9..ab72767 100644 (file)
@@ -32,6 +32,8 @@ import org.springframework.test.context.ContextConfiguration
 import spock.lang.Shared
 import spock.lang.Specification
 
+import java.util.concurrent.TimeUnit
+
 @SpringBootTest
 @EnableAsync
 @EnableConfigurationProperties
@@ -71,9 +73,11 @@ class NotificationServiceSpec extends Specification {
             mockCpsDataUpdatedEventFactory.createCpsDataUpdatedEvent(dataspaceName, myAnchorName) >> cpsDataUpdatedEvent
         when: 'dataUpdatedEvent is received'
             def future = objectUnderTest.processDataUpdatedEvent(dataspaceName, myAnchorName)
-        and: 'async processing is completed'
-            future.get()
-        then: 'notification is sent'
+        and: 'wait for async processing is completed'
+            future.get(10, TimeUnit.SECONDS)
+        then: 'async process completed successfully'
+            future.isDone()
+        and: 'notification is sent'
             expectedSendNotificationCount * mockNotificationPublisher.sendNotification(cpsDataUpdatedEvent)
         where:
             scenario                               | dataspaceName            || expectedSendNotificationCount
@@ -89,9 +93,11 @@ class NotificationServiceSpec extends Specification {
                 { throw new Exception("Could not create event") }
         when: 'event is sent for processing'
             def future = objectUnderTest.processDataUpdatedEvent(myDataspacePublishedName, myAnchorName)
-        and: 'async processing is completed'
-            future.get()
-        then: 'error is handled and not thrown to caller'
+        and: 'wait for async processing is completed'
+            future.get(10, TimeUnit.SECONDS)
+        then: 'async process completed successfully'
+            future.isDone()
+        and: 'error is handled and not thrown to caller'
             notThrown Exception
             1 * spyNotificationErrorHandler.onException(_, _, _, _)
     }