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