\BUG-7386 Remove blocking gracefulshutdown 26/51126/2
authorClaudio D. Gasparini <cgaspari@cisco.com>
Tue, 17 Jan 2017 10:59:21 +0000 (11:59 +0100)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Fri, 27 Jan 2017 14:49:59 +0000 (15:49 +0100)
Remove blocking gracefulshutdown for EventLoopGroup

Change-Id: I03fd04cd77d613ce4b8c83f1f48deb3142227bfb
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
bgp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/BmpDispatcherImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AdjRibInWriter.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImpl.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPDispatcherTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathAllPathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathBasePathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathNPathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/CheckUtil.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCDispatcherImplTest.java

index 0bd7036001bcffccc9a75f5a806fde77c75ddede..4fa2b04d5f5cd0696cbc88ab00f851f27f863ccf 100644 (file)
@@ -47,6 +47,7 @@ public class BmpDispatcherImpl implements BmpDispatcher {
     private static final int CONNECT_TIMEOUT = 5000;
     private static final int INITIAL_BACKOFF = 30_000;
     private static final int MAXIMUM_BACKOFF = 720_000;
+    private static final long TIMEOUT = 10;
 
     private final BmpHandlerFactory hf;
     private final EventLoopGroup bossGroup;
@@ -143,8 +144,8 @@ public class BmpDispatcherImpl implements BmpDispatcher {
     @Override
     public void close() {
         if (Epoll.isAvailable()) {
-            this.workerGroup.shutdownGracefully().awaitUninterruptibly();
-            this.bossGroup.shutdownGracefully().awaitUninterruptibly();
+            this.workerGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);
+            this.bossGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);
         }
     }
 
@@ -175,7 +176,7 @@ public class BmpDispatcherImpl implements BmpDispatcher {
                     return;
                 }
                 final EventLoop loop = cf.channel().eventLoop();
-                loop.schedule(() -> BootstrapListener.this.bootstrap.connect().addListener(BootstrapListener.this), this.delay, TimeUnit.MILLISECONDS);
+                loop.schedule(() -> this.bootstrap.connect().addListener(this), this.delay, TimeUnit.MILLISECONDS);
                 LOG.info("The connection try to BMP router {} failed. Next reconnection attempt in {} milliseconds.", this.address, this.delay);
                 this.delay *= 2;
             }
index e9a92b71a369032aaeaf8a81f8bbad2e6879fa79..6e6dee5e6e87f1d56eadff6d7c90bb26e1b607ac 100644 (file)
@@ -153,7 +153,12 @@ final class AdjRibInWriter {
 
             @Override
             public void onFailure(final Throwable throwable) {
-                LOG.error("Failed to register Application Peer Listener", throwable);
+                if(registerAppPeerListener != null) {
+                    LOG.error("Failed to create Empty Structure, Application Peer Listener won't be registered",
+                        throwable);
+                } else {
+                    LOG.error("Failed to create Empty Structure", throwable);
+                }
             }
         });
         return new AdjRibInWriter(this.ribPath, this.chain, this.role, this.simpleRoutingPolicy, newPeerPath, tb);
index d375bc0cdb69f5155dbfd44c42084a87c79290b3..5160d566b496ac3836ba4a0951f5f06ecd5a118f 100644 (file)
@@ -32,6 +32,7 @@ import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
 import java.net.InetSocketAddress;
+import java.util.concurrent.TimeUnit;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.protocol.BGPProtocolSessionPromise;
 import org.opendaylight.protocol.bgp.rib.impl.protocol.BGPReconnectPromise;
@@ -52,6 +53,7 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
     private static final int SOCKET_BACKLOG_SIZE = 128;
     private static final int HIGH_WATER_MARK = 256 * 1024;
     private static final int LOW_WATER_MARK = 128 * 1024;
+    private static final long TIMEOUT = 10;
 
     private final BGPHandlerFactory handlerFactory;
     private final EventLoopGroup bossGroup;
@@ -76,7 +78,7 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
     private synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry listener, final int retryTimer,
             final Bootstrap clientBootStrap) {
         final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(listener);
-        final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf);
+        final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(this.handlerFactory, snf);
 
         final BGPProtocolSessionPromise sessionPromise = new BGPProtocolSessionPromise(remoteAddress, retryTimer, clientBootStrap, listener);
         clientBootStrap.handler(BGPChannel.createClientChannelHandler(initializer, sessionPromise));
