Add graceful shutdown for Session Manager
[cps.git] / cps-ri / src / test / groovy / org / onap / cps / spi / utils / SessionManagerIntegrationSpec.groovy
index 9b58c8b..a1f6d58 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.cps.spi.utils
 
+import org.onap.cps.spi.config.CpsSessionFactory
 import org.onap.cps.spi.exceptions.SessionManagerException
 import org.onap.cps.spi.impl.CpsPersistenceSpecBase
 import org.springframework.beans.factory.annotation.Autowired
@@ -32,6 +33,9 @@ class SessionManagerIntegrationSpec extends CpsPersistenceSpecBase{
     @Autowired
     SessionManager objectUnderTest
 
+    @Autowired
+    CpsSessionFactory cpsSessionFactory
+
     def sessionId
     def shortTimeoutForTesting = 200L
 
@@ -40,7 +44,7 @@ class SessionManagerIntegrationSpec extends CpsPersistenceSpecBase{
     }
 
     def cleanup(){
-        objectUnderTest.closeSession(sessionId)
+        objectUnderTest.closeSession(sessionId, objectUnderTest.WITH_COMMIT)
     }
 
     @Sql([CLEAR_DATA, SET_DATA])
@@ -62,8 +66,18 @@ class SessionManagerIntegrationSpec extends CpsPersistenceSpecBase{
             def thrown = thrown(SessionManagerException)
             thrown.message.contains('Timeout')
         then: 'when the other session holding the lock is closed, lock can finally be acquired'
-            objectUnderTest.closeSession(otherSessionId)
+            objectUnderTest.closeSession(otherSessionId, objectUnderTest.WITH_COMMIT)
             objectUnderTest.lockAnchor(sessionId,DATASPACE_NAME,ANCHOR_NAME1,shortTimeoutForTesting)
     }
 
+    @Sql([CLEAR_DATA, SET_DATA])
+    def 'Lock anchor twice using the same session.'(){
+        given: 'session that already holds an anchor lock'
+            objectUnderTest.lockAnchor(sessionId, DATASPACE_NAME, ANCHOR_NAME1, shortTimeoutForTesting)
+        when: 'same session tries to acquire same anchor lock'
+            objectUnderTest.lockAnchor(sessionId, DATASPACE_NAME, ANCHOR_NAME1, shortTimeoutForTesting)
+        then: 'no exception is thrown'
+            noExceptionThrown()
+    }
+
 }