Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.serializers; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.ImmutableMap; |
| 20 | import com.google.common.collect.ImmutableSet; |
| 21 | import com.google.common.testing.EqualsTester; |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 22 | |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 23 | import org.junit.After; |
| 24 | import org.junit.Before; |
| 25 | import org.junit.BeforeClass; |
| 26 | import org.junit.Test; |
Sho SHIMIZU | 08ec48f | 2015-07-27 11:27:26 -0700 | [diff] [blame] | 27 | import org.onlab.packet.VlanId; |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 28 | import org.onlab.util.Bandwidth; |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 29 | import org.onlab.util.Frequency; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.cluster.NodeId; |
| 31 | import org.onosproject.cluster.RoleInfo; |
Ray Milkey | d13a37b | 2015-06-12 11:55:17 -0700 | [diff] [blame] | 32 | import org.onosproject.core.DefaultApplicationId; |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 33 | import org.onosproject.core.GroupId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.mastership.MastershipTerm; |
| 35 | import org.onosproject.net.Annotations; |
Sho SHIMIZU | 014c33a | 2015-04-30 11:40:37 -0700 | [diff] [blame] | 36 | import org.onosproject.net.ChannelSpacing; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 37 | import org.onosproject.net.ConnectPoint; |
| 38 | import org.onosproject.net.DefaultAnnotations; |
| 39 | import org.onosproject.net.DefaultDevice; |
| 40 | import org.onosproject.net.DefaultLink; |
| 41 | import org.onosproject.net.DefaultPort; |
| 42 | import org.onosproject.net.Device; |
| 43 | import org.onosproject.net.DeviceId; |
Sho SHIMIZU | 014c33a | 2015-04-30 11:40:37 -0700 | [diff] [blame] | 44 | import org.onosproject.net.GridType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 45 | import org.onosproject.net.HostLocation; |
| 46 | import org.onosproject.net.Link; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 47 | import org.onosproject.net.LinkKey; |
Yuta HIGUCHI | eb28a7c | 2017-01-13 18:59:27 -0800 | [diff] [blame] | 48 | import org.onosproject.net.MarkerResource; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 49 | import org.onosproject.net.PortNumber; |
| 50 | import org.onosproject.net.SparseAnnotations; |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 51 | import org.onosproject.net.flow.DefaultFlowRule; |
| 52 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 53 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 54 | import org.onosproject.net.flow.FlowId; |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 55 | import org.onosproject.net.flow.FlowRule; |
| 56 | import org.onosproject.net.flow.FlowRuleBatchEntry; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 57 | import org.onosproject.net.intent.IntentId; |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 58 | import org.onosproject.net.resource.ResourceAllocation; |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 59 | import org.onosproject.net.resource.ResourceConsumerId; |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 60 | import org.onosproject.net.resource.Resources; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 61 | import org.onosproject.net.provider.ProviderId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 62 | import org.onosproject.net.intent.constraint.AnnotationConstraint; |
| 63 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 64 | import org.onosproject.net.intent.constraint.LatencyConstraint; |
| 65 | import org.onosproject.net.intent.constraint.LinkTypeConstraint; |
| 66 | import org.onosproject.net.intent.constraint.ObstacleConstraint; |
| 67 | import org.onosproject.net.intent.constraint.WaypointConstraint; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 68 | import org.onlab.packet.ChassisId; |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 69 | import org.onlab.packet.IpAddress; |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 70 | import org.onlab.packet.Ip4Address; |
| 71 | import org.onlab.packet.Ip6Address; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 72 | import org.onlab.packet.IpPrefix; |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 73 | import org.onlab.packet.Ip4Prefix; |
| 74 | import org.onlab.packet.Ip6Prefix; |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 75 | import org.onlab.packet.MacAddress; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 76 | |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 77 | import java.nio.ByteBuffer; |
Yuta HIGUCHI | 91768e3 | 2014-11-22 05:06:35 -0800 | [diff] [blame] | 78 | import java.util.Arrays; |
Jordi Ortiz | 1b1a3b4 | 2017-03-03 12:36:54 +0100 | [diff] [blame] | 79 | import java.util.BitSet; |
Yuta HIGUCHI | ae1d210 | 2014-11-25 19:26:01 -0800 | [diff] [blame] | 80 | import java.util.Collections; |
Sho SHIMIZU | 977cb60 | 2014-11-13 08:40:50 -0800 | [diff] [blame] | 81 | import java.time.Duration; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 82 | |
| 83 | import static java.util.Arrays.asList; |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 84 | import static org.junit.Assert.*; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 85 | import static org.onosproject.net.DeviceId.deviceId; |
| 86 | import static org.onosproject.net.PortNumber.portNumber; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 87 | |
Yuta HIGUCHI | 9ee0d5b | 2014-10-05 00:03:47 -0700 | [diff] [blame] | 88 | public class KryoSerializerTest { |
| 89 | |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 90 | private static final ProviderId PID = new ProviderId("of", "foo"); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 91 | private static final ProviderId PIDA = new ProviderId("of", "foo", true); |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 92 | private static final DeviceId DID1 = deviceId("of:foo"); |
| 93 | private static final DeviceId DID2 = deviceId("of:bar"); |
| 94 | private static final PortNumber P1 = portNumber(1); |
| 95 | private static final PortNumber P2 = portNumber(2); |
| 96 | private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1); |
| 97 | private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2); |
| 98 | private static final String MFR = "whitebox"; |
| 99 | private static final String HW = "1.1.x"; |
| 100 | private static final String SW1 = "3.8.1"; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 101 | private static final String SN = "43311-12345"; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 102 | private static final ChassisId CID = new ChassisId(); |
| 103 | private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW, |
| 104 | SW1, SN, CID); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 105 | private static final SparseAnnotations A1 = DefaultAnnotations.builder() |
| 106 | .set("A1", "a1") |
| 107 | .set("B1", "b1") |
| 108 | .build(); |
| 109 | private static final SparseAnnotations A1_2 = DefaultAnnotations.builder() |
| 110 | .remove("A1") |
| 111 | .set("B3", "b3") |
| 112 | .build(); |
Sho SHIMIZU | 08ec48f | 2015-07-27 11:27:26 -0700 | [diff] [blame] | 113 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 114 | |
HIGUCHI Yuta | e729065 | 2016-05-18 11:29:01 -0700 | [diff] [blame] | 115 | private StoreSerializer serializer; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 116 | |
| 117 | @BeforeClass |
| 118 | public static void setUpBeforeClass() throws Exception { |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Before |
| 122 | public void setUp() throws Exception { |
HIGUCHI Yuta | e729065 | 2016-05-18 11:29:01 -0700 | [diff] [blame] | 123 | serializer = StoreSerializer.using(KryoNamespaces.API); |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @After |
| 127 | public void tearDown() throws Exception { |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Jordan Halterman | 0d1f3fa | 2017-05-26 00:14:27 -0700 | [diff] [blame^] | 130 | private byte[] serialize(Object object) { |
| 131 | ByteBuffer buffer = ByteBuffer.allocate(1024); |
| 132 | serializer.encode(object, buffer); |
| 133 | buffer.flip(); |
| 134 | byte[] bytes = new byte[buffer.remaining()]; |
| 135 | buffer.get(bytes); |
| 136 | return bytes; |
| 137 | } |
| 138 | |
| 139 | private <T> void testBytesEqual(T expected, T actual) { |
| 140 | byte[] expectedBytes = serialize(expected); |
| 141 | byte[] actualBytes = serialize(actual); |
| 142 | assertArrayEquals(expectedBytes, actualBytes); |
| 143 | } |
| 144 | |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 145 | private <T> void testSerializedEquals(T original) { |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 146 | ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 147 | serializer.encode(original, buffer); |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 148 | buffer.flip(); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 149 | T copy = serializer.decode(buffer); |
| 150 | |
| 151 | T copy2 = serializer.decode(serializer.encode(original)); |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 152 | |
| 153 | new EqualsTester() |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 154 | .addEqualityGroup(original, copy, copy2) |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 155 | .testEquals(); |
| 156 | } |
| 157 | |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 158 | private <T> void testSerializable(T original) { |
| 159 | byte[] bs = serializer.encode(original); |
| 160 | T copy = serializer.decode(bs); |
| 161 | assertNotNull(copy); |
| 162 | } |
| 163 | |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 164 | |
| 165 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 166 | public void testConnectPoint() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 167 | testSerializedEquals(new ConnectPoint(DID1, P1)); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Test |
| 171 | public void testDefaultLink() { |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 172 | testSerializedEquals(DefaultLink.builder() |
| 173 | .providerId(PID) |
| 174 | .src(CP1) |
| 175 | .dst(CP2) |
| 176 | .type(Link.Type.DIRECT) |
| 177 | .build()); |
| 178 | testSerializedEquals(DefaultLink.builder() |
| 179 | .providerId(PID) |
| 180 | .src(CP1) |
| 181 | .dst(CP2) |
| 182 | .type(Link.Type.DIRECT) |
| 183 | .annotations(A1) |
| 184 | .build()); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | @Test |
| 188 | public void testDefaultPort() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 189 | testSerializedEquals(new DefaultPort(DEV1, P1, true)); |
| 190 | testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2)); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | @Test |
| 194 | public void testDeviceId() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 195 | testSerializedEquals(DID1); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | @Test |
| 199 | public void testImmutableMap() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 200 | testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1)); |
| 201 | testSerializedEquals(ImmutableMap.of(DID1, DEV1)); |
| 202 | testSerializedEquals(ImmutableMap.of()); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | @Test |
| 206 | public void testImmutableSet() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 207 | testSerializedEquals(ImmutableSet.of(DID1, DID2)); |
| 208 | testSerializedEquals(ImmutableSet.of(DID1)); |
| 209 | testSerializedEquals(ImmutableSet.of()); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | @Test |
| 213 | public void testImmutableList() { |
Jordan Halterman | 0d1f3fa | 2017-05-26 00:14:27 -0700 | [diff] [blame^] | 214 | testBytesEqual(ImmutableList.of(DID1, DID2), ImmutableList.of(DID1, DID2, DID1, DID2).subList(0, 2)); |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 215 | testSerializedEquals(ImmutableList.of(DID1, DID2)); |
| 216 | testSerializedEquals(ImmutableList.of(DID1)); |
| 217 | testSerializedEquals(ImmutableList.of()); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | @Test |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 221 | public void testFlowRuleBatchEntry() { |
| 222 | final FlowRule rule1 = |
Ray Milkey | d13a37b | 2015-06-12 11:55:17 -0700 | [diff] [blame] | 223 | DefaultFlowRule.builder() |
| 224 | .forDevice(DID1) |
| 225 | .withSelector(DefaultTrafficSelector.emptySelector()) |
| 226 | .withTreatment(DefaultTrafficTreatment.emptyTreatment()) |
| 227 | .withPriority(0) |
| 228 | .fromApp(new DefaultApplicationId(1, "1")) |
| 229 | .makeTemporary(1) |
| 230 | .build(); |
| 231 | |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 232 | final FlowRuleBatchEntry entry1 = |
| 233 | new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1); |
| 234 | final FlowRuleBatchEntry entry2 = |
Sho SHIMIZU | 7446da9 | 2015-01-22 16:27:06 -0800 | [diff] [blame] | 235 | new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L); |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 236 | |
Sho SHIMIZU | 7446da9 | 2015-01-22 16:27:06 -0800 | [diff] [blame] | 237 | testSerializedEquals(entry1); |
| 238 | testSerializedEquals(entry2); |
Sho SHIMIZU | 166e61e | 2015-01-21 18:07:12 -0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 242 | public void testIpPrefix() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 243 | testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24")); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | @Test |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 247 | public void testIp4Prefix() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 248 | testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24")); |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Test |
| 252 | public void testIp6Prefix() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 253 | testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120")); |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 257 | public void testIpAddress() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 258 | testSerializedEquals(IpAddress.valueOf("192.168.0.1")); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | @Test |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 262 | public void testIp4Address() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 263 | testSerializedEquals(Ip4Address.valueOf("192.168.0.1")); |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Test |
| 267 | public void testIp6Address() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 268 | testSerializedEquals(Ip6Address.valueOf("1111:2222::")); |
Pavlin Radoslavov | 17378ef | 2014-11-05 16:13:47 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 272 | public void testMacAddress() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 273 | testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab")); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | @Test |
| 277 | public void testLinkKey() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 278 | testSerializedEquals(LinkKey.linkKey(CP1, CP2)); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | @Test |
| 282 | public void testNodeId() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 283 | testSerializedEquals(new NodeId("SomeNodeIdentifier")); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Test |
| 287 | public void testPortNumber() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 288 | testSerializedEquals(P1); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | @Test |
| 292 | public void testProviderId() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 293 | testSerializedEquals(PID); |
| 294 | testSerializedEquals(PIDA); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | @Test |
| 298 | public void testMastershipTerm() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 299 | testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2)); |
| 300 | testSerializedEquals(MastershipTerm.of(null, 0)); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Yuta HIGUCHI | 9ee0d5b | 2014-10-05 00:03:47 -0700 | [diff] [blame] | 303 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 304 | public void testHostLocation() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 305 | testSerializedEquals(new HostLocation(CP1, 1234L)); |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | @Test |
Yuta HIGUCHI | 2fcfde9 | 2014-10-20 18:37:14 -0700 | [diff] [blame] | 309 | public void testFlowId() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 310 | testSerializedEquals(FlowId.valueOf(0x12345678L)); |
Yuta HIGUCHI | 2fcfde9 | 2014-10-20 18:37:14 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | @Test |
Yuta HIGUCHI | 40d0177 | 2014-10-21 00:08:44 -0700 | [diff] [blame] | 314 | public void testRoleInfo() { |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 315 | testSerializedEquals(new RoleInfo(new NodeId("master"), |
Yuta HIGUCHI | 40d0177 | 2014-10-21 00:08:44 -0700 | [diff] [blame] | 316 | asList(new NodeId("stby1"), new NodeId("stby2")))); |
| 317 | } |
| 318 | |
| 319 | @Test |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 320 | public void testOchSignal() { |
| 321 | testSerializedEquals(org.onosproject.net.Lambda.ochSignal( |
| 322 | GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1 |
| 323 | )); |
| 324 | } |
| 325 | |
| 326 | @Test |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 327 | public void testResource() { |
Sho SHIMIZU | 460b972 | 2016-01-28 10:48:26 -0800 | [diff] [blame] | 328 | testSerializedEquals(Resources.discrete(DID1, P1, VLAN1).resource()); |
Sho SHIMIZU | 08ec48f | 2015-07-27 11:27:26 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | @Test |
Sho SHIMIZU | 8d5ff16 | 2016-01-22 12:56:31 -0800 | [diff] [blame] | 332 | public void testResourceId() { |
Sho SHIMIZU | 460b972 | 2016-01-28 10:48:26 -0800 | [diff] [blame] | 333 | testSerializedEquals(Resources.discrete(DID1, P1).id()); |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | @Test |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 337 | public void testResourceAllocation() { |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 338 | testSerializedEquals(new ResourceAllocation( |
Sho SHIMIZU | 460b972 | 2016-01-28 10:48:26 -0800 | [diff] [blame] | 339 | Resources.discrete(DID1, P1, VLAN1).resource(), |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 340 | ResourceConsumerId.of(30L, IntentId.class))); |
Sho SHIMIZU | 08ec48f | 2015-07-27 11:27:26 -0700 | [diff] [blame] | 341 | } |
Sho SHIMIZU | dee7871 | 2015-04-30 09:33:52 -0700 | [diff] [blame] | 342 | |
| 343 | @Test |
| 344 | public void testFrequency() { |
| 345 | testSerializedEquals(Frequency.ofGHz(100)); |
| 346 | } |
| 347 | |
Sho SHIMIZU | 977cb60 | 2014-11-13 08:40:50 -0800 | [diff] [blame] | 348 | @Test |
Sho SHIMIZU | 8169779 | 2015-05-08 11:09:38 -0700 | [diff] [blame] | 349 | public void testBandwidth() { |
Sho SHIMIZU | 31f37ed | 2016-01-08 18:45:54 -0800 | [diff] [blame] | 350 | testSerializedEquals(Bandwidth.mbps(1000)); |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 351 | testSerializedEquals(Bandwidth.mbps(1000.0)); |
Sho SHIMIZU | 8169779 | 2015-05-08 11:09:38 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | @Test |
Sho SHIMIZU | 977cb60 | 2014-11-13 08:40:50 -0800 | [diff] [blame] | 355 | public void testBandwidthConstraint() { |
Sho SHIMIZU | a88db49 | 2015-11-23 13:21:04 -0800 | [diff] [blame] | 356 | testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0))); |
Sho SHIMIZU | 977cb60 | 2014-11-13 08:40:50 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | @Test |
| 360 | public void testLinkTypeConstraint() { |
| 361 | testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT)); |
| 362 | } |
| 363 | |
| 364 | @Test |
| 365 | public void testLatencyConstraint() { |
| 366 | testSerializable(new LatencyConstraint(Duration.ofSeconds(10))); |
| 367 | } |
| 368 | |
| 369 | @Test |
| 370 | public void testWaypointConstraint() { |
| 371 | testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2"))); |
| 372 | } |
| 373 | |
| 374 | @Test |
| 375 | public void testObstacleConstraint() { |
| 376 | testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2"))); |
| 377 | } |
| 378 | |
| 379 | @Test |
Yuta HIGUCHI | 91768e3 | 2014-11-22 05:06:35 -0800 | [diff] [blame] | 380 | public void testArraysAsList() { |
| 381 | testSerializedEquals(Arrays.asList(1, 2, 3)); |
| 382 | } |
| 383 | |
| 384 | @Test |
Sho SHIMIZU | 977cb60 | 2014-11-13 08:40:50 -0800 | [diff] [blame] | 385 | public void testAnnotationConstraint() { |
| 386 | testSerializable(new AnnotationConstraint("distance", 100.0)); |
| 387 | } |
Yuta HIGUCHI | adac04a | 2014-11-13 00:02:45 -0800 | [diff] [blame] | 388 | |
| 389 | @Test |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 390 | public void testGroupId() { |
| 391 | testSerializedEquals(new GroupId(99)); |
Yuta HIGUCHI | f617123 | 2014-11-25 15:14:44 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Yuta HIGUCHI | ae1d210 | 2014-11-25 19:26:01 -0800 | [diff] [blame] | 394 | @Test |
| 395 | public void testEmptySet() { |
| 396 | testSerializedEquals(Collections.emptySet()); |
| 397 | } |
Yuta HIGUCHI | f617123 | 2014-11-25 15:14:44 -0800 | [diff] [blame] | 398 | |
| 399 | @Test |
Yuta HIGUCHI | eb28a7c | 2017-01-13 18:59:27 -0800 | [diff] [blame] | 400 | public void testMarkerResource() { |
| 401 | testSerializedEquals(MarkerResource.marker("testString")); |
| 402 | } |
| 403 | |
| 404 | @Test |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 405 | public void testAnnotations() { |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 406 | // Annotations does not have equals defined, manually test equality |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 407 | final byte[] a1Bytes = serializer.encode(A1); |
| 408 | SparseAnnotations copiedA1 = serializer.decode(a1Bytes); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 409 | assertAnnotationsEquals(copiedA1, A1); |
| 410 | |
Yuta HIGUCHI | aaac0d7 | 2014-10-19 17:57:47 -0700 | [diff] [blame] | 411 | final byte[] a12Bytes = serializer.encode(A1_2); |
| 412 | SparseAnnotations copiedA12 = serializer.decode(a12Bytes); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 413 | assertAnnotationsEquals(copiedA12, A1_2); |
| 414 | } |
| 415 | |
| 416 | // code clone |
Sho SHIMIZU | 7d4f2f7 | 2016-04-06 16:42:29 -0700 | [diff] [blame] | 417 | private static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) { |
Yuta HIGUCHI | 9ee0d5b | 2014-10-05 00:03:47 -0700 | [diff] [blame] | 418 | SparseAnnotations expected = DefaultAnnotations.builder().build(); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 419 | for (SparseAnnotations a : annotations) { |
Yuta HIGUCHI | 9ee0d5b | 2014-10-05 00:03:47 -0700 | [diff] [blame] | 420 | expected = DefaultAnnotations.union(expected, a); |
Yuta HIGUCHI | 5bdebe3 | 2014-10-04 21:40:41 -0700 | [diff] [blame] | 421 | } |
| 422 | assertEquals(expected.keys(), actual.keys()); |
| 423 | for (String key : expected.keys()) { |
| 424 | assertEquals(expected.value(key), actual.value(key)); |
| 425 | } |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Jordi Ortiz | 1b1a3b4 | 2017-03-03 12:36:54 +0100 | [diff] [blame] | 428 | @Test |
| 429 | public void testBitSet() { |
| 430 | BitSet bs = new BitSet(32); |
| 431 | bs.set(2); |
| 432 | bs.set(8); |
| 433 | bs.set(12); |
| 434 | bs.set(18); |
| 435 | bs.set(25); |
| 436 | bs.set(511); |
| 437 | |
| 438 | testSerializedEquals(bs); |
| 439 | } |
| 440 | |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 441 | } |