Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Thomas Vachuska | c97aa61 | 2015-06-23 16:00:18 -0700 | [diff] [blame] | 16 | package org.onosproject.store.trivial; |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | 0e752bd | 2014-10-22 22:33:41 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Iterables; |
Yuta HIGUCHI | 3e5d11a | 2014-11-04 14:16:44 -0800 | [diff] [blame] | 19 | |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 20 | import org.junit.After; |
| 21 | import org.junit.AfterClass; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.BeforeClass; |
| 24 | import org.junit.Ignore; |
| 25 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.net.AnnotationKeys; |
| 27 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.DefaultAnnotations; |
| 29 | import org.onosproject.net.DeviceId; |
| 30 | import org.onosproject.net.Link; |
| 31 | import org.onosproject.net.Link.Type; |
| 32 | import org.onosproject.net.LinkKey; |
| 33 | import org.onosproject.net.PortNumber; |
| 34 | import org.onosproject.net.SparseAnnotations; |
| 35 | import org.onosproject.net.link.DefaultLinkDescription; |
| 36 | import org.onosproject.net.link.LinkEvent; |
| 37 | import org.onosproject.net.link.LinkStore; |
| 38 | import org.onosproject.net.link.LinkStoreDelegate; |
| 39 | import org.onosproject.net.provider.ProviderId; |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 40 | |
Thomas Vachuska | 0e752bd | 2014-10-22 22:33:41 -0700 | [diff] [blame] | 41 | import java.util.HashMap; |
| 42 | import java.util.Map; |
| 43 | import java.util.Set; |
| 44 | import java.util.concurrent.CountDownLatch; |
| 45 | import java.util.concurrent.TimeUnit; |
| 46 | |
| 47 | import static org.junit.Assert.*; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 48 | import static org.onosproject.net.DeviceId.deviceId; |
| 49 | import static org.onosproject.net.Link.Type.*; |
| 50 | import static org.onosproject.net.link.LinkEvent.Type.*; |
| 51 | import static org.onosproject.net.NetTestTools.assertAnnotationsEquals; |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Test of the simple LinkStore implementation. |
| 55 | */ |
| 56 | public class SimpleLinkStoreTest { |
| 57 | |
| 58 | private static final ProviderId PID = new ProviderId("of", "foo"); |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 59 | private static final ProviderId PIDA = new ProviderId("of", "bar", true); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 60 | 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 HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 67 | 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 Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 84 | 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 HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 101 | |
| 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 Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 126 | DeviceId dstId, PortNumber dstNum, |
| 127 | Type type, boolean isDurable, |
Yuta HIGUCHI | 0d6a5e6 | 2014-10-03 15:54:09 -0700 | [diff] [blame] | 128 | SparseAnnotations... annotations) { |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 129 | ConnectPoint src = new ConnectPoint(srcId, srcNum); |
| 130 | ConnectPoint dst = new ConnectPoint(dstId, dstNum); |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 131 | linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, type, |
| 132 | annotations)); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Yuta HIGUCHI | 0d6a5e6 | 2014-10-03 15:54:09 -0700 | [diff] [blame] | 135 | private void putLink(LinkKey key, Type type, SparseAnnotations... annotations) { |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 136 | putLink(key.src().deviceId(), key.src().port(), |
| 137 | key.dst().deviceId(), key.dst().port(), |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 138 | type, false, annotations); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 139 | } |
| 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 Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 161 | putLink(DID1, P1, DID2, P2, DIRECT, false); |
| 162 | putLink(DID2, P2, DID1, P1, DIRECT, false); |
| 163 | putLink(DID1, P1, DID2, P2, DIRECT, false); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 164 | |
| 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 HIGUCHI | 18ab8a9 | 2014-10-13 11:16:19 -0700 | [diff] [blame] | 173 | 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 HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 175 | |
| 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 HIGUCHI | 18ab8a9 | 2014-10-13 11:16:19 -0700 | [diff] [blame] | 185 | links.put(LinkKey.linkKey(link), link); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 186 | } |
| 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 HIGUCHI | 18ab8a9 | 2014-10-13 11:16:19 -0700 | [diff] [blame] | 194 | 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 HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 197 | |
| 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 HIGUCHI | 18ab8a9 | 2014-10-13 11:16:19 -0700 | [diff] [blame] | 217 | 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 HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 220 | |
| 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 HIGUCHI | 18ab8a9 | 2014-10-13 11:16:19 -0700 | [diff] [blame] | 242 | LinkKey linkId1 = LinkKey.linkKey(src, dst); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 243 | |
| 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 HIGUCHI | 18ab8a9 | 2014-10-13 11:16:19 -0700 | [diff] [blame] | 257 | 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 HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 260 | |
| 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 HIGUCHI | 18ab8a9 | 2014-10-13 11:16:19 -0700 | [diff] [blame] | 282 | 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 HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 285 | |
| 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 HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 330 | 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 Vachuska | 0e752bd | 2014-10-22 22:33:41 -0700 | [diff] [blame] | 338 | assertNotNull("Ancillary only link is ignored", event); |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 339 | |
| 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 Vachuska | 0e752bd | 2014-10-22 22:33:41 -0700 | [diff] [blame] | 346 | assertEquals(LINK_UPDATED, event2.type()); |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 347 | |
| 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 Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 383 | 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 HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 424 | public final void testRemoveLink() { |
| 425 | final ConnectPoint d1P1 = new ConnectPoint(DID1, P1); |
| 426 | final ConnectPoint d2P2 = new ConnectPoint(DID2, P2); |
Yuta HIGUCHI | 18ab8a9 | 2014-10-13 11:16:19 -0700 | [diff] [blame] | 427 | LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2); |
| 428 | LinkKey linkId2 = LinkKey.linkKey(d2P2, d1P1); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 429 | |
Yuta HIGUCHI | 0d6a5e6 | 2014-10-03 15:54:09 -0700 | [diff] [blame] | 430 | putLink(linkId1, DIRECT, A1); |
| 431 | putLink(linkId2, DIRECT, A2); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 432 | |
| 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 HIGUCHI | 0d6a5e6 | 2014-10-03 15:54:09 -0700 | [diff] [blame] | 439 | assertAnnotationsEquals(event.subject().annotations(), A1); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 440 | LinkEvent event2 = linkStore.removeLink(d1P1, d2P2); |
| 441 | assertNull(event2); |
| 442 | |
| 443 | assertLink(linkId2, DIRECT, linkStore.getLink(d2P2, d1P1)); |
Yuta HIGUCHI | 0d6a5e6 | 2014-10-03 15:54:09 -0700 | [diff] [blame] | 444 | 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 HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 452 | @Test |
Thomas Vachuska | 0e752bd | 2014-10-22 22:33:41 -0700 | [diff] [blame] | 453 | public final void testAncillaryVisible() { |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 454 | 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 Vachuska | 0e752bd | 2014-10-22 22:33:41 -0700 | [diff] [blame] | 462 | assertEquals(1, linkStore.getLinkCount()); |
| 463 | assertNotNull(linkStore.getLink(src, dst)); |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 466 | @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); |
Ray Milkey | 8521f81 | 2017-05-24 09:49:26 -0700 | [diff] [blame] | 473 | assertTrue("should be be durable", linkStore.getLink(d1P1, d2P2).isExpected()); |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 474 | putLink(linkId1, DIRECT, NDA1); |
Ray Milkey | 8521f81 | 2017-05-24 09:49:26 -0700 | [diff] [blame] | 475 | assertFalse("should not be durable", linkStore.getLink(d1P1, d2P2).isExpected()); |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 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); |
Ray Milkey | 8521f81 | 2017-05-24 09:49:26 -0700 | [diff] [blame] | 485 | assertFalse("should not be durable", linkStore.getLink(d1P1, d2P2).isExpected()); |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 486 | putLink(linkId1, DIRECT, DA1); |
Ray Milkey | 8521f81 | 2017-05-24 09:49:26 -0700 | [diff] [blame] | 487 | assertTrue("should be durable", linkStore.getLink(d1P1, d2P2).isExpected()); |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 488 | } |
| 489 | |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 490 | // 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 HIGUCHI | 18ab8a9 | 2014-10-13 11:16:19 -0700 | [diff] [blame] | 498 | final LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 499 | |
| 500 | final CountDownLatch addLatch = new CountDownLatch(1); |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame] | 501 | LinkStoreDelegate checkAdd = event -> { |
| 502 | assertEquals(LINK_ADDED, event.type()); |
| 503 | assertLink(linkId1, INDIRECT, event.subject()); |
| 504 | addLatch.countDown(); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 505 | }; |
| 506 | final CountDownLatch updateLatch = new CountDownLatch(1); |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame] | 507 | LinkStoreDelegate checkUpdate = event -> { |
| 508 | assertEquals(LINK_UPDATED, event.type()); |
| 509 | assertLink(linkId1, DIRECT, event.subject()); |
| 510 | updateLatch.countDown(); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 511 | }; |
| 512 | final CountDownLatch removeLatch = new CountDownLatch(1); |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame] | 513 | LinkStoreDelegate checkRemove = event -> { |
| 514 | assertEquals(LINK_REMOVED, event.type()); |
| 515 | assertLink(linkId1, DIRECT, event.subject()); |
| 516 | removeLatch.countDown(); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 517 | }; |
| 518 | |
| 519 | linkStore.setDelegate(checkAdd); |
| 520 | putLink(linkId1, INDIRECT); |
| 521 | assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS)); |
| 522 | |
| 523 | linkStore.unsetDelegate(checkAdd); |
| 524 | linkStore.setDelegate(checkUpdate); |
| 525 | putLink(linkId1, DIRECT); |
| 526 | assertTrue("Update event fired", updateLatch.await(1, TimeUnit.SECONDS)); |
| 527 | |
| 528 | linkStore.unsetDelegate(checkUpdate); |
| 529 | linkStore.setDelegate(checkRemove); |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 530 | linkStore.removeOrDownLink(d1P1, d2P2); |
Yuta HIGUCHI | f5712ff | 2014-09-27 23:52:37 -0700 | [diff] [blame] | 531 | assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS)); |
| 532 | } |
| 533 | } |