2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.drools.m2.lock;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
27 import java.util.Properties;
28 import java.util.UUID;
29 import org.junit.AfterClass;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.onap.policy.drools.core.lock.Lock;
33 import org.onap.policy.drools.core.lock.LockCallback;
34 import org.onap.policy.drools.system.PolicyEngineConstants;
35 import org.onap.policy.m2.base.Transaction;
37 public class LockAdjunctTest {
39 public class TestOwner implements LockCallback {
42 public void lockAvailable(Lock arg0) {
47 public void lockUnavailable(Lock arg0) {
52 private LockCallback owner;
56 public static void start() {
57 PolicyEngineConstants.getManager().configure(new Properties());
58 PolicyEngineConstants.getManager().start();
62 public static void stop() {
63 PolicyEngineConstants.getManager().stop();
67 public void testLockAdjunct() {
68 owner = new TestOwner();
69 lock = PolicyEngineConstants.getManager().createLock("key", "ownerKey", 60, owner, false);
70 LockAdjunct lockA = new LockAdjunct();
74 lockA.lockUnavailable(lock);
75 assertTrue(lock.isActive());
76 assertTrue(lockA.getLock(null, "key", "ownerKey", false));
77 LockAdjunct lockB = new LockAdjunct();
78 assertFalse(lockB.getLock(null, "key", "ownerKey", false));
79 assertTrue(lock.free());
81 lockB.lockAvailable(lock);
82 assertFalse(lock.isActive());
83 assertTrue(lockB.getLock(null, "key", "ownerKey", false));
84 assertFalse(lock.free());
86 UUID uuid = UUID.randomUUID();
87 Transaction transaction = new Transaction(null, "1111", uuid, null);
88 lockA.cleanup(transaction);