blob: d0e1c6de7d6e2c31840da15a17a97c7eb4e1e377 [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;
Marc De Leenheerbb382352015-04-23 18:20:34 -070027import org.onlab.util.Frequency;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.cluster.NodeId;
29import org.onosproject.cluster.RoleInfo;
30import org.onosproject.core.DefaultGroupId;
31import org.onosproject.mastership.MastershipTerm;
32import org.onosproject.net.Annotations;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070033import org.onosproject.net.ChannelSpacing;
Brian O'Connorabafb502014-12-02 22:26:20 -080034import org.onosproject.net.ConnectPoint;
35import org.onosproject.net.DefaultAnnotations;
36import org.onosproject.net.DefaultDevice;
37import org.onosproject.net.DefaultLink;
38import org.onosproject.net.DefaultPort;
39import org.onosproject.net.Device;
40import org.onosproject.net.DeviceId;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070041import org.onosproject.net.GridType;
Brian O'Connorabafb502014-12-02 22:26:20 -080042import org.onosproject.net.HostLocation;
43import org.onosproject.net.Link;
44import org.onosproject.net.Link.Type;
45import org.onosproject.net.LinkKey;
Marc De Leenheerbb382352015-04-23 18:20:34 -070046import org.onosproject.net.OchPort;
47import org.onosproject.net.OduCltPort;
48import org.onosproject.net.OmsPort;
Brian O'Connorabafb502014-12-02 22:26:20 -080049import org.onosproject.net.PortNumber;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070050import org.onosproject.net.OduSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080051import org.onosproject.net.SparseAnnotations;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080052import org.onosproject.net.flow.DefaultFlowRule;
53import org.onosproject.net.flow.DefaultTrafficSelector;
54import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080055import org.onosproject.net.flow.FlowId;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080056import org.onosproject.net.flow.FlowRule;
57import org.onosproject.net.flow.FlowRuleBatchEntry;
Brian O'Connorabafb502014-12-02 22:26:20 -080058import org.onosproject.net.intent.IntentId;
59import org.onosproject.net.provider.ProviderId;
60import org.onosproject.net.resource.Bandwidth;
61import org.onosproject.net.resource.BandwidthResourceAllocation;
62import org.onosproject.net.resource.DefaultLinkResourceAllocations;
63import org.onosproject.net.resource.DefaultLinkResourceRequest;
64import org.onosproject.net.resource.Lambda;
65import org.onosproject.net.resource.LambdaResourceAllocation;
66import org.onosproject.net.resource.LinkResourceRequest;
67import org.onosproject.net.resource.ResourceAllocation;
68import org.onosproject.net.intent.constraint.AnnotationConstraint;
69import org.onosproject.net.intent.constraint.BandwidthConstraint;
70import org.onosproject.net.intent.constraint.LambdaConstraint;
71import org.onosproject.net.intent.constraint.LatencyConstraint;
72import org.onosproject.net.intent.constraint.LinkTypeConstraint;
73import org.onosproject.net.intent.constraint.ObstacleConstraint;
74import org.onosproject.net.intent.constraint.WaypointConstraint;
alshabib7911a052014-10-16 17:49:37 -070075import org.onlab.packet.ChassisId;
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070076import org.onlab.packet.IpAddress;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080077import org.onlab.packet.Ip4Address;
78import org.onlab.packet.Ip6Address;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070079import org.onlab.packet.IpPrefix;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080080import org.onlab.packet.Ip4Prefix;
81import org.onlab.packet.Ip6Prefix;
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -070082import org.onlab.packet.MacAddress;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070083import org.onlab.util.KryoNamespace;
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;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080088import java.util.HashMap;
89import java.util.Map;
90import java.util.Set;
Sho SHIMIZU977cb602014-11-13 08:40:50 -080091import java.time.Duration;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070092
93import static java.util.Arrays.asList;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080094import static org.junit.Assert.*;
Brian O'Connorabafb502014-12-02 22:26:20 -080095import static org.onosproject.net.DeviceId.deviceId;
96import static org.onosproject.net.PortNumber.portNumber;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070097
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -070098public class KryoSerializerTest {
99
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700100 private static final ProviderId PID = new ProviderId("of", "foo");
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700101 private static final ProviderId PIDA = new ProviderId("of", "foo", true);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700102 private static final DeviceId DID1 = deviceId("of:foo");
103 private static final DeviceId DID2 = deviceId("of:bar");
104 private static final PortNumber P1 = portNumber(1);
105 private static final PortNumber P2 = portNumber(2);
106 private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1);
107 private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2);
108 private static final String MFR = "whitebox";
109 private static final String HW = "1.1.x";
110 private static final String SW1 = "3.8.1";
111 private static final String SW2 = "3.9.5";
112 private static final String SN = "43311-12345";
alshabib7911a052014-10-16 17:49:37 -0700113 private static final ChassisId CID = new ChassisId();
114 private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW,
115 SW1, SN, CID);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700116 private static final SparseAnnotations A1 = DefaultAnnotations.builder()
117 .set("A1", "a1")
118 .set("B1", "b1")
119 .build();
120 private static final SparseAnnotations A1_2 = DefaultAnnotations.builder()
121 .remove("A1")
122 .set("B3", "b3")
123 .build();
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700124
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700125 private KryoSerializer 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 {
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700133 serializer = new KryoSerializer() {
134
135 @Override
136 protected void setupKryoPool() {
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700137 serializerPool = KryoNamespace.newBuilder()
138 .register(KryoNamespaces.API)
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800139 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID)
140 .build();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700141 }
142 };
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700143 }
144
145 @After
146 public void tearDown() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700147 }
148
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800149 private <T> void testSerializedEquals(T original) {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700150 ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700151 serializer.encode(original, buffer);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700152 buffer.flip();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700153 T copy = serializer.decode(buffer);
154
155 T copy2 = serializer.decode(serializer.encode(original));
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700156
157 new EqualsTester()
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700158 .addEqualityGroup(original, copy, copy2)
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700159 .testEquals();
160 }
161
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800162 private <T> void testSerializable(T original) {
163 byte[] bs = serializer.encode(original);
164 T copy = serializer.decode(bs);
165 assertNotNull(copy);
166 }
167
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700168
169 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700170 public void testConnectPoint() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800171 testSerializedEquals(new ConnectPoint(DID1, P1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700172 }
173
174 @Test
175 public void testDefaultLink() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800176 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT));
177 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT, A1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700178 }
179
180 @Test
181 public void testDefaultPort() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800182 testSerializedEquals(new DefaultPort(DEV1, P1, true));
183 testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700184 }
185
186 @Test
Marc De Leenheerbb382352015-04-23 18:20:34 -0700187 public void testOmsPort() {
188 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
189 Frequency.ofGHz(100)));
190 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
191 Frequency.ofGHz(100), A1_2));
192 }
193
194 @Test
195 public void testOchPort() {
Sho SHIMIZU014c33a2015-04-30 11:40:37 -0700196 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, GridType.DWDM,
197 ChannelSpacing.CHL_100GHZ, -8, 4));
198 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, GridType.DWDM,
199 ChannelSpacing.CHL_100GHZ, -8, 4, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700200 }
201
202 @Test
203 public void testOduCltPort() {
204 testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE));
205 testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE, A1_2));
206 }
207
208 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700209 public void testDeviceId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800210 testSerializedEquals(DID1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700211 }
212
213 @Test
214 public void testImmutableMap() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800215 testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1));
216 testSerializedEquals(ImmutableMap.of(DID1, DEV1));
217 testSerializedEquals(ImmutableMap.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700218 }
219
220 @Test
221 public void testImmutableSet() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800222 testSerializedEquals(ImmutableSet.of(DID1, DID2));
223 testSerializedEquals(ImmutableSet.of(DID1));
224 testSerializedEquals(ImmutableSet.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700225 }
226
227 @Test
228 public void testImmutableList() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800229 testSerializedEquals(ImmutableList.of(DID1, DID2));
230 testSerializedEquals(ImmutableList.of(DID1));
231 testSerializedEquals(ImmutableList.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700232 }
233
234 @Test
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800235 public void testFlowRuleBatchEntry() {
236 final FlowRule rule1 =
Brian O'Connor6b528132015-03-10 16:39:52 -0700237 new DefaultFlowRule(DID1, DefaultTrafficSelector.emptySelector(),
238 DefaultTrafficTreatment.emptyTreatment(), 0, 0, 0, true);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800239 final FlowRuleBatchEntry entry1 =
240 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
241 final FlowRuleBatchEntry entry2 =
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800242 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800243
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800244 testSerializedEquals(entry1);
245 testSerializedEquals(entry2);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800246 }
247
248 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700249 public void testIpPrefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800250 testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700251 }
252
253 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800254 public void testIp4Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800255 testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800256 }
257
258 @Test
259 public void testIp6Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800260 testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800261 }
262
263 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700264 public void testIpAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800265 testSerializedEquals(IpAddress.valueOf("192.168.0.1"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700266 }
267
268 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800269 public void testIp4Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800270 testSerializedEquals(Ip4Address.valueOf("192.168.0.1"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800271 }
272
273 @Test
274 public void testIp6Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800275 testSerializedEquals(Ip6Address.valueOf("1111:2222::"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800276 }
277
278 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700279 public void testMacAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800280 testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700281 }
282
283 @Test
284 public void testLinkKey() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800285 testSerializedEquals(LinkKey.linkKey(CP1, CP2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700286 }
287
288 @Test
289 public void testNodeId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800290 testSerializedEquals(new NodeId("SomeNodeIdentifier"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700291 }
292
293 @Test
294 public void testPortNumber() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800295 testSerializedEquals(P1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700296 }
297
298 @Test
299 public void testProviderId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800300 testSerializedEquals(PID);
301 testSerializedEquals(PIDA);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700302 }
303
304 @Test
305 public void testMastershipTerm() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800306 testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2));
307 testSerializedEquals(MastershipTerm.of(null, 0));
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700308 }
309
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700310 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700311 public void testHostLocation() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800312 testSerializedEquals(new HostLocation(CP1, 1234L));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700313 }
314
315 @Test
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700316 public void testFlowId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800317 testSerializedEquals(FlowId.valueOf(0x12345678L));
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700318 }
319
320 @Test
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700321 public void testRoleInfo() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800322 testSerializedEquals(new RoleInfo(new NodeId("master"),
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700323 asList(new NodeId("stby1"), new NodeId("stby2"))));
324 }
325
326 @Test
Sho SHIMIZU91210a72015-04-29 12:54:28 -0700327 public void testIndexedLambda() {
328 testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L));
329 }
330
331 @Test
332 public void testOchSignal() {
333 testSerializedEquals(org.onosproject.net.Lambda.ochSignal(
334 GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1
335 ));
336 }
337
338 @Test
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800339 public void testDefaultLinkResourceRequest() {
340 testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of())
Sho SHIMIZU014c33a2015-04-30 11:40:37 -0700341 .addLambdaRequest()
342 .addBandwidthRequest(32.195)
343 .build()
344 );
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800345 }
346
347 @Test
348 public void testDefaultLinkResourceAllocations() {
349 LinkResourceRequest request = DefaultLinkResourceRequest
350 .builder(IntentId.valueOf(2501), ImmutableList.of())
351 .addLambdaRequest()
352 .addBandwidthRequest(32.195)
353 .build();
354 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
355 allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT),
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -0800356 ImmutableSet.of(new BandwidthResourceAllocation(Bandwidth.bps(10.0)),
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800357 new LambdaResourceAllocation(Lambda.valueOf(1))));
358 testSerializable(new DefaultLinkResourceAllocations(request, allocations));
359 }
360
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
368 public void testLambdaConstraint() {
369 testSerializable(new LambdaConstraint(Lambda.valueOf(1)));
370 }
371
372 @Test
373 public void testBandwidthConstraint() {
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -0800374 testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800375 }
376
377 @Test
378 public void testLinkTypeConstraint() {
379 testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT));
380 }
381
382 @Test
383 public void testLatencyConstraint() {
384 testSerializable(new LatencyConstraint(Duration.ofSeconds(10)));
385 }
386
387 @Test
388 public void testWaypointConstraint() {
389 testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2")));
390 }
391
392 @Test
393 public void testObstacleConstraint() {
394 testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2")));
395 }
396
397 @Test
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800398 public void testArraysAsList() {
399 testSerializedEquals(Arrays.asList(1, 2, 3));
400 }
401
402 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800403 public void testAnnotationConstraint() {
404 testSerializable(new AnnotationConstraint("distance", 100.0));
405 }
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800406
407 @Test
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800408 public void testDefaultGroupId() {
409 testSerializedEquals(new DefaultGroupId(99));
410 }
411
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -0800412 @Test
413 public void testEmptySet() {
414 testSerializedEquals(Collections.emptySet());
415 }
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800416
417 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700418 public void testAnnotations() {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700419 // Annotations does not have equals defined, manually test equality
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700420 final byte[] a1Bytes = serializer.encode(A1);
421 SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700422 assertAnnotationsEquals(copiedA1, A1);
423
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700424 final byte[] a12Bytes = serializer.encode(A1_2);
425 SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700426 assertAnnotationsEquals(copiedA12, A1_2);
427 }
428
429 // code clone
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700430 protected static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700431 SparseAnnotations expected = DefaultAnnotations.builder().build();
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700432 for (SparseAnnotations a : annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700433 expected = DefaultAnnotations.union(expected, a);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700434 }
435 assertEquals(expected.keys(), actual.keys());
436 for (String key : expected.keys()) {
437 assertEquals(expected.value(key), actual.value(key));
438 }
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700439 }
440
441}