X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fpersisted%2FFrontendShardDataTreeSnapshotMetadataTest.java;h=7daafcd78605200e3e4b2d98bc401e9be1923d8f;hb=840006cda425b81bd15dc98cc560ca900f986936;hp=db52111ad22199270bac587fd8ce10cbc476f84a;hpb=b394690b52324ae91124735c4ec19acc3389d4ec;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendShardDataTreeSnapshotMetadataTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendShardDataTreeSnapshotMetadataTest.java index db52111ad2..7daafcd786 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendShardDataTreeSnapshotMetadataTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendShardDataTreeSnapshotMetadataTest.java @@ -10,12 +10,9 @@ package org.opendaylight.controller.cluster.datastore.persisted; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; 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; import com.google.common.primitives.UnsignedLong; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -23,8 +20,6 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,30 +28,33 @@ import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier; import org.opendaylight.controller.cluster.access.concepts.FrontendType; import org.opendaylight.controller.cluster.access.concepts.MemberName; +import org.opendaylight.controller.cluster.datastore.utils.ImmutableUnsignedLongSet; +import org.opendaylight.controller.cluster.datastore.utils.MutableUnsignedLongSet; +import org.opendaylight.controller.cluster.datastore.utils.UnsignedLongBitmap; public class FrontendShardDataTreeSnapshotMetadataTest { - @Test(expected = NullPointerException.class) - public final void testCreateMetadataSnapshotNullInput() { - new FrontendShardDataTreeSnapshotMetadata(null); + @Test + public void testCreateMetadataSnapshotNullInput() { + assertThrows(NullPointerException.class, () -> new FrontendShardDataTreeSnapshotMetadata(null)); } @Test - public final void testCreateMetadataSnapshotEmptyInput() throws Exception { + public void testCreateMetadataSnapshotEmptyInput() throws Exception { final FrontendShardDataTreeSnapshotMetadata emptyOrigSnapshot = createEmptyMetadataSnapshot(); final FrontendShardDataTreeSnapshotMetadata emptyCopySnapshot = copy(emptyOrigSnapshot, 127); testMetadataSnapshotEqual(emptyOrigSnapshot, emptyCopySnapshot); } @Test - public final void testSerializeMetadataSnapshotWithOneClient() throws Exception { + public void testSerializeMetadataSnapshotWithOneClient() throws Exception { final FrontendShardDataTreeSnapshotMetadata origSnapshot = createMetadataSnapshot(1); final FrontendShardDataTreeSnapshotMetadata copySnapshot = copy(origSnapshot, 162); testMetadataSnapshotEqual(origSnapshot, copySnapshot); } @Test - public final void testSerializeMetadataSnapshotWithMoreClients() throws Exception { + public void testSerializeMetadataSnapshotWithMoreClients() throws Exception { final FrontendShardDataTreeSnapshotMetadata origSnapshot = createMetadataSnapshot(5); final FrontendShardDataTreeSnapshotMetadata copySnapshot = copy(origSnapshot, 314); testMetadataSnapshotEqual(origSnapshot, copySnapshot); @@ -68,7 +66,7 @@ public class FrontendShardDataTreeSnapshotMetadataTest { final List origClientList = origSnapshot.getClients(); final List copyClientList = copySnapshot.getClients(); - assertTrue(origClientList.size() == copyClientList.size()); + assertEquals(origClientList.size(), copyClientList.size()); final Map origIdent = new HashMap<>(); final Map copyIdent = new HashMap<>(); @@ -81,13 +79,13 @@ public class FrontendShardDataTreeSnapshotMetadataTest { origIdent.values().forEach(client -> { final FrontendClientMetadata copyClient = copyIdent.get(client.getIdentifier()); testObject(client.getIdentifier(), copyClient.getIdentifier()); - assertTrue(client.getPurgedHistories().equals(copyClient.getPurgedHistories())); - assertTrue(client.getCurrentHistories().equals(copyClient.getCurrentHistories())); + assertEquals(client.getPurgedHistories(), copyClient.getPurgedHistories()); + assertEquals(client.getCurrentHistories(), copyClient.getCurrentHistories()); }); } private static FrontendShardDataTreeSnapshotMetadata createEmptyMetadataSnapshot() { - return new FrontendShardDataTreeSnapshotMetadata(Collections.emptyList()); + return new FrontendShardDataTreeSnapshotMetadata(List.of()); } private static FrontendShardDataTreeSnapshotMetadata createMetadataSnapshot(final int size) { @@ -105,14 +103,13 @@ public class FrontendShardDataTreeSnapshotMetadataTest { FrontendType.forName(index)); final ClientIdentifier clientIdentifier = ClientIdentifier.create(frontendIdentifier, num); - final RangeSet purgedHistories = TreeRangeSet.create(); - purgedHistories.add(Range.closed(UnsignedLong.ZERO, UnsignedLong.ONE)); - - final Collection currentHistories = Collections.singleton( - new FrontendHistoryMetadata(num, num, true, ImmutableMap.of(UnsignedLong.ZERO, Boolean.TRUE), - purgedHistories)); + final MutableUnsignedLongSet tmp = MutableUnsignedLongSet.of(); + tmp.add(0); + final ImmutableUnsignedLongSet purgedHistories = tmp.immutableCopy(); - return new FrontendClientMetadata(clientIdentifier, purgedHistories, currentHistories); + return new FrontendClientMetadata(clientIdentifier, purgedHistories.immutableCopy(), List.of( + new FrontendHistoryMetadata(num, num, true, + UnsignedLongBitmap.copyOf(Map.of(UnsignedLong.ZERO, Boolean.TRUE)), purgedHistories))); } private static void testObject(final T object, final T equalObject) {