summaryrefslogtreecommitdiffstats
path: root/integration-test/src/test/groovy
diff options
context:
space:
mode:
Diffstat (limited to 'integration-test/src/test/groovy')
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy12
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy15
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/functional/SessionManagerIntegrationSpec.groovy73
3 files changed, 90 insertions, 10 deletions
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy
index b942a43af2..a1e03529c3 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy
@@ -25,10 +25,12 @@ import org.onap.cps.api.impl.CpsAdminServiceImpl
import org.onap.cps.api.impl.CpsDataServiceImpl
import org.onap.cps.api.impl.CpsModuleServiceImpl
import org.onap.cps.integration.DatabaseTestContainer
+import org.onap.cps.spi.config.CpsSessionFactory
import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.model.DataNode
import org.onap.cps.spi.repository.DataspaceRepository
import org.onap.cps.spi.impl.utils.CpsValidatorImpl
+import org.onap.cps.spi.utils.SessionManager
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.autoconfigure.domain.EntityScan
@@ -42,12 +44,12 @@ import spock.lang.Specification
import java.time.OffsetDateTime
-@SpringBootTest(classes = [TestConfig, CpsAdminServiceImpl, CpsValidatorImpl])
+@SpringBootTest(classes = [TestConfig, CpsAdminServiceImpl, CpsValidatorImpl, SessionManager, CpsSessionFactory])
@Testcontainers
@EnableAutoConfiguration
@EnableJpaRepositories(basePackageClasses = [DataspaceRepository])
-@ComponentScan(basePackages = ["org.onap.cps.api", "org.onap.cps.spi.repository"])
-@EntityScan("org.onap.cps.spi.entities")
+@ComponentScan(basePackages = ['org.onap.cps.api', 'org.onap.cps.spi.repository'])
+@EntityScan('org.onap.cps.spi.entities')
class CpsIntegrationSpecBase extends Specification {
@Shared
@@ -69,6 +71,10 @@ class CpsIntegrationSpecBase extends Specification {
@Lazy
CpsQueryService cpsQueryService
+ @Autowired
+ @Lazy
+ SessionManager sessionManager
+
def static GENERAL_TEST_DATASPACE = 'generalTestDataspace'
def static BOOKSTORE_SCHEMA_SET = 'bookstoreSchemaSet'
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy
index 18a2941615..e39e114405 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy
@@ -34,6 +34,7 @@ import org.onap.cps.spi.repository.ModuleReferenceRepository
import org.onap.cps.spi.repository.SchemaSetRepository
import org.onap.cps.spi.repository.YangResourceRepository
import org.onap.cps.spi.utils.SessionManager
+import org.onap.cps.spi.utils.TimeLimiterProvider
import org.onap.cps.utils.JsonObjectMapper
import org.onap.cps.utils.TimedYangParser
import org.onap.cps.yang.TimedYangTextSchemaSourceSetBuilder
@@ -75,7 +76,7 @@ class TestConfig extends Specification{
@Autowired
@Lazy
- SessionManager stubbedSessionManager
+ SessionManager sessionManager
@Bean
CpsAdminPersistenceServiceImpl cpsAdminPersistenceService() {
@@ -84,7 +85,7 @@ class TestConfig extends Specification{
@Bean
CpsDataPersistenceService cpsDataPersistenceService() {
- return (CpsDataPersistenceService) new CpsDataPersistenceServiceImpl(dataspaceRepository, anchorRepository, fragmentRepository, jsonObjectMapper, stubbedSessionManager)
+ return (CpsDataPersistenceService) new CpsDataPersistenceServiceImpl(dataspaceRepository, anchorRepository, fragmentRepository, jsonObjectMapper, sessionManager)
}
@Bean
@@ -103,11 +104,6 @@ class TestConfig extends Specification{
}
@Bean
- SessionManager sessionManager() {
- return Stub(SessionManager)
- }
-
- @Bean
TimedYangParser timedYangParser() {
return new TimedYangParser()
}
@@ -117,4 +113,9 @@ class TestConfig extends Specification{
return new TimedYangTextSchemaSourceSetBuilder()
}
+ @Bean
+ TimeLimiterProvider timeLimiterProvider() {
+ return new TimeLimiterProvider()
+ }
+
}
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/SessionManagerIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/SessionManagerIntegrationSpec.groovy
new file mode 100644
index 0000000000..e0a2602b23
--- /dev/null
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/SessionManagerIntegrationSpec.groovy
@@ -0,0 +1,73 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022-2023 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.integration.functional
+
+import org.onap.cps.integration.base.FunctionalSpecBase
+import org.onap.cps.spi.exceptions.SessionManagerException
+import org.onap.cps.spi.utils.SessionManager
+
+class SessionManagerIntegrationSpec extends FunctionalSpecBase {
+
+ SessionManager objectUnderTest
+
+ def shortTimeoutForTesting = 300L
+ def sessionId
+
+ def setup() {
+ objectUnderTest = sessionManager
+ sessionId = objectUnderTest.startSession()
+ }
+
+ def cleanup(){
+ objectUnderTest.closeSession(sessionId, objectUnderTest.WITH_COMMIT)
+ }
+
+ def 'Lock anchor.'(){
+ when: 'session tries to acquire anchor lock by passing anchor entity details'
+ objectUnderTest.lockAnchor(sessionId, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, shortTimeoutForTesting)
+ then: 'no exception is thrown'
+ noExceptionThrown()
+ }
+
+ def 'Attempt to lock anchor when another session is holding the lock.'(){
+ given: 'another session that holds an anchor lock'
+ def otherSessionId = objectUnderTest.startSession()
+ objectUnderTest.lockAnchor(otherSessionId,FUNCTIONAL_TEST_DATASPACE_1,BOOKSTORE_ANCHOR_1,shortTimeoutForTesting)
+ when: 'a session tries to acquire the same anchor lock'
+ objectUnderTest.lockAnchor(sessionId,FUNCTIONAL_TEST_DATASPACE_1,BOOKSTORE_ANCHOR_1,shortTimeoutForTesting)
+ then: 'a session manager exception is thrown specifying operation reached timeout'
+ 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.WITH_COMMIT)
+ objectUnderTest.lockAnchor(sessionId,FUNCTIONAL_TEST_DATASPACE_1,BOOKSTORE_ANCHOR_1,shortTimeoutForTesting)
+ }
+
+ def 'Lock anchor twice using the same session.'(){
+ given: 'session that already holds an anchor lock'
+ objectUnderTest.lockAnchor(sessionId, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, shortTimeoutForTesting)
+ when: 'same session tries to acquire same anchor lock'
+ objectUnderTest.lockAnchor(sessionId, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, shortTimeoutForTesting)
+ then: 'no exception is thrown'
+ noExceptionThrown()
+ }
+
+}