2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.rib.spi.util;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.MockitoAnnotations.initMocks;
15 import static org.opendaylight.protocol.bgp.rib.spi.util.ClusterSingletonServiceRegistrationHelper.registerSingletonService;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
22 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
23 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
25 public class ClusterSingletonServiceRegistrationHelperTest {
28 private ClusterSingletonService clusterSingletonService;
30 private ClusterSingletonServiceProvider singletonProvider;
32 private ClusterSingletonServiceRegistration serviceRegistration;
37 doReturn(null).when(this.singletonProvider).registerClusterSingletonService(any());
38 Mockito.when(this.singletonProvider.registerClusterSingletonService(any()))
39 .thenThrow(new RuntimeException())
40 .thenReturn(this.serviceRegistration);
43 @Test(expected = RuntimeException.class)
44 public void testRegisterSingletonServiceFailure() {
45 registerSingletonService(this.singletonProvider, this.clusterSingletonService, 0, 1);
49 public void testRegisterSingletonServiceSuccessfulRetry() {
50 final ClusterSingletonServiceRegistration registerSingletonService =
51 registerSingletonService(this.singletonProvider, this.clusterSingletonService, 1, 1);
52 assertEquals(this.serviceRegistration, registerSingletonService);
53 //first reg. attempt failed, second succeeded
54 verify(this.singletonProvider, Mockito.times(2)).registerClusterSingletonService(any());