@@ -124,10 +126,11 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
     }
 
     @Override
-    public synchronized void close() {
+    public synchronized void close() throws InterruptedException {
         if (Epoll.isAvailable()) {
-            this.workerGroup.shutdownGracefully().awaitUninterruptibly();
-            this.bossGroup.shutdownGracefully().awaitUninterruptibly();
+            LOG.debug("Closing Dispatcher");
+            this.workerGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);
+            this.bossGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);
         }
     }
 
@@ -144,7 +147,7 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
         final Bootstrap bootstrap = createClientBootStrap(keys, reuseAddress);
         bootstrap.localAddress(localAddress);
         final BGPReconnectPromise reconnectPromise = new BGPReconnectPromise(GlobalEventExecutor.INSTANCE, remoteAddress,
-            retryTimer, bootstrap, peerRegistry, BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf));
+            retryTimer, bootstrap, peerRegistry, BGPChannel.createChannelPipelineInitializer(this.handlerFactory, snf));
         reconnectPromise.connect();
         return reconnectPromise;
     }
@@ -152,7 +155,7 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
     @Override
     public synchronized ChannelFuture createServer(final BGPPeerRegistry registry, final InetSocketAddress serverAddress) {
         final BGPServerSessionNegotiatorFactory snf = new BGPServerSessionNegotiatorFactory(registry);
-        final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf);
+        final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(this.handlerFactory, snf);
         final ServerBootstrap serverBootstrap = createServerBootstrap(initializer);
         final ChannelFuture channelFuture = serverBootstrap.bind(serverAddress);
         LOG.debug("Initiated server {} at {}.", channelFuture, serverAddress);
index e6267226fb3e8e09b900ea18050dae8c9d8eee91..241f6c5428d589206b4b9233e537fe54a4388770 100644 (file)
@@ -13,6 +13,7 @@ import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.readData;
 import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.waitFutureSuccess;
 
 import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.net.InetAddresses;
 import io.netty.channel.epoll.Epoll;
@@ -23,6 +24,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import javassist.ClassPool;
 import org.junit.After;
 import org.junit.Assert;
@@ -37,6 +39,7 @@ import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvid
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.protocol.bgp.inet.RIBActivator;
 import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.parser.impl.BGPActivator;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
@@ -77,6 +80,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.WithdrawnRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.SendReceive;
@@ -130,12 +134,14 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
     static final Update UPD_200 = createSimpleUpdate(PREFIX1, new PathId(3L), CLUSTER_ID, 200);
     static final Update UPD_20 = createSimpleUpdate(PREFIX1, new PathId(1L), CLUSTER_ID, 20);
     static final Update UPD_NA_100 = createSimpleUpdate(PREFIX1, null, CLUSTER_ID, 100);
-    static final Update UPD_NA_100_EBGP = createSimpleUpdateEbgp(PREFIX1, null);
+    static final Update UPD_NA_100_EBGP = createSimpleUpdateEbgp(PREFIX1);
     static final Update UPD_NA_200 = createSimpleUpdate(PREFIX1, null, CLUSTER_ID, 200);
-    static final Update UPD_NA_200_EBGP = createSimpleUpdateEbgp(PREFIX1, null);
+    static final Update UPD_NA_200_EBGP = createSimpleUpdateEbgp(PREFIX1);
     static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+    static final List<BgpTableType> TABLES_TYPE = ImmutableList.of(new BgpTableTypeImpl(TABLES_KEY.getAfi(),
+        TABLES_KEY.getSafi()));
     static final Set<TablesKey> AFI_SAFIS_ADVERTIZED = Collections.singleton(TABLES_KEY);
-    protected BGPExtensionProviderContext context;
+    private BGPExtensionProviderContext context;
     private static final InstanceIdentifier<BgpRib> BGP_IID = InstanceIdentifier.create(BgpRib.class);
     protected SchemaContext schemaContext;
     @Mock
@@ -163,8 +169,10 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
         this.bgpActivator.start(this.context);
         this.inetActivator.start(this.context);
 
