blob: dc455701412bc8a44d24dc78bba9b18aa7d945d7 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.serializers;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070017
Thomas Vachuskad16ce182014-10-29 17:25:29 -070018import com.google.common.collect.ImmutableList;
19import com.google.common.collect.ImmutableMap;
20import com.google.common.collect.ImmutableSet;
21import com.google.common.testing.EqualsTester;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080022
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070023import org.junit.After;
24import org.junit.Before;
25import org.junit.BeforeClass;
26import org.junit.Test;
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -070027import org.onlab.packet.VlanId;
Sho SHIMIZU63feca72015-05-07 10:44:25 -070028import org.onlab.util.Bandwidth;
Marc De Leenheerbb382352015-04-23 18:20:34 -070029import org.onlab.util.Frequency;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.cluster.NodeId;
31import org.onosproject.cluster.RoleInfo;
Ray Milkeyd13a37b2015-06-12 11:55:17 -070032import org.onosproject.core.DefaultApplicationId;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import org.onosproject.core.DefaultGroupId;
34import org.onosproject.mastership.MastershipTerm;
35import org.onosproject.net.Annotations;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070036import org.onosproject.net.ChannelSpacing;
Toru Furusawa72ee30c2016-01-08 13:29:04 -080037import org.onosproject.net.CltSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080038import org.onosproject.net.ConnectPoint;
39import org.onosproject.net.DefaultAnnotations;
40import org.onosproject.net.DefaultDevice;
41import org.onosproject.net.DefaultLink;
42import org.onosproject.net.DefaultPort;
43import org.onosproject.net.Device;
44import org.onosproject.net.DeviceId;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070045import org.onosproject.net.GridType;
Brian O'Connorabafb502014-12-02 22:26:20 -080046import org.onosproject.net.HostLocation;
47import org.onosproject.net.Link;
Brian O'Connorabafb502014-12-02 22:26:20 -080048import org.onosproject.net.LinkKey;
Yuta HIGUCHIeb28a7c2017-01-13 18:59:27 -080049import org.onosproject.net.MarkerResource;
Marc De Leenheerbb382352015-04-23 18:20:34 -070050import org.onosproject.net.OchPort;
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070051import org.onosproject.net.OchSignal;
Marc De Leenheerbb382352015-04-23 18:20:34 -070052import org.onosproject.net.OduCltPort;
53import org.onosproject.net.OmsPort;
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020054import org.onosproject.net.OtuPort;
55import org.onosproject.net.OtuSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080056import org.onosproject.net.PortNumber;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070057import org.onosproject.net.OduSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080058import org.onosproject.net.SparseAnnotations;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080059import org.onosproject.net.flow.DefaultFlowRule;
60import org.onosproject.net.flow.DefaultTrafficSelector;
61import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080062import org.onosproject.net.flow.FlowId;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080063import org.onosproject.net.flow.FlowRule;
64import org.onosproject.net.flow.FlowRuleBatchEntry;
Brian O'Connorabafb502014-12-02 22:26:20 -080065import org.onosproject.net.intent.IntentId;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080066import org.onosproject.net.resource.ResourceAllocation;
Naoki Shiotabd1974c2016-04-29 18:44:17 -070067import org.onosproject.net.resource.ResourceConsumerId;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080068import org.onosproject.net.resource.Resources;
Brian O'Connorabafb502014-12-02 22:26:20 -080069import org.onosproject.net.provider.ProviderId;
Brian O'Connorabafb502014-12-02 22:26:20 -080070import org.onosproject.net.intent.constraint.AnnotationConstraint;
71import org.onosproject.net.intent.constraint.BandwidthConstraint;
Brian O'Connorabafb502014-12-02 22:26:20 -080072import org.onosproject.net.intent.constraint.LatencyConstraint;
73import org.onosproject.net.intent.constraint.LinkTypeConstraint;
74import org.onosproject.net.intent.constraint.ObstacleConstraint;
75import org.onosproject.net.intent.constraint.WaypointConstraint;
alshabib7911a052014-10-16 17:49:37 -070076import org.onlab.packet.ChassisId;
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070077import org.onlab.packet.IpAddress;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080078import org.onlab.packet.Ip4Address;
79import org.onlab.packet.Ip6Address;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070080import org.onlab.packet.IpPrefix;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080081import org.onlab.packet.Ip4Prefix;
82import org.onlab.packet.Ip6Prefix;
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -070083import org.onlab.packet.MacAddress;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070084
Thomas Vachuskad16ce182014-10-29 17:25:29 -070085import java.nio.ByteBuffer;
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080086import java.util.Arrays;
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -080087import java.util.Collections;
Sho SHIMIZU977cb602014-11-13 08:40:50 -080088import java.time.Duration;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070089
90import static java.util.Arrays.asList;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080091import static org.junit.Assert.*;
Brian O'Connorabafb502014-12-02 22:26:20 -080092import static org.onosproject.net.DeviceId.deviceId;
93import static org.onosproject.net.PortNumber.portNumber;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070094
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -070095public class KryoSerializerTest {
96
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070097 private static final ProviderId PID = new ProviderId("of", "foo");
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070098 private static final ProviderId PIDA = new ProviderId("of", "foo", true);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070099 private static final DeviceId DID1 = deviceId("of:foo");
100 private static final DeviceId DID2 = deviceId("of:bar");
101 private static final PortNumber P1 = portNumber(1);
102 private static final PortNumber P2 = portNumber(2);
103 private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1);
104 private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2);
105 private static final String MFR = "whitebox";
106 private static final String HW = "1.1.x";
107 private static final String SW1 = "3.8.1";
108 private static final String SW2 = "3.9.5";
109 private static final String SN = "43311-12345";
alshabib7911a052014-10-16 17:49:37 -0700110 private static final ChassisId CID = new ChassisId();
111 private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW,
112 SW1, SN, CID);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700113 private static final SparseAnnotations A1 = DefaultAnnotations.builder()
114 .set("A1", "a1")
115 .set("B1", "b1")
116 .build();
117 private static final SparseAnnotations A1_2 = DefaultAnnotations.builder()
118 .remove("A1")
119 .set("B3", "b3")
120 .build();
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700121 private static final OchSignal OCH_SIGNAL1 = (OchSignal) org.onosproject.net.Lambda.ochSignal(
122 GridType.DWDM, ChannelSpacing.CHL_100GHZ, -8, 4);
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700123 private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700124
HIGUCHI Yutae7290652016-05-18 11:29:01 -0700125 private StoreSerializer serializer;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700126
127 @BeforeClass
128 public static void setUpBeforeClass() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700129 }
130
131 @Before
132 public void setUp() throws Exception {
HIGUCHI Yutae7290652016-05-18 11:29:01 -0700133 serializer = StoreSerializer.using(KryoNamespaces.API);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700134 }
135
136 @After
137 public void tearDown() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700138 }
139
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800140 private <T> void testSerializedEquals(T original) {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700141 ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700142 serializer.encode(original, buffer);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700143 buffer.flip();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700144 T copy = serializer.decode(buffer);
145
146 T copy2 = serializer.decode(serializer.encode(original));
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700147
148 new EqualsTester()
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700149 .addEqualityGroup(original, copy, copy2)
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700150 .testEquals();
151 }
152
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800153 private <T> void testSerializable(T original) {
154 byte[] bs = serializer.encode(original);
155 T copy = serializer.decode(bs);
156 assertNotNull(copy);
157 }
158
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700159
160 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700161 public void testConnectPoint() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800162 testSerializedEquals(new ConnectPoint(DID1, P1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700163 }
164
165 @Test
166 public void testDefaultLink() {
Ray Milkey2693bda2016-01-22 16:08:14 -0800167 testSerializedEquals(DefaultLink.builder()
168 .providerId(PID)
169 .src(CP1)
170 .dst(CP2)
171 .type(Link.Type.DIRECT)
172 .build());
173 testSerializedEquals(DefaultLink.builder()
174 .providerId(PID)
175 .src(CP1)
176 .dst(CP2)
177 .type(Link.Type.DIRECT)
178 .annotations(A1)
179 .build());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700180 }
181
182 @Test
183 public void testDefaultPort() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800184 testSerializedEquals(new DefaultPort(DEV1, P1, true));
185 testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700186 }
187
188 @Test
Marc De Leenheerbb382352015-04-23 18:20:34 -0700189 public void testOmsPort() {
190 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
191 Frequency.ofGHz(100)));
192 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
193 Frequency.ofGHz(100), A1_2));
194 }
195
196 @Test
197 public void testOchPort() {
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700198 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1));
199 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700200 }
201
202 @Test
203 public void testOduCltPort() {
Toru Furusawa72ee30c2016-01-08 13:29:04 -0800204 testSerializedEquals(new OduCltPort(DEV1, P1, true, CltSignalType.CLT_10GBE));
205 testSerializedEquals(new OduCltPort(DEV1, P1, true, CltSignalType.CLT_10GBE, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700206 }
207
208 @Test
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200209 public void testOtuPort() {
210 testSerializedEquals(new OtuPort(DEV1, P1, true, OtuSignalType.OTU2));
211 testSerializedEquals(new OtuPort(DEV1, P1, true, OtuSignalType.OTU2, A1_2));
212 }
213 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700214 public void testDeviceId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800215 testSerializedEquals(DID1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700216 }
217
218 @Test
219 public void testImmutableMap() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800220 testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1));
221 testSerializedEquals(ImmutableMap.of(DID1, DEV1));
222 testSerializedEquals(ImmutableMap.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700223 }
224
225 @Test
226 public void testImmutableSet() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800227 testSerializedEquals(ImmutableSet.of(DID1, DID2));
228 testSerializedEquals(ImmutableSet.of(DID1));
229 testSerializedEquals(ImmutableSet.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700230 }
231
232 @Test
233 public void testImmutableList() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800234 testSerializedEquals(ImmutableList.of(DID1, DID2));
235 testSerializedEquals(ImmutableList.of(DID1));
236 testSerializedEquals(ImmutableList.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700237 }
238
239 @Test
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800240 public void testFlowRuleBatchEntry() {
241 final FlowRule rule1 =
Ray Milkeyd13a37b2015-06-12 11:55:17 -0700242 DefaultFlowRule.builder()
243 .forDevice(DID1)
244 .withSelector(DefaultTrafficSelector.emptySelector())
245 .withTreatment(DefaultTrafficTreatment.emptyTreatment())
246 .withPriority(0)
247 .fromApp(new DefaultApplicationId(1, "1"))
248 .makeTemporary(1)
249 .build();
250
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800251 final FlowRuleBatchEntry entry1 =
252 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
253 final FlowRuleBatchEntry entry2 =
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800254 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800255
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800256 testSerializedEquals(entry1);
257 testSerializedEquals(entry2);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800258 }
259
260 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700261 public void testIpPrefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800262 testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700263 }
264
265 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800266 public void testIp4Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800267 testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800268 }
269
270 @Test
271 public void testIp6Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800272 testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800273 }
274
275 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700276 public void testIpAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800277 testSerializedEquals(IpAddress.valueOf("192.168.0.1"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700278 }
279
280 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800281 public void testIp4Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800282 testSerializedEquals(Ip4Address.valueOf("192.168.0.1"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800283 }
284
285 @Test
286 public void testIp6Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800287 testSerializedEquals(Ip6Address.valueOf("1111:2222::"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800288 }
289
290 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700291 public void testMacAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800292 testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700293 }
294
295 @Test
296 public void testLinkKey() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800297 testSerializedEquals(LinkKey.linkKey(CP1, CP2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700298 }
299
300 @Test
301 public void testNodeId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800302 testSerializedEquals(new NodeId("SomeNodeIdentifier"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700303 }
304
305 @Test
306 public void testPortNumber() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800307 testSerializedEquals(P1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700308 }
309
310 @Test
311 public void testProviderId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800312 testSerializedEquals(PID);
313 testSerializedEquals(PIDA);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700314 }
315
316 @Test
317 public void testMastershipTerm() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800318 testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2));
319 testSerializedEquals(MastershipTerm.of(null, 0));
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700320 }
321
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700322 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700323 public void testHostLocation() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800324 testSerializedEquals(new HostLocation(CP1, 1234L));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700325 }
326
327 @Test
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700328 public void testFlowId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800329 testSerializedEquals(FlowId.valueOf(0x12345678L));
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700330 }
331
332 @Test
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700333 public void testRoleInfo() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800334 testSerializedEquals(new RoleInfo(new NodeId("master"),
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700335 asList(new NodeId("stby1"), new NodeId("stby2"))));
336 }
337
338 @Test
Sho SHIMIZU91210a72015-04-29 12:54:28 -0700339 public void testOchSignal() {
340 testSerializedEquals(org.onosproject.net.Lambda.ochSignal(
341 GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1
342 ));
343 }
344
345 @Test
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -0800346 public void testResource() {
Sho SHIMIZU460b9722016-01-28 10:48:26 -0800347 testSerializedEquals(Resources.discrete(DID1, P1, VLAN1).resource());
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700348 }
349
350 @Test
Sho SHIMIZU8d5ff162016-01-22 12:56:31 -0800351 public void testResourceId() {
Sho SHIMIZU460b9722016-01-28 10:48:26 -0800352 testSerializedEquals(Resources.discrete(DID1, P1).id());
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800353 }
354
355 @Test
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700356 public void testResourceAllocation() {
Sho SHIMIZUe18cb122016-02-22 21:04:56 -0800357 testSerializedEquals(new ResourceAllocation(
Sho SHIMIZU460b9722016-01-28 10:48:26 -0800358 Resources.discrete(DID1, P1, VLAN1).resource(),
Naoki Shiotabd1974c2016-04-29 18:44:17 -0700359 ResourceConsumerId.of(30L, IntentId.class)));
Sho SHIMIZU08ec48f2015-07-27 11:27:26 -0700360 }
Sho SHIMIZUdee78712015-04-30 09:33:52 -0700361
362 @Test
363 public void testFrequency() {
364 testSerializedEquals(Frequency.ofGHz(100));
365 }
366
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800367 @Test
Sho SHIMIZU81697792015-05-08 11:09:38 -0700368 public void testBandwidth() {
Sho SHIMIZU31f37ed2016-01-08 18:45:54 -0800369 testSerializedEquals(Bandwidth.mbps(1000));
Sho SHIMIZU63feca72015-05-07 10:44:25 -0700370 testSerializedEquals(Bandwidth.mbps(1000.0));
Sho SHIMIZU81697792015-05-08 11:09:38 -0700371 }
372
373 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800374 public void testBandwidthConstraint() {
Sho SHIMIZUa88db492015-11-23 13:21:04 -0800375 testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800376 }
377
378 @Test
379 public void testLinkTypeConstraint() {
380 testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT));
381 }
382
383 @Test
384 public void testLatencyConstraint() {
385 testSerializable(new LatencyConstraint(Duration.ofSeconds(10)));
386 }
387
388 @Test
389 public void testWaypointConstraint() {
390 testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2")));
391 }
392
393 @Test
394 public void testObstacleConstraint() {
395 testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2")));
396 }
397
398 @Test
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800399 public void testArraysAsList() {
400 testSerializedEquals(Arrays.asList(1, 2, 3));
401 }
402
403 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800404 public void testAnnotationConstraint() {
405 testSerializable(new AnnotationConstraint("distance", 100.0));
406 }
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800407
408 @Test
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800409 public void testDefaultGroupId() {
410 testSerializedEquals(new DefaultGroupId(99));
411 }
412
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -0800413 @Test
414 public void testEmptySet() {
415 testSerializedEquals(Collections.emptySet());
416 }
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800417
418 @Test
Yuta HIGUCHIeb28a7c2017-01-13 18:59:27 -0800419 public void testMarkerResource() {
420 testSerializedEquals(MarkerResource.marker("testString"));
421 }
422
423 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700424 public void testAnnotations() {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700425 // Annotations does not have equals defined, manually test equality
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700426 final byte[] a1Bytes = serializer.encode(A1);
427 SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700428 assertAnnotationsEquals(copiedA1, A1);
429
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700430 final byte[] a12Bytes = serializer.encode(A1_2);
431 SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700432 assertAnnotationsEquals(copiedA12, A1_2);
433 }
434
435 // code clone
Sho SHIMIZU7d4f2f72016-04-06 16:42:29 -0700436 private static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700437 SparseAnnotations expected = DefaultAnnotations.builder().build();
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700438 for (SparseAnnotations a : annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700439 expected = DefaultAnnotations.union(expected, a);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700440 }
441 assertEquals(expected.keys(), actual.keys());
442 for (String key : expected.keys()) {
443 assertEquals(expected.value(key), actual.value(key));
444 }
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700445 }
446
447}