Replace UnsignedInt32Counter by LongAdder
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / stats / rib / impl / BGPRenderStatsImplTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl;
10
11 import static org.junit.Assert.assertEquals;
12
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.concurrent.atomic.LongAdder;
16 import org.junit.Test;
17 import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpRenderState;
18 import org.opendaylight.controller.config.yang.bgp.rib.impl.LocRibRouteTable;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.ZeroBasedCounter32;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
27
28 public class BGPRenderStatsImplTest {
29     private final static BgpId BGP_ID = new BgpId("127.0.0.1");
30     private static final RibId RIB_ID = new RibId("test-rib");
31     private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier("192.168.1.2");
32     private static final AsNumber AS = new AsNumber(0x10L);
33     private static final ZeroBasedCounter32 COUTER = new ZeroBasedCounter32(0L);
34
35     @Test
36     public void getBgpRenderState() throws Exception {
37         final BGPRenderStatsImpl render = new BGPRenderStatsImpl(BGP_ID, RIB_ID, AS, CLUSTER_ID);
38
39         final BgpRenderState renderStateExpected = new BgpRenderState();
40         renderStateExpected.setRibId(RIB_ID);
41         renderStateExpected.setBgpRibId(BGP_ID);
42         renderStateExpected.setClusterId(CLUSTER_ID);
43         renderStateExpected.setLocalAs(AS);
44         renderStateExpected.setConfiguredPeerCount(COUTER);
45         renderStateExpected.setConnectedPeerCount(COUTER);
46         final List<LocRibRouteTable> locRibRouteTableList = new ArrayList<>();
47         renderStateExpected.setLocRibRouteTable(locRibRouteTableList);
48         renderStateExpected.setLocRibRoutesCount(COUTER);
49
50         assertEquals(renderStateExpected, render.getBgpRenderState());
51         LongAdder counter = render.getLocRibRouteCounter().init(new TablesKey(Ipv4AddressFamily.class,
52             UnicastSubsequentAddressFamily.class));
53         counter.increment();
54         assertEquals(1L, counter.longValue());
55         counter = render.getConfiguredPeerCounter();
56         counter.increment();
57         assertEquals(1L, counter.longValue());
58         counter = render.getConnectedPeerCounter();
59         counter.increment();
60         assertEquals(1L, counter.longValue());
61     }
62 }