1 /* 2 * Copyright (C) 2020 The Android Open Source Project 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 */ 16 17 package com.android.car.vms; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.junit.Assert.assertThrows; 22 import static org.mockito.ArgumentMatchers.any; 23 import static org.mockito.ArgumentMatchers.eq; 24 import static org.mockito.Mockito.never; 25 import static org.mockito.Mockito.timeout; 26 import static org.mockito.Mockito.times; 27 import static org.mockito.Mockito.verify; 28 29 import static java.util.Collections.emptySet; 30 31 import android.car.Car; 32 import android.car.vms.VmsAssociatedLayer; 33 import android.car.vms.VmsAvailableLayers; 34 import android.car.vms.VmsClient; 35 import android.car.vms.VmsClientManager; 36 import android.car.vms.VmsClientManager.VmsClientCallback; 37 import android.car.vms.VmsLayer; 38 import android.car.vms.VmsLayerDependency; 39 import android.car.vms.VmsSubscriptionState; 40 41 import androidx.test.ext.junit.runners.AndroidJUnit4; 42 import androidx.test.filters.MediumTest; 43 44 import com.android.car.MockedCarTestBase; 45 46 import org.junit.Before; 47 import org.junit.Rule; 48 import org.junit.Test; 49 import org.junit.runner.RunWith; 50 import org.mockito.ArgumentCaptor; 51 import org.mockito.Captor; 52 import org.mockito.Mock; 53 import org.mockito.junit.MockitoJUnit; 54 import org.mockito.junit.MockitoRule; 55 56 import java.util.Arrays; 57 import java.util.HashSet; 58 import java.util.Set; 59 import java.util.concurrent.ExecutorService; 60 import java.util.concurrent.Executors; 61 import java.util.concurrent.TimeUnit; 62 63 @RunWith(AndroidJUnit4.class) 64 @MediumTest 65 public class VmsClientTest extends MockedCarTestBase { 66 private static final long CONNECT_TIMEOUT = 10_000; 67 68 private static final byte[] PROVIDER_DESC1 = {1, 2, 3, 4, 5}; 69 private static final byte[] PROVIDER_DESC2 = {5, 4, 3, 2, 1}; 70 71 private static final VmsAvailableLayers DEFAULT_AVAILABLE_LAYERS = 72 new VmsAvailableLayers(0, emptySet()); 73 private static final VmsSubscriptionState DEFAULT_SUBSCRIPTION_STATE = 74 new VmsSubscriptionState(0, emptySet(), emptySet()); 75 76 private static final VmsLayer LAYER1 = new VmsLayer(1, 1, 1); 77 private static final VmsLayer LAYER2 = new VmsLayer(2, 1, 1); 78 private static final VmsLayer LAYER3 = new VmsLayer(3, 1, 1); 79 80 private static final byte[] PAYLOAD = {1, 2, 3, 4, 5, 6, 7, 8}; 81 private static final byte[] LARGE_PAYLOAD = new byte[16 * 1024]; // 16KB 82 83 @Rule 84 public MockitoRule mMockitoRule = MockitoJUnit.rule(); 85 @Mock 86 private VmsClientCallback mClientCallback1; 87 @Captor 88 private ArgumentCaptor<VmsClient> mClientCaptor; 89 @Mock 90 private VmsClientCallback mClientCallback2; 91 92 private final ExecutorService mExecutor = Executors.newSingleThreadExecutor(); 93 94 private VmsClientManager mClientManager; 95 96 @Before setUpTest()97 public void setUpTest() { 98 mClientManager = (VmsClientManager) getCar().getCarManager(Car.VEHICLE_MAP_SERVICE); 99 LARGE_PAYLOAD[0] = 123; 100 } 101 102 @Test testRegister()103 public void testRegister() { 104 VmsClient client = connectVmsClient(mClientCallback1); 105 106 awaitTaskCompletion(); 107 assertThat(client.getAvailableLayers()).isEqualTo(DEFAULT_AVAILABLE_LAYERS); 108 assertThat(client.getSubscriptionState()).isEqualTo(DEFAULT_SUBSCRIPTION_STATE); 109 verifyLayerAvailability(mClientCallback1, DEFAULT_AVAILABLE_LAYERS); 110 verifySubscriptionState(mClientCallback1, DEFAULT_SUBSCRIPTION_STATE); 111 } 112 113 @Test testRegister_ReceivesCurrentLayerAvailabilityAndSubscriptions()114 public void testRegister_ReceivesCurrentLayerAvailabilityAndSubscriptions() { 115 VmsClient client = connectVmsClient(mClientCallback1); 116 int providerId = client.registerProvider(PROVIDER_DESC1); 117 client.setProviderOfferings(providerId, asSet( 118 new VmsLayerDependency(LAYER1))); 119 client.setSubscriptions(asSet( 120 new VmsAssociatedLayer(LAYER1, emptySet()), 121 new VmsAssociatedLayer(LAYER2, asSet(12345)) 122 )); 123 VmsClient client2 = connectVmsClient(mClientCallback2); 124 125 awaitTaskCompletion(); 126 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, asSet( 127 new VmsAssociatedLayer(LAYER1, 128 asSet(providerId))) 129 ); 130 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 131 asSet(LAYER1), 132 asSet(new VmsAssociatedLayer(LAYER2, asSet(12345))) 133 ); 134 assertThat(client2.getAvailableLayers()).isEqualTo(expectedLayers); 135 assertThat(client2.getSubscriptionState()).isEqualTo(expectedSubscriptions); 136 verify(mClientCallback2).onLayerAvailabilityChanged(expectedLayers); 137 verify(mClientCallback2).onSubscriptionStateChanged(expectedSubscriptions); 138 } 139 140 @Test testRegisterProvider_SameIdForSameInfo()141 public void testRegisterProvider_SameIdForSameInfo() { 142 VmsClient client = connectVmsClient(mClientCallback1); 143 144 int providerId = client.registerProvider(PROVIDER_DESC1); 145 int providerId2 = client.registerProvider(PROVIDER_DESC1); 146 147 assertThat(providerId).isEqualTo(providerId2); 148 } 149 150 @Test testRegisterProvider_SameIdForSameInfo_MultipleClients()151 public void testRegisterProvider_SameIdForSameInfo_MultipleClients() { 152 VmsClient client = connectVmsClient(mClientCallback1); 153 VmsClient client2 = connectVmsClient(mClientCallback2); 154 155 int providerId = client.registerProvider(PROVIDER_DESC1); 156 int providerId2 = client2.registerProvider(PROVIDER_DESC1); 157 158 assertThat(providerId).isEqualTo(providerId2); 159 } 160 161 @Test testRegisterProvider_DifferentIdForDifferentInfo()162 public void testRegisterProvider_DifferentIdForDifferentInfo() { 163 VmsClient client = connectVmsClient(mClientCallback1); 164 165 int providerId = client.registerProvider(PROVIDER_DESC1); 166 int providerId2 = client.registerProvider(PROVIDER_DESC2); 167 168 assertThat(providerId).isNotEqualTo(providerId2); 169 } 170 171 @Test testUnregisterProvider()172 public void testUnregisterProvider() { 173 VmsClient client = connectVmsClient(mClientCallback1); 174 int providerId = client.registerProvider(PROVIDER_DESC1); 175 176 client.setProviderOfferings(providerId, asSet( 177 new VmsLayerDependency(LAYER1) 178 )); 179 180 client.unregisterProvider(providerId); 181 182 awaitTaskCompletion(); 183 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 184 verifyLayerAvailability(mClientCallback1, expectedLayers); 185 } 186 187 @Test testUnregisterProvider_UnknownId()188 public void testUnregisterProvider_UnknownId() { 189 VmsClient client = connectVmsClient(mClientCallback1); 190 191 client.unregisterProvider(12345); 192 } 193 194 @Test testGetProviderDescription_UnknownId()195 public void testGetProviderDescription_UnknownId() { 196 VmsClient client = connectVmsClient(mClientCallback1); 197 198 assertThat(client.getProviderDescription(12345)).isNull(); 199 } 200 201 @Test testGetProviderDescription_RegisteredProvider()202 public void testGetProviderDescription_RegisteredProvider() { 203 VmsClient client = connectVmsClient(mClientCallback1); 204 205 int providerId = client.registerProvider(PROVIDER_DESC1); 206 207 assertThat(client.getProviderDescription(providerId)).isEqualTo(PROVIDER_DESC1); 208 } 209 210 @Test testSetSubscriptions()211 public void testSetSubscriptions() { 212 VmsClient client = connectVmsClient(mClientCallback1); 213 214 client.setSubscriptions(asSet( 215 new VmsAssociatedLayer(LAYER1, emptySet()) 216 )); 217 218 awaitTaskCompletion(); 219 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 220 asSet(LAYER1), 221 emptySet()); 222 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 223 } 224 225 @Test testSetSubscriptions_MultipleClients()226 public void testSetSubscriptions_MultipleClients() { 227 VmsClient client = connectVmsClient(mClientCallback1); 228 VmsClient client2 = connectVmsClient(mClientCallback2); 229 230 client.setSubscriptions(asSet( 231 new VmsAssociatedLayer(LAYER1, emptySet()) 232 )); 233 client2.setSubscriptions(asSet( 234 new VmsAssociatedLayer(LAYER1, emptySet()) 235 )); 236 237 awaitTaskCompletion(); 238 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 239 asSet(LAYER1), 240 emptySet()); 241 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 242 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 243 } 244 245 @Test testSetSubscriptions_OverwriteSubscription()246 public void testSetSubscriptions_OverwriteSubscription() { 247 VmsClient client = connectVmsClient(mClientCallback1); 248 249 client.setSubscriptions(asSet( 250 new VmsAssociatedLayer(LAYER1, emptySet()) 251 )); 252 client.setSubscriptions(asSet( 253 new VmsAssociatedLayer(LAYER2, emptySet()) 254 )); 255 256 awaitTaskCompletion(); 257 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 258 asSet(LAYER2), 259 emptySet()); 260 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 261 } 262 263 @Test testSetSubscriptions_OverwriteSubscription_MultipleClients()264 public void testSetSubscriptions_OverwriteSubscription_MultipleClients() { 265 VmsClient client = connectVmsClient(mClientCallback1); 266 VmsClient client2 = connectVmsClient(mClientCallback2); 267 268 client.setSubscriptions(asSet( 269 new VmsAssociatedLayer(LAYER1, emptySet()) 270 )); 271 client2.setSubscriptions(asSet( 272 new VmsAssociatedLayer(LAYER2, emptySet()) 273 )); 274 client2.setSubscriptions(asSet( 275 new VmsAssociatedLayer(LAYER3, emptySet()) 276 )); 277 278 awaitTaskCompletion(); 279 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 280 asSet(LAYER1, LAYER3), 281 emptySet()); 282 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 283 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 284 } 285 286 @Test testSetSubscriptions_RemoveSubscription()287 public void testSetSubscriptions_RemoveSubscription() { 288 VmsClient client = connectVmsClient(mClientCallback1); 289 290 client.setSubscriptions(asSet( 291 new VmsAssociatedLayer(LAYER1, emptySet()) 292 )); 293 client.setSubscriptions(emptySet()); 294 295 awaitTaskCompletion(); 296 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 297 emptySet(), 298 emptySet()); 299 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 300 } 301 302 @Test testSetSubscriptions_RemoveSubscription_MultipleClients()303 public void testSetSubscriptions_RemoveSubscription_MultipleClients() { 304 VmsClient client = connectVmsClient(mClientCallback1); 305 VmsClient client2 = connectVmsClient(mClientCallback2); 306 307 client.setSubscriptions(asSet( 308 new VmsAssociatedLayer(LAYER1, emptySet()) 309 )); 310 client2.setSubscriptions(asSet( 311 new VmsAssociatedLayer(LAYER2, emptySet()) 312 )); 313 client2.setSubscriptions(emptySet()); 314 315 awaitTaskCompletion(); 316 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 317 asSet(LAYER1), 318 emptySet()); 319 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 320 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 321 } 322 323 @Test testSetSubscriptions_RemoveSubscription_MultipleClients_SameLayer()324 public void testSetSubscriptions_RemoveSubscription_MultipleClients_SameLayer() { 325 VmsClient client = connectVmsClient(mClientCallback1); 326 VmsClient client2 = connectVmsClient(mClientCallback2); 327 328 client.setSubscriptions(asSet( 329 new VmsAssociatedLayer(LAYER1, emptySet()) 330 )); 331 client2.setSubscriptions(asSet( 332 new VmsAssociatedLayer(LAYER1, emptySet()) 333 )); 334 client2.setSubscriptions(emptySet()); 335 336 awaitTaskCompletion(); 337 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 338 asSet(LAYER1), 339 emptySet()); 340 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 341 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 342 } 343 344 @Test testSetSubscriptions_RemoveSubscription_OnUnregister_MultipleClients()345 public void testSetSubscriptions_RemoveSubscription_OnUnregister_MultipleClients() { 346 VmsClient client = connectVmsClient(mClientCallback1); 347 VmsClient client2 = connectVmsClient(mClientCallback2); 348 349 client.setSubscriptions(asSet( 350 new VmsAssociatedLayer(LAYER1, emptySet()) 351 )); 352 client2.setSubscriptions(asSet( 353 new VmsAssociatedLayer(LAYER2, emptySet()) 354 )); 355 mClientManager.unregisterVmsClientCallback(mClientCallback2); 356 357 awaitTaskCompletion(); 358 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 359 asSet(LAYER1), 360 emptySet()); 361 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 362 } 363 364 @Test testSetSubscriptions_RemoveSubscription_OnUnregister_MultipleClients_SameLayer()365 public void testSetSubscriptions_RemoveSubscription_OnUnregister_MultipleClients_SameLayer() { 366 VmsClient client = connectVmsClient(mClientCallback1); 367 VmsClient client2 = connectVmsClient(mClientCallback2); 368 369 client.setSubscriptions(asSet( 370 new VmsAssociatedLayer(LAYER1, emptySet()) 371 )); 372 client2.setSubscriptions(asSet( 373 new VmsAssociatedLayer(LAYER1, emptySet()) 374 )); 375 mClientManager.unregisterVmsClientCallback(mClientCallback2); 376 377 awaitTaskCompletion(); 378 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 379 asSet(LAYER1), 380 emptySet()); 381 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 382 } 383 384 @Test testSetSubscriptions_MultipleLayers()385 public void testSetSubscriptions_MultipleLayers() { 386 VmsClient client = connectVmsClient(mClientCallback1); 387 388 client.setSubscriptions(asSet( 389 new VmsAssociatedLayer(LAYER1, emptySet()), 390 new VmsAssociatedLayer(LAYER2, emptySet()) 391 )); 392 393 awaitTaskCompletion(); 394 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 395 asSet(LAYER1, LAYER2), 396 emptySet()); 397 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 398 } 399 400 @Test testSetSubscriptions_MultipleLayers_MultipleClients()401 public void testSetSubscriptions_MultipleLayers_MultipleClients() { 402 VmsClient client = connectVmsClient(mClientCallback1); 403 VmsClient client2 = connectVmsClient(mClientCallback2); 404 405 client.setSubscriptions(asSet( 406 new VmsAssociatedLayer(LAYER1, emptySet()) 407 )); 408 client2.setSubscriptions(asSet( 409 new VmsAssociatedLayer(LAYER2, emptySet()), 410 new VmsAssociatedLayer(LAYER3, emptySet()) 411 )); 412 413 awaitTaskCompletion(); 414 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 415 asSet(LAYER1, LAYER2, LAYER3), 416 emptySet()); 417 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 418 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 419 } 420 421 @Test testSetSubscriptions_LayerAndProvider()422 public void testSetSubscriptions_LayerAndProvider() { 423 VmsClient client = connectVmsClient(mClientCallback1); 424 425 client.setSubscriptions(asSet( 426 new VmsAssociatedLayer(LAYER1, asSet(12345)) 427 )); 428 429 awaitTaskCompletion(); 430 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 431 emptySet(), 432 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345)))); 433 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 434 } 435 436 @Test testSetSubscriptions_LayerAndProvider_MultipleClients()437 public void testSetSubscriptions_LayerAndProvider_MultipleClients() { 438 VmsClient client = connectVmsClient(mClientCallback1); 439 VmsClient client2 = connectVmsClient(mClientCallback2); 440 441 client.setSubscriptions(asSet( 442 new VmsAssociatedLayer(LAYER1, asSet(12345)) 443 )); 444 client2.setSubscriptions(asSet( 445 new VmsAssociatedLayer(LAYER1, asSet(54321)) 446 )); 447 448 awaitTaskCompletion(); 449 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 450 emptySet(), 451 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345, 54321)))); 452 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 453 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 454 } 455 456 @Test testSetSubscriptions_LayerAndProvider_OverwriteSubscription()457 public void testSetSubscriptions_LayerAndProvider_OverwriteSubscription() { 458 VmsClient client = connectVmsClient(mClientCallback1); 459 460 client.setSubscriptions(asSet( 461 new VmsAssociatedLayer(LAYER1, asSet(12345)) 462 )); 463 client.setSubscriptions(asSet( 464 new VmsAssociatedLayer(LAYER2, asSet(54321)) 465 )); 466 467 awaitTaskCompletion(); 468 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 469 emptySet(), 470 asSet(new VmsAssociatedLayer(LAYER2, asSet(54321)))); 471 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 472 } 473 474 @Test testSetSubscriptions_LayerAndProvider_OverwriteSubscription_MultipleClients()475 public void testSetSubscriptions_LayerAndProvider_OverwriteSubscription_MultipleClients() { 476 VmsClient client = connectVmsClient(mClientCallback1); 477 VmsClient client2 = connectVmsClient(mClientCallback2); 478 479 client.setSubscriptions(asSet( 480 new VmsAssociatedLayer(LAYER1, asSet(12345)) 481 )); 482 client2.setSubscriptions(asSet( 483 new VmsAssociatedLayer(LAYER2, asSet(54321)) 484 )); 485 client2.setSubscriptions(asSet( 486 new VmsAssociatedLayer(LAYER3, asSet(98765)) 487 )); 488 489 awaitTaskCompletion(); 490 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 491 emptySet(), 492 asSet( 493 new VmsAssociatedLayer(LAYER1, asSet(12345)), 494 new VmsAssociatedLayer(LAYER3, asSet(98765)))); 495 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 496 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 497 } 498 499 @Test testSetSubscriptions_LayerAndProvider_OverwriteSubscription_MultipleClients_SameLayer()500 public void testSetSubscriptions_LayerAndProvider_OverwriteSubscription_MultipleClients_SameLayer() { 501 VmsClient client = connectVmsClient(mClientCallback1); 502 VmsClient client2 = connectVmsClient(mClientCallback2); 503 504 client.setSubscriptions(asSet( 505 new VmsAssociatedLayer(LAYER1, asSet(12345)) 506 )); 507 client2.setSubscriptions(asSet( 508 new VmsAssociatedLayer(LAYER2, asSet(54321)) 509 )); 510 client2.setSubscriptions(asSet( 511 new VmsAssociatedLayer(LAYER1, asSet(98765)) 512 )); 513 514 awaitTaskCompletion(); 515 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 516 emptySet(), 517 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345, 98765)))); 518 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 519 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 520 } 521 522 @Test testSetSubscriptions_LayerAndProvider_OverwriteSubscription_MultipleClients_SameLayerAndProvider()523 public void testSetSubscriptions_LayerAndProvider_OverwriteSubscription_MultipleClients_SameLayerAndProvider() { 524 VmsClient client = connectVmsClient(mClientCallback1); 525 VmsClient client2 = connectVmsClient(mClientCallback2); 526 527 client.setSubscriptions(asSet( 528 new VmsAssociatedLayer(LAYER1, asSet(12345)) 529 )); 530 client2.setSubscriptions(asSet( 531 new VmsAssociatedLayer(LAYER2, asSet(54321)) 532 )); 533 client2.setSubscriptions(asSet( 534 new VmsAssociatedLayer(LAYER1, asSet(12345)) 535 )); 536 537 awaitTaskCompletion(); 538 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 539 emptySet(), 540 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345)))); 541 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 542 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 543 } 544 545 @Test testSetSubscriptions_LayerAndProvider_RemoveSubscription()546 public void testSetSubscriptions_LayerAndProvider_RemoveSubscription() { 547 VmsClient client = connectVmsClient(mClientCallback1); 548 549 client.setSubscriptions(asSet( 550 new VmsAssociatedLayer(LAYER1, asSet(12345)) 551 )); 552 client.setSubscriptions(emptySet()); 553 554 awaitTaskCompletion(); 555 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 556 emptySet(), 557 emptySet()); 558 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 559 } 560 561 @Test testSetSubscriptions_LayerAndProvider_RemoveSubscription_MultipleClients()562 public void testSetSubscriptions_LayerAndProvider_RemoveSubscription_MultipleClients() { 563 VmsClient client = connectVmsClient(mClientCallback1); 564 VmsClient client2 = connectVmsClient(mClientCallback2); 565 566 client.setSubscriptions(asSet( 567 new VmsAssociatedLayer(LAYER1, asSet(12345)) 568 )); 569 client2.setSubscriptions(asSet( 570 new VmsAssociatedLayer(LAYER2, asSet(54321)) 571 )); 572 client2.setSubscriptions(emptySet()); 573 574 awaitTaskCompletion(); 575 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 576 emptySet(), 577 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345)))); 578 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 579 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 580 } 581 582 @Test testSetSubscriptions_LayerAndProvider_RemoveSubscription_MultipleClients_SameLayer()583 public void testSetSubscriptions_LayerAndProvider_RemoveSubscription_MultipleClients_SameLayer() { 584 VmsClient client = connectVmsClient(mClientCallback1); 585 VmsClient client2 = connectVmsClient(mClientCallback2); 586 587 client.setSubscriptions(asSet( 588 new VmsAssociatedLayer(LAYER1, asSet(12345)) 589 )); 590 client2.setSubscriptions(asSet( 591 new VmsAssociatedLayer(LAYER1, asSet(54321)) 592 )); 593 client2.setSubscriptions(emptySet()); 594 595 awaitTaskCompletion(); 596 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 597 emptySet(), 598 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345)))); 599 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 600 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 601 } 602 603 @Test testSetSubscriptions_LayerAndProvider_RemoveSubscription_MultipleClients_SameLayerAndProvider()604 public void testSetSubscriptions_LayerAndProvider_RemoveSubscription_MultipleClients_SameLayerAndProvider() { 605 VmsClient client = connectVmsClient(mClientCallback1); 606 VmsClient client2 = connectVmsClient(mClientCallback2); 607 608 client.setSubscriptions(asSet( 609 new VmsAssociatedLayer(LAYER1, asSet(12345)) 610 )); 611 client2.setSubscriptions(asSet( 612 new VmsAssociatedLayer(LAYER1, asSet(12345)) 613 )); 614 client2.setSubscriptions(emptySet()); 615 616 awaitTaskCompletion(); 617 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 618 emptySet(), 619 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345)))); 620 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 621 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 622 } 623 624 @Test testSetSubscriptions_LayerAndProvider_RemoveSubscription_OnUnregister_MultipleClients()625 public void testSetSubscriptions_LayerAndProvider_RemoveSubscription_OnUnregister_MultipleClients() { 626 VmsClient client = connectVmsClient(mClientCallback1); 627 VmsClient client2 = connectVmsClient(mClientCallback2); 628 629 client.setSubscriptions(asSet( 630 new VmsAssociatedLayer(LAYER1, asSet(12345)) 631 )); 632 client2.setSubscriptions(asSet( 633 new VmsAssociatedLayer(LAYER2, asSet(54321)) 634 )); 635 mClientManager.unregisterVmsClientCallback(mClientCallback2); 636 637 awaitTaskCompletion(); 638 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 639 emptySet(), 640 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345)))); 641 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 642 } 643 644 @Test testSetSubscriptions_LayerAndProvider_RemoveSubscription_OnUnregister_MultipleClients_SameLayer()645 public void testSetSubscriptions_LayerAndProvider_RemoveSubscription_OnUnregister_MultipleClients_SameLayer() { 646 VmsClient client = connectVmsClient(mClientCallback1); 647 VmsClient client2 = connectVmsClient(mClientCallback2); 648 649 client.setSubscriptions(asSet( 650 new VmsAssociatedLayer(LAYER1, asSet(12345)) 651 )); 652 client2.setSubscriptions(asSet( 653 new VmsAssociatedLayer(LAYER1, asSet(54321)) 654 )); 655 mClientManager.unregisterVmsClientCallback(mClientCallback2); 656 657 awaitTaskCompletion(); 658 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 659 emptySet(), 660 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345)))); 661 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 662 } 663 664 @Test testSetSubscriptions_LayerAndProvider_RemoveSubscription_OnUnregister_MultipleClients_SameLayerAndProvider()665 public void testSetSubscriptions_LayerAndProvider_RemoveSubscription_OnUnregister_MultipleClients_SameLayerAndProvider() { 666 VmsClient client = connectVmsClient(mClientCallback1); 667 VmsClient client2 = connectVmsClient(mClientCallback2); 668 669 client.setSubscriptions(asSet( 670 new VmsAssociatedLayer(LAYER1, asSet(12345)) 671 )); 672 client2.setSubscriptions(asSet( 673 new VmsAssociatedLayer(LAYER1, asSet(12345)) 674 )); 675 mClientManager.unregisterVmsClientCallback(mClientCallback2); 676 677 awaitTaskCompletion(); 678 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 679 emptySet(), 680 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345)))); 681 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 682 } 683 684 @Test testSetSubscriptions_LayerAndMultipleProviders()685 public void testSetSubscriptions_LayerAndMultipleProviders() { 686 VmsClient client = connectVmsClient(mClientCallback1); 687 688 client.setSubscriptions(asSet( 689 new VmsAssociatedLayer(LAYER1, asSet(12345, 54321)) 690 )); 691 692 awaitTaskCompletion(); 693 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 694 emptySet(), 695 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345, 54321)))); 696 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 697 } 698 699 @Test testSetSubscriptions_LayerAndMultipleProviders_MultipleClients()700 public void testSetSubscriptions_LayerAndMultipleProviders_MultipleClients() { 701 VmsClient client = connectVmsClient(mClientCallback1); 702 VmsClient client2 = connectVmsClient(mClientCallback2); 703 704 client.setSubscriptions(asSet( 705 new VmsAssociatedLayer(LAYER1, asSet(12345)) 706 )); 707 client2.setSubscriptions(asSet( 708 new VmsAssociatedLayer(LAYER1, asSet(54321)) 709 )); 710 711 awaitTaskCompletion(); 712 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 713 emptySet(), 714 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345, 54321)))); 715 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 716 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 717 } 718 719 @Test testSetSubscriptions_MultipleLayersAndProvider()720 public void testSetSubscriptions_MultipleLayersAndProvider() { 721 VmsClient client = connectVmsClient(mClientCallback1); 722 723 client.setSubscriptions(asSet( 724 new VmsAssociatedLayer(LAYER1, emptySet()), 725 new VmsAssociatedLayer(LAYER2, asSet(12345)) 726 )); 727 728 awaitTaskCompletion(); 729 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 730 asSet(LAYER1), 731 asSet(new VmsAssociatedLayer(LAYER2, asSet(12345)))); 732 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 733 } 734 735 @Test testSetSubscriptions_MultipleLayersAndProvider_MultipleClients()736 public void testSetSubscriptions_MultipleLayersAndProvider_MultipleClients() { 737 VmsClient client = connectVmsClient(mClientCallback1); 738 VmsClient client2 = connectVmsClient(mClientCallback2); 739 740 client.setSubscriptions(asSet( 741 new VmsAssociatedLayer(LAYER1, emptySet()), 742 new VmsAssociatedLayer(LAYER2, asSet(12345)) 743 )); 744 client2.setSubscriptions(asSet( 745 new VmsAssociatedLayer(LAYER3, emptySet()), 746 new VmsAssociatedLayer(LAYER2, asSet(54321)) 747 )); 748 749 awaitTaskCompletion(); 750 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 751 asSet(LAYER1, LAYER3), 752 asSet(new VmsAssociatedLayer(LAYER2, asSet(12345, 54321)))); 753 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 754 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 755 } 756 757 @Test testSetSubscriptions_MultipleLayersAndProvider_OverwriteSubscription()758 public void testSetSubscriptions_MultipleLayersAndProvider_OverwriteSubscription() { 759 VmsClient client = connectVmsClient(mClientCallback1); 760 761 client.setSubscriptions(asSet( 762 new VmsAssociatedLayer(LAYER1, emptySet()), 763 new VmsAssociatedLayer(LAYER2, asSet(12345)) 764 )); 765 client.setSubscriptions(asSet( 766 new VmsAssociatedLayer(LAYER2, emptySet()), 767 new VmsAssociatedLayer(LAYER1, asSet(54321)) 768 )); 769 770 awaitTaskCompletion(); 771 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 772 asSet(LAYER2), 773 asSet(new VmsAssociatedLayer(LAYER1, asSet(54321)))); 774 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 775 } 776 777 @Test testSetSubscriptions_MultipleLayersAndProvider_OverwriteSubscription_MultipleClients()778 public void testSetSubscriptions_MultipleLayersAndProvider_OverwriteSubscription_MultipleClients() { 779 VmsClient client = connectVmsClient(mClientCallback1); 780 VmsClient client2 = connectVmsClient(mClientCallback2); 781 782 client.setSubscriptions(asSet( 783 new VmsAssociatedLayer(LAYER1, emptySet()), 784 new VmsAssociatedLayer(LAYER2, asSet(12345)) 785 )); 786 client2.setSubscriptions(asSet( 787 new VmsAssociatedLayer(LAYER2, emptySet()), 788 new VmsAssociatedLayer(LAYER1, asSet(54321)) 789 )); 790 client2.setSubscriptions(asSet( 791 new VmsAssociatedLayer(LAYER3, emptySet()), 792 new VmsAssociatedLayer(LAYER2, asSet(54321)) 793 )); 794 795 awaitTaskCompletion(); 796 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 797 asSet(LAYER1, LAYER3), 798 asSet(new VmsAssociatedLayer(LAYER2, asSet(12345, 54321)))); 799 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 800 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 801 } 802 803 @Test testSetSubscriptions_MultipleLayersAndProvider_RemoveSubscription()804 public void testSetSubscriptions_MultipleLayersAndProvider_RemoveSubscription() { 805 VmsClient client = connectVmsClient(mClientCallback1); 806 807 client.setSubscriptions(asSet( 808 new VmsAssociatedLayer(LAYER1, emptySet()), 809 new VmsAssociatedLayer(LAYER2, asSet(12345)) 810 )); 811 client.setSubscriptions(emptySet()); 812 813 awaitTaskCompletion(); 814 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 815 emptySet(), 816 emptySet()); 817 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 818 } 819 820 @Test testSetSubscriptions_MultipleLayersAndProvider_RemoveSubscription_MultipleClients()821 public void testSetSubscriptions_MultipleLayersAndProvider_RemoveSubscription_MultipleClients() { 822 VmsClient client = connectVmsClient(mClientCallback1); 823 VmsClient client2 = connectVmsClient(mClientCallback2); 824 825 client.setSubscriptions(asSet( 826 new VmsAssociatedLayer(LAYER1, emptySet()), 827 new VmsAssociatedLayer(LAYER2, asSet(12345)) 828 )); 829 client2.setSubscriptions(asSet( 830 new VmsAssociatedLayer(LAYER2, emptySet()), 831 new VmsAssociatedLayer(LAYER1, asSet(54321)) 832 )); 833 client2.setSubscriptions(emptySet()); 834 835 awaitTaskCompletion(); 836 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 837 asSet(LAYER1), 838 asSet(new VmsAssociatedLayer(LAYER2, asSet(12345)))); 839 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 840 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 841 } 842 843 @Test testSetSubscriptions_MultipleLayersAndProvider_RemoveSubscription_OnUnregister_MultipleClients()844 public void testSetSubscriptions_MultipleLayersAndProvider_RemoveSubscription_OnUnregister_MultipleClients() { 845 VmsClient client = connectVmsClient(mClientCallback1); 846 VmsClient client2 = connectVmsClient(mClientCallback2); 847 848 client.setSubscriptions(asSet( 849 new VmsAssociatedLayer(LAYER1, emptySet()), 850 new VmsAssociatedLayer(LAYER2, asSet(12345)) 851 )); 852 client2.setSubscriptions(asSet( 853 new VmsAssociatedLayer(LAYER2, emptySet()), 854 new VmsAssociatedLayer(LAYER1, asSet(54321)) 855 )); 856 mClientManager.unregisterVmsClientCallback(mClientCallback2); 857 858 awaitTaskCompletion(); 859 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 860 asSet(LAYER1), 861 asSet(new VmsAssociatedLayer(LAYER2, asSet(12345)))); 862 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 863 } 864 865 @Test testSetSubscriptions_MultipleLayersAndMultipleProviders()866 public void testSetSubscriptions_MultipleLayersAndMultipleProviders() { 867 VmsClient client = connectVmsClient(mClientCallback1); 868 869 client.setSubscriptions(asSet( 870 new VmsAssociatedLayer(LAYER1, asSet(54321)), 871 new VmsAssociatedLayer(LAYER2, asSet(12345)) 872 )); 873 874 awaitTaskCompletion(); 875 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 876 emptySet(), 877 asSet( 878 new VmsAssociatedLayer(LAYER1, asSet(54321)), 879 new VmsAssociatedLayer(LAYER2, asSet(12345)))); 880 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 881 } 882 883 @Test testSetSubscriptions_MultipleLayersAndMultipleProviders_MultipleClients()884 public void testSetSubscriptions_MultipleLayersAndMultipleProviders_MultipleClients() { 885 VmsClient client = connectVmsClient(mClientCallback1); 886 VmsClient client2 = connectVmsClient(mClientCallback2); 887 888 client.setSubscriptions(asSet( 889 new VmsAssociatedLayer(LAYER1, asSet(54321)) 890 )); 891 client2.setSubscriptions(asSet( 892 new VmsAssociatedLayer(LAYER2, asSet(12345)) 893 )); 894 895 awaitTaskCompletion(); 896 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 897 emptySet(), 898 asSet( 899 new VmsAssociatedLayer(LAYER1, asSet(54321)), 900 new VmsAssociatedLayer(LAYER2, asSet(12345)))); 901 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 902 } 903 904 @Test testSetSubscriptions_LayerOnlySupersedesLayerAndProvider()905 public void testSetSubscriptions_LayerOnlySupersedesLayerAndProvider() { 906 VmsClient client = connectVmsClient(mClientCallback1); 907 908 client.setSubscriptions(asSet( 909 new VmsAssociatedLayer(LAYER1, emptySet()), 910 new VmsAssociatedLayer(LAYER1, asSet(12345)) 911 )); 912 913 awaitTaskCompletion(); 914 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 915 asSet(LAYER1), 916 emptySet()); 917 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 918 } 919 920 @Test testSetSubscriptions_LayerOnlySupersedesLayerAndProvider_MultipleClients()921 public void testSetSubscriptions_LayerOnlySupersedesLayerAndProvider_MultipleClients() { 922 VmsClient client = connectVmsClient(mClientCallback1); 923 VmsClient client2 = connectVmsClient(mClientCallback2); 924 925 client.setSubscriptions(asSet( 926 new VmsAssociatedLayer(LAYER1, emptySet()) 927 )); 928 client2.setSubscriptions(asSet( 929 new VmsAssociatedLayer(LAYER1, asSet(12345)) 930 )); 931 932 awaitTaskCompletion(); 933 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(1, 934 asSet(LAYER1), 935 emptySet()); 936 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 937 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 938 } 939 940 @Test testSetSubscriptions_LayerOnlySupersedesLayerAndProvider_RemoveLayerSubscription()941 public void testSetSubscriptions_LayerOnlySupersedesLayerAndProvider_RemoveLayerSubscription() { 942 VmsClient client = connectVmsClient(mClientCallback1); 943 944 client.setSubscriptions(asSet( 945 new VmsAssociatedLayer(LAYER1, emptySet()), 946 new VmsAssociatedLayer(LAYER1, asSet(12345)) 947 )); 948 client.setSubscriptions(asSet( 949 new VmsAssociatedLayer(LAYER1, asSet(12345)) 950 )); 951 952 awaitTaskCompletion(); 953 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(2, 954 emptySet(), 955 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345)))); 956 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 957 } 958 959 @Test testSetSubscriptions_LayerOnlySupersedesLayerAndProvider_RemoveLayerSubscription_MultipleClients()960 public void testSetSubscriptions_LayerOnlySupersedesLayerAndProvider_RemoveLayerSubscription_MultipleClients() { 961 VmsClient client = connectVmsClient(mClientCallback1); 962 VmsClient client2 = connectVmsClient(mClientCallback2); 963 964 client.setSubscriptions(asSet( 965 new VmsAssociatedLayer(LAYER1, asSet(12345)) 966 )); 967 client2.setSubscriptions(asSet( 968 new VmsAssociatedLayer(LAYER1, emptySet()) 969 )); 970 client2.setSubscriptions(emptySet()); 971 972 awaitTaskCompletion(); 973 VmsSubscriptionState expectedSubscriptions = new VmsSubscriptionState(3, 974 emptySet(), 975 asSet(new VmsAssociatedLayer(LAYER1, asSet(12345)))); 976 verifySubscriptionState(mClientCallback1, expectedSubscriptions); 977 verifySubscriptionState(mClientCallback2, expectedSubscriptions); 978 } 979 980 @Test testSetMonitoringEnabled_Enable_NoSubscriptionChange()981 public void testSetMonitoringEnabled_Enable_NoSubscriptionChange() { 982 VmsClient client = connectVmsClient(mClientCallback1); 983 984 client.setMonitoringEnabled(true); 985 986 awaitTaskCompletion(); 987 verifySubscriptionState(mClientCallback1, DEFAULT_SUBSCRIPTION_STATE); 988 } 989 990 @Test testSetMonitoringEnabled_Disable_NoSubscriptionChange()991 public void testSetMonitoringEnabled_Disable_NoSubscriptionChange() { 992 VmsClient client = connectVmsClient(mClientCallback1); 993 994 client.setMonitoringEnabled(false); 995 996 awaitTaskCompletion(); 997 verifySubscriptionState(mClientCallback1, DEFAULT_SUBSCRIPTION_STATE); 998 } 999 1000 @Test testSetProviderOfferings_UnknownProviderId()1001 public void testSetProviderOfferings_UnknownProviderId() { 1002 VmsClient client = connectVmsClient(mClientCallback1); 1003 1004 assertThrows( 1005 IllegalArgumentException.class, 1006 () -> client.setProviderOfferings(12345, emptySet())); 1007 } 1008 1009 @Test testSetProviderOfferings_OtherClientsProviderId()1010 public void testSetProviderOfferings_OtherClientsProviderId() { 1011 VmsClient client = connectVmsClient(mClientCallback1); 1012 int providerId = client.registerProvider(PROVIDER_DESC1); 1013 VmsClient client2 = connectVmsClient(mClientCallback2); 1014 1015 assertThrows( 1016 IllegalArgumentException.class, 1017 () -> client2.setProviderOfferings(providerId, emptySet())); 1018 } 1019 1020 @Test testSetProviderOfferings_SingleProvider()1021 public void testSetProviderOfferings_SingleProvider() { 1022 VmsClient client = connectVmsClient(mClientCallback1); 1023 int providerId = client.registerProvider(PROVIDER_DESC1); 1024 1025 client.setProviderOfferings(providerId, asSet( 1026 new VmsLayerDependency(LAYER1) 1027 )); 1028 1029 awaitTaskCompletion(); 1030 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, asSet( 1031 new VmsAssociatedLayer(LAYER1, asSet(providerId))) 1032 ); 1033 verifyLayerAvailability(mClientCallback1, expectedLayers); 1034 } 1035 1036 @Test testSetProviderOfferings_MultipleProviders()1037 public void testSetProviderOfferings_MultipleProviders() { 1038 VmsClient client = connectVmsClient(mClientCallback1); 1039 int providerId = client.registerProvider(PROVIDER_DESC1); 1040 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1041 1042 client.setProviderOfferings(providerId, asSet( 1043 new VmsLayerDependency(LAYER1) 1044 )); 1045 client.setProviderOfferings(providerId2, asSet( 1046 new VmsLayerDependency(LAYER1) 1047 )); 1048 1049 awaitTaskCompletion(); 1050 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1051 new VmsAssociatedLayer(LAYER1, asSet(providerId, providerId2))) 1052 ); 1053 verifyLayerAvailability(mClientCallback1, expectedLayers); 1054 } 1055 1056 @Test testSetProviderOfferings_MultipleClients()1057 public void testSetProviderOfferings_MultipleClients() { 1058 VmsClient client = connectVmsClient(mClientCallback1); 1059 int providerId = client.registerProvider(PROVIDER_DESC1); 1060 1061 VmsClient client2 = connectVmsClient(mClientCallback2); 1062 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1063 1064 client.setProviderOfferings(providerId, asSet( 1065 new VmsLayerDependency(LAYER1) 1066 )); 1067 client2.setProviderOfferings(providerId2, asSet( 1068 new VmsLayerDependency(LAYER1) 1069 )); 1070 1071 awaitTaskCompletion(); 1072 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1073 new VmsAssociatedLayer(LAYER1, asSet(providerId, providerId2))) 1074 ); 1075 verifyLayerAvailability(mClientCallback1, expectedLayers); 1076 verifyLayerAvailability(mClientCallback2, expectedLayers); 1077 } 1078 1079 @Test testSetProviderOfferings_MultipleClients_SingleProvider()1080 public void testSetProviderOfferings_MultipleClients_SingleProvider() { 1081 VmsClient client = connectVmsClient(mClientCallback1); 1082 int providerId = client.registerProvider(PROVIDER_DESC1); 1083 1084 VmsClient client2 = connectVmsClient(mClientCallback2); 1085 client2.registerProvider(PROVIDER_DESC1); 1086 1087 client.setProviderOfferings(providerId, asSet( 1088 new VmsLayerDependency(LAYER1) 1089 )); 1090 client2.setProviderOfferings(providerId, asSet( 1091 new VmsLayerDependency(LAYER1) 1092 )); 1093 1094 awaitTaskCompletion(); 1095 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, asSet( 1096 new VmsAssociatedLayer(LAYER1, asSet(providerId))) 1097 ); 1098 verifyLayerAvailability(mClientCallback1, expectedLayers); 1099 verifyLayerAvailability(mClientCallback2, expectedLayers); 1100 } 1101 1102 @Test testSetProviderOfferings_MultipleLayers_SingleProvider()1103 public void testSetProviderOfferings_MultipleLayers_SingleProvider() { 1104 VmsClient client = connectVmsClient(mClientCallback1); 1105 int providerId = client.registerProvider(PROVIDER_DESC1); 1106 1107 client.setProviderOfferings(providerId, asSet( 1108 new VmsLayerDependency(LAYER1), 1109 new VmsLayerDependency(LAYER2) 1110 )); 1111 1112 awaitTaskCompletion(); 1113 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, asSet( 1114 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1115 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 1116 ); 1117 verifyLayerAvailability(mClientCallback1, expectedLayers); 1118 } 1119 1120 @Test testSetProviderOfferings_MultipleLayers_MultipleProviders()1121 public void testSetProviderOfferings_MultipleLayers_MultipleProviders() { 1122 VmsClient client = connectVmsClient(mClientCallback1); 1123 int providerId = client.registerProvider(PROVIDER_DESC1); 1124 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1125 1126 client.setProviderOfferings(providerId, asSet( 1127 new VmsLayerDependency(LAYER1) 1128 )); 1129 client.setProviderOfferings(providerId2, asSet( 1130 new VmsLayerDependency(LAYER2) 1131 )); 1132 1133 awaitTaskCompletion(); 1134 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1135 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1136 new VmsAssociatedLayer(LAYER2, asSet(providerId2))) 1137 ); 1138 verifyLayerAvailability(mClientCallback1, expectedLayers); 1139 } 1140 1141 @Test testSetProviderOfferings_MultipleLayers_MultipleClients()1142 public void testSetProviderOfferings_MultipleLayers_MultipleClients() { 1143 VmsClient client = connectVmsClient(mClientCallback1); 1144 int providerId = client.registerProvider(PROVIDER_DESC1); 1145 1146 VmsClient client2 = connectVmsClient(mClientCallback2); 1147 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1148 1149 client.setProviderOfferings(providerId, asSet( 1150 new VmsLayerDependency(LAYER1) 1151 )); 1152 client2.setProviderOfferings(providerId2, asSet( 1153 new VmsLayerDependency(LAYER2) 1154 )); 1155 1156 awaitTaskCompletion(); 1157 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1158 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1159 new VmsAssociatedLayer(LAYER2, asSet(providerId2))) 1160 ); 1161 verifyLayerAvailability(mClientCallback1, expectedLayers); 1162 verifyLayerAvailability(mClientCallback2, expectedLayers); 1163 } 1164 1165 @Test testSetProviderOfferings_MultipleLayers_MultipleClients_SingleProvider()1166 public void testSetProviderOfferings_MultipleLayers_MultipleClients_SingleProvider() { 1167 VmsClient client = connectVmsClient(mClientCallback1); 1168 int providerId = client.registerProvider(PROVIDER_DESC1); 1169 1170 VmsClient client2 = connectVmsClient(mClientCallback2); 1171 client2.registerProvider(PROVIDER_DESC1); 1172 1173 client.setProviderOfferings(providerId, asSet( 1174 new VmsLayerDependency(LAYER1) 1175 )); 1176 client2.setProviderOfferings(providerId, asSet( 1177 new VmsLayerDependency(LAYER2) 1178 )); 1179 1180 awaitTaskCompletion(); 1181 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1182 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1183 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 1184 ); 1185 verifyLayerAvailability(mClientCallback1, expectedLayers); 1186 verifyLayerAvailability(mClientCallback2, expectedLayers); 1187 } 1188 1189 @Test testSetProviderOfferings_OverwriteOffering_SingleProvider()1190 public void testSetProviderOfferings_OverwriteOffering_SingleProvider() { 1191 VmsClient client = connectVmsClient(mClientCallback1); 1192 int providerId = client.registerProvider(PROVIDER_DESC1); 1193 1194 client.setProviderOfferings(providerId, asSet( 1195 new VmsLayerDependency(LAYER1) 1196 )); 1197 client.setProviderOfferings(providerId, asSet( 1198 new VmsLayerDependency(LAYER2) 1199 )); 1200 1201 awaitTaskCompletion(); 1202 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1203 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 1204 ); 1205 verifyLayerAvailability(mClientCallback1, expectedLayers); 1206 } 1207 1208 @Test testSetProviderOfferings_OverwriteOffering_MultipleProviders()1209 public void testSetProviderOfferings_OverwriteOffering_MultipleProviders() { 1210 VmsClient client = connectVmsClient(mClientCallback1); 1211 int providerId = client.registerProvider(PROVIDER_DESC1); 1212 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1213 1214 client.setProviderOfferings(providerId, asSet( 1215 new VmsLayerDependency(LAYER1) 1216 )); 1217 client.setProviderOfferings(providerId2, asSet( 1218 new VmsLayerDependency(LAYER1) 1219 )); 1220 client.setProviderOfferings(providerId2, asSet( 1221 new VmsLayerDependency(LAYER2) 1222 )); 1223 1224 awaitTaskCompletion(); 1225 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(3, asSet( 1226 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1227 new VmsAssociatedLayer(LAYER2, asSet(providerId2))) 1228 ); 1229 verifyLayerAvailability(mClientCallback1, expectedLayers); 1230 } 1231 1232 @Test testSetProviderOfferings_OverwriteOffering_MultipleClients()1233 public void testSetProviderOfferings_OverwriteOffering_MultipleClients() { 1234 VmsClient client = connectVmsClient(mClientCallback1); 1235 int providerId = client.registerProvider(PROVIDER_DESC1); 1236 1237 VmsClient client2 = connectVmsClient(mClientCallback2); 1238 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1239 1240 client.setProviderOfferings(providerId, asSet( 1241 new VmsLayerDependency(LAYER1) 1242 )); 1243 client2.setProviderOfferings(providerId2, asSet( 1244 new VmsLayerDependency(LAYER1) 1245 )); 1246 client2.setProviderOfferings(providerId2, asSet( 1247 new VmsLayerDependency(LAYER2) 1248 )); 1249 1250 awaitTaskCompletion(); 1251 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(3, asSet( 1252 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1253 new VmsAssociatedLayer(LAYER2, asSet(providerId2))) 1254 ); 1255 verifyLayerAvailability(mClientCallback1, expectedLayers); 1256 verifyLayerAvailability(mClientCallback2, expectedLayers); 1257 } 1258 1259 @Test testSetProviderOfferings_OverwriteOffering_MultipleClients_SingleProvider()1260 public void testSetProviderOfferings_OverwriteOffering_MultipleClients_SingleProvider() { 1261 VmsClient client = connectVmsClient(mClientCallback1); 1262 int providerId = client.registerProvider(PROVIDER_DESC1); 1263 1264 VmsClient client2 = connectVmsClient(mClientCallback2); 1265 client2.registerProvider(PROVIDER_DESC1); 1266 1267 client.setProviderOfferings(providerId, asSet( 1268 new VmsLayerDependency(LAYER1) 1269 )); 1270 client2.setProviderOfferings(providerId, asSet( 1271 new VmsLayerDependency(LAYER1) 1272 )); 1273 client2.setProviderOfferings(providerId, asSet( 1274 new VmsLayerDependency(LAYER2) 1275 )); 1276 1277 awaitTaskCompletion(); 1278 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1279 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1280 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 1281 ); 1282 verifyLayerAvailability(mClientCallback1, expectedLayers); 1283 verifyLayerAvailability(mClientCallback2, expectedLayers); 1284 } 1285 1286 @Test testSetProviderOfferings_RemoveOfferings_SingleProvider()1287 public void testSetProviderOfferings_RemoveOfferings_SingleProvider() { 1288 VmsClient client = connectVmsClient(mClientCallback1); 1289 int providerId = client.registerProvider(PROVIDER_DESC1); 1290 1291 client.setProviderOfferings(providerId, asSet( 1292 new VmsLayerDependency(LAYER1) 1293 )); 1294 client.setProviderOfferings(providerId, emptySet()); 1295 1296 awaitTaskCompletion(); 1297 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 1298 verifyLayerAvailability(mClientCallback1, expectedLayers); 1299 } 1300 1301 @Test testSetProviderOfferings_RemoveOfferings_MultipleProviders()1302 public void testSetProviderOfferings_RemoveOfferings_MultipleProviders() { 1303 VmsClient client = connectVmsClient(mClientCallback1); 1304 int providerId = client.registerProvider(PROVIDER_DESC1); 1305 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1306 1307 client.setProviderOfferings(providerId, asSet( 1308 new VmsLayerDependency(LAYER1) 1309 )); 1310 client.setProviderOfferings(providerId2, asSet( 1311 new VmsLayerDependency(LAYER1) 1312 )); 1313 client.setProviderOfferings(providerId2, emptySet()); 1314 1315 awaitTaskCompletion(); 1316 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(3, asSet( 1317 new VmsAssociatedLayer(LAYER1, asSet(providerId))) 1318 ); 1319 verifyLayerAvailability(mClientCallback1, expectedLayers); 1320 } 1321 1322 @Test testSetProviderOfferings_RemoveOfferings_MultipleClients()1323 public void testSetProviderOfferings_RemoveOfferings_MultipleClients() { 1324 VmsClient client = connectVmsClient(mClientCallback1); 1325 int providerId = client.registerProvider(PROVIDER_DESC1); 1326 1327 VmsClient client2 = connectVmsClient(mClientCallback2); 1328 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1329 1330 client.setProviderOfferings(providerId, asSet( 1331 new VmsLayerDependency(LAYER1) 1332 )); 1333 client2.setProviderOfferings(providerId2, asSet( 1334 new VmsLayerDependency(LAYER1) 1335 )); 1336 client2.setProviderOfferings(providerId2, emptySet()); 1337 1338 awaitTaskCompletion(); 1339 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(3, asSet( 1340 new VmsAssociatedLayer(LAYER1, asSet(providerId))) 1341 ); 1342 verifyLayerAvailability(mClientCallback1, expectedLayers); 1343 verifyLayerAvailability(mClientCallback2, expectedLayers); 1344 } 1345 1346 @Test testSetProviderOfferings_RemoveOfferings_MultipleClients_SingleProvider()1347 public void testSetProviderOfferings_RemoveOfferings_MultipleClients_SingleProvider() { 1348 VmsClient client = connectVmsClient(mClientCallback1); 1349 int providerId = client.registerProvider(PROVIDER_DESC1); 1350 1351 VmsClient client2 = connectVmsClient(mClientCallback2); 1352 client2.registerProvider(PROVIDER_DESC1); 1353 1354 client.setProviderOfferings(providerId, asSet( 1355 new VmsLayerDependency(LAYER1) 1356 )); 1357 client2.setProviderOfferings(providerId, asSet( 1358 new VmsLayerDependency(LAYER1) 1359 )); 1360 client2.setProviderOfferings(providerId, emptySet()); 1361 1362 awaitTaskCompletion(); 1363 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1364 new VmsAssociatedLayer(LAYER1, asSet(providerId))) 1365 ); 1366 verifyLayerAvailability(mClientCallback1, expectedLayers); 1367 verifyLayerAvailability(mClientCallback2, expectedLayers); 1368 } 1369 1370 @Test testSetProviderOfferings_RemoveOfferings_OnUnregister_SingleProvider()1371 public void testSetProviderOfferings_RemoveOfferings_OnUnregister_SingleProvider() { 1372 VmsClient client = connectVmsClient(mClientCallback1); 1373 int providerId = client.registerProvider(PROVIDER_DESC1); 1374 1375 // Register second client to verify layer availability after first client disconnects 1376 connectVmsClient(mClientCallback2); 1377 1378 client.setProviderOfferings(providerId, asSet( 1379 new VmsLayerDependency(LAYER1) 1380 )); 1381 mClientManager.unregisterVmsClientCallback(mClientCallback1); 1382 1383 awaitTaskCompletion(); 1384 VmsAvailableLayers expectedLayers1 = new VmsAvailableLayers(1, asSet( 1385 new VmsAssociatedLayer(LAYER1, asSet(providerId))) 1386 ); 1387 VmsAvailableLayers expectedLayers2 = new VmsAvailableLayers(2, emptySet()); 1388 verifyLayerAvailability(mClientCallback1, expectedLayers1); 1389 verifyLayerAvailability(mClientCallback2, expectedLayers2); 1390 } 1391 1392 @Test testSetProviderOfferings_RemoveOfferings_OnUnregister_MultipleProviders()1393 public void testSetProviderOfferings_RemoveOfferings_OnUnregister_MultipleProviders() { 1394 VmsClient client = connectVmsClient(mClientCallback1); 1395 int providerId = client.registerProvider(PROVIDER_DESC1); 1396 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1397 1398 // Register second client to verify layer availability after first client disconnects 1399 connectVmsClient(mClientCallback2); 1400 1401 client.setProviderOfferings(providerId, asSet( 1402 new VmsLayerDependency(LAYER1) 1403 )); 1404 client.setProviderOfferings(providerId2, asSet( 1405 new VmsLayerDependency(LAYER1) 1406 )); 1407 mClientManager.unregisterVmsClientCallback(mClientCallback1); 1408 1409 awaitTaskCompletion(); 1410 VmsAvailableLayers expectedLayers1 = new VmsAvailableLayers(2, asSet( 1411 new VmsAssociatedLayer(LAYER1, asSet(providerId, providerId2))) 1412 ); 1413 VmsAvailableLayers expectedLayers2 = new VmsAvailableLayers(3, emptySet()); 1414 verifyLayerAvailability(mClientCallback1, expectedLayers1); 1415 verifyLayerAvailability(mClientCallback2, expectedLayers2); 1416 } 1417 1418 @Test testSetProviderOfferings_RemoveOfferings_OnUnregister_MultipleClients()1419 public void testSetProviderOfferings_RemoveOfferings_OnUnregister_MultipleClients() { 1420 VmsClient client = connectVmsClient(mClientCallback1); 1421 int providerId = client.registerProvider(PROVIDER_DESC1); 1422 1423 VmsClient client2 = connectVmsClient(mClientCallback2); 1424 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1425 1426 client.setProviderOfferings(providerId, asSet( 1427 new VmsLayerDependency(LAYER1) 1428 )); 1429 client2.setProviderOfferings(providerId2, asSet( 1430 new VmsLayerDependency(LAYER1) 1431 )); 1432 mClientManager.unregisterVmsClientCallback(mClientCallback1); 1433 1434 awaitTaskCompletion(); 1435 VmsAvailableLayers expectedLayers1 = new VmsAvailableLayers(2, asSet( 1436 new VmsAssociatedLayer(LAYER1, asSet(providerId, providerId2))) 1437 ); 1438 VmsAvailableLayers expectedLayers2 = new VmsAvailableLayers(3, asSet( 1439 new VmsAssociatedLayer(LAYER1, asSet(providerId2))) 1440 ); 1441 verifyLayerAvailability(mClientCallback1, expectedLayers1); 1442 verifyLayerAvailability(mClientCallback2, expectedLayers2); 1443 } 1444 1445 @Test testSetProviderOfferings_RemoveOfferings_OnUnregister_MultipleClients_SingleProvider()1446 public void testSetProviderOfferings_RemoveOfferings_OnUnregister_MultipleClients_SingleProvider() { 1447 VmsClient client = connectVmsClient(mClientCallback1); 1448 int providerId = client.registerProvider(PROVIDER_DESC1); 1449 1450 VmsClient client2 = connectVmsClient(mClientCallback2); 1451 client2.registerProvider(PROVIDER_DESC1); 1452 1453 client.setProviderOfferings(providerId, asSet( 1454 new VmsLayerDependency(LAYER1) 1455 )); 1456 client2.setProviderOfferings(providerId, asSet( 1457 new VmsLayerDependency(LAYER1) 1458 )); 1459 mClientManager.unregisterVmsClientCallback(mClientCallback1); 1460 1461 awaitTaskCompletion(); 1462 VmsAvailableLayers expectedLayers1 = new VmsAvailableLayers(1, asSet( 1463 new VmsAssociatedLayer(LAYER1, asSet(providerId))) 1464 ); 1465 VmsAvailableLayers expectedLayers2 = new VmsAvailableLayers(1, asSet( 1466 new VmsAssociatedLayer(LAYER1, asSet(providerId))) 1467 ); 1468 verifyLayerAvailability(mClientCallback1, expectedLayers1); 1469 verifyLayerAvailability(mClientCallback2, expectedLayers2); 1470 } 1471 1472 @Test testSetProviderOfferings_DependencyMet_SingleProvider()1473 public void testSetProviderOfferings_DependencyMet_SingleProvider() { 1474 VmsClient client = connectVmsClient(mClientCallback1); 1475 int providerId = client.registerProvider(PROVIDER_DESC1); 1476 1477 client.setProviderOfferings(providerId, asSet( 1478 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 1479 new VmsLayerDependency(LAYER2) 1480 )); 1481 1482 awaitTaskCompletion(); 1483 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, asSet( 1484 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1485 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 1486 ); 1487 verifyLayerAvailability(mClientCallback1, expectedLayers); 1488 } 1489 1490 @Test testSetProviderOfferings_DependencyMet_MultipleProviders()1491 public void testSetProviderOfferings_DependencyMet_MultipleProviders() { 1492 VmsClient client = connectVmsClient(mClientCallback1); 1493 int providerId = client.registerProvider(PROVIDER_DESC1); 1494 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1495 1496 client.setProviderOfferings(providerId, asSet( 1497 new VmsLayerDependency(LAYER1, asSet(LAYER2)) 1498 )); 1499 client.setProviderOfferings(providerId2, asSet( 1500 new VmsLayerDependency(LAYER2) 1501 )); 1502 1503 awaitTaskCompletion(); 1504 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1505 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1506 new VmsAssociatedLayer(LAYER2, asSet(providerId2))) 1507 ); 1508 verifyLayerAvailability(mClientCallback1, expectedLayers); 1509 } 1510 1511 @Test testSetProviderOfferings_DependencyMet_MultipleClients()1512 public void testSetProviderOfferings_DependencyMet_MultipleClients() { 1513 VmsClient client = connectVmsClient(mClientCallback1); 1514 int providerId = client.registerProvider(PROVIDER_DESC1); 1515 1516 VmsClient client2 = connectVmsClient(mClientCallback2); 1517 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1518 1519 client.setProviderOfferings(providerId, asSet( 1520 new VmsLayerDependency(LAYER1, asSet(LAYER2)) 1521 )); 1522 client2.setProviderOfferings(providerId2, asSet( 1523 new VmsLayerDependency(LAYER2) 1524 )); 1525 1526 awaitTaskCompletion(); 1527 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1528 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1529 new VmsAssociatedLayer(LAYER2, asSet(providerId2))) 1530 ); 1531 verifyLayerAvailability(mClientCallback1, expectedLayers); 1532 verifyLayerAvailability(mClientCallback2, expectedLayers); 1533 } 1534 1535 @Test testSetProviderOfferings_DependencyMet_MultipleClients_SingleProvider()1536 public void testSetProviderOfferings_DependencyMet_MultipleClients_SingleProvider() { 1537 VmsClient client = connectVmsClient(mClientCallback1); 1538 int providerId = client.registerProvider(PROVIDER_DESC1); 1539 1540 VmsClient client2 = connectVmsClient(mClientCallback2); 1541 client2.registerProvider(PROVIDER_DESC1); 1542 1543 client.setProviderOfferings(providerId, asSet( 1544 new VmsLayerDependency(LAYER1, asSet(LAYER2)) 1545 )); 1546 client2.setProviderOfferings(providerId, asSet( 1547 new VmsLayerDependency(LAYER2) 1548 )); 1549 1550 awaitTaskCompletion(); 1551 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1552 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1553 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 1554 ); 1555 verifyLayerAvailability(mClientCallback1, expectedLayers); 1556 verifyLayerAvailability(mClientCallback2, expectedLayers); 1557 } 1558 1559 @Test testSetProviderOfferings_DependencyMet_MultipleDependencies_SingleProvider()1560 public void testSetProviderOfferings_DependencyMet_MultipleDependencies_SingleProvider() { 1561 VmsClient client = connectVmsClient(mClientCallback1); 1562 int providerId = client.registerProvider(PROVIDER_DESC1); 1563 1564 client.setProviderOfferings(providerId, asSet( 1565 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)), 1566 new VmsLayerDependency(LAYER2), 1567 new VmsLayerDependency(LAYER3) 1568 )); 1569 1570 awaitTaskCompletion(); 1571 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, asSet( 1572 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1573 new VmsAssociatedLayer(LAYER2, asSet(providerId)), 1574 new VmsAssociatedLayer(LAYER3, asSet(providerId))) 1575 ); 1576 verifyLayerAvailability(mClientCallback1, expectedLayers); 1577 } 1578 1579 @Test testSetProviderOfferings_DependencyMet_MultipleDependencies_MultipleProviders()1580 public void testSetProviderOfferings_DependencyMet_MultipleDependencies_MultipleProviders() { 1581 VmsClient client = connectVmsClient(mClientCallback1); 1582 int providerId = client.registerProvider(PROVIDER_DESC1); 1583 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1584 1585 client.setProviderOfferings(providerId, asSet( 1586 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)), 1587 new VmsLayerDependency(LAYER2) 1588 )); 1589 client.setProviderOfferings(providerId2, asSet( 1590 new VmsLayerDependency(LAYER3) 1591 )); 1592 1593 awaitTaskCompletion(); 1594 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1595 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1596 new VmsAssociatedLayer(LAYER2, asSet(providerId)), 1597 new VmsAssociatedLayer(LAYER3, asSet(providerId2))) 1598 ); 1599 verifyLayerAvailability(mClientCallback1, expectedLayers); 1600 } 1601 1602 @Test testSetProviderOfferings_DependencyMet_MultipleDependencies_MultipleClients()1603 public void testSetProviderOfferings_DependencyMet_MultipleDependencies_MultipleClients() { 1604 VmsClient client = connectVmsClient(mClientCallback1); 1605 int providerId = client.registerProvider(PROVIDER_DESC1); 1606 1607 VmsClient client2 = connectVmsClient(mClientCallback2); 1608 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1609 1610 client.setProviderOfferings(providerId, asSet( 1611 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)), 1612 new VmsLayerDependency(LAYER2) 1613 )); 1614 client2.setProviderOfferings(providerId2, asSet( 1615 new VmsLayerDependency(LAYER3) 1616 )); 1617 1618 awaitTaskCompletion(); 1619 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1620 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1621 new VmsAssociatedLayer(LAYER2, asSet(providerId)), 1622 new VmsAssociatedLayer(LAYER3, asSet(providerId2))) 1623 ); 1624 verifyLayerAvailability(mClientCallback1, expectedLayers); 1625 verifyLayerAvailability(mClientCallback2, expectedLayers); 1626 } 1627 1628 @Test testSetProviderOfferings_DependencyMet_MultipleDependencies_MultipleClients_SingleProvider()1629 public void testSetProviderOfferings_DependencyMet_MultipleDependencies_MultipleClients_SingleProvider() { 1630 VmsClient client = connectVmsClient(mClientCallback1); 1631 int providerId = client.registerProvider(PROVIDER_DESC1); 1632 1633 VmsClient client2 = connectVmsClient(mClientCallback2); 1634 client2.registerProvider(PROVIDER_DESC1); 1635 1636 client.setProviderOfferings(providerId, asSet( 1637 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)), 1638 new VmsLayerDependency(LAYER2) 1639 )); 1640 client2.setProviderOfferings(providerId, asSet( 1641 new VmsLayerDependency(LAYER3) 1642 )); 1643 1644 awaitTaskCompletion(); 1645 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1646 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1647 new VmsAssociatedLayer(LAYER2, asSet(providerId)), 1648 new VmsAssociatedLayer(LAYER3, asSet(providerId))) 1649 ); 1650 verifyLayerAvailability(mClientCallback1, expectedLayers); 1651 verifyLayerAvailability(mClientCallback2, expectedLayers); 1652 } 1653 1654 @Test testSetProviderOfferings_DependencyMet_ChainedDependencies_SingleProvider()1655 public void testSetProviderOfferings_DependencyMet_ChainedDependencies_SingleProvider() { 1656 VmsClient client = connectVmsClient(mClientCallback1); 1657 int providerId = client.registerProvider(PROVIDER_DESC1); 1658 1659 client.setProviderOfferings(providerId, asSet( 1660 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 1661 new VmsLayerDependency(LAYER2, asSet(LAYER3)), 1662 new VmsLayerDependency(LAYER3) 1663 )); 1664 1665 awaitTaskCompletion(); 1666 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, asSet( 1667 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1668 new VmsAssociatedLayer(LAYER2, asSet(providerId)), 1669 new VmsAssociatedLayer(LAYER3, asSet(providerId))) 1670 ); 1671 verifyLayerAvailability(mClientCallback1, expectedLayers); 1672 } 1673 1674 @Test testSetProviderOfferings_DependencyMet_ChainedDependencies_MultipleProviders()1675 public void testSetProviderOfferings_DependencyMet_ChainedDependencies_MultipleProviders() { 1676 VmsClient client = connectVmsClient(mClientCallback1); 1677 int providerId = client.registerProvider(PROVIDER_DESC1); 1678 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1679 1680 client.setProviderOfferings(providerId, asSet( 1681 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 1682 new VmsLayerDependency(LAYER3) 1683 )); 1684 client.setProviderOfferings(providerId2, asSet( 1685 new VmsLayerDependency(LAYER2, asSet(LAYER3)) 1686 )); 1687 1688 awaitTaskCompletion(); 1689 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1690 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1691 new VmsAssociatedLayer(LAYER2, asSet(providerId2)), 1692 new VmsAssociatedLayer(LAYER3, asSet(providerId))) 1693 ); 1694 verifyLayerAvailability(mClientCallback1, expectedLayers); 1695 } 1696 1697 @Test testSetProviderOfferings_DependencyMet_ChainedDependencies_MultipleClients()1698 public void testSetProviderOfferings_DependencyMet_ChainedDependencies_MultipleClients() { 1699 VmsClient client = connectVmsClient(mClientCallback1); 1700 int providerId = client.registerProvider(PROVIDER_DESC1); 1701 1702 VmsClient client2 = connectVmsClient(mClientCallback2); 1703 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1704 1705 client.setProviderOfferings(providerId, asSet( 1706 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 1707 new VmsLayerDependency(LAYER3) 1708 )); 1709 client2.setProviderOfferings(providerId2, asSet( 1710 new VmsLayerDependency(LAYER2, asSet(LAYER3)) 1711 )); 1712 1713 awaitTaskCompletion(); 1714 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1715 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1716 new VmsAssociatedLayer(LAYER2, asSet(providerId2)), 1717 new VmsAssociatedLayer(LAYER3, asSet(providerId))) 1718 ); 1719 verifyLayerAvailability(mClientCallback1, expectedLayers); 1720 verifyLayerAvailability(mClientCallback2, expectedLayers); 1721 } 1722 1723 @Test testSetProviderOfferings_DependencyMet_ChainedDependencies_MultipleClients_SingleProvider()1724 public void testSetProviderOfferings_DependencyMet_ChainedDependencies_MultipleClients_SingleProvider() { 1725 VmsClient client = connectVmsClient(mClientCallback1); 1726 int providerId = client.registerProvider(PROVIDER_DESC1); 1727 1728 VmsClient client2 = connectVmsClient(mClientCallback2); 1729 client2.registerProvider(PROVIDER_DESC1); 1730 1731 client.setProviderOfferings(providerId, asSet( 1732 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 1733 new VmsLayerDependency(LAYER3) 1734 )); 1735 client2.setProviderOfferings(providerId, asSet( 1736 new VmsLayerDependency(LAYER2, asSet(LAYER3)) 1737 )); 1738 1739 awaitTaskCompletion(); 1740 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1741 new VmsAssociatedLayer(LAYER1, asSet(providerId)), 1742 new VmsAssociatedLayer(LAYER2, asSet(providerId)), 1743 new VmsAssociatedLayer(LAYER3, asSet(providerId))) 1744 ); 1745 verifyLayerAvailability(mClientCallback1, expectedLayers); 1746 } 1747 1748 @Test testSetProviderOfferings_DependencyCircular_SingleProvider()1749 public void testSetProviderOfferings_DependencyCircular_SingleProvider() { 1750 VmsClient client = connectVmsClient(mClientCallback1); 1751 int providerId = client.registerProvider(PROVIDER_DESC1); 1752 1753 client.setProviderOfferings(providerId, asSet( 1754 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 1755 new VmsLayerDependency(LAYER2, asSet(LAYER1)) 1756 )); 1757 1758 awaitTaskCompletion(); 1759 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, emptySet()); 1760 verifyLayerAvailability(mClientCallback1, expectedLayers); 1761 } 1762 1763 @Test testSetProviderOfferings_DependencyCircular_MultipleProviders()1764 public void testSetProviderOfferings_DependencyCircular_MultipleProviders() { 1765 VmsClient client = connectVmsClient(mClientCallback1); 1766 int providerId = client.registerProvider(PROVIDER_DESC1); 1767 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1768 1769 client.setProviderOfferings(providerId, asSet( 1770 new VmsLayerDependency(LAYER1, asSet(LAYER2)) 1771 )); 1772 client.setProviderOfferings(providerId2, asSet( 1773 new VmsLayerDependency(LAYER2, asSet(LAYER1)) 1774 )); 1775 1776 awaitTaskCompletion(); 1777 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 1778 verifyLayerAvailability(mClientCallback1, expectedLayers); 1779 } 1780 1781 @Test testSetProviderOfferings_DependencyCircular_MultipleClients()1782 public void testSetProviderOfferings_DependencyCircular_MultipleClients() { 1783 VmsClient client = connectVmsClient(mClientCallback1); 1784 int providerId = client.registerProvider(PROVIDER_DESC1); 1785 1786 VmsClient client2 = connectVmsClient(mClientCallback2); 1787 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1788 1789 client.setProviderOfferings(providerId, asSet( 1790 new VmsLayerDependency(LAYER1, asSet(LAYER2)) 1791 )); 1792 client2.setProviderOfferings(providerId2, asSet( 1793 new VmsLayerDependency(LAYER2, asSet(LAYER1)) 1794 )); 1795 1796 awaitTaskCompletion(); 1797 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 1798 verifyLayerAvailability(mClientCallback1, expectedLayers); 1799 verifyLayerAvailability(mClientCallback2, expectedLayers); 1800 } 1801 1802 @Test testSetProviderOfferings_DependencyCircular_MultipleClients_SingleProvider()1803 public void testSetProviderOfferings_DependencyCircular_MultipleClients_SingleProvider() { 1804 VmsClient client = connectVmsClient(mClientCallback1); 1805 int providerId = client.registerProvider(PROVIDER_DESC1); 1806 1807 VmsClient client2 = connectVmsClient(mClientCallback2); 1808 client2.registerProvider(PROVIDER_DESC1); 1809 1810 client.setProviderOfferings(providerId, asSet( 1811 new VmsLayerDependency(LAYER1, asSet(LAYER2)) 1812 )); 1813 client2.setProviderOfferings(providerId, asSet( 1814 new VmsLayerDependency(LAYER2, asSet(LAYER1)) 1815 )); 1816 1817 awaitTaskCompletion(); 1818 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 1819 verifyLayerAvailability(mClientCallback1, expectedLayers); 1820 verifyLayerAvailability(mClientCallback2, expectedLayers); 1821 } 1822 1823 @Test testSetProviderOfferings_DependencyCircular_MultipleDependencies_SingleProvider()1824 public void testSetProviderOfferings_DependencyCircular_MultipleDependencies_SingleProvider() { 1825 VmsClient client = connectVmsClient(mClientCallback1); 1826 int providerId = client.registerProvider(PROVIDER_DESC1); 1827 1828 client.setProviderOfferings(providerId, asSet( 1829 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)), 1830 new VmsLayerDependency(LAYER2), 1831 new VmsLayerDependency(LAYER3, asSet(LAYER1)) 1832 )); 1833 1834 awaitTaskCompletion(); 1835 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, asSet( 1836 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 1837 ); 1838 verifyLayerAvailability(mClientCallback1, expectedLayers); 1839 } 1840 1841 @Test testSetProviderOfferings_DependencyCircular_MultipleDependencies_MultipleProviders()1842 public void testSetProviderOfferings_DependencyCircular_MultipleDependencies_MultipleProviders() { 1843 VmsClient client = connectVmsClient(mClientCallback1); 1844 int providerId = client.registerProvider(PROVIDER_DESC1); 1845 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1846 1847 client.setProviderOfferings(providerId, asSet( 1848 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)), 1849 new VmsLayerDependency(LAYER2) 1850 )); 1851 client.setProviderOfferings(providerId2, asSet( 1852 new VmsLayerDependency(LAYER3, asSet(LAYER1)) 1853 )); 1854 1855 awaitTaskCompletion(); 1856 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1857 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 1858 ); 1859 verifyLayerAvailability(mClientCallback1, expectedLayers); 1860 } 1861 1862 @Test testSetProviderOfferings_DependencyCircular_MultipleDependencies_MultipleClients()1863 public void testSetProviderOfferings_DependencyCircular_MultipleDependencies_MultipleClients() { 1864 VmsClient client = connectVmsClient(mClientCallback1); 1865 int providerId = client.registerProvider(PROVIDER_DESC1); 1866 1867 VmsClient client2 = connectVmsClient(mClientCallback2); 1868 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1869 1870 client.setProviderOfferings(providerId, asSet( 1871 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)), 1872 new VmsLayerDependency(LAYER2) 1873 )); 1874 client2.setProviderOfferings(providerId2, asSet( 1875 new VmsLayerDependency(LAYER3, asSet(LAYER1)) 1876 )); 1877 1878 awaitTaskCompletion(); 1879 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1880 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 1881 ); 1882 verifyLayerAvailability(mClientCallback1, expectedLayers); 1883 verifyLayerAvailability(mClientCallback2, expectedLayers); 1884 } 1885 1886 @Test testSetProviderOfferings_DependencyCircular_MultipleDependencies_MultipleClients_SingleProvider()1887 public void testSetProviderOfferings_DependencyCircular_MultipleDependencies_MultipleClients_SingleProvider() { 1888 VmsClient client = connectVmsClient(mClientCallback1); 1889 int providerId = client.registerProvider(PROVIDER_DESC1); 1890 1891 VmsClient client2 = connectVmsClient(mClientCallback2); 1892 client2.registerProvider(PROVIDER_DESC1); 1893 1894 client.setProviderOfferings(providerId, asSet( 1895 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)), 1896 new VmsLayerDependency(LAYER2) 1897 )); 1898 client2.setProviderOfferings(providerId, asSet( 1899 new VmsLayerDependency(LAYER3, asSet(LAYER1)) 1900 )); 1901 1902 awaitTaskCompletion(); 1903 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 1904 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 1905 ); 1906 verifyLayerAvailability(mClientCallback1, expectedLayers); 1907 verifyLayerAvailability(mClientCallback2, expectedLayers); 1908 } 1909 1910 @Test testSetProviderOfferings_DependencyCircular_ChainedDependencies_SingleProvider()1911 public void testSetProviderOfferings_DependencyCircular_ChainedDependencies_SingleProvider() { 1912 VmsClient client = connectVmsClient(mClientCallback1); 1913 int providerId = client.registerProvider(PROVIDER_DESC1); 1914 1915 client.setProviderOfferings(providerId, asSet( 1916 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 1917 new VmsLayerDependency(LAYER2, asSet(LAYER3)), 1918 new VmsLayerDependency(LAYER3, asSet(LAYER1)) 1919 )); 1920 1921 awaitTaskCompletion(); 1922 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, emptySet()); 1923 verifyLayerAvailability(mClientCallback1, expectedLayers); 1924 } 1925 1926 @Test testSetProviderOfferings_DependencyCircular_ChainedDependencies_MultipleProviders()1927 public void testSetProviderOfferings_DependencyCircular_ChainedDependencies_MultipleProviders() { 1928 VmsClient client = connectVmsClient(mClientCallback1); 1929 int providerId = client.registerProvider(PROVIDER_DESC1); 1930 int providerId2 = client.registerProvider(PROVIDER_DESC2); 1931 1932 client.setProviderOfferings(providerId, asSet( 1933 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 1934 new VmsLayerDependency(LAYER3, asSet(LAYER1)) 1935 )); 1936 client.setProviderOfferings(providerId2, asSet( 1937 new VmsLayerDependency(LAYER2, asSet(LAYER3)) 1938 )); 1939 1940 awaitTaskCompletion(); 1941 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 1942 verifyLayerAvailability(mClientCallback1, expectedLayers); 1943 } 1944 1945 @Test testSetProviderOfferings_DependencyCircular_ChainedDependencies_MultipleClients()1946 public void testSetProviderOfferings_DependencyCircular_ChainedDependencies_MultipleClients() { 1947 VmsClient client = connectVmsClient(mClientCallback1); 1948 int providerId = client.registerProvider(PROVIDER_DESC1); 1949 1950 VmsClient client2 = connectVmsClient(mClientCallback2); 1951 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 1952 1953 client.setProviderOfferings(providerId, asSet( 1954 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 1955 new VmsLayerDependency(LAYER3, asSet(LAYER1)) 1956 )); 1957 client2.setProviderOfferings(providerId2, asSet( 1958 new VmsLayerDependency(LAYER2, asSet(LAYER3)) 1959 )); 1960 1961 awaitTaskCompletion(); 1962 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 1963 verifyLayerAvailability(mClientCallback1, expectedLayers); 1964 verifyLayerAvailability(mClientCallback2, expectedLayers); 1965 } 1966 1967 @Test testSetProviderOfferings_DependencyCircular_ChainedDependencies_MultipleClients_SingleProvider()1968 public void testSetProviderOfferings_DependencyCircular_ChainedDependencies_MultipleClients_SingleProvider() { 1969 VmsClient client = connectVmsClient(mClientCallback1); 1970 int providerId = client.registerProvider(PROVIDER_DESC1); 1971 1972 VmsClient client2 = connectVmsClient(mClientCallback2); 1973 client2.registerProvider(PROVIDER_DESC1); 1974 1975 client.setProviderOfferings(providerId, asSet( 1976 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 1977 new VmsLayerDependency(LAYER3, asSet(LAYER1)) 1978 )); 1979 client2.setProviderOfferings(providerId, asSet( 1980 new VmsLayerDependency(LAYER2, asSet(LAYER3)) 1981 )); 1982 1983 awaitTaskCompletion(); 1984 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 1985 verifyLayerAvailability(mClientCallback1, expectedLayers); 1986 verifyLayerAvailability(mClientCallback2, expectedLayers); 1987 } 1988 1989 @Test testSetProviderOfferings_DependencyUnmet_SingleProvider()1990 public void testSetProviderOfferings_DependencyUnmet_SingleProvider() { 1991 VmsClient client = connectVmsClient(mClientCallback1); 1992 int providerId = client.registerProvider(PROVIDER_DESC1); 1993 1994 client.setProviderOfferings(providerId, asSet( 1995 new VmsLayerDependency(LAYER1, asSet(LAYER2)) 1996 )); 1997 1998 awaitTaskCompletion(); 1999 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, emptySet()); 2000 verifyLayerAvailability(mClientCallback1, expectedLayers); 2001 } 2002 2003 @Test testSetProviderOfferings_DependencyUnmet_MultipleDependencies_SingleProvider()2004 public void testSetProviderOfferings_DependencyUnmet_MultipleDependencies_SingleProvider() { 2005 VmsClient client = connectVmsClient(mClientCallback1); 2006 int providerId = client.registerProvider(PROVIDER_DESC1); 2007 2008 client.setProviderOfferings(providerId, asSet( 2009 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)), 2010 new VmsLayerDependency(LAYER2) 2011 )); 2012 2013 awaitTaskCompletion(); 2014 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, asSet( 2015 new VmsAssociatedLayer(LAYER2, asSet(providerId))) 2016 ); 2017 verifyLayerAvailability(mClientCallback1, expectedLayers); 2018 } 2019 2020 @Test testSetProviderOfferings_DependencyUnmet_MultipleDependencies_MultipleProviders()2021 public void testSetProviderOfferings_DependencyUnmet_MultipleDependencies_MultipleProviders() { 2022 VmsClient client = connectVmsClient(mClientCallback1); 2023 int providerId = client.registerProvider(PROVIDER_DESC1); 2024 int providerId2 = client.registerProvider(PROVIDER_DESC2); 2025 2026 client.setProviderOfferings(providerId, asSet( 2027 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)) 2028 )); 2029 client.setProviderOfferings(providerId2, asSet( 2030 new VmsLayerDependency(LAYER3) 2031 )); 2032 2033 awaitTaskCompletion(); 2034 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 2035 new VmsAssociatedLayer(LAYER3, asSet(providerId2))) 2036 ); 2037 verifyLayerAvailability(mClientCallback1, expectedLayers); 2038 } 2039 2040 @Test testSetProviderOfferings_DependencyUnmet_MultipleDependencies_MultipleClients()2041 public void testSetProviderOfferings_DependencyUnmet_MultipleDependencies_MultipleClients() { 2042 VmsClient client = connectVmsClient(mClientCallback1); 2043 int providerId = client.registerProvider(PROVIDER_DESC1); 2044 2045 VmsClient client2 = connectVmsClient(mClientCallback2); 2046 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 2047 2048 client.setProviderOfferings(providerId, asSet( 2049 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)) 2050 )); 2051 client2.setProviderOfferings(providerId2, asSet( 2052 new VmsLayerDependency(LAYER3) 2053 )); 2054 2055 awaitTaskCompletion(); 2056 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 2057 new VmsAssociatedLayer(LAYER3, asSet(providerId2))) 2058 ); 2059 verifyLayerAvailability(mClientCallback1, expectedLayers); 2060 verifyLayerAvailability(mClientCallback2, expectedLayers); 2061 } 2062 2063 @Test testSetProviderOfferings_DependencyUnmet_MultipleDependencies_MultipleClients_SingleProvider()2064 public void testSetProviderOfferings_DependencyUnmet_MultipleDependencies_MultipleClients_SingleProvider() { 2065 VmsClient client = connectVmsClient(mClientCallback1); 2066 int providerId = client.registerProvider(PROVIDER_DESC1); 2067 2068 VmsClient client2 = connectVmsClient(mClientCallback2); 2069 client2.registerProvider(PROVIDER_DESC1); 2070 2071 client.setProviderOfferings(providerId, asSet( 2072 new VmsLayerDependency(LAYER1, asSet(LAYER2, LAYER3)) 2073 )); 2074 client2.setProviderOfferings(providerId, asSet( 2075 new VmsLayerDependency(LAYER3) 2076 )); 2077 2078 awaitTaskCompletion(); 2079 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, asSet( 2080 new VmsAssociatedLayer(LAYER3, asSet(providerId))) 2081 ); 2082 verifyLayerAvailability(mClientCallback1, expectedLayers); 2083 verifyLayerAvailability(mClientCallback2, expectedLayers); 2084 } 2085 2086 @Test testSetProviderOfferings_DependencyUnmet_ChainedDependencies_SingleProvider()2087 public void testSetProviderOfferings_DependencyUnmet_ChainedDependencies_SingleProvider() { 2088 VmsClient client = connectVmsClient(mClientCallback1); 2089 int providerId = client.registerProvider(PROVIDER_DESC1); 2090 2091 client.setProviderOfferings(providerId, asSet( 2092 new VmsLayerDependency(LAYER1, asSet(LAYER2)), 2093 new VmsLayerDependency(LAYER2, asSet(LAYER3)) 2094 )); 2095 2096 awaitTaskCompletion(); 2097 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(1, emptySet()); 2098 verifyLayerAvailability(mClientCallback1, expectedLayers); 2099 } 2100 2101 @Test testSetProviderOfferings_DependencyUnmet_ChainedDependencies_MultipleProviders()2102 public void testSetProviderOfferings_DependencyUnmet_ChainedDependencies_MultipleProviders() { 2103 VmsClient client = connectVmsClient(mClientCallback1); 2104 int providerId = client.registerProvider(PROVIDER_DESC1); 2105 int providerId2 = client.registerProvider(PROVIDER_DESC2); 2106 2107 client.setProviderOfferings(providerId, asSet( 2108 new VmsLayerDependency(LAYER1, asSet(LAYER2)) 2109 )); 2110 client.setProviderOfferings(providerId2, asSet( 2111 new VmsLayerDependency(LAYER2, asSet(LAYER3)) 2112 )); 2113 2114 awaitTaskCompletion(); 2115 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 2116 verifyLayerAvailability(mClientCallback1, expectedLayers); 2117 } 2118 2119 @Test testSetProviderOfferings_DependencyUnmet_ChainedDependencies_MultipleClients()2120 public void testSetProviderOfferings_DependencyUnmet_ChainedDependencies_MultipleClients() { 2121 VmsClient client = connectVmsClient(mClientCallback1); 2122 int providerId = client.registerProvider(PROVIDER_DESC1); 2123 2124 VmsClient client2 = connectVmsClient(mClientCallback2); 2125 int providerId2 = client2.registerProvider(PROVIDER_DESC2); 2126 2127 client.setProviderOfferings(providerId, asSet( 2128 new VmsLayerDependency(LAYER1, asSet(LAYER2)) 2129 )); 2130 client2.setProviderOfferings(providerId2, asSet( 2131 new VmsLayerDependency(LAYER2, asSet(LAYER3)) 2132 )); 2133 2134 awaitTaskCompletion(); 2135 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 2136 verifyLayerAvailability(mClientCallback1, expectedLayers); 2137 verifyLayerAvailability(mClientCallback2, expectedLayers); 2138 } 2139 2140 @Test testSetProviderOfferings_DependencyUnmet_ChainedDependencies_MultipleClients_SingleProvider()2141 public void testSetProviderOfferings_DependencyUnmet_ChainedDependencies_MultipleClients_SingleProvider() { 2142 VmsClient client = connectVmsClient(mClientCallback1); 2143 int providerId = client.registerProvider(PROVIDER_DESC1); 2144 2145 VmsClient client2 = connectVmsClient(mClientCallback2); 2146 client2.registerProvider(PROVIDER_DESC1); 2147 2148 client.setProviderOfferings(providerId, asSet( 2149 new VmsLayerDependency(LAYER1, asSet(LAYER2)) 2150 )); 2151 client2.setProviderOfferings(providerId, asSet( 2152 new VmsLayerDependency(LAYER2, asSet(LAYER3)) 2153 )); 2154 2155 awaitTaskCompletion(); 2156 VmsAvailableLayers expectedLayers = new VmsAvailableLayers(2, emptySet()); 2157 verifyLayerAvailability(mClientCallback1, expectedLayers); 2158 verifyLayerAvailability(mClientCallback2, expectedLayers); 2159 } 2160 2161 @Test testPublishPacket_UnknownOffering()2162 public void testPublishPacket_UnknownOffering() { 2163 VmsClient client = connectVmsClient(mClientCallback1); 2164 int providerId = client.registerProvider(PROVIDER_DESC1); 2165 2166 assertThrows( 2167 IllegalArgumentException.class, 2168 () -> client.publishPacket(providerId, LAYER1, PAYLOAD)); 2169 } 2170 2171 @Test testPublishPacket_NoSubscribers()2172 public void testPublishPacket_NoSubscribers() { 2173 VmsClient client = connectVmsClient(mClientCallback1); 2174 int providerId = client.registerProvider(PROVIDER_DESC1); 2175 client.setProviderOfferings(providerId, asSet( 2176 new VmsLayerDependency(LAYER1) 2177 )); 2178 connectVmsClient(mClientCallback2); 2179 2180 client.publishPacket(providerId, LAYER1, PAYLOAD); 2181 2182 awaitTaskCompletion(); 2183 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2184 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2185 } 2186 2187 @Test testPublishPacket_MonitorSubscriber_Enabled()2188 public void testPublishPacket_MonitorSubscriber_Enabled() { 2189 VmsClient client = connectVmsClient(mClientCallback1); 2190 int providerId = client.registerProvider(PROVIDER_DESC1); 2191 client.setProviderOfferings(providerId, asSet( 2192 new VmsLayerDependency(LAYER1) 2193 )); 2194 connectVmsClient(mClientCallback2); 2195 2196 client.setMonitoringEnabled(true); 2197 client.publishPacket(providerId, LAYER1, PAYLOAD); 2198 2199 awaitTaskCompletion(); 2200 verifyPacketReceived(mClientCallback1, providerId, LAYER1, PAYLOAD); 2201 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2202 } 2203 2204 @Test testPublishPacket_MonitorSubscriber_EnabledAndDisabled()2205 public void testPublishPacket_MonitorSubscriber_EnabledAndDisabled() { 2206 VmsClient client = connectVmsClient(mClientCallback1); 2207 int providerId = client.registerProvider(PROVIDER_DESC1); 2208 client.setProviderOfferings(providerId, asSet( 2209 new VmsLayerDependency(LAYER1) 2210 )); 2211 connectVmsClient(mClientCallback2); 2212 2213 client.setMonitoringEnabled(true); 2214 client.setMonitoringEnabled(false); 2215 client.publishPacket(providerId, LAYER1, PAYLOAD); 2216 2217 awaitTaskCompletion(); 2218 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2219 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2220 } 2221 2222 @Test testPublishPacket_LayerSubscriber()2223 public void testPublishPacket_LayerSubscriber() { 2224 VmsClient client = connectVmsClient(mClientCallback1); 2225 int providerId = client.registerProvider(PROVIDER_DESC1); 2226 client.setProviderOfferings(providerId, asSet( 2227 new VmsLayerDependency(LAYER1) 2228 )); 2229 connectVmsClient(mClientCallback2); 2230 2231 client.setSubscriptions(asSet( 2232 new VmsAssociatedLayer(LAYER1, emptySet()) 2233 )); 2234 client.publishPacket(providerId, LAYER1, PAYLOAD); 2235 2236 awaitTaskCompletion(); 2237 verifyPacketReceived(mClientCallback1, providerId, LAYER1, PAYLOAD); 2238 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2239 } 2240 2241 @Test testPublishPacket_LayerSubscriber_Unsubscribe()2242 public void testPublishPacket_LayerSubscriber_Unsubscribe() { 2243 VmsClient client = connectVmsClient(mClientCallback1); 2244 int providerId = client.registerProvider(PROVIDER_DESC1); 2245 client.setProviderOfferings(providerId, asSet( 2246 new VmsLayerDependency(LAYER1) 2247 )); 2248 connectVmsClient(mClientCallback2); 2249 2250 client.setSubscriptions(asSet( 2251 new VmsAssociatedLayer(LAYER1, emptySet()) 2252 )); 2253 client.setSubscriptions(emptySet()); 2254 client.publishPacket(providerId, LAYER1, PAYLOAD); 2255 2256 awaitTaskCompletion(); 2257 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2258 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2259 } 2260 2261 @Test testPublishPacket_LayerSubscriber_DifferentLayer()2262 public void testPublishPacket_LayerSubscriber_DifferentLayer() { 2263 VmsClient client = connectVmsClient(mClientCallback1); 2264 int providerId = client.registerProvider(PROVIDER_DESC1); 2265 client.setProviderOfferings(providerId, asSet( 2266 new VmsLayerDependency(LAYER1) 2267 )); 2268 connectVmsClient(mClientCallback2); 2269 2270 client.setSubscriptions(asSet( 2271 new VmsAssociatedLayer(LAYER2, emptySet()) 2272 )); 2273 client.publishPacket(providerId, LAYER1, PAYLOAD); 2274 2275 awaitTaskCompletion(); 2276 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2277 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2278 } 2279 2280 @Test testPublishPacket_MultipleLayerSubscribers()2281 public void testPublishPacket_MultipleLayerSubscribers() { 2282 VmsClient client = connectVmsClient(mClientCallback1); 2283 int providerId = client.registerProvider(PROVIDER_DESC1); 2284 client.setProviderOfferings(providerId, asSet( 2285 new VmsLayerDependency(LAYER1) 2286 )); 2287 VmsClient client2 = connectVmsClient(mClientCallback2); 2288 2289 client.setSubscriptions(asSet( 2290 new VmsAssociatedLayer(LAYER1, emptySet()) 2291 )); 2292 client2.setSubscriptions(asSet( 2293 new VmsAssociatedLayer(LAYER1, emptySet()) 2294 )); 2295 client.publishPacket(providerId, LAYER1, PAYLOAD); 2296 2297 awaitTaskCompletion(); 2298 verifyPacketReceived(mClientCallback1, providerId, LAYER1, PAYLOAD); 2299 verifyPacketReceived(mClientCallback2, providerId, LAYER1, PAYLOAD); 2300 } 2301 2302 @Test testPublishPacket_LayerAndProviderSubscriber()2303 public void testPublishPacket_LayerAndProviderSubscriber() { 2304 VmsClient client = connectVmsClient(mClientCallback1); 2305 int providerId = client.registerProvider(PROVIDER_DESC1); 2306 client.setProviderOfferings(providerId, asSet( 2307 new VmsLayerDependency(LAYER1) 2308 )); 2309 connectVmsClient(mClientCallback2); 2310 2311 client.setSubscriptions(asSet( 2312 new VmsAssociatedLayer(LAYER1, asSet(providerId)) 2313 )); 2314 client.publishPacket(providerId, LAYER1, PAYLOAD); 2315 2316 awaitTaskCompletion(); 2317 verifyPacketReceived(mClientCallback1, providerId, LAYER1, PAYLOAD); 2318 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2319 } 2320 2321 @Test testPublishPacket_LayerAndProviderSubscriber_Unsubscribe()2322 public void testPublishPacket_LayerAndProviderSubscriber_Unsubscribe() { 2323 VmsClient client = connectVmsClient(mClientCallback1); 2324 int providerId = client.registerProvider(PROVIDER_DESC1); 2325 client.setProviderOfferings(providerId, asSet( 2326 new VmsLayerDependency(LAYER1) 2327 )); 2328 connectVmsClient(mClientCallback2); 2329 2330 client.setSubscriptions(asSet( 2331 new VmsAssociatedLayer(LAYER1, asSet(providerId)) 2332 )); 2333 client.setSubscriptions(emptySet()); 2334 client.publishPacket(providerId, LAYER1, PAYLOAD); 2335 2336 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2337 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2338 } 2339 2340 @Test testPublishPacket_LayerAndProviderSubscriber_DifferentProvider()2341 public void testPublishPacket_LayerAndProviderSubscriber_DifferentProvider() { 2342 VmsClient client = connectVmsClient(mClientCallback1); 2343 int providerId = client.registerProvider(PROVIDER_DESC1); 2344 int providerId2 = client.registerProvider(PROVIDER_DESC2); 2345 client.setProviderOfferings(providerId, asSet( 2346 new VmsLayerDependency(LAYER1) 2347 )); 2348 connectVmsClient(mClientCallback2); 2349 2350 client.setSubscriptions(asSet( 2351 new VmsAssociatedLayer(LAYER1, asSet(providerId2)) 2352 )); 2353 client.publishPacket(providerId, LAYER1, PAYLOAD); 2354 2355 awaitTaskCompletion(); 2356 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2357 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2358 } 2359 2360 @Test testPublishPacket_MultipleLayerAndProviderSubscribers()2361 public void testPublishPacket_MultipleLayerAndProviderSubscribers() { 2362 VmsClient client = connectVmsClient(mClientCallback1); 2363 int providerId = client.registerProvider(PROVIDER_DESC1); 2364 client.setProviderOfferings(providerId, asSet( 2365 new VmsLayerDependency(LAYER1) 2366 )); 2367 VmsClient client2 = connectVmsClient(mClientCallback2); 2368 2369 client.setSubscriptions(asSet( 2370 new VmsAssociatedLayer(LAYER1, asSet(providerId)) 2371 )); 2372 client2.setSubscriptions(asSet( 2373 new VmsAssociatedLayer(LAYER1, asSet(providerId)) 2374 )); 2375 client.publishPacket(providerId, LAYER1, PAYLOAD); 2376 2377 awaitTaskCompletion(); 2378 verifyPacketReceived(mClientCallback1, providerId, LAYER1, PAYLOAD); 2379 verifyPacketReceived(mClientCallback2, providerId, LAYER1, PAYLOAD); 2380 } 2381 2382 @Test testPublishPacket_Large_UnknownOffering()2383 public void testPublishPacket_Large_UnknownOffering() { 2384 VmsClient client = connectVmsClient(mClientCallback1); 2385 int providerId = client.registerProvider(PROVIDER_DESC1); 2386 2387 assertThrows( 2388 IllegalArgumentException.class, 2389 () -> client.publishPacket(providerId, LAYER1, LARGE_PAYLOAD)); 2390 } 2391 2392 @Test testPublishPacket_Large_NoSubscribers()2393 public void testPublishPacket_Large_NoSubscribers() { 2394 VmsClient client = connectVmsClient(mClientCallback1); 2395 int providerId = client.registerProvider(PROVIDER_DESC1); 2396 client.setProviderOfferings(providerId, asSet( 2397 new VmsLayerDependency(LAYER1) 2398 )); 2399 connectVmsClient(mClientCallback2); 2400 2401 client.publishPacket(providerId, LAYER1, LARGE_PAYLOAD); 2402 2403 awaitTaskCompletion(); 2404 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2405 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2406 } 2407 2408 @Test testPublishPacket_Large_MonitorSubscriber_Enabled()2409 public void testPublishPacket_Large_MonitorSubscriber_Enabled() { 2410 VmsClient client = connectVmsClient(mClientCallback1); 2411 int providerId = client.registerProvider(PROVIDER_DESC1); 2412 client.setProviderOfferings(providerId, asSet( 2413 new VmsLayerDependency(LAYER1) 2414 )); 2415 connectVmsClient(mClientCallback2); 2416 2417 client.setMonitoringEnabled(true); 2418 client.publishPacket(providerId, LAYER1, LARGE_PAYLOAD); 2419 2420 awaitTaskCompletion(); 2421 verifyPacketReceived(mClientCallback1, providerId, LAYER1, LARGE_PAYLOAD); 2422 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2423 } 2424 2425 @Test testPublishPacket_Large_MonitorSubscriber_EnabledAndDisabled()2426 public void testPublishPacket_Large_MonitorSubscriber_EnabledAndDisabled() { 2427 VmsClient client = connectVmsClient(mClientCallback1); 2428 int providerId = client.registerProvider(PROVIDER_DESC1); 2429 client.setProviderOfferings(providerId, asSet( 2430 new VmsLayerDependency(LAYER1) 2431 )); 2432 connectVmsClient(mClientCallback2); 2433 2434 client.setMonitoringEnabled(true); 2435 client.setMonitoringEnabled(false); 2436 client.publishPacket(providerId, LAYER1, LARGE_PAYLOAD); 2437 2438 awaitTaskCompletion(); 2439 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2440 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2441 } 2442 2443 @Test testPublishPacket_Large_LayerSubscriber()2444 public void testPublishPacket_Large_LayerSubscriber() { 2445 VmsClient client = connectVmsClient(mClientCallback1); 2446 int providerId = client.registerProvider(PROVIDER_DESC1); 2447 client.setProviderOfferings(providerId, asSet( 2448 new VmsLayerDependency(LAYER1) 2449 )); 2450 connectVmsClient(mClientCallback2); 2451 2452 client.setSubscriptions(asSet( 2453 new VmsAssociatedLayer(LAYER1, emptySet()) 2454 )); 2455 client.publishPacket(providerId, LAYER1, LARGE_PAYLOAD); 2456 2457 awaitTaskCompletion(); 2458 verifyPacketReceived(mClientCallback1, providerId, LAYER1, LARGE_PAYLOAD); 2459 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2460 } 2461 2462 @Test testPublishPacket_Large_LayerSubscriber_Unsubscribe()2463 public void testPublishPacket_Large_LayerSubscriber_Unsubscribe() { 2464 VmsClient client = connectVmsClient(mClientCallback1); 2465 int providerId = client.registerProvider(PROVIDER_DESC1); 2466 client.setProviderOfferings(providerId, asSet( 2467 new VmsLayerDependency(LAYER1) 2468 )); 2469 connectVmsClient(mClientCallback2); 2470 2471 client.setSubscriptions(asSet( 2472 new VmsAssociatedLayer(LAYER1, emptySet()) 2473 )); 2474 client.setSubscriptions(emptySet()); 2475 client.publishPacket(providerId, LAYER1, LARGE_PAYLOAD); 2476 2477 awaitTaskCompletion(); 2478 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2479 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2480 } 2481 2482 @Test testPublishPacket_Large_LayerSubscriber_DifferentLayer()2483 public void testPublishPacket_Large_LayerSubscriber_DifferentLayer() { 2484 VmsClient client = connectVmsClient(mClientCallback1); 2485 int providerId = client.registerProvider(PROVIDER_DESC1); 2486 client.setProviderOfferings(providerId, asSet( 2487 new VmsLayerDependency(LAYER1) 2488 )); 2489 connectVmsClient(mClientCallback2); 2490 2491 client.setSubscriptions(asSet( 2492 new VmsAssociatedLayer(LAYER2, emptySet()) 2493 )); 2494 client.publishPacket(providerId, LAYER1, LARGE_PAYLOAD); 2495 2496 awaitTaskCompletion(); 2497 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2498 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2499 } 2500 2501 @Test testPublishPacket_Large_LayerAndProviderSubscriber()2502 public void testPublishPacket_Large_LayerAndProviderSubscriber() { 2503 VmsClient client = connectVmsClient(mClientCallback1); 2504 int providerId = client.registerProvider(PROVIDER_DESC1); 2505 client.setProviderOfferings(providerId, asSet( 2506 new VmsLayerDependency(LAYER1) 2507 )); 2508 connectVmsClient(mClientCallback2); 2509 2510 client.setSubscriptions(asSet( 2511 new VmsAssociatedLayer(LAYER1, asSet(providerId)) 2512 )); 2513 client.publishPacket(providerId, LAYER1, LARGE_PAYLOAD); 2514 2515 awaitTaskCompletion(); 2516 verifyPacketReceived(mClientCallback1, providerId, LAYER1, LARGE_PAYLOAD); 2517 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2518 } 2519 2520 @Test testPublishPacket_Large_LayerAndProviderSubscriber_Unsubscribe()2521 public void testPublishPacket_Large_LayerAndProviderSubscriber_Unsubscribe() { 2522 VmsClient client = connectVmsClient(mClientCallback1); 2523 int providerId = client.registerProvider(PROVIDER_DESC1); 2524 client.setProviderOfferings(providerId, asSet( 2525 new VmsLayerDependency(LAYER1) 2526 )); 2527 connectVmsClient(mClientCallback2); 2528 2529 client.setSubscriptions(asSet( 2530 new VmsAssociatedLayer(LAYER1, asSet(providerId)) 2531 )); 2532 client.setSubscriptions(emptySet()); 2533 client.publishPacket(providerId, LAYER1, LARGE_PAYLOAD); 2534 2535 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2536 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2537 } 2538 2539 @Test testPublishPacket_Large_LayerAndProviderSubscriber_DifferentProvider()2540 public void testPublishPacket_Large_LayerAndProviderSubscriber_DifferentProvider() { 2541 VmsClient client = connectVmsClient(mClientCallback1); 2542 int providerId = client.registerProvider(PROVIDER_DESC1); 2543 int providerId2 = client.registerProvider(PROVIDER_DESC2); 2544 client.setProviderOfferings(providerId, asSet( 2545 new VmsLayerDependency(LAYER1) 2546 )); 2547 connectVmsClient(mClientCallback2); 2548 2549 client.setSubscriptions(asSet( 2550 new VmsAssociatedLayer(LAYER1, asSet(providerId2)) 2551 )); 2552 client.publishPacket(providerId, LAYER1, LARGE_PAYLOAD); 2553 2554 awaitTaskCompletion(); 2555 verifyNoPacketsReceived(mClientCallback1, providerId, LAYER1); 2556 verifyNoPacketsReceived(mClientCallback2, providerId, LAYER1); 2557 } 2558 connectVmsClient(VmsClientCallback callback)2559 private VmsClient connectVmsClient(VmsClientCallback callback) { 2560 mClientManager.registerVmsClientCallback(mExecutor, callback); 2561 verify(callback, timeout(CONNECT_TIMEOUT)).onClientConnected(mClientCaptor.capture()); 2562 return mClientCaptor.getValue(); 2563 } 2564 awaitTaskCompletion()2565 private void awaitTaskCompletion() { 2566 mExecutor.shutdown(); 2567 try { 2568 mExecutor.awaitTermination(2L, TimeUnit.SECONDS); 2569 } catch (InterruptedException e) { 2570 throw new AssertionError("Executor termination interrupted", e); 2571 } 2572 } 2573 verifyLayerAvailability( VmsClientCallback callback, VmsAvailableLayers availableLayers)2574 private static void verifyLayerAvailability( 2575 VmsClientCallback callback, 2576 VmsAvailableLayers availableLayers) { 2577 ArgumentCaptor<VmsAvailableLayers> availableLayersCaptor = 2578 ArgumentCaptor.forClass(VmsAvailableLayers.class); 2579 verify(callback, times(availableLayers.getSequenceNumber() + 1)) 2580 .onLayerAvailabilityChanged(availableLayersCaptor.capture()); 2581 assertThat(availableLayersCaptor.getValue()).isEqualTo(availableLayers); 2582 } 2583 verifySubscriptionState( VmsClientCallback callback, VmsSubscriptionState subscriptionState)2584 private static void verifySubscriptionState( 2585 VmsClientCallback callback, 2586 VmsSubscriptionState subscriptionState) { 2587 ArgumentCaptor<VmsSubscriptionState> subscriptionStateCaptor = 2588 ArgumentCaptor.forClass(VmsSubscriptionState.class); 2589 verify(callback, times(subscriptionState.getSequenceNumber() + 1)) 2590 .onSubscriptionStateChanged(subscriptionStateCaptor.capture()); 2591 assertThat(subscriptionStateCaptor.getValue()).isEqualTo(subscriptionState); 2592 } 2593 verifyNoPacketsReceived( VmsClientCallback callback, int providerId, VmsLayer layer)2594 private static void verifyNoPacketsReceived( 2595 VmsClientCallback callback, 2596 int providerId, VmsLayer layer) { 2597 verify(callback, never()).onPacketReceived(eq(providerId), eq(layer), any()); 2598 } 2599 verifyPacketReceived( VmsClientCallback callback, int providerId, VmsLayer layer, byte[] payload)2600 private static void verifyPacketReceived( 2601 VmsClientCallback callback, 2602 int providerId, VmsLayer layer, byte[] payload) { 2603 verify(callback).onPacketReceived(providerId, layer, payload); 2604 } 2605 asSet(T... values)2606 private static <T> Set<T> asSet(T... values) { 2607 return new HashSet<T>(Arrays.asList(values)); 2608 } 2609 } 2610