Add DistributedLock test commands and STC tests
Change-Id: If410a91418fe1749e738cdc12494859af1c74245
diff --git a/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/DistributedPrimitivesTest.java b/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/DistributedPrimitivesTest.java
index a83c7db..3296046 100644
--- a/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/DistributedPrimitivesTest.java
+++ b/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/DistributedPrimitivesTest.java
@@ -27,6 +27,7 @@
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.DistributedLock;
import org.onosproject.store.service.EventuallyConsistentMap;
import org.onosproject.store.service.LeaderElector;
import org.onosproject.store.service.StorageService;
@@ -35,7 +36,6 @@
import static org.slf4j.LoggerFactory.getLogger;
-
/**
* Simple application to test distributed primitives.
*/
@@ -56,6 +56,7 @@
private final Map<String, EventuallyConsistentMap<String, String>> maps = Maps.newConcurrentMap();
private final Map<String, LeaderElector> electors = Maps.newConcurrentMap();
+ private final Map<String, DistributedLock> locks = Maps.newConcurrentMap();
@Activate
protected void activate() {
@@ -90,8 +91,21 @@
*/
public LeaderElector getLeaderElector(String name) {
return electors.computeIfAbsent(name, n -> storageService.leaderElectorBuilder()
- .withName(name)
- .build()
- .asLeaderElector());
+ .withName(name)
+ .build()
+ .asLeaderElector());
+ }
+
+ /**
+ * Returns a lock instance by name.
+ *
+ * @param name the lock name
+ * @return the lock
+ */
+ public DistributedLock getLock(String name) {
+ return locks.computeIfAbsent(name, n -> storageService.lockBuilder()
+ .withName(name)
+ .build()
+ .asLock());
}
}