BGPCEP-754: PeerTracker Impl
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / BGPDispatcherImplTest.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.protocol.bgp.rib.impl;
9
10
11 import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.checkIdleState;
12 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
13
14 import com.google.common.collect.Sets;
15 import io.netty.channel.Channel;
16 import io.netty.util.concurrent.Future;
17 import java.net.InetSocketAddress;
18 import java.util.concurrent.ExecutionException;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.opendaylight.protocol.bgp.rib.spi.State;
22 import org.opendaylight.protocol.concepts.KeyMapping;
23 import org.opendaylight.protocol.util.InetSocketAddressUtil;
24
25 public class BGPDispatcherImplTest extends AbstractBGPDispatcherTest {
26     @Test
27     public void testCreateClient() throws InterruptedException, ExecutionException {
28         final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
29         final Channel serverChannel = createServer(serverAddress);
30         final Future<BGPSessionImpl> futureClient = this.clientDispatcher.createClient(this.clientAddress,
31             serverAddress, 2, true);
32         waitFutureSuccess(futureClient);
33         final BGPSessionImpl session = futureClient.get();
34         Assert.assertEquals(State.UP, this.clientListener.getState());
35         Assert.assertEquals(State.UP, this.serverListener.getState());
36         Assert.assertEquals(AS_NUMBER, session.getAsNumber());
37         Assert.assertEquals(Sets.newHashSet(IPV_4_TT), session.getAdvertisedTableTypes());
38         Assert.assertTrue(serverChannel.isWritable());
39         session.close();
40         this.serverListener.releaseConnection();
41         checkIdleState(this.clientListener);
42         checkIdleState(this.serverListener);
43     }
44
45     @Test
46     public void testCreateReconnectingClient() throws Exception {
47         final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
48         final Future<Void> future = this.clientDispatcher.createReconnectingClient(serverAddress, RETRY_TIMER,
49             KeyMapping.getKeyMapping(), this.clientAddress, true);
50         final Channel serverChannel = createServer(serverAddress);
51         Assert.assertEquals(State.UP, this.serverListener.getState());
52         Assert.assertTrue(serverChannel.isWritable());
53         future.cancel(true);
54         this.serverListener.releaseConnection();
55         checkIdleState(this.serverListener);
56     }
57
58 }