blob: ac9da385526fc31890380bdcb7e99d41b70cc6f3 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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 SHIMIZU63feca72015-05-07 10:44:25 -070027import org.onlab.util.Bandwidth;
Marc De Leenheerbb382352015-04-23 18:20:34 -070028import org.onlab.util.Frequency;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.cluster.NodeId;
30import org.onosproject.cluster.RoleInfo;
31import org.onosproject.core.DefaultGroupId;
32import org.onosproject.mastership.MastershipTerm;
33import org.onosproject.net.Annotations;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070034import org.onosproject.net.ChannelSpacing;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.ConnectPoint;
36import org.onosproject.net.DefaultAnnotations;
37import org.onosproject.net.DefaultDevice;
38import org.onosproject.net.DefaultLink;
39import org.onosproject.net.DefaultPort;
40import org.onosproject.net.Device;
41import org.onosproject.net.DeviceId;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070042import org.onosproject.net.GridType;
Brian O'Connorabafb502014-12-02 22:26:20 -080043import org.onosproject.net.HostLocation;
44import org.onosproject.net.Link;
45import org.onosproject.net.Link.Type;
46import org.onosproject.net.LinkKey;
Marc De Leenheerbb382352015-04-23 18:20:34 -070047import org.onosproject.net.OchPort;
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070048import org.onosproject.net.OchSignal;
Marc De Leenheerbb382352015-04-23 18:20:34 -070049import org.onosproject.net.OduCltPort;
50import org.onosproject.net.OmsPort;
Brian O'Connorabafb502014-12-02 22:26:20 -080051import org.onosproject.net.PortNumber;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070052import org.onosproject.net.OduSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080053import org.onosproject.net.SparseAnnotations;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080054import org.onosproject.net.flow.DefaultFlowRule;
55import org.onosproject.net.flow.DefaultTrafficSelector;
56import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080057import org.onosproject.net.flow.FlowId;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080058import org.onosproject.net.flow.FlowRule;
59import org.onosproject.net.flow.FlowRuleBatchEntry;
Brian O'Connorabafb502014-12-02 22:26:20 -080060import org.onosproject.net.intent.IntentId;
61import org.onosproject.net.provider.ProviderId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070062import org.onosproject.net.resource.link.BandwidthResource;
63import org.onosproject.net.resource.link.BandwidthResourceAllocation;
64import org.onosproject.net.resource.link.DefaultLinkResourceAllocations;
65import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
66import org.onosproject.net.resource.link.LambdaResource;
67import org.onosproject.net.resource.link.LambdaResourceAllocation;
68import org.onosproject.net.resource.link.LinkResourceRequest;
Brian O'Connorabafb502014-12-02 22:26:20 -080069import org.onosproject.net.resource.ResourceAllocation;
70import org.onosproject.net.intent.constraint.AnnotationConstraint;
71import org.onosproject.net.intent.constraint.BandwidthConstraint;
72import org.onosproject.net.intent.constraint.LambdaConstraint;
73import org.onosproject.net.intent.constraint.LatencyConstraint;
74import org.onosproject.net.intent.constraint.LinkTypeConstraint;
75import org.onosproject.net.intent.constraint.ObstacleConstraint;
76import org.onosproject.net.intent.constraint.WaypointConstraint;
alshabib7911a052014-10-16 17:49:37 -070077import org.onlab.packet.ChassisId;
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070078import org.onlab.packet.IpAddress;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080079import org.onlab.packet.Ip4Address;
80import org.onlab.packet.Ip6Address;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070081import org.onlab.packet.IpPrefix;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080082import org.onlab.packet.Ip4Prefix;
83import org.onlab.packet.Ip6Prefix;
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -070084import org.onlab.packet.MacAddress;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070085import org.onlab.util.KryoNamespace;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070086
Thomas Vachuskad16ce182014-10-29 17:25:29 -070087import java.nio.ByteBuffer;
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080088import java.util.Arrays;
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -080089import java.util.Collections;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080090import java.util.HashMap;
91import java.util.Map;
92import java.util.Set;
Sho SHIMIZU977cb602014-11-13 08:40:50 -080093import java.time.Duration;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070094
95import static java.util.Arrays.asList;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080096import static org.junit.Assert.*;
Brian O'Connorabafb502014-12-02 22:26:20 -080097import static org.onosproject.net.DeviceId.deviceId;
98import static org.onosproject.net.PortNumber.portNumber;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070099
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700100public class KryoSerializerTest {
101
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700102 private static final ProviderId PID = new ProviderId("of", "foo");
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700103 private static final ProviderId PIDA = new ProviderId("of", "foo", true);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700104 private static final DeviceId DID1 = deviceId("of:foo");
105 private static final DeviceId DID2 = deviceId("of:bar");
106 private static final PortNumber P1 = portNumber(1);
107 private static final PortNumber P2 = portNumber(2);
108 private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1);
109 private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2);
110 private static final String MFR = "whitebox";
111 private static final String HW = "1.1.x";
112 private static final String SW1 = "3.8.1";
113 private static final String SW2 = "3.9.5";
114 private static final String SN = "43311-12345";
alshabib7911a052014-10-16 17:49:37 -0700115 private static final ChassisId CID = new ChassisId();
116 private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW,
117 SW1, SN, CID);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700118 private static final SparseAnnotations A1 = DefaultAnnotations.builder()
119 .set("A1", "a1")
120 .set("B1", "b1")
121 .build();
122 private static final SparseAnnotations A1_2 = DefaultAnnotations.builder()
123 .remove("A1")
124 .set("B3", "b3")
125 .build();
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700126 private static final OchSignal OCH_SIGNAL1 = (OchSignal) org.onosproject.net.Lambda.ochSignal(
127 GridType.DWDM, ChannelSpacing.CHL_100GHZ, -8, 4);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700128
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700129 private KryoSerializer serializer;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700130
131 @BeforeClass
132 public static void setUpBeforeClass() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700133 }
134
135 @Before
136 public void setUp() throws Exception {
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700137 serializer = new KryoSerializer() {
138
139 @Override
140 protected void setupKryoPool() {
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700141 serializerPool = KryoNamespace.newBuilder()
142 .register(KryoNamespaces.API)
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800143 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID)
144 .build();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700145 }
146 };
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700147 }
148
149 @After
150 public void tearDown() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700151 }
152
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800153 private <T> void testSerializedEquals(T original) {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700154 ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700155 serializer.encode(original, buffer);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700156 buffer.flip();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700157 T copy = serializer.decode(buffer);
158
159 T copy2 = serializer.decode(serializer.encode(original));
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700160
161 new EqualsTester()
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700162 .addEqualityGroup(original, copy, copy2)
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700163 .testEquals();
164 }
165
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800166 private <T> void testSerializable(T original) {
167 byte[] bs = serializer.encode(original);
168 T copy = serializer.decode(bs);
169 assertNotNull(copy);
170 }
171
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700172
173 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700174 public void testConnectPoint() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800175 testSerializedEquals(new ConnectPoint(DID1, P1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700176 }
177
178 @Test
179 public void testDefaultLink() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800180 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT));
181 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT, A1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700182 }
183
184 @Test
185 public void testDefaultPort() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800186 testSerializedEquals(new DefaultPort(DEV1, P1, true));
187 testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700188 }
189
190 @Test
Marc De Leenheerbb382352015-04-23 18:20:34 -0700191 public void testOmsPort() {
192 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
193 Frequency.ofGHz(100)));
194 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
195 Frequency.ofGHz(100), A1_2));
196 }
197
198 @Test
199 public void testOchPort() {
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700200 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1));
201 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700202 }
203
204 @Test
205 public void testOduCltPort() {
206 testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE));
207 testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE, A1_2));
208 }
209
210 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700211 public void testDeviceId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800212 testSerializedEquals(DID1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700213 }
214
215 @Test
216 public void testImmutableMap() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800217 testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1));
218 testSerializedEquals(ImmutableMap.of(DID1, DEV1));
219 testSerializedEquals(ImmutableMap.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700220 }
221
222 @Test
223 public void testImmutableSet() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800224 testSerializedEquals(ImmutableSet.of(DID1, DID2));
225 testSerializedEquals(ImmutableSet.of(DID1));
226 testSerializedEquals(ImmutableSet.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700227 }
228
229 @Test
230 public void testImmutableList() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800231 testSerializedEquals(ImmutableList.of(DID1, DID2));
232 testSerializedEquals(ImmutableList.of(DID1));
233 testSerializedEquals(ImmutableList.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700234 }
235
236 @Test
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800237 public void testFlowRuleBatchEntry() {
238 final FlowRule rule1 =
Brian O'Connor6b528132015-03-10 16:39:52 -0700239 new DefaultFlowRule(DID1, DefaultTrafficSelector.emptySelector(),
240 DefaultTrafficTreatment.emptyTreatment(), 0, 0, 0, true);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800241 final FlowRuleBatchEntry entry1 =
242 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
243 final FlowRuleBatchEntry entry2 =
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800244 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800245
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800246 testSerializedEquals(entry1);
247 testSerializedEquals(entry2);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800248 }
249
250 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700251 public void testIpPrefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800252 testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700253 }
254
255 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800256 public void testIp4Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800257 testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800258 }
259
260 @Test
261 public void testIp6Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800262 testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800263 }
264
265 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700266 public void testIpAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800267 testSerializedEquals(IpAddress.valueOf("192.168.0.1"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700268 }
269
270 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800271 public void testIp4Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800272 testSerializedEquals(Ip4Address.valueOf("192.168.0.1"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800273 }
274
275 @Test
276 public void testIp6Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800277 testSerializedEquals(Ip6Address.valueOf("1111:2222::"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800278 }
279
280 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700281 public void testMacAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800282 testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700283 }
284
285 @Test
286 public void testLinkKey() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800287 testSerializedEquals(LinkKey.linkKey(CP1, CP2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700288 }
289
290 @Test
291 public void testNodeId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800292 testSerializedEquals(new NodeId("SomeNodeIdentifier"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700293 }
294
295 @Test
296 public void testPortNumber() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800297 testSerializedEquals(P1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700298 }
299
300 @Test
301 public void testProviderId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800302 testSerializedEquals(PID);
303 testSerializedEquals(PIDA);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700304 }
305
306 @Test
307 public void testMastershipTerm() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800308 testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2));
309 testSerializedEquals(MastershipTerm.of(null, 0));
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700310 }
311
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700312 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700313 public void testHostLocation() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800314 testSerializedEquals(new HostLocation(CP1, 1234L));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700315 }
316
317 @Test
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700318 public void testFlowId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800319 testSerializedEquals(FlowId.valueOf(0x12345678L));
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700320 }
321
322 @Test
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700323 public void testRoleInfo() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800324 testSerializedEquals(new RoleInfo(new NodeId("master"),
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700325 asList(new NodeId("stby1"), new NodeId("stby2"))));
326 }
327
328 @Test
Sho SHIMIZU91210a72015-04-29 12:54:28 -0700329 public void testIndexedLambda() {
330 testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L));
331 }
332
333 @Test
334 public void testOchSignal() {
335 testSerializedEquals(org.onosproject.net.Lambda.ochSignal(
336 GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1
337 ));
338 }
339
340 @Test
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800341 public void testDefaultLinkResourceRequest() {
342 testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of())
Sho SHIMIZU014c33a2015-04-30 11:40:37 -0700343 .addLambdaRequest()
344 .addBandwidthRequest(32.195)
345 .build()
346 );
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800347 }
348
349 @Test
350 public void testDefaultLinkResourceAllocations() {
351 LinkResourceRequest request = DefaultLinkResourceRequest
352 .builder(IntentId.valueOf(2501), ImmutableList.of())
353 .addLambdaRequest()
354 .addBandwidthRequest(32.195)
355 .build();
356 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
357 allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT),
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -0700358 ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))),
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -0700359 new LambdaResourceAllocation(LambdaResource.valueOf(1))));
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800360 testSerializable(new DefaultLinkResourceAllocations(request, allocations));
361 }
362
Sho SHIMIZUdee78712015-04-30 09:33:52 -0700363
364 @Test
365 public void testFrequency() {
366 testSerializedEquals(Frequency.ofGHz(100));
367 }
368
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800369 @Test
Sho SHIMIZU81697792015-05-08 11:09:38 -0700370 public void testBandwidth() {
Sho SHIMIZU63feca72015-05-07 10:44:25 -0700371 testSerializedEquals(Bandwidth.mbps(1000.0));
Sho SHIMIZU81697792015-05-08 11:09:38 -0700372 }
373
374 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800375 public void testLambdaConstraint() {
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -0700376 testSerializable(new LambdaConstraint(LambdaResource.valueOf(1)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800377 }
378
379 @Test
380 public void testBandwidthConstraint() {
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -0700381 testSerializable(new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(1000.0))));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800382 }
383
384 @Test
385 public void testLinkTypeConstraint() {
386 testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT));
387 }
388
389 @Test
390 public void testLatencyConstraint() {
391 testSerializable(new LatencyConstraint(Duration.ofSeconds(10)));
392 }
393
394 @Test
395 public void testWaypointConstraint() {
396 testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2")));
397 }
398
399 @Test
400 public void testObstacleConstraint() {
401 testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2")));
402 }
403
404 @Test
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800405 public void testArraysAsList() {
406 testSerializedEquals(Arrays.asList(1, 2, 3));
407 }
408
409 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800410 public void testAnnotationConstraint() {
411 testSerializable(new AnnotationConstraint("distance", 100.0));
412 }
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800413
414 @Test
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800415 public void testDefaultGroupId() {
416 testSerializedEquals(new DefaultGroupId(99));
417 }
418
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -0800419 @Test
420 public void testEmptySet() {
421 testSerializedEquals(Collections.emptySet());
422 }
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800423
424 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700425 public void testAnnotations() {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700426 // Annotations does not have equals defined, manually test equality
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700427 final byte[] a1Bytes = serializer.encode(A1);
428 SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700429 assertAnnotationsEquals(copiedA1, A1);
430
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700431 final byte[] a12Bytes = serializer.encode(A1_2);
432 SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700433 assertAnnotationsEquals(copiedA12, A1_2);
434 }
435
436 // code clone
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700437 protected static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700438 SparseAnnotations expected = DefaultAnnotations.builder().build();
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700439 for (SparseAnnotations a : annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700440 expected = DefaultAnnotations.union(expected, a);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700441 }
442 assertEquals(expected.keys(), actual.keys());
443 for (String key : expected.keys()) {
444 assertEquals(expected.value(key), actual.value(key));
445 }
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700446 }
447
448}