-        this.mappingService = new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(),
-            new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()))));
+        this.mappingService = new BindingToNormalizedNodeCodec(
+            GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(),
+            new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(
+                JavassistUtils.forClassPool(ClassPool.getDefault()))));
         final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
         moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(BgpParameters.class));
         moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(MultiprotocolCapability.class));
@@ -185,11 +193,11 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
     }
 
     @After
-    public void tearDown() {
+    public void tearDown() throws ExecutionException, InterruptedException {
         this.dispatcher.close();
         if (!Epoll.isAvailable()) {
-            this.worker.shutdownGracefully().awaitUninterruptibly();
-            this.boss.shutdownGracefully().awaitUninterruptibly();
+            this.worker.shutdownGracefully(0, 0, TimeUnit.SECONDS);
+            this.boss.shutdownGracefully(0, 0, TimeUnit.SECONDS);
         }
         this.mappingService.close();
         this.ribActivator.close();
@@ -197,21 +205,21 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
         this.bgpActivator.close();
     }
 
-    void sendRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix, final long localPreference, final int expectedRoutesOnDS)
-        throws Exception {
+    void sendRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix, final long localPreference,
+        final int expectedRoutesOnDS) throws Exception {
         waitFutureSuccess(session.writeAndFlush(createSimpleUpdate(prefix, null, null, localPreference)));
         checkLocRib(expectedRoutesOnDS);
     }
 
-    void sendWithdrawalRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix, final long localPreference, final int expectedRoutesOnDS)
-        throws Exception {
+    void sendWithdrawalRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix,
+        final long localPreference, final int expectedRoutesOnDS) throws Exception {
         waitFutureSuccess(session.writeAndFlush(createSimpleWithdrawalUpdate(prefix, localPreference)));
         checkLocRib(expectedRoutesOnDS);
     }
 
     void sendNotification(final BGPSessionImpl session) {
-        Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(
-            BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
+        final Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode())
+            .setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
         waitFutureSuccess(session.writeAndFlush(notMsg));
     }
 
@@ -224,7 +232,8 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
     private void checkLocRib(final int expectedRoutesOnDS) throws Exception {
         Thread.sleep(100);
         readData(getDataBroker(), BGP_IID, bgpRib -> {
-            final Ipv4RoutesCase routes = ((Ipv4RoutesCase) bgpRib.getRib().get(0).getLocRib().getTables().get(0).getRoutes());
+            final Ipv4RoutesCase routes = ((Ipv4RoutesCase) bgpRib.getRib().get(0).getLocRib().getTables().get(0)
+                .getRoutes());
             final List<Ipv4Route> routeList = routes.getIpv4Routes().getIpv4Route();
             Assert.assertEquals(expectedRoutesOnDS, routeList.size());
             return bgpRib;
@@ -313,28 +322,31 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
         return new UpdateBuilder().setAttributes(attBuilder.build()).build();
     }
 
-    private static Update createSimpleUpdateEbgp(final Ipv4Prefix prefix, final PathId pathId) {
+    private static Update createSimpleUpdateEbgp(final Ipv4Prefix prefix) {
         final AttributesBuilder attBuilder = new AttributesBuilder();
         attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
         attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
             new SegmentsBuilder().setAsSequence(Collections.singletonList(AS_NUMBER)).build())).build());
-        addAttributeAugmentation(attBuilder, prefix, pathId);
+        addAttributeAugmentation(attBuilder, prefix, null);
 
         return new UpdateBuilder().setAttributes(attBuilder.build()).build();
     }
 
-    private static void addAttributeAugmentation(final AttributesBuilder attBuilder, final Ipv4Prefix prefix, final PathId pathId) {
+    private static void addAttributeAugmentation(final AttributesBuilder attBuilder, final Ipv4Prefix prefix,
+        final PathId pathId) {
         attBuilder.setUnrecognizedAttributes(Collections.emptyList());
         attBuilder.addAugmentation(Attributes1.class,
             new Attributes1Builder().setMpReachNlri(
                 new MpReachNlriBuilder()
-                    .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NH1).build()).build())
+                    .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NH1)
+                        .build()).build())
                     .setAfi(Ipv4AddressFamily.class)
                     .setSafi(UnicastSubsequentAddressFamily.class)
                     .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
                         new DestinationIpv4CaseBuilder().setDestinationIpv4(
                             new DestinationIpv4Builder().setIpv4Prefixes(Collections.singletonList(
-                                new Ipv4PrefixesBuilder().setPathId(pathId).setPrefix(new Ipv4Prefix(prefix)).build())).build())
+                                new Ipv4PrefixesBuilder().setPathId(pathId).setPrefix(new Ipv4Prefix(prefix)).build()))
+                                .build())
                             .build()).build())
                     .build()).build());
     }
