blob: cfd9d24f6a7daf037da3f413f186955a39dd5b38 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
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 */
tomea961ff2014-10-01 12:45:15 -070016package org.onlab.onos.store.trivial.impl;
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -070017
Thomas Vachuska0e752bd2014-10-22 22:33:41 -070018import com.google.common.collect.Iterables;
Yuta HIGUCHI3e5d11a2014-11-04 14:16:44 -080019
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -070020import org.junit.After;
21import org.junit.AfterClass;
22import org.junit.Before;
23import org.junit.BeforeClass;
24import org.junit.Ignore;
25import org.junit.Test;
Thomas Vachuska57126fe2014-11-11 17:13:24 -080026import org.onlab.onos.net.AnnotationKeys;
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -070027import org.onlab.onos.net.ConnectPoint;
Yuta HIGUCHI39ede6a2014-10-03 15:23:33 -070028import org.onlab.onos.net.DefaultAnnotations;
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -070029import org.onlab.onos.net.DeviceId;
30import org.onlab.onos.net.Link;
Thomas Vachuska0e752bd2014-10-22 22:33:41 -070031import org.onlab.onos.net.Link.Type;
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -070032import org.onlab.onos.net.LinkKey;
33import org.onlab.onos.net.PortNumber;
Yuta HIGUCHI39ede6a2014-10-03 15:23:33 -070034import org.onlab.onos.net.SparseAnnotations;
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -070035import org.onlab.onos.net.link.DefaultLinkDescription;
36import org.onlab.onos.net.link.LinkEvent;
37import org.onlab.onos.net.link.LinkStore;
38import org.onlab.onos.net.link.LinkStoreDelegate;
39import org.onlab.onos.net.provider.ProviderId;
40
Thomas Vachuska0e752bd2014-10-22 22:33:41 -070041import java.util.HashMap;
42import java.util.Map;
43import java.util.Set;
44import java.util.concurrent.CountDownLatch;
45import java.util.concurrent.TimeUnit;
46
47import static org.junit.Assert.*;
48import static org.onlab.onos.net.DeviceId.deviceId;
49import static org.onlab.onos.net.Link.Type.*;
50import static org.onlab.onos.net.link.LinkEvent.Type.*;
Yuta HIGUCHI3e5d11a2014-11-04 14:16:44 -080051import static org.onlab.onos.net.NetTestTools.assertAnnotationsEquals;
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -070052
53/**
54 * Test of the simple LinkStore implementation.
55 */
56public class SimpleLinkStoreTest {
57
58 private static final ProviderId PID = new ProviderId("of", "foo");
Yuta HIGUCHI39ede6a2014-10-03 15:23:33 -070059 private static final ProviderId PIDA = new ProviderId("of", "bar", true);
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -070060 private static final DeviceId DID1 = deviceId("of:foo");
61 private static final DeviceId DID2 = deviceId("of:bar");
62
63 private static final PortNumber P1 = PortNumber.portNumber(1);
64 private static final PortNumber P2 = PortNumber.portNumber(2);
65 private static final PortNumber P3 = PortNumber.portNumber(3);
66
Yuta HIGUCHI39ede6a2014-10-03 15:23:33 -070067 private static final SparseAnnotations A1 = DefaultAnnotations.builder()
68 .set("A1", "a1")
69 .set("B1", "b1")
70 .build();
71 private static final SparseAnnotations A1_2 = DefaultAnnotations.builder()
72 .remove("A1")
73 .set("B3", "b3")
74 .build();
75 private static final SparseAnnotations A2 = DefaultAnnotations.builder()
76 .set("A2", "a2")
77 .set("B2", "b2")
78 .build();
79 private static final SparseAnnotations A2_2 = DefaultAnnotations.builder()
80 .remove("A2")
81 .set("B4", "b4")
82 .build();
83
Thomas Vachuska57126fe2014-11-11 17:13:24 -080084 private static final SparseAnnotations DA1 = DefaultAnnotations.builder()
85 .set("A1", "a1")
86 .set("B1", "b1")
87 .set(AnnotationKeys.DURABLE, "true")
88 .build();
89 private static final SparseAnnotations DA2 = DefaultAnnotations.builder()
90 .set("A2", "a2")
91 .set("B2", "b2")
92 .set(AnnotationKeys.DURABLE, "true")
93 .build();
94 private static final SparseAnnotations NDA1 = DefaultAnnotations.builder()
95 .set("A1", "a1")
96 .set("B1", "b1")
97 .remove(AnnotationKeys.DURABLE)
98 .build();
99
100
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700101
102 private SimpleLinkStore simpleLinkStore;
103 private LinkStore linkStore;
104
105 @BeforeClass
106 public static void setUpBeforeClass() throws Exception {
107 }
108
109 @AfterClass
110 public static void tearDownAfterClass() throws Exception {
111 }
112
113 @Before
114 public void setUp() throws Exception {
115 simpleLinkStore = new SimpleLinkStore();
116 simpleLinkStore.activate();
117 linkStore = simpleLinkStore;
118 }
119
120 @After
121 public void tearDown() throws Exception {
122 simpleLinkStore.deactivate();
123 }
124
125 private void putLink(DeviceId srcId, PortNumber srcNum,
Thomas Vachuska57126fe2014-11-11 17:13:24 -0800126 DeviceId dstId, PortNumber dstNum,
127 Type type, boolean isDurable,
Yuta HIGUCHI0d6a5e62014-10-03 15:54:09 -0700128 SparseAnnotations... annotations) {
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700129 ConnectPoint src = new ConnectPoint(srcId, srcNum);
130 ConnectPoint dst = new ConnectPoint(dstId, dstNum);
Thomas Vachuska57126fe2014-11-11 17:13:24 -0800131 linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, type,
132 annotations));
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700133 }
134
Yuta HIGUCHI0d6a5e62014-10-03 15:54:09 -0700135 private void putLink(LinkKey key, Type type, SparseAnnotations... annotations) {
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700136 putLink(key.src().deviceId(), key.src().port(),
137 key.dst().deviceId(), key.dst().port(),
Thomas Vachuska57126fe2014-11-11 17:13:24 -0800138 type, false, annotations);
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700139 }
140
141 private static void assertLink(DeviceId srcId, PortNumber srcNum,
142 DeviceId dstId, PortNumber dstNum, Type type,
143 Link link) {
144 assertEquals(srcId, link.src().deviceId());
145 assertEquals(srcNum, link.src().port());
146 assertEquals(dstId, link.dst().deviceId());
147 assertEquals(dstNum, link.dst().port());
148 assertEquals(type, link.type());
149 }
150
151 private static void assertLink(LinkKey key, Type type, Link link) {
152 assertLink(key.src().deviceId(), key.src().port(),
153 key.dst().deviceId(), key.dst().port(),
154 type, link);
155 }
156
157 @Test
158 public final void testGetLinkCount() {
159 assertEquals("initialy empty", 0, linkStore.getLinkCount());
160
Thomas Vachuska57126fe2014-11-11 17:13:24 -0800161 putLink(DID1, P1, DID2, P2, DIRECT, false);
162 putLink(DID2, P2, DID1, P1, DIRECT, false);
163 putLink(DID1, P1, DID2, P2, DIRECT, false);
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700164
165 assertEquals("expecting 2 unique link", 2, linkStore.getLinkCount());
166 }
167
168 @Test
169 public final void testGetLinks() {
170 assertEquals("initialy empty", 0,
171 Iterables.size(linkStore.getLinks()));
172
Yuta HIGUCHI18ab8a92014-10-13 11:16:19 -0700173 LinkKey linkId1 = LinkKey.linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
174 LinkKey linkId2 = LinkKey.linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700175
176 putLink(linkId1, DIRECT);
177 putLink(linkId2, DIRECT);
178 putLink(linkId1, DIRECT);
179
180 assertEquals("expecting 2 unique link", 2,
181 Iterables.size(linkStore.getLinks()));
182
183 Map<LinkKey, Link> links = new HashMap<>();
184 for (Link link : linkStore.getLinks()) {
Yuta HIGUCHI18ab8a92014-10-13 11:16:19 -0700185 links.put(LinkKey.linkKey(link), link);
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700186 }
187
188 assertLink(linkId1, DIRECT, links.get(linkId1));
189 assertLink(linkId2, DIRECT, links.get(linkId2));
190 }
191
192 @Test
193 public final void testGetDeviceEgressLinks() {
Yuta HIGUCHI18ab8a92014-10-13 11:16:19 -0700194 LinkKey linkId1 = LinkKey.linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
195 LinkKey linkId2 = LinkKey.linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
196 LinkKey linkId3 = LinkKey.linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700197
198 putLink(linkId1, DIRECT);
199 putLink(linkId2, DIRECT);
200 putLink(linkId3, DIRECT);
201
202 // DID1,P1 => DID2,P2
203 // DID2,P2 => DID1,P1
204 // DID1,P2 => DID2,P3
205
206 Set<Link> links1 = linkStore.getDeviceEgressLinks(DID1);
207 assertEquals(2, links1.size());
208 // check
209
210 Set<Link> links2 = linkStore.getDeviceEgressLinks(DID2);
211 assertEquals(1, links2.size());
212 assertLink(linkId2, DIRECT, links2.iterator().next());
213 }
214
215 @Test
216 public final void testGetDeviceIngressLinks() {
Yuta HIGUCHI18ab8a92014-10-13 11:16:19 -0700217 LinkKey linkId1 = LinkKey.linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
218 LinkKey linkId2 = LinkKey.linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
219 LinkKey linkId3 = LinkKey.linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700220
221 putLink(linkId1, DIRECT);
222 putLink(linkId2, DIRECT);
223 putLink(linkId3, DIRECT);
224
225 // DID1,P1 => DID2,P2
226 // DID2,P2 => DID1,P1
227 // DID1,P2 => DID2,P3
228
229 Set<Link> links1 = linkStore.getDeviceIngressLinks(DID2);
230 assertEquals(2, links1.size());
231 // check
232
233 Set<Link> links2 = linkStore.getDeviceIngressLinks(DID1);
234 assertEquals(1, links2.size());
235 assertLink(linkId2, DIRECT, links2.iterator().next());
236 }
237
238 @Test
239 public final void testGetLink() {
240 ConnectPoint src = new ConnectPoint(DID1, P1);
241 ConnectPoint dst = new ConnectPoint(DID2, P2);
Yuta HIGUCHI18ab8a92014-10-13 11:16:19 -0700242 LinkKey linkId1 = LinkKey.linkKey(src, dst);
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700243
244 putLink(linkId1, DIRECT);
245
246 Link link = linkStore.getLink(src, dst);
247 assertLink(linkId1, DIRECT, link);
248
249 assertNull("There shouldn't be reverese link",
250 linkStore.getLink(dst, src));
251 }
252
253 @Test
254 public final void testGetEgressLinks() {
255 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
256 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
Yuta HIGUCHI18ab8a92014-10-13 11:16:19 -0700257 LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
258 LinkKey linkId2 = LinkKey.linkKey(d2P2, d1P1);
259 LinkKey linkId3 = LinkKey.linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700260
261 putLink(linkId1, DIRECT);
262 putLink(linkId2, DIRECT);
263 putLink(linkId3, DIRECT);
264
265 // DID1,P1 => DID2,P2
266 // DID2,P2 => DID1,P1
267 // DID1,P2 => DID2,P3
268
269 Set<Link> links1 = linkStore.getEgressLinks(d1P1);
270 assertEquals(1, links1.size());
271 assertLink(linkId1, DIRECT, links1.iterator().next());
272
273 Set<Link> links2 = linkStore.getEgressLinks(d2P2);
274 assertEquals(1, links2.size());
275 assertLink(linkId2, DIRECT, links2.iterator().next());
276 }
277
278 @Test
279 public final void testGetIngressLinks() {
280 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
281 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
Yuta HIGUCHI18ab8a92014-10-13 11:16:19 -0700282 LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
283 LinkKey linkId2 = LinkKey.linkKey(d2P2, d1P1);
284 LinkKey linkId3 = LinkKey.linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700285
286 putLink(linkId1, DIRECT);
287 putLink(linkId2, DIRECT);
288 putLink(linkId3, DIRECT);
289
290 // DID1,P1 => DID2,P2
291 // DID2,P2 => DID1,P1
292 // DID1,P2 => DID2,P3
293
294 Set<Link> links1 = linkStore.getIngressLinks(d2P2);
295 assertEquals(1, links1.size());
296 assertLink(linkId1, DIRECT, links1.iterator().next());
297
298 Set<Link> links2 = linkStore.getIngressLinks(d1P1);
299 assertEquals(1, links2.size());
300 assertLink(linkId2, DIRECT, links2.iterator().next());
301 }
302
303 @Test
304 public final void testCreateOrUpdateLink() {
305 ConnectPoint src = new ConnectPoint(DID1, P1);
306 ConnectPoint dst = new ConnectPoint(DID2, P2);
307
308 // add link
309 LinkEvent event = linkStore.createOrUpdateLink(PID,
310 new DefaultLinkDescription(src, dst, INDIRECT));
311
312 assertLink(DID1, P1, DID2, P2, INDIRECT, event.subject());
313 assertEquals(LINK_ADDED, event.type());
314
315 // update link type
316 LinkEvent event2 = linkStore.createOrUpdateLink(PID,
317 new DefaultLinkDescription(src, dst, DIRECT));
318
319 assertLink(DID1, P1, DID2, P2, DIRECT, event2.subject());
320 assertEquals(LINK_UPDATED, event2.type());
321
322 // no change
323 LinkEvent event3 = linkStore.createOrUpdateLink(PID,
324 new DefaultLinkDescription(src, dst, DIRECT));
325
326 assertNull("No change event expected", event3);
327 }
328
329 @Test
Yuta HIGUCHI39ede6a2014-10-03 15:23:33 -0700330 public final void testCreateOrUpdateLinkAncillary() {
331 ConnectPoint src = new ConnectPoint(DID1, P1);
332 ConnectPoint dst = new ConnectPoint(DID2, P2);
333
334 // add Ancillary link
335 LinkEvent event = linkStore.createOrUpdateLink(PIDA,
336 new DefaultLinkDescription(src, dst, INDIRECT, A1));
337
Thomas Vachuska0e752bd2014-10-22 22:33:41 -0700338 assertNotNull("Ancillary only link is ignored", event);
Yuta HIGUCHI39ede6a2014-10-03 15:23:33 -0700339
340 // add Primary link
341 LinkEvent event2 = linkStore.createOrUpdateLink(PID,
342 new DefaultLinkDescription(src, dst, INDIRECT, A2));
343
344 assertLink(DID1, P1, DID2, P2, INDIRECT, event2.subject());
345 assertAnnotationsEquals(event2.subject().annotations(), A2, A1);
Thomas Vachuska0e752bd2014-10-22 22:33:41 -0700346 assertEquals(LINK_UPDATED, event2.type());
Yuta HIGUCHI39ede6a2014-10-03 15:23:33 -0700347
348 // update link type
349 LinkEvent event3 = linkStore.createOrUpdateLink(PID,
350 new DefaultLinkDescription(src, dst, DIRECT, A2));
351 assertLink(DID1, P1, DID2, P2, DIRECT, event3.subject());
352 assertAnnotationsEquals(event3.subject().annotations(), A2, A1);
353 assertEquals(LINK_UPDATED, event3.type());
354
355
356 // no change
357 LinkEvent event4 = linkStore.createOrUpdateLink(PID,
358 new DefaultLinkDescription(src, dst, DIRECT));
359 assertNull("No change event expected", event4);
360
361 // update link annotation (Primary)
362 LinkEvent event5 = linkStore.createOrUpdateLink(PID,
363 new DefaultLinkDescription(src, dst, DIRECT, A2_2));
364 assertLink(DID1, P1, DID2, P2, DIRECT, event5.subject());
365 assertAnnotationsEquals(event5.subject().annotations(), A2, A2_2, A1);
366 assertEquals(LINK_UPDATED, event5.type());
367
368 // update link annotation (Ancillary)
369 LinkEvent event6 = linkStore.createOrUpdateLink(PIDA,
370 new DefaultLinkDescription(src, dst, DIRECT, A1_2));
371 assertLink(DID1, P1, DID2, P2, DIRECT, event6.subject());
372 assertAnnotationsEquals(event6.subject().annotations(), A2, A2_2, A1, A1_2);
373 assertEquals(LINK_UPDATED, event6.type());
374
375 // update link type (Ancillary) : ignored
376 LinkEvent event7 = linkStore.createOrUpdateLink(PIDA,
377 new DefaultLinkDescription(src, dst, EDGE));
378 assertNull("Ancillary change other than annotation is ignored", event7);
379 }
380
381
382 @Test
Thomas Vachuska57126fe2014-11-11 17:13:24 -0800383 public final void testRemoveOrDownLink() {
384 removeOrDownLink(false);
385 }
386
387 @Test
388 public final void testRemoveOrDownLinkDurable() {
389 removeOrDownLink(true);
390 }
391
392 private void removeOrDownLink(boolean isDurable) {
393 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
394 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
395 LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
396 LinkKey linkId2 = LinkKey.linkKey(d2P2, d1P1);
397
398 putLink(linkId1, DIRECT, isDurable ? DA1 : A1);
399 putLink(linkId2, DIRECT, isDurable ? DA2 : A2);
400
401 // DID1,P1 => DID2,P2
402 // DID2,P2 => DID1,P1
403 // DID1,P2 => DID2,P3
404
405 LinkEvent event = linkStore.removeOrDownLink(d1P1, d2P2);
406 assertEquals(isDurable ? LINK_UPDATED : LINK_REMOVED, event.type());
407 assertAnnotationsEquals(event.subject().annotations(), isDurable ? DA1 : A1);
408 LinkEvent event2 = linkStore.removeOrDownLink(d1P1, d2P2);
409 assertNull(event2);
410
411 assertLink(linkId2, DIRECT, linkStore.getLink(d2P2, d1P1));
412 assertAnnotationsEquals(linkStore.getLink(d2P2, d1P1).annotations(),
413 isDurable ? DA2 : A2);
414
415 // annotations, etc. should not survive remove
416 if (!isDurable) {
417 putLink(linkId1, DIRECT);
418 assertLink(linkId1, DIRECT, linkStore.getLink(d1P1, d2P2));
419 assertAnnotationsEquals(linkStore.getLink(d1P1, d2P2).annotations());
420 }
421 }
422
423 @Test
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700424 public final void testRemoveLink() {
425 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
426 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
Yuta HIGUCHI18ab8a92014-10-13 11:16:19 -0700427 LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
428 LinkKey linkId2 = LinkKey.linkKey(d2P2, d1P1);
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700429
Yuta HIGUCHI0d6a5e62014-10-03 15:54:09 -0700430 putLink(linkId1, DIRECT, A1);
431 putLink(linkId2, DIRECT, A2);
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700432
433 // DID1,P1 => DID2,P2
434 // DID2,P2 => DID1,P1
435 // DID1,P2 => DID2,P3
436
437 LinkEvent event = linkStore.removeLink(d1P1, d2P2);
438 assertEquals(LINK_REMOVED, event.type());
Yuta HIGUCHI0d6a5e62014-10-03 15:54:09 -0700439 assertAnnotationsEquals(event.subject().annotations(), A1);
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700440 LinkEvent event2 = linkStore.removeLink(d1P1, d2P2);
441 assertNull(event2);
442
443 assertLink(linkId2, DIRECT, linkStore.getLink(d2P2, d1P1));
Yuta HIGUCHI0d6a5e62014-10-03 15:54:09 -0700444 assertAnnotationsEquals(linkStore.getLink(d2P2, d1P1).annotations(), A2);
445
446 // annotations, etc. should not survive remove
447 putLink(linkId1, DIRECT);
448 assertLink(linkId1, DIRECT, linkStore.getLink(d1P1, d2P2));
449 assertAnnotationsEquals(linkStore.getLink(d1P1, d2P2).annotations());
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700450 }
451
Yuta HIGUCHI39ede6a2014-10-03 15:23:33 -0700452 @Test
Thomas Vachuska0e752bd2014-10-22 22:33:41 -0700453 public final void testAncillaryVisible() {
Yuta HIGUCHI39ede6a2014-10-03 15:23:33 -0700454 ConnectPoint src = new ConnectPoint(DID1, P1);
455 ConnectPoint dst = new ConnectPoint(DID2, P2);
456
457 // add Ancillary link
458 linkStore.createOrUpdateLink(PIDA,
459 new DefaultLinkDescription(src, dst, INDIRECT, A1));
460
461 // Ancillary only link should not be visible
Thomas Vachuska0e752bd2014-10-22 22:33:41 -0700462 assertEquals(1, linkStore.getLinkCount());
463 assertNotNull(linkStore.getLink(src, dst));
Yuta HIGUCHI39ede6a2014-10-03 15:23:33 -0700464 }
465
Thomas Vachuska57126fe2014-11-11 17:13:24 -0800466 @Test
467 public void testDurableToNonDurable() {
468 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
469 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
470 LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
471
472 putLink(linkId1, DIRECT, DA1);
473 assertTrue("should be be durable", linkStore.getLink(d1P1, d2P2).isDurable());
474 putLink(linkId1, DIRECT, NDA1);
475 assertFalse("should not be durable", linkStore.getLink(d1P1, d2P2).isDurable());
476 }
477
478 @Test
479 public void testNonDurableToDurable() {
480 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
481 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
482 LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
483
484 putLink(linkId1, DIRECT, A1);
485 assertFalse("should not be durable", linkStore.getLink(d1P1, d2P2).isDurable());
486 putLink(linkId1, DIRECT, DA1);
487 assertTrue("should be durable", linkStore.getLink(d1P1, d2P2).isDurable());
488 }
489
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700490 // If Delegates should be called only on remote events,
491 // then Simple* should never call them, thus not test required.
492 @Ignore("Ignore until Delegate spec. is clear.")
493 @Test
494 public final void testEvents() throws InterruptedException {
495
496 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
497 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
Yuta HIGUCHI18ab8a92014-10-13 11:16:19 -0700498 final LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700499
500 final CountDownLatch addLatch = new CountDownLatch(1);
501 LinkStoreDelegate checkAdd = new LinkStoreDelegate() {
502 @Override
503 public void notify(LinkEvent event) {
504 assertEquals(LINK_ADDED, event.type());
505 assertLink(linkId1, INDIRECT, event.subject());
506 addLatch.countDown();
507 }
508 };
509 final CountDownLatch updateLatch = new CountDownLatch(1);
510 LinkStoreDelegate checkUpdate = new LinkStoreDelegate() {
511 @Override
512 public void notify(LinkEvent event) {
513 assertEquals(LINK_UPDATED, event.type());
514 assertLink(linkId1, DIRECT, event.subject());
515 updateLatch.countDown();
516 }
517 };
518 final CountDownLatch removeLatch = new CountDownLatch(1);
519 LinkStoreDelegate checkRemove = new LinkStoreDelegate() {
520 @Override
521 public void notify(LinkEvent event) {
522 assertEquals(LINK_REMOVED, event.type());
523 assertLink(linkId1, DIRECT, event.subject());
524 removeLatch.countDown();
525 }
526 };
527
528 linkStore.setDelegate(checkAdd);
529 putLink(linkId1, INDIRECT);
530 assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS));
531
532 linkStore.unsetDelegate(checkAdd);
533 linkStore.setDelegate(checkUpdate);
534 putLink(linkId1, DIRECT);
535 assertTrue("Update event fired", updateLatch.await(1, TimeUnit.SECONDS));
536
537 linkStore.unsetDelegate(checkUpdate);
538 linkStore.setDelegate(checkRemove);
Thomas Vachuska57126fe2014-11-11 17:13:24 -0800539 linkStore.removeOrDownLink(d1P1, d2P2);
Yuta HIGUCHIf5712ff2014-09-27 23:52:37 -0700540 assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS));
541 }
542}