Correctly persists the old value in TestConsistentMap by deep cloning the entry

In addition, inject TestApplicationId into DistributedMeterStore serializer when running MeterManagerTest

Change-Id: I8dcb4b2953a8d7e0fa1e5d765c859cde31d7633b
diff --git a/core/api/src/test/java/org/onosproject/store/service/TestConsistentMap.java b/core/api/src/test/java/org/onosproject/store/service/TestConsistentMap.java
index e34d110..673a531 100644
--- a/core/api/src/test/java/org/onosproject/store/service/TestConsistentMap.java
+++ b/core/api/src/test/java/org/onosproject/store/service/TestConsistentMap.java
@@ -42,11 +42,13 @@
     private final Map<K, Versioned<V>> map;
     private final String mapName;
     private final AtomicLong counter = new AtomicLong(0);
+    private final Serializer serializer;
 
-    private TestConsistentMap(String mapName) {
+    private TestConsistentMap(String mapName, Serializer serializer) {
         map = new HashMap<>();
         listeners = new LinkedList<>();
         this.mapName = mapName;
+        this.serializer = serializer;
     }
 
     private Versioned<V> version(V v) {
@@ -111,7 +113,7 @@
             AtomicReference<Versioned<V>> previousValue = new AtomicReference<>();
             Versioned<V> result = map.compute(key, (k, v) -> {
                     updated.set(true);
-                    previousValue.set(v);
+                    previousValue.set(serializer.decode(serializer.encode(v)));
                     return version(remappingFunction.apply(k, Versioned.valueOrNull(v)));
                 });
             if (updated.get()) {
@@ -127,7 +129,7 @@
         Versioned<V> result = map.compute(key, (k, v) -> {
             if (v != null) {
                 updated.set(true);
-                previousValue.set(v);
+                previousValue.set(serializer.decode(serializer.encode(v)));
                 return version(remappingFunction.apply(k, v.value()));
             }
             return v;
@@ -145,7 +147,7 @@
         AtomicReference<Versioned<V>> previousValue = new AtomicReference<>();
         Versioned<V> result = map.compute(key, (k, v) -> {
             if (condition.test(Versioned.valueOrNull(v))) {
-                previousValue.set(v);
+                previousValue.set(serializer.decode(serializer.encode(v)));
                 updated.set(true);
                 return version(remappingFunction.apply(k, Versioned.valueOrNull(v)));
             }
@@ -296,7 +298,7 @@
 
         @Override
         public ConsistentMap<K, V> build() {
-            return new TestConsistentMap<>(name());
+            return new TestConsistentMap<>(name(), serializer());
         }
 
         @Override