@@ -345,6 +357,7 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
         attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
         attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
         attBuilder.setUnrecognizedAttributes(Collections.emptyList());
-        return new UpdateBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setWithdrawnRoutes(Collections.singletonList(prefix)).build()).build();
+        return new UpdateBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder()
+            .setWithdrawnRoutes(Collections.singletonList(prefix)).build()).build();
     }
 }
index 5fd5865863ff97dd2df5c90c1a8e0eeb1b483e84..1361764d9896f658a870b6ca43a7dab288612e5f 100644 (file)
@@ -79,8 +79,8 @@ public class AbstractBGPDispatcherTest {
         this.serverDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
 
         this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
-        final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(clientAddress.getAddress().getHostAddress()));
-        this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(clientAddress));
+        final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(this.clientAddress.getAddress().getHostAddress()));
+        this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(this.clientAddress));
         this.clientDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
     }
 
@@ -89,19 +89,8 @@ public class AbstractBGPDispatcherTest {
         this.serverDispatcher.close();
         this.registry.close();
         if (!Epoll.isAvailable()) {
-            this.worker.shutdownGracefully().awaitUninterruptibly();
-            this.boss.shutdownGracefully().awaitUninterruptibly();
-        }
-    }
-
-    private void configureClient(final BGPExtensionProviderContext ctx) {
-        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 BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
-        if (!Epoll.isAvailable()) {
-            this.worker.shutdownGracefully().awaitUninterruptibly();
-            this.boss.shutdownGracefully().awaitUninterruptibly();
+            this.worker.shutdownGracefully(0, 0, TimeUnit.SECONDS);;
+            this.boss.shutdownGracefully(0, 0, TimeUnit.SECONDS);;
         }
     }
 
@@ -120,7 +109,7 @@ public class AbstractBGPDispatcherTest {
     }
 
     public static void checkIdleState(final SimpleSessionListener listener) {
-        Stopwatch sw = Stopwatch.createStarted();
+        final Stopwatch sw = Stopwatch.createStarted();
         while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
             if (State.IDLE != listener.getState()) {
                 Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
index 437953e64ce998302032e596f63c7f51eb85a1d7..3283a73b8b412e703252d61d4800396a3898b2e7 100644 (file)
@@ -18,12 +18,17 @@ import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.util.concurrent.Uninterruptibles;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
 import java.net.InetSocketAddress;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
+import org.junit.After;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
 import org.opendaylight.protocol.bgp.mode.impl.add.all.paths.AllPathSelection;
@@ -50,10 +55,36 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 
 public class AddPathAllPathsTest extends AbstractAddPathTest {
+    private RIBImpl ribImpl;
+    private Channel serverChannel;
+
     @FunctionalInterface
     private interface CheckEquals {
         void check();
     }
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, new AllPathSelection());
+
+        this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
+            AS_NUMBER, BGP_ID, null, this.ribExtension, this.dispatcher, this.mappingService.getCodecFactory(),
+            getDomBroker(), TABLES_TYPE, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
+
+        this.ribImpl.instantiateServiceInstance();
+        this.ribImpl.onGlobalContextUpdated(this.schemaContext);
+        final ChannelFuture channelFuture = this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL,
+            new InetSocketAddress(RIB_ID, PORT));
+        waitFutureSuccess(channelFuture);
+        this.serverChannel = channelFuture.channel();
+    }
+
+    @After
+    public void tearDown() throws ExecutionException, InterruptedException {
+        waitFutureSuccess(this.serverChannel.close());
+        super.tearDown();
+    }
     /*
      * All-Paths
      *                                            ___________________
@@ -66,32 +97,20 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
      */
     @Test
     public void testUseCase1() throws Exception {
-
-        final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
-        final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, new AllPathSelection());
-
-
-        final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"), AS_NUMBER, BGP_ID, null, this.ribExtension,
-                this.dispatcher, this.mappingService.getCodecFactory(), getDomBroker(), tables, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
-
-        ribImpl.instantiateServiceInstance();
-        ribImpl.onGlobalContextUpdated(this.schemaContext);
-
-        waitFutureSuccess(this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL, new InetSocketAddress(RIB_ID, PORT)));
         final BgpParameters nonAddPathParams = createParameter(false);
         final BgpParameters addPathParams = createParameter(true);
 
