Clean up DropTest{Committer,RpcSender} 16/104116/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 24 Jan 2023 22:29:24 +0000 (23:29 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 24 Jan 2023 22:31:20 +0000 (23:31 +0100)
There is no point in catching exceptions during DTCL registration,
those are not allowed to fail transiently. Also do not catch exceptions
around Registration.close(), as those can never fail, either.

Change-Id: I8411c0b3a5da508a0a59db95f4bca982f6a4ce21
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/AbstractDropTest.java
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestCommiter.java
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestRpcSender.java

index f0c47fb9510da3a2923f4a902df9efca8f4b6ab3..0a1ff72cd94393d580d1c158f8f0e208d976c87a 100644 (file)
@@ -53,14 +53,11 @@ abstract class AbstractDropTest implements Listener<PacketReceived>, AutoCloseab
     protected static final Uint16 IDLE_TIMEOUT = Uint16.valueOf(240);
     protected static final Uint8 TABLE_ID = Uint8.ZERO;
 
-    static final long STARTUP_LOOP_TICK = 500L;
-    static final int STARTUP_LOOP_MAX_RETRIES = 8;
     private static final int PROCESSING_POOL_SIZE = 10000;
 
     private static final int POOL_THREAD_AMOUNT = 8;
     private final ExecutorService executorService;
 
-
     private static final AtomicIntegerFieldUpdater<AbstractDropTest> SENT_UPDATER = AtomicIntegerFieldUpdater
             .newUpdater(AbstractDropTest.class, "sent");
     private volatile int sent;
index 0fbfcb0d769b7f6777bb745a15140a364c4a6618..6bb4d4ca2ca551d20aa64d7b7bcbe019917dcfed 100644 (file)
@@ -12,7 +12,6 @@ import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.NotificationService;
 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
@@ -45,19 +44,16 @@ public class DropTestCommiter extends AbstractDropTest {
     private static final AtomicLong ID_COUNTER = new AtomicLong();
 
     private static final ThreadLocal<FlowBuilder> BUILDER = ThreadLocal.withInitial(() -> {
-        final FlowBuilder fb = new FlowBuilder();
-
-        fb.setPriority(PRIORITY);
-        fb.setBufferId(BUFFER_ID);
-        final FlowCookie cookie = new FlowCookie(Uint64.TEN);
-        fb.setCookie(cookie);
-        fb.setCookieMask(cookie);
-
-        fb.setTableId(TABLE_ID);
-        fb.setHardTimeout(HARD_TIMEOUT);
-        fb.setIdleTimeout(IDLE_TIMEOUT);
-        fb.setFlags(new FlowModFlags(false, false, false, false, false));
-        return fb;
+        final var cookie = new FlowCookie(Uint64.TEN);
+        return new FlowBuilder()
+            .setPriority(PRIORITY)
+            .setBufferId(BUFFER_ID)
+            .setCookie(cookie)
+            .setCookieMask(cookie)
+            .setTableId(TABLE_ID)
+            .setHardTimeout(HARD_TIMEOUT)
+            .setIdleTimeout(IDLE_TIMEOUT)
+            .setFlags(new FlowModFlags(false, false, false, false, false));
     });
 
     private NotificationService notificationService;
@@ -67,18 +63,8 @@ public class DropTestCommiter extends AbstractDropTest {
     /**
      * start listening on packetIn.
      */
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void start() {
-        final SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK,
-                STARTUP_LOOP_MAX_RETRIES);
-        try {
-            notificationRegistration = looper.loopUntilNoException(
-                () -> notificationService.registerListener(PacketReceived.class, this));
-        } catch (Exception e) {
-            LOG.warn("DropTest committer notification listener registration fail!");
-            LOG.debug("DropTest committer notification listener registration fail! ..", e);
-            throw new IllegalStateException("DropTest startup fail! Try again later.", e);
-        }
+        notificationRegistration = notificationService.registerListener(PacketReceived.class, this);
     }
 
     public void setDataService(final DataBroker dataService) {
@@ -117,17 +103,11 @@ public class DropTestCommiter extends AbstractDropTest {
     }
 
     @Override
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void close() {
         super.close();
-        try {
-            LOG.debug("DropTestProvider stopped.");
-            if (notificationRegistration != null) {
-                notificationRegistration.close();
-            }
-        } catch (RuntimeException e) {
-            LOG.warn("unregistration of notification listener failed: {}", e.getMessage());
-            LOG.debug("unregistration of notification listener failed.. ", e);
+        LOG.debug("DropTestProvider stopped.");
+        if (notificationRegistration != null) {
+            notificationRegistration.close();
         }
     }
 
index f1b263e4a1391c9e32c5abaab38d7bd84b7f0332..885b1191676eda05a9b13596fa81e182bdb6b81c 100644 (file)
@@ -12,7 +12,6 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import org.opendaylight.mdsal.binding.api.NotificationService;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
@@ -45,20 +44,16 @@ public class DropTestRpcSender extends AbstractDropTest {
     }
 
     private static final ThreadLocal<AddFlowInputBuilder> BUILDER = ThreadLocal.withInitial(() -> {
-        final AddFlowInputBuilder fb = new AddFlowInputBuilder();
-
-        fb.setPriority(PRIORITY);
-        fb.setBufferId(BUFFER_ID);
-
-        final FlowCookie cookie = new FlowCookie(Uint64.TEN);
-        fb.setCookie(cookie);
-        fb.setCookieMask(cookie);
-        fb.setTableId(TABLE_ID);
-        fb.setHardTimeout(HARD_TIMEOUT);
-        fb.setIdleTimeout(IDLE_TIMEOUT);
-        fb.setFlags(new FlowModFlags(false, false, false, false, false));
-
-        return fb;
+        final var cookie = new FlowCookie(Uint64.TEN);
+        return new AddFlowInputBuilder()
+            .setPriority(PRIORITY)
+            .setBufferId(BUFFER_ID)
+            .setCookie(cookie)
+            .setCookieMask(cookie)
+            .setTableId(TABLE_ID)
+            .setHardTimeout(HARD_TIMEOUT)
+            .setIdleTimeout(IDLE_TIMEOUT)
+            .setFlags(new FlowModFlags(false, false, false, false, false));
     });
 
     private NotificationService notificationService;
@@ -68,18 +63,8 @@ public class DropTestRpcSender extends AbstractDropTest {
     /**
      * Start listening on packetIn.
      */
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void start() {
-        final SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK,
-                STARTUP_LOOP_MAX_RETRIES);
-        try {
-            notificationRegistration = looper.loopUntilNoException(
-                () -> notificationService.registerListener(PacketReceived.class, this));
-        } catch (Exception e) {
-            LOG.warn("DropTest sender notification listener registration fail!");
-            LOG.debug("DropTest sender notification listener registration fail! ..", e);
-            throw new IllegalStateException("DropTest startup fail! Try again later.", e);
-        }
+        notificationRegistration = notificationService.registerListener(PacketReceived.class, this);
     }
 
     @Override
@@ -97,9 +82,7 @@ public class DropTestRpcSender extends AbstractDropTest {
 
         // Add flow
         final AddFlowInput flow = fb.build();
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("onPacketReceived - About to write flow (via SalFlowService) {}", flow);
-        }
+        LOG.debug("onPacketReceived - About to write flow (via SalFlowService) {}", flow);
         ListenableFuture<RpcResult<AddFlowOutput>> result = flowService.addFlow(flow);
         Futures.addCallback(result, new FutureCallback<RpcResult<AddFlowOutput>>() {
             @Override
@@ -119,17 +102,11 @@ public class DropTestRpcSender extends AbstractDropTest {
     }
 
     @Override
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void close() {
         super.close();
-        try {
-            LOG.debug("DropTestProvider stopped.");
-            if (notificationRegistration != null) {
-                notificationRegistration.close();
-            }
-        } catch (RuntimeException e) {
-            LOG.warn("unregistration of notification listener failed: {}", e.getMessage());
-            LOG.debug("unregistration of notification listener failed.. ", e);
+        LOG.debug("DropTestProvider stopped.");
+        if (notificationRegistration != null) {
+            notificationRegistration.close();
         }
     }
 }