BUG-7006: Unit-tests sometimes hangs during execution
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / AbstractBGPDispatcherTest.java
index 570c74467b8f95c72793eb933d9ecb9e51065832..8f3eb0c5d2db0fe1d35b3b80afe11f2238e16d1b 100644 (file)
@@ -56,11 +56,12 @@ public class AbstractBGPDispatcherTest {
     protected static final int RETRY_TIMER = 1;
     protected static final BgpTableType IPV_4_TT = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
     private static final short HOLD_TIMER = 30;
-    protected TestClientDispatcher clientDispatcher;
+    protected BGPDispatcherImpl clientDispatcher;
     protected BGPPeerRegistry registry;
     protected SimpleSessionListener clientListener;
     protected BGPDispatcherImpl serverDispatcher;
     protected SimpleSessionListener serverListener;
+    protected InetSocketAddress clientAddress;
     private EventLoopGroup boss;
     private EventLoopGroup worker;
 
@@ -75,7 +76,11 @@ public class AbstractBGPDispatcherTest {
         this.serverListener = new SimpleSessionListener();
         final BGPExtensionProviderContext ctx = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
         this.serverDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
-        configureClient(ctx);
+
+        this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
+        final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(clientAddress.getAddress().getHostAddress()));
+        this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(clientAddress));
+        this.clientDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
     }
 
     @After
@@ -92,7 +97,11 @@ public class AbstractBGPDispatcherTest {
         final InetSocketAddress clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(clientAddress.getAddress().getHostAddress()));
         this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(clientAddress));
-        this.clientDispatcher = new TestClientDispatcher(this.boss, this.worker, ctx.getMessageRegistry(), clientAddress);
+        this.clientDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
+        if (!Epoll.isAvailable()) {
+            this.worker.shutdownGracefully().awaitUninterruptibly();
+            this.boss.shutdownGracefully().awaitUninterruptibly();
+        }
     }
 
     protected BGPSessionPreferences createPreferences(final InetSocketAddress socketAddress) {