diff options
author | Jim Hahn <jrh3@att.com> | 2019-09-24 10:51:21 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-10-17 15:40:32 -0400 |
commit | 6e0b450abe7e62fa47ffe14e95a67d035174dbdb (patch) | |
tree | e91c7bfb7365f9a06ad5674bc83e041b7237e378 /policy-core/src/test/java/org/onap/policy/drools/core/lock/LockTest.java | |
parent | 1528214803af722cd660b7c4a3129f3de5b4ea7f (diff) |
Reimplement Lock API using Lock objects
Modified PolicyResourceLockManager to just return a feature, deferring
the lock() call/method to the feature, itself. The manager was also
modified so that, if it can't find an enabled provider, it will return
a default provider, whose lock() methods always fail. Once a feature
has been identified, the manager will cache it for use thereafter.
Modified the feature API to return lock objects and simplified the
interface to remove the beforeXxx and afterXxx methods.
Moved the unlock and refresh methods from the feature API into the
lock class, renaming them to free and extend, respectively.
Added a separate, feature-simple-locking project, which implements
a simple version of the locking feature, over a single JVM.
Extensively revised the distributed locking feature to fit in with
the new API.
Added support for persistence so that the various LockImpl classes
can be serialized and still function correctly when they are
deserialized back into new feature instances
Added default implementations of free & extend to LockImpl.
Modified API to take the ownerKey string, instead of the owner object.
Removed Extractor as unneeded - may add via another review, if still useful.
Updates per review comments:
- Updated licenses in feature-simple-locking
- Added beforeCreateLock & afterCreateLock to feature API
- Moved SimpleLockingFeature into policy-management so that it's
always available
- Moved the executor service, "exsvc", into PolicyEngine
- Moved Extrator into policy-utils
- Changed Extractor logging level for exceptions
- Fixed feature sequence numbers
- Fixed mixing of seconds and milliseconds
- Renamed exsvc
- Modified to use property method with default value
- Configured scheduled executor
- Added suffix to Extractor.register()
- Eliminated Feature Api and tied lock manager into engine
- Added non-null checks to LockImpl parameters
- Added non-null checks to createLock() parameters
- Checked that lockManager is initialized
Change-Id: Iddba38157ddc5f7277656979c0e679e5489eb7b1
Issue-ID: POLICY-2113
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-core/src/test/java/org/onap/policy/drools/core/lock/LockTest.java')
-rw-r--r-- | policy-core/src/test/java/org/onap/policy/drools/core/lock/LockTest.java | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockTest.java deleted file mode 100644 index 5a88b02f..00000000 --- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.drools.core.lock; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.drools.core.lock.Lock.RemoveResult; -import org.onap.policy.drools.utils.Pair; - -public class LockTest { - - private static final String OWNER = "my.owner"; - private static final String OWNER2 = "another.owner"; - private static final String OWNER3 = "third.owner"; - - private static final Integer ITEM2 = 10; - private static final Integer ITEM3 = 20; - - private Lock<Integer> lock; - private Pair<String, Integer> newOwner; - - @Before - public void setUp() { - lock = new Lock<>(OWNER); - newOwner = new Pair<>(null, null); - } - - - @Test - public void testLock() { - assertEquals(OWNER, lock.getOwner()); - } - - @Test - public void testGetOwner() { - assertEquals(OWNER, lock.getOwner()); - } - - @Test - public void testAdd() { - assertTrue(lock.add(OWNER2, ITEM2)); - assertTrue(lock.add(OWNER3, ITEM3)); - - // attempt to re-add owner2 with the same item - should fail - assertFalse(lock.add(OWNER2, ITEM2)); - - // attempt to re-add owner2 with a different item - should fail - assertFalse(lock.add(OWNER2, ITEM3)); - } - - @Test(expected = IllegalArgumentException.class) - public void testAdd_ArgEx() { - lock.add(OWNER2, null); - } - - @Test - public void testAdd_AlreadyOwner() { - assertFalse(lock.add(OWNER, ITEM2)); - } - - @Test - public void testAdd_AlreadyInQueue() { - lock.add(OWNER2, ITEM2); - - assertFalse(lock.add(OWNER2, ITEM2)); - } - - @Test - public void testRemoveRequester_Owner_QueueEmpty() { - assertEquals(RemoveResult.UNLOCKED, lock.removeRequester(OWNER, newOwner)); - } - - @Test - public void testRemoveRequester_Owner_QueueHasOneItem() { - lock.add(OWNER2, ITEM2); - - assertEquals(RemoveResult.RELOCKED, lock.removeRequester(OWNER, newOwner)); - assertEquals(OWNER2, newOwner.first()); - assertEquals(ITEM2, newOwner.second()); - - assertEquals(RemoveResult.UNLOCKED, lock.removeRequester(OWNER2, newOwner)); - } - - @Test - public void testRemoveRequester_Owner_QueueHasMultipleItems() { - lock.add(OWNER2, ITEM2); - lock.add(OWNER3, ITEM3); - - assertEquals(RemoveResult.RELOCKED, lock.removeRequester(OWNER, newOwner)); - assertEquals(OWNER2, newOwner.first()); - assertEquals(ITEM2, newOwner.second()); - - assertEquals(RemoveResult.RELOCKED, lock.removeRequester(OWNER2, newOwner)); - assertEquals(OWNER3, newOwner.first()); - assertEquals(ITEM3, newOwner.second()); - - assertEquals(RemoveResult.UNLOCKED, lock.removeRequester(OWNER3, newOwner)); - } - - @Test - public void testRemoveRequester_InQueue() { - lock.add(OWNER2, ITEM2); - - assertEquals(RemoveResult.REMOVED, lock.removeRequester(OWNER2, newOwner)); - } - - @Test - public void testRemoveRequester_NeitherOwnerNorInQueue() { - assertEquals(RemoveResult.NOT_FOUND, lock.removeRequester(OWNER2, newOwner)); - } - -} |