-        final BGPPeer peer1 = configurePeer(PEER1, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        final BGPPeer peer1 = configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
         final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER2, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
         final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER3, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
         final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
 
         final SimpleSessionListener listener4 = new SimpleSessionListener();
-        final BGPPeer peer4 = configurePeer(PEER4, ribImpl, nonAddPathParams, PeerRole.RrClient);
+        final BGPPeer peer4 = configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
 
         BGPPeerState peer4State = peer4.getPeerState();
         assertNull(peer4State.getGroupId());
@@ -127,7 +146,7 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
         final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
 
         final SimpleSessionListener listener5 = new SimpleSessionListener();
-        configurePeer(PEER5, ribImpl, addPathParams, PeerRole.RrClient);
+        configurePeer(PEER5, this.ribImpl, addPathParams, PeerRole.RrClient);
         final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
         checkPeersPresentOnDataStore(5);
 
@@ -175,7 +194,7 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
         assertFalse(afiSafiStatePeer1.isPeerRestarting());
         assertTrue(afiSafiStatePeer1.isAfiSafiSupported(TABLES_KEY));
 
-        final BGPRIBState ribState = ribImpl.getRIBState();
+        final BGPRIBState ribState = this.ribImpl.getRIBState();
         assertEquals(1, ribState.getPathsCount().size());
         assertEquals(1L,  ribState.getPrefixesCount().size());
         assertEquals(BGP_ID, ribState.getRouteId());
@@ -186,7 +205,7 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
         assertEquals(1L, ribState.getTotalPrefixesCount());
 
         final SimpleSessionListener listener6 = new SimpleSessionListener();
-        final BGPPeer peer6 = configurePeer(PEER6, ribImpl, nonAddPathParams, PeerRole.RrClient);
+        final BGPPeer peer6 = configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
         final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
         checkPeersPresentOnDataStore(6);
         checkReceivedMessages(listener6, 1);
@@ -294,7 +313,7 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
 
     private static void checkEquals(final CheckEquals function) throws Exception {
         AssertionError lastError = null;
-        Stopwatch sw = Stopwatch.createStarted();
+        final Stopwatch sw = Stopwatch.createStarted();
         while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
             try {
                 function.check();
index 2c7d127408b40b0ff6240169cd469ad6dd28de40..8cc0ede88bd814d26739fce4537ac3efd7ed883e 100644 (file)
@@ -14,9 +14,14 @@ import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.waitFutureSuccess
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
 import java.net.InetSocketAddress;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
 import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
@@ -31,6 +36,33 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 
 public class AddPathBasePathsTest extends AbstractAddPathTest {
+    private RIBImpl ribImpl;
+    private Channel serverChannel;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+        final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk,
+            BasePathSelectionModeFactory.createBestPathSelectionStrategy());
+
+        this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
+            AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher,
+            this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
+            this.ribExtension.getClassLoadingStrategy(), null);
+        this.ribImpl.instantiateServiceInstance();
+        this.ribImpl.onGlobalContextUpdated(this.schemaContext);
+        final ChannelFuture channelFuture = this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL,
+            new InetSocketAddress(RIB_ID, PORT));
+        waitFutureSuccess(channelFuture);
+        this.serverChannel = channelFuture.channel();
+    }
+
+    @After
+    public void tearDown() throws ExecutionException, InterruptedException {
+        waitFutureSuccess(this.serverChannel.close());
+        super.tearDown();
+    }
     /*
     * Base-Paths
     *                                            ___________________
@@ -43,35 +75,23 @@ public class AddPathBasePathsTest extends AbstractAddPathTest {
     */
     @Test
     public void testUseCase1() throws Exception {
-
-        final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
-        final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
-        final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk, BasePathSelectionModeFactory.createBestPathSelectionStrategy());
-
-        final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"), AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension,
-            this.dispatcher, this.mappingService.getCodecFactory(), getDomBroker(), tables, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
-
-        ribImpl.instantiateServiceInstance();
-        ribImpl.onGlobalContextUpdated(this.schemaContext);
-
-        waitFutureSuccess(this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL, new InetSocketAddress(RIB_ID, PORT)));
         final BgpParameters nonAddPathParams = createParameter(false);
 
