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 <robert.varga@pantheon.tech>
final UnsignedLong lower = UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, header));
final UnsignedLong upper = UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, header));
final UnsignedLong lower = UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, header));
final UnsignedLong upper = UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, header));
- b.add(Range.closed(lower, upper));
+ b.add(Range.closedOpen(lower, upper));
}
final int currentSize = in.readInt();
}
final int currentSize = in.readInt();
final byte h = WritableObjects.readLongHeader(in);
final UnsignedLong l = UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, h));
final UnsignedLong u = UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, h));
final byte h = WritableObjects.readLongHeader(in);
final UnsignedLong l = UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, h));
final UnsignedLong u = UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, h));
- purgedTransactions.add(Range.closed(l, u));
+ purgedTransactions.add(Range.closedOpen(l, u));
}
return new FrontendHistoryMetadata(historyId, cookie, closed, closedTransactions, purgedTransactions);
}
return new FrontendHistoryMetadata(historyId, cookie, closed, closedTransactions, purgedTransactions);
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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 static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableMap;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
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;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
import org.junit.Test;
import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
public class FrontendShardDataTreeSnapshotMetadataTest {
public class FrontendShardDataTreeSnapshotMetadataTest {
- @Test(expected = NullPointerException.class)
- public final void testCreateMetadataSnapshotNullInput() {
- new FrontendShardDataTreeSnapshotMetadata(null);
+ @Test
+ public void testCreateMetadataSnapshotNullInput() {
+ assertThrows(NullPointerException.class, () -> new FrontendShardDataTreeSnapshotMetadata(null));
- 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
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
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);
final FrontendShardDataTreeSnapshotMetadata origSnapshot = createMetadataSnapshot(5);
final FrontendShardDataTreeSnapshotMetadata copySnapshot = copy(origSnapshot, 314);
testMetadataSnapshotEqual(origSnapshot, copySnapshot);
final List<FrontendClientMetadata> origClientList = origSnapshot.getClients();
final List<FrontendClientMetadata> copyClientList = copySnapshot.getClients();
final List<FrontendClientMetadata> origClientList = origSnapshot.getClients();
final List<FrontendClientMetadata> copyClientList = copySnapshot.getClients();
- assertTrue(origClientList.size() == copyClientList.size());
+ assertEquals(origClientList.size(), copyClientList.size());
final Map<ClientIdentifier, FrontendClientMetadata> origIdent = new HashMap<>();
final Map<ClientIdentifier, FrontendClientMetadata> copyIdent = new HashMap<>();
final Map<ClientIdentifier, FrontendClientMetadata> origIdent = new HashMap<>();
final Map<ClientIdentifier, FrontendClientMetadata> copyIdent = new HashMap<>();
origIdent.values().forEach(client -> {
final FrontendClientMetadata copyClient = copyIdent.get(client.getIdentifier());
testObject(client.getIdentifier(), copyClient.getIdentifier());
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() {
});
}
private static FrontendShardDataTreeSnapshotMetadata createEmptyMetadataSnapshot() {
- return new FrontendShardDataTreeSnapshotMetadata(Collections.<FrontendClientMetadata>emptyList());
+ return new FrontendShardDataTreeSnapshotMetadata(List.of());
}
private static FrontendShardDataTreeSnapshotMetadata createMetadataSnapshot(final int size) {
}
private static FrontendShardDataTreeSnapshotMetadata createMetadataSnapshot(final int size) {
final ClientIdentifier clientIdentifier = ClientIdentifier.create(frontendIdentifier, num);
final RangeSet<UnsignedLong> purgedHistories = TreeRangeSet.create();
final ClientIdentifier clientIdentifier = ClientIdentifier.create(frontendIdentifier, num);
final RangeSet<UnsignedLong> purgedHistories = TreeRangeSet.create();
- purgedHistories.add(Range.closed(UnsignedLong.ZERO, UnsignedLong.ONE));
+ purgedHistories.add(Range.closedOpen(UnsignedLong.ZERO, UnsignedLong.ONE));
- final Collection<FrontendHistoryMetadata> currentHistories = Collections.singleton(
+ final Set<FrontendHistoryMetadata> currentHistories = Set.of(
new FrontendHistoryMetadata(num, num, true, ImmutableMap.of(UnsignedLong.ZERO, Boolean.TRUE),
purgedHistories));
new FrontendHistoryMetadata(num, num, true, ImmutableMap.of(UnsignedLong.ZERO, Boolean.TRUE),
purgedHistories));