Cleanup client dispatchers 47/78847/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 17 Dec 2018 19:29:49 +0000 (20:29 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 18 Dec 2018 09:36:24 +0000 (09:36 +0000)
In presence of Epoll support, each BGPDispatcherImpl is a heavy-weight
resource, which must be properly cleaned up.

Register all created dispatchers and tear them down when the test
finishes.

Change-Id: I3df7e72039a38f6f159e5a5cecf376d85529627a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java

index 296b274afbb754fcc0bb153af231ccac13a6f869..11d33409cad8e96d160940f92521aa8959b48c29 100644 (file)
@@ -18,6 +18,7 @@ import io.netty.channel.epoll.Epoll;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.concurrent.Future;
 import java.net.InetSocketAddress;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -133,6 +134,8 @@ public abstract class AbstractAddPathTest extends DefaultRibPoliciesMockTest {
     protected StrictBGPPeerRegistry serverRegistry;
     protected CodecsRegistryImpl codecsRegistry;
 
+    private List<BGPDispatcherImpl> clientDispatchers;
+
     @Override
     @Before
     public void setUp() throws Exception {
@@ -159,6 +162,7 @@ public abstract class AbstractAddPathTest extends DefaultRibPoliciesMockTest {
 
         this.codecsRegistry = CodecsRegistryImpl.create(this.mappingService.getCodecFactory(),
                 this.ribExtension.getClassLoadingStrategy());
+        this.clientDispatchers = new ArrayList<>();
     }
 
     @Override
@@ -173,6 +177,8 @@ public abstract class AbstractAddPathTest extends DefaultRibPoliciesMockTest {
         this.ribActivator.close();
         this.inetActivator.close();
         this.bgpActivator.close();
+        this.clientDispatchers.forEach(BGPDispatcherImpl::close);
+        this.clientDispatchers = null;
         super.tearDown();
     }
 
@@ -242,6 +248,8 @@ public abstract class AbstractAddPathTest extends DefaultRibPoliciesMockTest {
         final StrictBGPPeerRegistry clientRegistry = new StrictBGPPeerRegistry();
         final BGPDispatcherImpl clientDispatcher = new BGPDispatcherImpl(this.context.getMessageRegistry(), this.boss,
                 this.worker, clientRegistry);
+
+        clientDispatchers.add(clientDispatcher);
         clientRegistry.addPeer(new IpAddress(new Ipv4Address(RIB_ID)), sessionListener,
                 new BGPSessionPreferences(remoteAsNumber, HOLDTIMER, new BgpId(peer),
                         AS_NUMBER, Lists.newArrayList(bgpParameters)));