-        configurePeer(PEER1, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
         final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER2, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
         final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER3, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
         final BGPSessionImpl session3 = createPeerSession(PEER3,nonAddPathParams, new SimpleSessionListener());
 
         final SimpleSessionListener listener4 = new SimpleSessionListener();
-        configurePeer(PEER4, ribImpl, nonAddPathParams, PeerRole.RrClient);
+        configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
         final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
 
         final SimpleSessionListener listener5 = new SimpleSessionListener();
-        configurePeer(PEER5, ribImpl, nonAddPathParams, PeerRole.Ebgp);
+        configurePeer(PEER5, this.ribImpl, nonAddPathParams, PeerRole.Ebgp);
         final BGPSessionImpl session5 = createPeerSession(PEER5, nonAddPathParams, listener5);
         checkPeersPresentOnDataStore(5);
 
@@ -95,7 +115,7 @@ public class AddPathBasePathsTest extends AbstractAddPathTest {
         assertEquals(UPD_NA_200_EBGP, listener5.getListMsg().get(1));
 
         final SimpleSessionListener listener6 = new SimpleSessionListener();
-        configurePeer(PEER6, ribImpl, nonAddPathParams, PeerRole.RrClient);
+        configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
         final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
 
         checkPeersPresentOnDataStore(6);
index 1351c5bbba49a73ee7deff163292ff20a2c6bfdc..f4d67a50edc5712ac0956da540a3b3466f064c77 100644 (file)
@@ -14,9 +14,14 @@ import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.waitFutureSuccess
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
 import java.net.InetSocketAddress;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
 import org.opendaylight.protocol.bgp.mode.impl.add.n.paths.AddPathBestNPathSelection;
@@ -31,7 +36,33 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 
 public class AddPathNPathsTest extends AbstractAddPathTest {
+    private RIBImpl ribImpl;
+    private Channel serverChannel;
 
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+        final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk, new AddPathBestNPathSelection(2L));
+
+        this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
+            AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher,
+            this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
+            this.ribExtension.getClassLoadingStrategy(), null);
+
+        this.ribImpl.instantiateServiceInstance();
+        this.ribImpl.onGlobalContextUpdated(this.schemaContext);
+        final ChannelFuture channelFuture = this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL,
+            new InetSocketAddress(RIB_ID, PORT));
+        waitFutureSuccess(channelFuture);
+        this.serverChannel = channelFuture.channel();
+    }
+
+    @After
+    public void tearDown() throws ExecutionException, InterruptedException {
+        waitFutureSuccess(this.serverChannel.close());
+        super.tearDown();
+    }
     /*
      * N-Paths
      *                                            ___________________
@@ -44,36 +75,24 @@ public class AddPathNPathsTest extends AbstractAddPathTest {
      */
     @Test
     public void testUseCase1() throws Exception {
-
-        final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
-        final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
-        final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk, new AddPathBestNPathSelection(2L));
-
-        final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"), AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension,
-                this.dispatcher, this.mappingService.getCodecFactory(), getDomBroker(), tables, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
-
-        ribImpl.instantiateServiceInstance();
-        ribImpl.onGlobalContextUpdated(this.schemaContext);
-
-        waitFutureSuccess(this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL, new InetSocketAddress(RIB_ID, PORT)));
         final BgpParameters nonAddPathParams = createParameter(false);
         final BgpParameters addPathParams = createParameter(true);
 
