blob: 9795dab76db297293555cd9c8cca8d687f0f98aa [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;
Ray Milkeyd13a37b2015-06-12 11:55:17 -070031import org.onosproject.core.DefaultApplicationId;
Brian O'Connorabafb502014-12-02 22:26:20 -080032import org.onosproject.core.DefaultGroupId;
33import org.onosproject.mastership.MastershipTerm;
34import org.onosproject.net.Annotations;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070035import org.onosproject.net.ChannelSpacing;
Brian O'Connorabafb502014-12-02 22:26:20 -080036import org.onosproject.net.ConnectPoint;
37import org.onosproject.net.DefaultAnnotations;
38import org.onosproject.net.DefaultDevice;
39import org.onosproject.net.DefaultLink;
40import org.onosproject.net.DefaultPort;
41import org.onosproject.net.Device;
42import org.onosproject.net.DeviceId;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070043import org.onosproject.net.GridType;
Brian O'Connorabafb502014-12-02 22:26:20 -080044import org.onosproject.net.HostLocation;
45import org.onosproject.net.Link;
46import org.onosproject.net.Link.Type;
47import org.onosproject.net.LinkKey;
Marc De Leenheerbb382352015-04-23 18:20:34 -070048import org.onosproject.net.OchPort;
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070049import org.onosproject.net.OchSignal;
Marc De Leenheerbb382352015-04-23 18:20:34 -070050import org.onosproject.net.OduCltPort;
51import org.onosproject.net.OmsPort;
Brian O'Connorabafb502014-12-02 22:26:20 -080052import org.onosproject.net.PortNumber;
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070053import org.onosproject.net.OduSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080054import org.onosproject.net.SparseAnnotations;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080055import org.onosproject.net.flow.DefaultFlowRule;
56import org.onosproject.net.flow.DefaultTrafficSelector;
57import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080058import org.onosproject.net.flow.FlowId;
Sho SHIMIZU166e61e2015-01-21 18:07:12 -080059import org.onosproject.net.flow.FlowRule;
60import org.onosproject.net.flow.FlowRuleBatchEntry;
Brian O'Connorabafb502014-12-02 22:26:20 -080061import org.onosproject.net.intent.IntentId;
62import org.onosproject.net.provider.ProviderId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070063import org.onosproject.net.resource.link.BandwidthResource;
64import org.onosproject.net.resource.link.BandwidthResourceAllocation;
65import org.onosproject.net.resource.link.DefaultLinkResourceAllocations;
66import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
67import org.onosproject.net.resource.link.LambdaResource;
68import org.onosproject.net.resource.link.LambdaResourceAllocation;
69import org.onosproject.net.resource.link.LinkResourceRequest;
Brian O'Connorabafb502014-12-02 22:26:20 -080070import org.onosproject.net.resource.ResourceAllocation;
71import org.onosproject.net.intent.constraint.AnnotationConstraint;
72import org.onosproject.net.intent.constraint.BandwidthConstraint;
73import org.onosproject.net.intent.constraint.LambdaConstraint;
74import org.onosproject.net.intent.constraint.LatencyConstraint;
75import org.onosproject.net.intent.constraint.LinkTypeConstraint;
76import org.onosproject.net.intent.constraint.ObstacleConstraint;
77import org.onosproject.net.intent.constraint.WaypointConstraint;
alshabib7911a052014-10-16 17:49:37 -070078import org.onlab.packet.ChassisId;
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070079import org.onlab.packet.IpAddress;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080080import org.onlab.packet.Ip4Address;
81import org.onlab.packet.Ip6Address;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070082import org.onlab.packet.IpPrefix;
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -080083import org.onlab.packet.Ip4Prefix;
84import org.onlab.packet.Ip6Prefix;
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -070085import org.onlab.packet.MacAddress;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070086import org.onlab.util.KryoNamespace;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070087
Thomas Vachuskad16ce182014-10-29 17:25:29 -070088import java.nio.ByteBuffer;
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080089import java.util.Arrays;
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -080090import java.util.Collections;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080091import java.util.HashMap;
92import java.util.Map;
93import java.util.Set;
Sho SHIMIZU977cb602014-11-13 08:40:50 -080094import java.time.Duration;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070095
96import static java.util.Arrays.asList;
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -080097import static org.junit.Assert.*;
Brian O'Connorabafb502014-12-02 22:26:20 -080098import static org.onosproject.net.DeviceId.deviceId;
99import static org.onosproject.net.PortNumber.portNumber;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700100
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700101public class KryoSerializerTest {
102
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700103 private static final ProviderId PID = new ProviderId("of", "foo");
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700104 private static final ProviderId PIDA = new ProviderId("of", "foo", true);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700105 private static final DeviceId DID1 = deviceId("of:foo");
106 private static final DeviceId DID2 = deviceId("of:bar");
107 private static final PortNumber P1 = portNumber(1);
108 private static final PortNumber P2 = portNumber(2);
109 private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1);
110 private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2);
111 private static final String MFR = "whitebox";
112 private static final String HW = "1.1.x";
113 private static final String SW1 = "3.8.1";
114 private static final String SW2 = "3.9.5";
115 private static final String SN = "43311-12345";
alshabib7911a052014-10-16 17:49:37 -0700116 private static final ChassisId CID = new ChassisId();
117 private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW,
118 SW1, SN, CID);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700119 private static final SparseAnnotations A1 = DefaultAnnotations.builder()
120 .set("A1", "a1")
121 .set("B1", "b1")
122 .build();
123 private static final SparseAnnotations A1_2 = DefaultAnnotations.builder()
124 .remove("A1")
125 .set("B3", "b3")
126 .build();
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700127 private static final OchSignal OCH_SIGNAL1 = (OchSignal) org.onosproject.net.Lambda.ochSignal(
128 GridType.DWDM, ChannelSpacing.CHL_100GHZ, -8, 4);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700129
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700130 private KryoSerializer serializer;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700131
132 @BeforeClass
133 public static void setUpBeforeClass() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700134 }
135
136 @Before
137 public void setUp() throws Exception {
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700138 serializer = new KryoSerializer() {
139
140 @Override
141 protected void setupKryoPool() {
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -0700142 serializerPool = KryoNamespace.newBuilder()
143 .register(KryoNamespaces.API)
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800144 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID)
145 .build();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700146 }
147 };
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700148 }
149
150 @After
151 public void tearDown() throws Exception {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700152 }
153
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800154 private <T> void testSerializedEquals(T original) {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700155 ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700156 serializer.encode(original, buffer);
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700157 buffer.flip();
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700158 T copy = serializer.decode(buffer);
159
160 T copy2 = serializer.decode(serializer.encode(original));
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700161
162 new EqualsTester()
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700163 .addEqualityGroup(original, copy, copy2)
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700164 .testEquals();
165 }
166
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800167 private <T> void testSerializable(T original) {
168 byte[] bs = serializer.encode(original);
169 T copy = serializer.decode(bs);
170 assertNotNull(copy);
171 }
172
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700173
174 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700175 public void testConnectPoint() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800176 testSerializedEquals(new ConnectPoint(DID1, P1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700177 }
178
179 @Test
180 public void testDefaultLink() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800181 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT));
182 testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT, A1));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700183 }
184
185 @Test
186 public void testDefaultPort() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800187 testSerializedEquals(new DefaultPort(DEV1, P1, true));
188 testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700189 }
190
191 @Test
Marc De Leenheerbb382352015-04-23 18:20:34 -0700192 public void testOmsPort() {
193 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
194 Frequency.ofGHz(100)));
195 testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300),
196 Frequency.ofGHz(100), A1_2));
197 }
198
199 @Test
200 public void testOchPort() {
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700201 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1));
202 testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1, A1_2));
Marc De Leenheerbb382352015-04-23 18:20:34 -0700203 }
204
205 @Test
206 public void testOduCltPort() {
207 testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE));
208 testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE, A1_2));
209 }
210
211 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700212 public void testDeviceId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800213 testSerializedEquals(DID1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700214 }
215
216 @Test
217 public void testImmutableMap() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800218 testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1));
219 testSerializedEquals(ImmutableMap.of(DID1, DEV1));
220 testSerializedEquals(ImmutableMap.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700221 }
222
223 @Test
224 public void testImmutableSet() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800225 testSerializedEquals(ImmutableSet.of(DID1, DID2));
226 testSerializedEquals(ImmutableSet.of(DID1));
227 testSerializedEquals(ImmutableSet.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700228 }
229
230 @Test
231 public void testImmutableList() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800232 testSerializedEquals(ImmutableList.of(DID1, DID2));
233 testSerializedEquals(ImmutableList.of(DID1));
234 testSerializedEquals(ImmutableList.of());
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700235 }
236
237 @Test
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800238 public void testFlowRuleBatchEntry() {
239 final FlowRule rule1 =
Ray Milkeyd13a37b2015-06-12 11:55:17 -0700240 DefaultFlowRule.builder()
241 .forDevice(DID1)
242 .withSelector(DefaultTrafficSelector.emptySelector())
243 .withTreatment(DefaultTrafficTreatment.emptyTreatment())
244 .withPriority(0)
245 .fromApp(new DefaultApplicationId(1, "1"))
246 .makeTemporary(1)
247 .build();
248
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800249 final FlowRuleBatchEntry entry1 =
250 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
251 final FlowRuleBatchEntry entry2 =
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800252 new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800253
Sho SHIMIZU7446da92015-01-22 16:27:06 -0800254 testSerializedEquals(entry1);
255 testSerializedEquals(entry2);
Sho SHIMIZU166e61e2015-01-21 18:07:12 -0800256 }
257
258 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700259 public void testIpPrefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800260 testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700261 }
262
263 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800264 public void testIp4Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800265 testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800266 }
267
268 @Test
269 public void testIp6Prefix() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800270 testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800271 }
272
273 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700274 public void testIpAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800275 testSerializedEquals(IpAddress.valueOf("192.168.0.1"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700276 }
277
278 @Test
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800279 public void testIp4Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800280 testSerializedEquals(Ip4Address.valueOf("192.168.0.1"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800281 }
282
283 @Test
284 public void testIp6Address() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800285 testSerializedEquals(Ip6Address.valueOf("1111:2222::"));
Pavlin Radoslavov17378ef2014-11-05 16:13:47 -0800286 }
287
288 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700289 public void testMacAddress() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800290 testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700291 }
292
293 @Test
294 public void testLinkKey() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800295 testSerializedEquals(LinkKey.linkKey(CP1, CP2));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700296 }
297
298 @Test
299 public void testNodeId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800300 testSerializedEquals(new NodeId("SomeNodeIdentifier"));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700301 }
302
303 @Test
304 public void testPortNumber() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800305 testSerializedEquals(P1);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700306 }
307
308 @Test
309 public void testProviderId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800310 testSerializedEquals(PID);
311 testSerializedEquals(PIDA);
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700312 }
313
314 @Test
315 public void testMastershipTerm() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800316 testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2));
317 testSerializedEquals(MastershipTerm.of(null, 0));
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700318 }
319
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700320 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700321 public void testHostLocation() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800322 testSerializedEquals(new HostLocation(CP1, 1234L));
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700323 }
324
325 @Test
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700326 public void testFlowId() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800327 testSerializedEquals(FlowId.valueOf(0x12345678L));
Yuta HIGUCHI2fcfde92014-10-20 18:37:14 -0700328 }
329
330 @Test
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700331 public void testRoleInfo() {
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800332 testSerializedEquals(new RoleInfo(new NodeId("master"),
Yuta HIGUCHI40d01772014-10-21 00:08:44 -0700333 asList(new NodeId("stby1"), new NodeId("stby2"))));
334 }
335
336 @Test
Sho SHIMIZU91210a72015-04-29 12:54:28 -0700337 public void testIndexedLambda() {
338 testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L));
339 }
340
341 @Test
342 public void testOchSignal() {
343 testSerializedEquals(org.onosproject.net.Lambda.ochSignal(
344 GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1
345 ));
346 }
347
348 @Test
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800349 public void testDefaultLinkResourceRequest() {
350 testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of())
Sho SHIMIZU014c33a2015-04-30 11:40:37 -0700351 .addLambdaRequest()
352 .addBandwidthRequest(32.195)
353 .build()
354 );
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800355 }
356
357 @Test
358 public void testDefaultLinkResourceAllocations() {
359 LinkResourceRequest request = DefaultLinkResourceRequest
360 .builder(IntentId.valueOf(2501), ImmutableList.of())
361 .addLambdaRequest()
362 .addBandwidthRequest(32.195)
363 .build();
364 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
365 allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT),
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -0700366 ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))),
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -0700367 new LambdaResourceAllocation(LambdaResource.valueOf(1))));
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800368 testSerializable(new DefaultLinkResourceAllocations(request, allocations));
369 }
370
Sho SHIMIZUdee78712015-04-30 09:33:52 -0700371
372 @Test
373 public void testFrequency() {
374 testSerializedEquals(Frequency.ofGHz(100));
375 }
376
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800377 @Test
Sho SHIMIZU81697792015-05-08 11:09:38 -0700378 public void testBandwidth() {
Sho SHIMIZU63feca72015-05-07 10:44:25 -0700379 testSerializedEquals(Bandwidth.mbps(1000.0));
Sho SHIMIZU81697792015-05-08 11:09:38 -0700380 }
381
382 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800383 public void testLambdaConstraint() {
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -0700384 testSerializable(new LambdaConstraint(LambdaResource.valueOf(1)));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800385 }
386
387 @Test
388 public void testBandwidthConstraint() {
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -0700389 testSerializable(new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(1000.0))));
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800390 }
391
392 @Test
393 public void testLinkTypeConstraint() {
394 testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT));
395 }
396
397 @Test
398 public void testLatencyConstraint() {
399 testSerializable(new LatencyConstraint(Duration.ofSeconds(10)));
400 }
401
402 @Test
403 public void testWaypointConstraint() {
404 testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2")));
405 }
406
407 @Test
408 public void testObstacleConstraint() {
409 testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2")));
410 }
411
412 @Test
Yuta HIGUCHI91768e32014-11-22 05:06:35 -0800413 public void testArraysAsList() {
414 testSerializedEquals(Arrays.asList(1, 2, 3));
415 }
416
417 @Test
Sho SHIMIZU977cb602014-11-13 08:40:50 -0800418 public void testAnnotationConstraint() {
419 testSerializable(new AnnotationConstraint("distance", 100.0));
420 }
Yuta HIGUCHIadac04a2014-11-13 00:02:45 -0800421
422 @Test
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800423 public void testDefaultGroupId() {
424 testSerializedEquals(new DefaultGroupId(99));
425 }
426
Yuta HIGUCHIae1d2102014-11-25 19:26:01 -0800427 @Test
428 public void testEmptySet() {
429 testSerializedEquals(Collections.emptySet());
430 }
Yuta HIGUCHIf6171232014-11-25 15:14:44 -0800431
432 @Test
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700433 public void testAnnotations() {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700434 // Annotations does not have equals defined, manually test equality
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700435 final byte[] a1Bytes = serializer.encode(A1);
436 SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700437 assertAnnotationsEquals(copiedA1, A1);
438
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700439 final byte[] a12Bytes = serializer.encode(A1_2);
440 SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700441 assertAnnotationsEquals(copiedA12, A1_2);
442 }
443
444 // code clone
Yuta HIGUCHIaaac0d72014-10-19 17:57:47 -0700445 protected static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700446 SparseAnnotations expected = DefaultAnnotations.builder().build();
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700447 for (SparseAnnotations a : annotations) {
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -0700448 expected = DefaultAnnotations.union(expected, a);
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -0700449 }
450 assertEquals(expected.keys(), actual.keys());
451 for (String key : expected.keys()) {
452 assertEquals(expected.value(key), actual.value(key));
453 }
Yuta HIGUCHI533ec322014-09-30 13:29:52 -0700454 }
455
456}