some drop tests statistics were not cleaned on clearstats command
[openflowplugin.git] / test-common / src / main / java / org / opendaylight / openflowplugin / testcommon / DropTestCommiter.java
index 0de0f82c2e65fd75b26156587278f998ff004a27..f38cbcdd35c3e141950d995ffb9eff7c2ee13394 100644 (file)
@@ -11,9 +11,9 @@ import java.math.BigInteger;
 import java.util.concurrent.Callable;
 import java.util.concurrent.atomic.AtomicLong;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 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;
@@ -31,7 +31,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.NotificationListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -65,24 +64,24 @@ public class DropTestCommiter extends AbstractDropTest {
         }
     };
 
-    private NotificationProviderService notificationService;
+    private NotificationService notificationService;
 
-    private ListenerRegistration<NotificationListener> notificationRegistration;
+    private ListenerRegistration<DropTestCommiter> notificationRegistration;
 
     /**
      * start listening on packetIn
      */
     public void start() {
-        SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK,
+        final SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK,
                 STARTUP_LOOP_MAX_RETRIES);
         try {
-            notificationRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<NotificationListener>>() {
+            notificationRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<DropTestCommiter>>() {
                 @Override
-                public ListenerRegistration<NotificationListener> call() throws Exception {
+                public ListenerRegistration<DropTestCommiter> call() throws Exception {
                     return notificationService.registerNotificationListener(DropTestCommiter.this);
                 }
             });
-        } catch (Exception e) {
+        } catch (final 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);
@@ -92,7 +91,7 @@ public class DropTestCommiter extends AbstractDropTest {
     /**
      * @param dataService the dataService to set
      */
-    public void setDataService(DataBroker dataService) {
+    public void setDataService(final DataBroker dataService) {
         this.dataService = dataService;
     }
 
@@ -103,7 +102,7 @@ public class DropTestCommiter extends AbstractDropTest {
         final FlowBuilder fb = BUILDER.get();
         fb.setMatch(match);
         fb.setInstructions(instructions);
-        fb.setId(new FlowId(String.valueOf(fb.hashCode()) +"."+ ID_COUNTER.getAndIncrement()));
+        fb.setId(new FlowId(String.valueOf(fb.hashCode()) + "." + ID_COUNTER.getAndIncrement()));
 
         // Construct the flow instance id
         final InstanceIdentifier<Flow> flowInstanceId =
@@ -111,11 +110,11 @@ public class DropTestCommiter extends AbstractDropTest {
                 InstanceIdentifier.builder(Nodes.class)
                         // A particular node identified by nodeKey
                         .child(Node.class, node)
-                        // That is flow capable, only FlowCapableNodes have tables
+                                // That is flow capable, only FlowCapableNodes have tables
                         .augmentation(FlowCapableNode.class)
-                        // In the table identified by TableKey
+                                // In the table identified by TableKey
                         .child(Table.class, new TableKey((short) 0))
-                        // A flow identified by flowKey
+                                // A flow identified by flowKey
                         .child(Flow.class, new FlowKey(fb.getId()))
                         .build();
 
@@ -132,20 +131,22 @@ public class DropTestCommiter extends AbstractDropTest {
 
     @Override
     public void close() {
+        super.close();
         try {
             LOG.debug("DropTestProvider stopped.");
             if (notificationRegistration != null) {
                 notificationRegistration.close();
             }
-        } catch (Exception e) {
-            LOG.error("unregistration of notification listener failed", e);
+        } catch (final Exception e) {
+            LOG.warn("unregistration of notification listener failed: {}", e.getMessage());
+            LOG.debug("unregistration of notification listener failed.. ", e);
         }
     }
 
     /**
      * @param notificationService
      */
-    public void setNotificationService(NotificationProviderService notificationService) {
+    public void setNotificationService(final NotificationService notificationService) {
         this.notificationService = notificationService;
     }
 }