Programming Clean up 16/52616/4
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Thu, 2 Mar 2017 07:35:07 +0000 (08:35 +0100)
committerRobert Varga <rovarga@cisco.com>
Tue, 7 Mar 2017 07:18:58 +0000 (08:18 +0100)
Migrate deprecated classes
Code clean up

Change-Id: I06551491a30499d81d4c0dc7f0e1dbe68dc04eab
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
12 files changed:
programming/api/src/main/java/org/opendaylight/bgpcep/programming/NanotimeUtil.java
programming/impl/pom.xml
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/InstructionDeployedImpl.java
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/InstructionImpl.java
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImpl.java
programming/impl/src/main/resources/org/opendaylight/blueprint/programming.xml
programming/impl/src/test/java/org/opendaylight/bgpcep/programming/impl/MockedExecutorWrapper.java
programming/impl/src/test/java/org/opendaylight/bgpcep/programming/impl/MockedNotificationServiceWrapper.java
programming/impl/src/test/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImplTest.java
programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/ExecutionResult.java
programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/SchedulerException.java
programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/SuccessfulRpcResult.java

index 63949f15959ef33d3bcbd75dbe33c7d00194a279..b295c41caa114baad19843268e8e253fd83df44a 100644 (file)
@@ -50,7 +50,7 @@ public final class NanotimeUtil {
      * providing System.nanoTime(). This method should be called whenever there is a hint of the two diverging: either
      * when time shifts or periodically.
      */
-    public static void calibrate() {
+    private static void calibrate() {
         final long tm1 = System.currentTimeMillis();
         final long nt1 = System.nanoTime();
         final long tm2 = System.currentTimeMillis();
index 0be2c48c1977bfca7008160726f3b27eab782a1b..5313e3945aa07b8785daa4b94f07fa49909c48ae 100644 (file)
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
-
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>testtool-util</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
index 27f1a614b9e608955ec88aad2c278b7e1d5be14e..5e84791bff1a250399b3d3292a02edb2b63fb54e 100644 (file)
@@ -31,10 +31,10 @@ import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.programming.config.rev170301.OdlProgramming;
@@ -42,7 +42,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.prog
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.programming.config.rev170301.odl.programming.OdlProgrammingConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.programming.config.rev170301.odl.programming.OdlProgrammingConfigBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.programming.config.rev170301.odl.programming.OdlProgrammingConfigKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionsQueueKey;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.osgi.framework.BundleContext;
@@ -57,7 +56,7 @@ public final class InstructionDeployedImpl implements IntructionDeployer,
     private final RpcProviderRegistry rpcProviderRegistry;
     private final ListeningExecutorService exec = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
     private final DataBroker dataProvider;
-    private final NotificationProviderService notifs;
+    private final NotificationPublishService notifs;
     private final Timer timer;
     private final BundleContext bundleContext;
     @GuardedBy("this")
@@ -67,7 +66,7 @@ public final class InstructionDeployedImpl implements IntructionDeployer,
     private final ClusterSingletonServiceProvider cssp;
 
     public InstructionDeployedImpl(final DataBroker dataProvider, final RpcProviderRegistry rpcProviderRegistry,
-        final NotificationProviderService notifs, final Timer timer, final ClusterSingletonServiceProvider cssp,
+        final NotificationPublishService notifs, final Timer timer, final ClusterSingletonServiceProvider cssp,
         final BundleContext bundleContext) {
         this.dataProvider = Preconditions.checkNotNull(dataProvider);
         this.notifs = Preconditions.checkNotNull(notifs);
index 15af7ac3dadd83358f1c7c882b18a595f63d446c..d56970c2ac2397b9a5cb14963204698848c83058 100644 (file)
@@ -56,7 +56,7 @@ final class InstructionImpl implements Instruction {
         return this.status;
     }
 
-    synchronized void setStatus(final InstructionStatus status, final Details details) {
+    private synchronized void setStatus(final InstructionStatus status, final Details details) {
         // Set the status
         this.status = status;
         LOG.debug("Instruction {} transitioned to status {}", this.id, status);
@@ -193,7 +193,7 @@ final class InstructionImpl implements Instruction {
             cancelTimeout();
 
             // We reuse the preconditions set down in this class
-            result = new ExecutionResult<Details>(status, details);
+            result = new ExecutionResult<>(status, details);
             setStatus(status, details);
         }
 
@@ -217,13 +217,13 @@ final class InstructionImpl implements Instruction {
     }
 
     synchronized void clean() {
-        for (final Iterator<InstructionImpl> it = this.dependencies.iterator(); it.hasNext();) {
-            it.next().removeDependant(this);
+        for (final InstructionImpl dependency : this.dependencies) {
+            dependency.removeDependant(this);
         }
         this.dependencies.clear();
 
-        for (final Iterator<InstructionImpl> it = this.dependants.iterator(); it.hasNext();) {
-            it.next().removeDependency(this);
+        for (final InstructionImpl dependant : this.dependants) {
+            dependant.removeDependency(this);
         }
         this.dependants.clear();
 
index d61745fec1c25176fab6e296efc76d55a60b5a5a..834fae584fd5bf50f015656c6197577a4253dcab 100644 (file)
@@ -33,9 +33,9 @@ import org.opendaylight.bgpcep.programming.spi.SuccessfulRpcResult;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
@@ -77,7 +77,7 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
 
     private final Map<InstructionId, InstructionImpl> insns = new HashMap<>();
     private final InstanceIdentifier<InstructionsQueue> qid;
-    private final NotificationProviderService notifs;
+    private final NotificationPublishService notifs;
     private final ListeningExecutorService executor;
     private final DataBroker dataProvider;
     private final Timer timer;
@@ -121,7 +121,12 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
                 });
             }
 
-            ProgrammingServiceImpl.this.notifs.publish(new InstructionStatusChangedBuilder().setId(this.builder.getId()).setStatus(status).setDetails(details).build());
+            try {
+                ProgrammingServiceImpl.this.notifs.putNotification(new InstructionStatusChangedBuilder()
+                    .setId(this.builder.getId()).setStatus(status).setDetails(details).build());
+            } catch (final InterruptedException e) {
+                LOG.debug("Failed to publish notification", e);
+            }
         }
 
         @Override
@@ -144,7 +149,7 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
         }
     }
 
-    ProgrammingServiceImpl(final DataBroker dataProvider, final NotificationProviderService notifs,
+    ProgrammingServiceImpl(final DataBroker dataProvider, final NotificationPublishService notifs,
         final ListeningExecutorService executor, final RpcProviderRegistry rpcProviderRegistry,
         final ClusterSingletonServiceProvider cssp, final Timer timer, final String instructionId) {
         this.dataProvider = Preconditions.checkNotNull(dataProvider);
index 05706a98f3740eb8dd0ef38f2b10243609c39f25..38bd0fe749af098e10ed3d14278052d9e5190e83 100644 (file)
@@ -14,7 +14,7 @@
                odl:type="default"/>
     <reference id="rpcRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"/>
     <reference id="notificationService"
-               interface="org.opendaylight.controller.sal.binding.api.NotificationProviderService" />
+               interface="org.opendaylight.controller.md.sal.binding.api.NotificationPublishService"/>
     <reference id="timer" interface="io.netty.util.Timer" odl:type="global-timer"/>
     <reference id="clusterSingletonServiceProvider"
                interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
index da944a89d6407c0bca9c6f4b676c8b5bdf22be5c..26f4541ad03fbbc5e40cbb470e334aab781799d1 100644 (file)
@@ -25,38 +25,35 @@ import org.mockito.stubbing.Answer;
 
 final class MockedExecutorWrapper {
 
-    private List<Object> submittedTasksToExecutor;
+    private final List<Object> submittedTasksToExecutor;
 
     MockedExecutorWrapper() {
-        submittedTasksToExecutor = Lists.newArrayList();
+        this.submittedTasksToExecutor = Lists.newArrayList();
     }
 
     ListeningExecutorService getMockedExecutor() {
-        ListeningExecutorService mockedExecutor = mock(ListeningExecutorService.class);
-        Answer<ListenableFuture<?>> submitAnswer = new Answer<ListenableFuture<?>>() {
-            @Override
-            public ListenableFuture<?> answer(InvocationOnMock invocation) throws Throwable {
-                Object task = invocation.getArguments()[0];
-                submittedTasksToExecutor.add(task);
-
-                Object result = null;
-                if (task instanceof Runnable) {
-                    ((Runnable) task).run();
-                } else if (task instanceof Callable) {
-                    result = ((Callable<?>) task).call();
-                }
-
-                ListenableFuture<?> mockedFuture = mock(ListenableFuture.class);
-                doReturn(result).when(mockedFuture).get();
-                return mockedFuture;
+        final ListeningExecutorService mockedExecutor = mock(ListeningExecutorService.class);
+        final Answer<ListenableFuture<?>> submitAnswer = invocation -> {
+            final Object task = invocation.getArguments()[0];
+            this.submittedTasksToExecutor.add(task);
+
+            Object result = null;
+            if (task instanceof Runnable) {
+                ((Runnable) task).run();
+            } else if (task instanceof Callable) {
+                result = ((Callable<?>) task).call();
             }
+
+            final ListenableFuture<?> mockedFuture = mock(ListenableFuture.class);
+            doReturn(result).when(mockedFuture).get();
+            return mockedFuture;
         };
         doAnswer(submitAnswer).when(mockedExecutor).submit(any(Runnable.class));
         doAnswer(submitAnswer).when(mockedExecutor).submit(any(Callable.class));
         return mockedExecutor;
     }
 
-    void assertSubmittedTasksSize(int taskCount) {
-        assertEquals(taskCount, submittedTasksToExecutor.size());
+    void assertSubmittedTasksSize(final int taskCount) {
+        assertEquals(taskCount, this.submittedTasksToExecutor.size());
     }
 }
index a12f9db32853de6cf73f2d24d5dd98904aa8bdbb..c286c13c1d4f0ccd0df22ea7759450641bac3c8a 100644 (file)
@@ -16,9 +16,7 @@ import static org.mockito.Mockito.mock;
 import com.google.common.collect.Lists;
 import java.util.List;
 import org.junit.Assert;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionStatus;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionStatusChanged;
@@ -31,18 +29,15 @@ final class MockedNotificationServiceWrapper {
         this.publishedNotifications = Lists.newArrayList();
     }
 
-    NotificationProviderService getMockedNotificationService() {
-        final NotificationProviderService mockedNotificationService = mock(NotificationProviderService.class);
+    NotificationPublishService getMockedNotificationService() throws InterruptedException {
+        final NotificationPublishService mockedNotificationService = mock(NotificationPublishService.class);
 
-        doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Object notif = invocation.getArguments()[0];
-                assertTrue(Notification.class.isAssignableFrom(notif.getClass()));
-                MockedNotificationServiceWrapper.this.publishedNotifications.add((Notification) notif);
-                return null;
-            }
-        }).when(mockedNotificationService).publish(any(Notification.class));
+        doAnswer(invocation -> {
+            final Object notif = invocation.getArguments()[0];
+            assertTrue(Notification.class.isAssignableFrom(notif.getClass()));
+            MockedNotificationServiceWrapper.this.publishedNotifications.add((Notification) notif);
+            return null;
+        }).when(mockedNotificationService).putNotification(any(Notification.class));
         return mockedNotificationService;
     }
 
@@ -50,7 +45,7 @@ final class MockedNotificationServiceWrapper {
         assertEquals(count, this.publishedNotifications.size());
     }
 
-    public void assertInstructionStatusChangedNotification(final int idx, final InstructionId id, final InstructionStatus status) {
+    void assertInstructionStatusChangedNotification(final int idx, final InstructionId id, final InstructionStatus status) {
         assertTrue(InstructionStatusChanged.class.isAssignableFrom(this.publishedNotifications.get(idx).getClass()));
         final InstructionStatusChanged firstNotification = (InstructionStatusChanged) this.publishedNotifications.get(idx);
         assertInstructionStatusChangedNotification(id, status, firstNotification);
index 930b3c1bb8496d81502a9c88bb83f24528917136..5b618a8a9f80d068ec3e68cf0c5bc3ef1ce09c33 100644 (file)
@@ -18,6 +18,7 @@ import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
+import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
 
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -36,7 +37,7 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.bgpcep.programming.NanotimeUtil;
 import org.opendaylight.bgpcep.programming.spi.Instruction;
 import org.opendaylight.bgpcep.programming.spi.SchedulerException;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
@@ -62,7 +63,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
-public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
+public class ProgrammingServiceImplTest extends AbstractConcurrentDataBrokerTest {
 
     private static final int INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS = 3;
     private static final String INSTRUCTIONS_QUEUE_KEY = "test-instraction-queue";
@@ -116,7 +117,7 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         final SubmitInstructionInput mockedSubmit = getMockedSubmitInstructionInput("mockedSubmit");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit);
 
-        assertTrue(assertInstructionExists(mockedSubmit.getId()));
+        checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit.getId())));
 
         // assert Schedule to executor
         this.mockedExecutorWrapper.assertSubmittedTasksSize(1);
@@ -155,7 +156,7 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         final SubmitInstructionInput mockedSubmit = getMockedSubmitInstructionInput("mockedSubmit");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit);
 
-        assertTrue(assertInstructionExists(mockedSubmit.getId()));
+        checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit.getId())));
 
         final CancelInstructionInput mockedCancel = getCancelInstruction("mockedSubmit");
         this.testedProgrammingService.cancelInstruction(mockedCancel);
@@ -185,9 +186,9 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit2.getId(), InstructionStatus.Cancelled);
         this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit3.getId(), InstructionStatus.Cancelled);
 