-        configurePeer(PEER1, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
         final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER2, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
         final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER3, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
         final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
 
         final SimpleSessionListener listener4 = new SimpleSessionListener();
-        configurePeer(PEER4, ribImpl, nonAddPathParams, PeerRole.RrClient);
+        configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
         final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
 
         final SimpleSessionListener listener5 = new SimpleSessionListener();
-        configurePeer(PEER5, ribImpl, addPathParams, PeerRole.RrClient);
+        configurePeer(PEER5, this.ribImpl, addPathParams, PeerRole.RrClient);
         final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
         checkPeersPresentOnDataStore(5);
 
@@ -84,7 +103,7 @@ public class AddPathNPathsTest extends AbstractAddPathTest {
         assertEquals(UPD_100, listener5.getListMsg().get(0));
 
         final SimpleSessionListener listener6 = new SimpleSessionListener();
-        configurePeer(PEER6, ribImpl, nonAddPathParams, PeerRole.RrClient);
+        configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
         final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
         checkPeersPresentOnDataStore(6);
         checkReceivedMessages(listener6, 1);
index 7a3d5bf4edbc17c6b6d1f20b4898a7bee8f7e50f..6d0e3697dbccb6c6495878fd15e4bf6d8304e3bf 100644 (file)
@@ -27,9 +27,9 @@ public final class CheckUtil {
     private static final int LATCH_TIMEOUT = 10;
     private static final int SLEEP_FOR = 20;
     private static final int SLEEP_UNINTERRUPTIBLY = 50;
-    public static void checkReceivedMessages(final SimpleSessionListener listener, final int numberOfMessages)
+    static void checkReceivedMessages(final SimpleSessionListener listener, final int numberOfMessages)
         throws ReadFailedException {
-        Stopwatch sw = Stopwatch.createStarted();
+        final Stopwatch sw = Stopwatch.createStarted();
         while (sw.elapsed(TimeUnit.SECONDS) <= TIMEOUT) {
             if (listener.getListMsg().size() != numberOfMessages) {
                 Uninterruptibles.sleepUninterruptibly(SLEEP_UNINTERRUPTIBLY, TimeUnit.MILLISECONDS);
@@ -40,7 +40,8 @@ public final class CheckUtil {
         Assert.fail();
     }
 
-    public static <R, T extends DataObject> R readData(final DataBroker dataBroker, final InstanceIdentifier<T> iid, final Function<T, R> function)
+    public static <R, T extends DataObject> R readData(final DataBroker dataBroker, final InstanceIdentifier<T> iid,
+        final Function<T, R> function)
         throws ReadFailedException {
         AssertionError lastError = null;
         final Stopwatch sw = Stopwatch.createStarted();
index 91d734a8b4ae79dd42b7da6a95858230977b62cd..80e823fc81bacb26b77cec0db13d7753a14ef963 100644 (file)
@@ -28,6 +28,7 @@ import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
 import java.io.Closeable;
 import java.net.InetSocketAddress;
+import java.util.concurrent.TimeUnit;
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.protocol.concepts.KeyMapping;
@@ -45,6 +46,7 @@ import org.slf4j.LoggerFactory;
 public class PCEPDispatcherImpl implements PCEPDispatcher, Closeable {
     private static final Logger LOG = LoggerFactory.getLogger(PCEPDispatcherImpl.class);
     private static final Integer SOCKET_BACKLOG_SIZE = 128;
+    private static final long TIMEOUT = 10;
     private final PCEPSessionNegotiatorFactory snf;
     private final PCEPHandlerFactory hf;
     private final EventLoopGroup bossGroup;
@@ -140,8 +142,8 @@ public class PCEPDispatcherImpl implements PCEPDispatcher, Closeable {
     @Override
     public final void close() {
         if (Epoll.isAvailable()) {
-            this.workerGroup.shutdownGracefully().awaitUninterruptibly();
-            this.bossGroup.shutdownGracefully().awaitUninterruptibly();
+            this.workerGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);;
+            this.bossGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);;
         }
     }
 
index 1963453619e8e7e3b08ef139de6aba379194dbc1..fb19558affc50ffc71aa87b2caa2615d6ac4b8d5 100644 (file)
@@ -20,6 +20,7 @@ import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -65,8 +66,8 @@ public class PCCDispatcherImplTest {
     }
 
     private void closeEventLoopGroups() throws ExecutionException, InterruptedException {
-        this.workerGroup.shutdownGracefully().get();
-        this.bossGroup.shutdownGracefully().get();
+        this.workerGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
+        this.bossGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
     }
 
     @Test