Remove prefix shard leftovers
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / persisted / FrontendShardDataTreeSnapshotMetadataTest.java
index e175a09eb41ff50f0b5efeba613d94f1afdd96a0..db52111ad22199270bac587fd8ce10cbc476f84a 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Range;
 import com.google.common.collect.RangeSet;
 import com.google.common.collect.TreeRangeSet;
@@ -43,21 +44,21 @@ public class FrontendShardDataTreeSnapshotMetadataTest {
     @Test
     public final void testCreateMetadataSnapshotEmptyInput() throws Exception {
         final FrontendShardDataTreeSnapshotMetadata emptyOrigSnapshot = createEmptyMetadataSnapshot();
-        final FrontendShardDataTreeSnapshotMetadata emptyCopySnapshot = copy(emptyOrigSnapshot);
+        final FrontendShardDataTreeSnapshotMetadata emptyCopySnapshot = copy(emptyOrigSnapshot, 127);
         testMetadataSnapshotEqual(emptyOrigSnapshot, emptyCopySnapshot);
     }
 
     @Test
     public final void testSerializeMetadataSnapshotWithOneClient() throws Exception {
         final FrontendShardDataTreeSnapshotMetadata origSnapshot = createMetadataSnapshot(1);
-        final FrontendShardDataTreeSnapshotMetadata copySnapshot = copy(origSnapshot);
+        final FrontendShardDataTreeSnapshotMetadata copySnapshot = copy(origSnapshot, 162);
         testMetadataSnapshotEqual(origSnapshot, copySnapshot);
     }
 
     @Test
     public final void testSerializeMetadataSnapshotWithMoreClients() throws Exception {
         final FrontendShardDataTreeSnapshotMetadata origSnapshot = createMetadataSnapshot(5);
-        final FrontendShardDataTreeSnapshotMetadata copySnapshot = copy(origSnapshot);
+        final FrontendShardDataTreeSnapshotMetadata copySnapshot = copy(origSnapshot, 314);
         testMetadataSnapshotEqual(origSnapshot, copySnapshot);
     }
 
@@ -90,7 +91,7 @@ public class FrontendShardDataTreeSnapshotMetadataTest {
     }
 
     private static FrontendShardDataTreeSnapshotMetadata createMetadataSnapshot(final int size) {
-        final List<FrontendClientMetadata> clients = new ArrayList<>();
+        final List<FrontendClientMetadata> clients = new ArrayList<>(size);
         for (long i = 0; i < size; i++) {
             clients.add(createFrontedClientMetadata(i));
         }
@@ -107,8 +108,9 @@ public class FrontendShardDataTreeSnapshotMetadataTest {
         final RangeSet<UnsignedLong> purgedHistories = TreeRangeSet.create();
         purgedHistories.add(Range.closed(UnsignedLong.ZERO, UnsignedLong.ONE));
 
-        final Collection<FrontendHistoryMetadata> currentHistories = Collections
-                .singleton(new FrontendHistoryMetadata(num, num, num, true));
+        final Collection<FrontendHistoryMetadata> currentHistories = Collections.singleton(
+            new FrontendHistoryMetadata(num, num, true, ImmutableMap.of(UnsignedLong.ZERO, Boolean.TRUE),
+                purgedHistories));
 
         return new FrontendClientMetadata(clientIdentifier, purgedHistories, currentHistories);
     }
@@ -122,13 +124,16 @@ public class FrontendShardDataTreeSnapshotMetadataTest {
     }
 
     @SuppressWarnings("unchecked")
-    private static <T> T copy(final T obj) throws IOException, ClassNotFoundException {
+    private static <T> T copy(final T obj, final int expectedSize) throws IOException, ClassNotFoundException {
         final ByteArrayOutputStream bos = new ByteArrayOutputStream();
         try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
             oos.writeObject(obj);
         }
 
-        try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
+        final byte[] bytes = bos.toByteArray();
+        assertEquals(expectedSize, bytes.length);
+
+        try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
             return (T) ois.readObject();
         }
     }