-        assertTrue(assertInstructionExists(mockedSubmit1.getId()));
-        assertTrue(assertInstructionExists(mockedSubmit2.getId()));
-        assertTrue(assertInstructionExists(mockedSubmit3.getId()));
+        checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit1.getId())));
+        checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit2.getId())));
+        checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit3.getId())));
     }
 
     @Test
@@ -210,8 +211,8 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         cleanedInstructionOutput = this.testedProgrammingService.cleanInstructions(cleanInstructionsInput);
         assertCleanInstructionOutput(cleanedInstructionOutput, 0);
 
-        assertFalse(assertInstructionExists(mockedSubmit1.getId()));
-        assertFalse(assertInstructionExists(mockedSubmit2.getId()));
+        checkEquals(()-> assertFalse(assertInstructionExists(mockedSubmit1.getId())));
+        checkEquals(()-> assertFalse(assertInstructionExists(mockedSubmit2.getId())));
     }
 
     private void assertCleanInstructionOutput(final ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput,
index ed10d87ee70d20af1e0283ae4bee4c200f30f43c..79fdc6dfb5a2c8ffc85a31b5a02388eb8590d92c 100644 (file)
@@ -25,15 +25,15 @@ public final class ExecutionResult<T extends Details> {
     }
 
     public InstructionStatus getStatus() {
-        return status;
+        return this.status;
     }
 
     public T getDetails() {
-        return details;
+        return this.details;
     }
 
     @Override
     public String toString() {
-        return "ExecutionResult [status=" + status + ", details=" + details + "]";
+        return "ExecutionResult [status=" + this.status + ", details=" + this.details + "]";
     }
 }
index c0ad09dee546ba9fe861ddae533dbd58790257e8..b5eea8e1a6bbe464352bd2580a4a0eb11ae1cbde 100644 (file)
@@ -22,6 +22,6 @@ public class SchedulerException extends Exception {
     }
 
     public final Failure getFailure() {
-        return failure;
+        return this.failure;
     }
 }
index 9aaa15365b5204fb0896814049603f4d8f99d2d5..9dd6fc15723d4f377383b0423201a98c4a814260 100644 (file)
@@ -21,7 +21,7 @@ public final class SuccessfulRpcResult<T> implements RpcResult<T> {
     }
 
     public static <T> SuccessfulRpcResult<T> create(final T value) {
-        return new SuccessfulRpcResult<T>(value);
+        return new SuccessfulRpcResult<>(value);
     }
 
     @Override
@@ -31,7 +31,7 @@ public final class SuccessfulRpcResult<T> implements RpcResult<T> {
 
     @Override
     public T getResult() {
-        return value;
+        return this.value;
     }
 
     @Override