BUG-6844: Wire BGP server with blueprint
[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 import com.google.common.base.Optional;
11 import com.google.common.collect.Sets;
12 import io.netty.channel.Channel;
13 import io.netty.util.concurrent.Future;
14 import java.net.InetSocketAddress;
15 import java.util.concurrent.ExecutionException;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.protocol.util.InetSocketAddressUtil;
19
20 public class BGPDispatcherImplTest extends AbstractBGPDispatcherTest {
21     @Test
22     public void testCreateClient() throws InterruptedException, ExecutionException {
23         final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
24         final Channel serverChannel = createServer(serverAddress);
25         Thread.sleep(1000);
26         final Future<BGPSessionImpl> futureClient = this.clientDispatcher.createClient(serverAddress, this.registry, 2, Optional.absent());
27         waitFutureSuccess(futureClient);
28         final BGPSessionImpl session = futureClient.get();
29         Assert.assertEquals(BGPSessionImpl.State.UP, this.clientListener.getState());
30         Assert.assertEquals(BGPSessionImpl.State.UP, this.serverListener.getState());
31         Assert.assertEquals(AS_NUMBER, session.getAsNumber());
32         Assert.assertEquals(Sets.newHashSet(IPV_4_TT), session.getAdvertisedTableTypes());
33         Assert.assertTrue(serverChannel.isWritable());
34         session.close();
35         this.serverListener.releaseConnection();
36         checkIdleState(this.clientListener);
37         checkIdleState(this.serverListener);
38     }
39
40     @Test
41     public void testCreateReconnectingClient() throws Exception {
42         final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
43         final Future<Void> future = this.clientDispatcher.createReconnectingClient(serverAddress, this.registry, RETRY_TIMER, Optional.absent());
44         waitFutureSuccess(future);
45         final Channel serverChannel = createServer(serverAddress);
46         Assert.assertEquals(BGPSessionImpl.State.UP, this.serverListener.getState());
47         Assert.assertTrue(serverChannel.isWritable());
48         future.cancel(true);
49         this.serverListener.releaseConnection();
50         checkIdleState(this.serverListener);
51     }
52
53 }