2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.spi.utils
23 import org.onap.cps.spi.exceptions.SessionManagerException
24 import org.onap.cps.spi.impl.CpsPersistenceSpecBase
25 import org.springframework.beans.factory.annotation.Autowired
26 import org.springframework.test.context.jdbc.Sql
28 class SessionManagerIntegrationSpec extends CpsPersistenceSpecBase{
30 final static String SET_DATA = '/data/anchor.sql'
33 SessionManager objectUnderTest
36 def shortTimeoutForTesting = 200L
39 sessionId = objectUnderTest.startSession()
43 objectUnderTest.closeSession(sessionId)
46 @Sql([CLEAR_DATA, SET_DATA])
48 when: 'session tries to acquire anchor lock by passing anchor entity details'
49 objectUnderTest.lockAnchor(sessionId, DATASPACE_NAME, ANCHOR_NAME1, shortTimeoutForTesting)
50 then: 'no exception is thrown'
54 @Sql([CLEAR_DATA, SET_DATA])
55 def 'Attempt to lock anchor when another session is holding the lock.'(){
56 given: 'another session that holds an anchor lock'
57 def otherSessionId = objectUnderTest.startSession()
58 objectUnderTest.lockAnchor(otherSessionId,DATASPACE_NAME,ANCHOR_NAME1,shortTimeoutForTesting)
59 when: 'a session tries to acquire the same anchor lock'
60 objectUnderTest.lockAnchor(sessionId,DATASPACE_NAME,ANCHOR_NAME1,shortTimeoutForTesting)
61 then: 'a session manager exception is thrown specifying operation reached timeout'
62 def thrown = thrown(SessionManagerException)
63 thrown.message.contains('Timeout')
64 then: 'when the other session holding the lock is closed, lock can finally be acquired'
65 objectUnderTest.closeSession(otherSessionId)
66 objectUnderTest.lockAnchor(sessionId,DATASPACE_NAME,ANCHOR_NAME1,shortTimeoutForTesting)