[ONOS-7599] Test application to test cluster stability after multiple SDNC node reboots

Change-Id: Iedb57017d9247d13569b2ccfea559d905286acf3
diff --git a/apps/test/cluster-ha/src/main/java/org/onosproject/clusterha/ClusterHATest.java b/apps/test/cluster-ha/src/main/java/org/onosproject/clusterha/ClusterHATest.java
new file mode 100644
index 0000000..0ccca0a
--- /dev/null
+++ b/apps/test/cluster-ha/src/main/java/org/onosproject/clusterha/ClusterHATest.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+
+package org.onosproject.clusterha;
+
+
+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.onlab.util.KryoNamespace;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.StorageException;
+import org.onosproject.store.service.StorageService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * Cluster HA Test.
+ */
+@Component(immediate = true)
+@Service(value = ClusterHATest.class)
+public class ClusterHATest {
+
+    protected final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected StorageService storageService;
+
+    private ApplicationId appId;
+    private List<ConsistentMap<String, String>> stringStoreList;
+    private int numStores = 10;
+
+    @Activate
+    protected void activate() {
+        appId = coreService.registerApplication("org.onosproject.cluster");
+        stringStoreList = new ArrayList<ConsistentMap<String, String>>();
+        for (int i = 0; i < numStores; i++) {
+            ConsistentMap<String, String> stringStore = storageService.<String, String>consistentMapBuilder()
+                    .withName("cluster-ha-store" + i)
+                    .withApplicationId(appId)
+                    .withSerializer(Serializer.using(new KryoNamespace.Builder()
+                                                             .register(KryoNamespaces.API)
+                                                             .register(String.class)
+                                                             .build("string")))
+                    .build();
+            stringStoreList.add(stringStore);
+        }
+        log.info("Started");
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        for (ConsistentMap<String, String> stringStore: stringStoreList) {
+            stringStore.clear();
+        }
+        log.info("Stopped");
+    }
+
+    public void addToStringStore(int key, String str) {
+        try {
+            for (ConsistentMap<String, String> stringStore: stringStoreList) {
+                stringStore.put(String.valueOf(key), str);
+            }
+        } catch (StorageException e) {
+            log.error("StringStore - put got exception {} , for the key {} string {}", e, key, str);
+        }
+    }
+
+    public void removeStringFromStore(int key) {
+        try {
+            for (ConsistentMap<String, String> stringStore: stringStoreList) {
+                stringStore.remove(String.valueOf(key));
+            }
+        } catch (StorageException e) {
+            log.error("StringStore - put got exception {} , for the key {}", e, key);
+        }
+    }
+}
\ No newline at end of file