[ONOS-6443] Add eventually consistent map test commands
Change-Id: If6a1814bccbd95c5e01e344b2f39132760c6af89
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 850401f..3191696 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
@@ -15,13 +15,21 @@
*/
package org.onosproject.distributedprimitives;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.EventuallyConsistentMap;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.WallClockTimestamp;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
@@ -31,6 +39,7 @@
* Simple application to test distributed primitives.
*/
@Component(immediate = true)
+@Service(value = DistributedPrimitivesTest.class)
public class DistributedPrimitivesTest {
private final Logger log = getLogger(getClass());
@@ -41,17 +50,33 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected StorageService storageService;
+
+ private final Map<String, EventuallyConsistentMap<String, String>> maps = Maps.newConcurrentMap();
@Activate
protected void activate() {
-
log.info("Distributed-Primitives-test app started");
appId = coreService.registerApplication(APP_NAME);
}
@Deactivate
protected void deactivate() {
-
log.info("Distributed-Primitives-test app Stopped");
}
+
+ /**
+ * Returns an eventually consistent test map by name.
+ *
+ * @param name the test map name
+ * @return the test map
+ */
+ public EventuallyConsistentMap<String, String> getEcMap(String name) {
+ return maps.computeIfAbsent(name, n -> storageService.<String, String>eventuallyConsistentMapBuilder()
+ .withName(name)
+ .withSerializer(KryoNamespaces.BASIC)
+ .withTimestampProvider((k, v) -> new WallClockTimestamp())
+ .build());
+ }
}