From 546cd1fd100dbaa36908b22c2f422320dbd8c4b2 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 6 Nov 2021 10:08:05 +0100 Subject: [PATCH] Correct Frontend{Client,History}Metadata deserialization We are turning Range.closedOpen() into Range.closed() during deserialization, which the resulting ends up also covering the upper bound, which it should not. JIRA: CONTROLLER-1942 Change-Id: Ib8f9016e2eddcf014ff5e451ac82cd77b66d7019 Signed-off-by: Robert Varga --- .../persisted/FrontendClientMetadata.java | 2 +- .../persisted/FrontendHistoryMetadata.java | 2 +- ...tendShardDataTreeSnapshotMetadataTest.java | 28 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendClientMetadata.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendClientMetadata.java index a3f41ed65d..c9b2430528 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendClientMetadata.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendClientMetadata.java @@ -78,7 +78,7 @@ public final class FrontendClientMetadata implements Identifiable 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 +68,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 +81,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) { @@ -106,9 +106,9 @@ public class FrontendShardDataTreeSnapshotMetadataTest { final ClientIdentifier clientIdentifier = ClientIdentifier.create(frontendIdentifier, num); final RangeSet purgedHistories = TreeRangeSet.create(); - purgedHistories.add(Range.closed(UnsignedLong.ZERO, UnsignedLong.ONE)); + purgedHistories.add(Range.closedOpen(UnsignedLong.ZERO, UnsignedLong.ONE)); - final Collection currentHistories = Collections.singleton( + final Set currentHistories = Set.of( new FrontendHistoryMetadata(num, num, true, ImmutableMap.of(UnsignedLong.ZERO, Boolean.TRUE), purgedHistories)); -- 2.36.6