Ditch ListeningExecutorService
[bgpcep.git] / programming / impl / src / test / java / org / opendaylight / bgpcep / programming / impl / ProgrammingServiceImplTest.java
index 889b400b51c5b2318dd0df0c59a2247247aef014..b22c136c6a3268bb4040264aa7148d79f3b6fb6d 100644 (file)
@@ -8,40 +8,31 @@
 package org.opendaylight.bgpcep.programming.impl;
 
 import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-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.mockito.MockitoAnnotations.initMocks;
-import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
-import static org.opendaylight.protocol.util.CheckUtil.checkPresentOperational;
+import static org.opendaylight.protocol.util.CheckTestUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckTestUtil.checkPresentOperational;
 
-import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ListenableFuture;
 import io.netty.util.HashedWheelTimer;
 import io.netty.util.Timer;
 import java.math.BigInteger;
-import java.util.List;
+import java.util.Arrays;
 import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
 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.AbstractConcurrentDataBrokerTest;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CancelInstructionInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CancelInstructionInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CleanInstructionsInput;
@@ -52,17 +43,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programm
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionsQueue;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionsQueueKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.Nanotime;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.ProgrammingService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.SubmitInstructionInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.queue.InstructionKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.status.changed.Details;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.status.changed.DetailsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepUpdateTunnelInput;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint64;
 
-public class ProgrammingServiceImplTest extends AbstractConcurrentDataBrokerTest {
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class ProgrammingServiceImplTest extends AbstractProgrammingTest {
 
     private static final int INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS = 3;
     private static final String INSTRUCTIONS_QUEUE_KEY = "test-instraction-queue";
@@ -70,128 +61,104 @@ public class ProgrammingServiceImplTest extends AbstractConcurrentDataBrokerTest
     private MockedExecutorWrapper mockedExecutorWrapper;
     private MockedNotificationServiceWrapper mockedNotificationServiceWrapper;
     private ProgrammingServiceImpl testedProgrammingService;
-    @Mock
-    private ClusterSingletonServiceProvider cssp;
-    @Mock
-    private ClusterSingletonServiceRegistration singletonServiceRegistration;
-    @Mock
-    private RpcProviderRegistry rpcRegistry;
-    @Mock
-    private RoutedRpcRegistration<ProgrammingService> registration;
-    private ClusterSingletonService singletonService;
 
     @Before
+    @Override
     public void setUp() throws Exception {
-        initMocks(this);
-        doAnswer(invocationOnMock -> {
-            this.singletonService = (ClusterSingletonService) invocationOnMock.getArguments()[0];
-            return this.singletonServiceRegistration;
-        }).when(this.cssp).registerClusterSingletonService(any(ClusterSingletonService.class));
-
-        doAnswer(invocationOnMock -> {
-            this.singletonService.closeServiceInstance();
-            return null;
-        }).when(this.singletonServiceRegistration).close();
-        doReturn(this.registration).when(this.rpcRegistry).addRpcImplementation(Mockito.any(),
-            Mockito.any(ProgrammingService.class));
-        doNothing().when(this.registration).close();
-        this.mockedExecutorWrapper = new MockedExecutorWrapper();
-        this.mockedNotificationServiceWrapper = new MockedNotificationServiceWrapper();
-
-        this.testedProgrammingService = new ProgrammingServiceImpl(getDataBroker(),
-            this.mockedNotificationServiceWrapper.getMockedNotificationService(),
-            this.mockedExecutorWrapper.getMockedExecutor(), this.rpcRegistry, this.cssp, this.timer,
-            INSTRUCTIONS_QUEUE_KEY);
-        this.singletonService.instantiateServiceInstance();
+        super.setUp();
+        mockedExecutorWrapper = new MockedExecutorWrapper();
+        mockedNotificationServiceWrapper = new MockedNotificationServiceWrapper();
+
+        testedProgrammingService = new ProgrammingServiceImpl(getDataBroker(),
+                mockedNotificationServiceWrapper.getMockedNotificationService(),
+                mockedExecutorWrapper.getMockedExecutor(), rpcRegistry, cssp, timer,
+                INSTRUCTIONS_QUEUE_KEY);
+        singletonService.instantiateServiceInstance();
     }
 
     @After
     public void tearDown() throws Exception {
-        this.singletonService.closeServiceInstance();
-        this.testedProgrammingService.close();
+        singletonService.closeServiceInstance();
+        testedProgrammingService.close();
     }
 
     @Test
     public void testScheduleInstruction() throws Exception {
         final SubmitInstructionInput mockedSubmit = getMockedSubmitInstructionInput("mockedSubmit");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit);
+        testedProgrammingService.scheduleInstruction(mockedSubmit);
 
         checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit.getId()));
 
         // assert Schedule to executor
-        this.mockedExecutorWrapper.assertSubmittedTasksSize(1);
+        mockedExecutorWrapper.assertSubmittedTasksSize(1);
 
         // assert Notification
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit.getId(),
-            InstructionStatus.Scheduled);
+        mockedNotificationServiceWrapper.assertNotificationsCount(1);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit.getId(),
+                InstructionStatus.Scheduled);
     }
 
     @Test
     public void testScheduleDependingInstruction() throws Exception {
-        this.testedProgrammingService.scheduleInstruction(getMockedSubmitInstructionInput("mockedSubmit1"));
+        testedProgrammingService.scheduleInstruction(getMockedSubmitInstructionInput("mockedSubmit1"));
         final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
-            "mockedSubmit1");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
+                "mockedSubmit1");
+        testedProgrammingService.scheduleInstruction(mockedSubmit2);
 
-        this.mockedExecutorWrapper.assertSubmittedTasksSize(2);
+        mockedExecutorWrapper.assertSubmittedTasksSize(2);
 
         // First is in state scheduled, so second could not be scheduled yet
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
+        mockedNotificationServiceWrapper.assertNotificationsCount(1);
     }
 
     @Test
     public void testScheduleDependingInstructionToFail() throws Exception {
-        try {
-            this.testedProgrammingService.scheduleInstruction(getMockedSubmitInstructionInput("mockedSubmit",
-                "dep1"));
-        } catch (final SchedulerException e) {
-            assertThat(e.getMessage(), containsString("Unknown dependency ID"));
-            this.mockedNotificationServiceWrapper.assertNotificationsCount(0);
-            return;
-        }
-        fail("Instruction schedule should fail on unresolved dependencies");
+        final var insn = getMockedSubmitInstructionInput("mockedSubmit", "dep1");
+        final var ex = assertThrows(SchedulerException.class, () -> testedProgrammingService.scheduleInstruction(insn));
+        assertThat(ex.getMessage(), containsString("Unknown dependency ID"));
+        mockedNotificationServiceWrapper.assertNotificationsCount(0);
     }
 
     @Test
     public void testCancelInstruction() throws Exception {
         final SubmitInstructionInput mockedSubmit = getMockedSubmitInstructionInput("mockedSubmit");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit);
+        testedProgrammingService.scheduleInstruction(mockedSubmit);
         checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit.getId()));
 
         final CancelInstructionInput mockedCancel = getCancelInstruction("mockedSubmit");
-        this.testedProgrammingService.cancelInstruction(mockedCancel);
+        testedProgrammingService.cancelInstruction(mockedCancel);
 
         checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit.getId()));
-        this.mockedExecutorWrapper.assertSubmittedTasksSize(2);
+        mockedExecutorWrapper.assertSubmittedTasksSize(2);
 
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(2);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit.getId(),
-            InstructionStatus.Cancelled);
+        mockedNotificationServiceWrapper.assertNotificationsCount(2);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit.getId(),
+                InstructionStatus.Cancelled);
     }
 
     @Test
     public void testCancelDependantInstruction() throws Exception {
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
+        testedProgrammingService.scheduleInstruction(mockedSubmit1);
         final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
-            "mockedSubmit1");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
+                "mockedSubmit1");
+        testedProgrammingService.scheduleInstruction(mockedSubmit2);
         final SubmitInstructionInput mockedSubmit3 = getMockedSubmitInstructionInput("mockedSubmit3",
-            "mockedSubmit1", "mockedSubmit2");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit3);
-
-        this.testedProgrammingService.cancelInstruction(getCancelInstruction("mockedSubmit1"));
-
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(1 /*First Scheduled*/+ 3 /*First and all dependencies cancelled*/);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit1.getId(),
-            InstructionStatus.Scheduled);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
-            InstructionStatus.Cancelled);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit2.getId(),
-            InstructionStatus.Cancelled);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit3.getId(),
-            InstructionStatus.Cancelled);
+                "mockedSubmit1", "mockedSubmit2");
+        testedProgrammingService.scheduleInstruction(mockedSubmit3);
+
+        testedProgrammingService.cancelInstruction(getCancelInstruction("mockedSubmit1"));
+
+        mockedNotificationServiceWrapper
+                .assertNotificationsCount(1 /*First Scheduled*/ + 3 /*First and all dependencies cancelled*/);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit1.getId(),
+                InstructionStatus.Scheduled);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+                InstructionStatus.Cancelled);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit2.getId(),
+                InstructionStatus.Cancelled);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit3.getId(),
+                InstructionStatus.Cancelled);
 
         checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit1.getId()));
         checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit2.getId()));
@@ -201,34 +168,34 @@ public class ProgrammingServiceImplTest extends AbstractConcurrentDataBrokerTest
     @Test
     public void testCleanInstructions() throws Exception {
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
+        testedProgrammingService.scheduleInstruction(mockedSubmit1);
         final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
-            "mockedSubmit1");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
+                "mockedSubmit1");
+        testedProgrammingService.scheduleInstruction(mockedSubmit2);
 
         final CleanInstructionsInputBuilder cleanInstructionsInputBuilder = new CleanInstructionsInputBuilder();
         final CleanInstructionsInput cleanInstructionsInput = cleanInstructionsInputBuilder.setId(
-                Lists.newArrayList(mockedSubmit1.getId(), mockedSubmit2.getId())).build();
+                Set.of(mockedSubmit1.getId(), mockedSubmit2.getId())).build();
 
-        ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput = this.testedProgrammingService
-            .cleanInstructions(cleanInstructionsInput);
+        ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput = testedProgrammingService
+                .cleanInstructions(cleanInstructionsInput);
 
         assertCleanInstructionOutput(cleanedInstructionOutput, 2);
 
-        this.testedProgrammingService.cancelInstruction(getCancelInstruction("mockedSubmit1"));
+        testedProgrammingService.cancelInstruction(getCancelInstruction("mockedSubmit1"));
 
-        cleanedInstructionOutput = this.testedProgrammingService.cleanInstructions(cleanInstructionsInput);
+        cleanedInstructionOutput = testedProgrammingService.cleanInstructions(cleanInstructionsInput);
         assertCleanInstructionOutput(cleanedInstructionOutput, 0);
 
         checkNotPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit1.getId()));
         checkNotPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit2.getId()));
     }
 
-    private void assertCleanInstructionOutput(final ListenableFuture<RpcResult<CleanInstructionsOutput>>
-        cleanedInstructionOutput, final int unflushedCount) throws InterruptedException,
-        java.util.concurrent.ExecutionException {
+    private static void assertCleanInstructionOutput(final ListenableFuture<RpcResult<CleanInstructionsOutput>>
+            cleanedInstructionOutput, final int unflushedCount) throws InterruptedException,
+            java.util.concurrent.ExecutionException {
         if (unflushedCount == 0) {
-            final List<InstructionId> unflushed = cleanedInstructionOutput.get().getResult().getUnflushed();
+            final Set<InstructionId> unflushed = cleanedInstructionOutput.get().getResult().getUnflushed();
             assertTrue(unflushed == null || unflushed.isEmpty());
         } else {
             assertEquals(unflushedCount, cleanedInstructionOutput.get().getResult().getUnflushed().size());
@@ -239,89 +206,89 @@ public class ProgrammingServiceImplTest extends AbstractConcurrentDataBrokerTest
     @Test
     public void testCloseProgrammingService() throws Exception {
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
+        testedProgrammingService.scheduleInstruction(mockedSubmit1);
         final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
-            "mockedSubmit1");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
+                "mockedSubmit1");
+        testedProgrammingService.scheduleInstruction(mockedSubmit2);
 
-        this.testedProgrammingService.close();
+        testedProgrammingService.close();
 
-        this.mockedNotificationServiceWrapper
-            .assertNotificationsCount(1/* First scheduled */+ 2/* Both cancelled at close */);
+        mockedNotificationServiceWrapper
+                .assertNotificationsCount(1/* First scheduled */ + 2/* Both cancelled at close */);
     }
 
     @Test(timeout = 30 * 1000)
     public void testTimeoutWhileScheduledTransaction() throws Exception {
-        final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 *
-            INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
+        final BigInteger deadlineOffset = BigInteger.valueOf(
+                1000L * 1000 * 1000 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
         final Nanotime current = NanotimeUtil.currentTime();
-        final Nanotime deadlineNano = new Nanotime(current.getValue().add(deadlineOffset));
+        final Nanotime deadlineNano = new Nanotime(Uint64.valueOf(current.getValue().toJava().add(deadlineOffset)));
 
         final Optional<Nanotime> deadline = Optional.of(deadlineNano);
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1", deadline);
-        final ListenableFuture<Instruction> future = this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
+        final ListenableFuture<Instruction> future = testedProgrammingService.scheduleInstruction(mockedSubmit1);
 
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
+        mockedNotificationServiceWrapper.assertNotificationsCount(1);
 
         future.get();
 
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(2);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
-            InstructionStatus.Cancelled);
+        mockedNotificationServiceWrapper.assertNotificationsCount(2);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+                InstructionStatus.Cancelled);
     }
 
     @Test(timeout = 30 * 1000)
     public void testTimeoutWhileSuccessfulTransaction() throws Exception {
-        final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 *
-            INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
+        final BigInteger deadlineOffset = BigInteger.valueOf(
+                1000L * 1000 * 1000 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
         final Nanotime current = NanotimeUtil.currentTime();
-        final Nanotime deadlineNano = new Nanotime(current.getValue().add(deadlineOffset));
+        final Nanotime deadlineNano = new Nanotime(Uint64.valueOf(current.getValue().toJava().add(deadlineOffset)));
 
         final Optional<Nanotime> deadline = Optional.of(deadlineNano);
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1", deadline);
-        final ListenableFuture<Instruction> future = this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
+        final ListenableFuture<Instruction> future = testedProgrammingService.scheduleInstruction(mockedSubmit1);
 
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
+        mockedNotificationServiceWrapper.assertNotificationsCount(1);
 
         final Instruction i = future.get();
         i.checkedExecutionStart();
         i.executionCompleted(InstructionStatus.Successful, getDetails());
 
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(3);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
-            InstructionStatus.Executing);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
-            InstructionStatus.Successful);
+        mockedNotificationServiceWrapper.assertNotificationsCount(3);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+                InstructionStatus.Executing);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
+                InstructionStatus.Successful);
         // Timeout in success should not do anything
     }
 
     @Test(timeout = 30 * 1000)
     public void testTimeoutWhileExecutingWithDependenciesTransaction() throws Exception {
-        final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 *
-            INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
+        final BigInteger deadlineOffset = BigInteger.valueOf(
+                1000L * 1000 * 1000 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
         final Nanotime current = NanotimeUtil.currentTime();
-        final Nanotime deadlineNano = new Nanotime(current.getValue().add(deadlineOffset));
+        final Nanotime deadlineNano = new Nanotime(Uint64.valueOf(current.getValue().toJava().add(deadlineOffset)));
 
         final Optional<Nanotime> deadline = Optional.of(deadlineNano);
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1", deadline);
-        final ListenableFuture<Instruction> future = this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
+        final ListenableFuture<Instruction> future = testedProgrammingService.scheduleInstruction(mockedSubmit1);
 
         final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
-            "mockedSubmit1");
-        this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
+                "mockedSubmit1");
+        testedProgrammingService.scheduleInstruction(mockedSubmit2);
 
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
+        mockedNotificationServiceWrapper.assertNotificationsCount(1);
 
         final Instruction i = future.get();
         i.checkedExecutionStart();
 
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(4);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
-            InstructionStatus.Executing);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
-            InstructionStatus.Unknown);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(),
-            InstructionStatus.Cancelled);
+        mockedNotificationServiceWrapper.assertNotificationsCount(4);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+                InstructionStatus.Executing);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
+                InstructionStatus.Unknown);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(),
+                InstructionStatus.Cancelled);
     }
 
     // TODO test deadline with state Queued
@@ -329,75 +296,71 @@ public class ProgrammingServiceImplTest extends AbstractConcurrentDataBrokerTest
     @Test
     public void testSuccessExecutingWithDependenciesTransaction() throws Exception {
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
-        final ListenableFuture<Instruction> future = this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
-
-        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
-        final ListenableFuture<Instruction> future2 = this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
-
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
-
-        Instruction i = future.get();
-        i.checkedExecutionStart();
-        i.executionCompleted(InstructionStatus.Successful, getDetails());
-
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(4);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
-            InstructionStatus.Executing);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
-            InstructionStatus.Successful);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(),
-            InstructionStatus.Scheduled);
-
-        i = future2.get();
-        i.checkedExecutionStart();
-        i.executionCompleted(InstructionStatus.Successful, getDetails());
-
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(6);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(4, mockedSubmit2.getId(),
-            InstructionStatus.Executing);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(5, mockedSubmit2.getId(),
-            InstructionStatus.Successful);
+        final ListenableFuture<Instruction> future = testedProgrammingService.scheduleInstruction(mockedSubmit1);
+
+        final SubmitInstructionInput mockedSubmit2 =
+                getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+        final ListenableFuture<Instruction> future2 = testedProgrammingService.scheduleInstruction(mockedSubmit2);
+
+        mockedNotificationServiceWrapper.assertNotificationsCount(1);
+
+        Instruction instruction = future.get();
+        instruction.checkedExecutionStart();
+        instruction.executionCompleted(InstructionStatus.Successful, getDetails());
+
+        mockedNotificationServiceWrapper.assertNotificationsCount(4);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+                InstructionStatus.Executing);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
+                InstructionStatus.Successful);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(),
+                InstructionStatus.Scheduled);
+
+        instruction = future2.get();
+        instruction.checkedExecutionStart();
+        instruction.executionCompleted(InstructionStatus.Successful, getDetails());
+
+        mockedNotificationServiceWrapper.assertNotificationsCount(6);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(4, mockedSubmit2.getId(),
+                InstructionStatus.Executing);
+        mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(5, mockedSubmit2.getId(),
+                InstructionStatus.Successful);
     }
 
-    private Details getDetails() {
+    private static Details getDetails() {
         return new DetailsBuilder().build();
     }
 
-    private SubmitInstructionInput getMockedSubmitInstructionInput(final String id, final String... dependencyIds) {
+    private static SubmitInstructionInput getMockedSubmitInstructionInput(final String id,
+            final String... dependencyIds) {
         return getMockedSubmitInstructionInput(id, Optional.empty(), dependencyIds);
     }
 
-    private SubmitInstructionInput getMockedSubmitInstructionInput(final String id, final Optional<Nanotime> deadline,
-        final String... dependencyIds) {
+    private static SubmitInstructionInput getMockedSubmitInstructionInput(final String id,
+            final Optional<Nanotime> deadline, final String... dependencyIds) {
         final SubmitInstructionInput mockedSubmitInstruction = mock(SubmitInstructionInput.class);
 
-        doReturn(PcepUpdateTunnelInput.class).when(mockedSubmitInstruction).getImplementedInterface();
-        final List<InstructionId> dependencies = Lists.newArrayList();
-        for (final String dependencyId : dependencyIds) {
-            dependencies.add(getInstructionId(dependencyId));
-        }
+        final Set<InstructionId> dependencies = Arrays.stream(dependencyIds)
+            .map(InstructionId::new)
+            .collect(Collectors.toUnmodifiableSet());
 
         doReturn(dependencies).when(mockedSubmitInstruction).getPreconditions();
-        doReturn(getInstructionId(id)).when(mockedSubmitInstruction).getId();
-        doReturn(deadline.isPresent() ? deadline.get() : new Nanotime(BigInteger.valueOf(Long.MAX_VALUE)))
-            .when(mockedSubmitInstruction).getDeadline();
+        doReturn(new InstructionId(id)).when(mockedSubmitInstruction).getId();
+        doReturn(deadline.orElseGet(() -> new Nanotime(Uint64.valueOf(Long.MAX_VALUE))))
+                .when(mockedSubmitInstruction).getDeadline();
         return mockedSubmitInstruction;
     }
 
-    private CancelInstructionInput getCancelInstruction(final String instructionId) {
+    private static CancelInstructionInput getCancelInstruction(final String instructionId) {
         final CancelInstructionInputBuilder builder = new CancelInstructionInputBuilder();
-        builder.setId(getInstructionId(instructionId));
+        builder.setId(new InstructionId(instructionId));
         return builder.build();
     }
 
-    private InstructionId getInstructionId(final String id) {
-        return new InstructionId(id);
-    }
-
-    private KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.
-        rev150720.instruction.queue.Instruction, InstructionKey> buildInstructionIID(final InstructionId id) {
+    private static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming
+            .rev150720.instruction.queue.Instruction, InstructionKey> buildInstructionIID(final InstructionId id) {
         return InstanceIdentifier.builder(InstructionsQueue.class, new InstructionsQueueKey(INSTRUCTIONS_QUEUE_KEY))
-            .build().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720
-                .instruction.queue.Instruction.class, new InstructionKey(id));
+                .build().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720
+                        .instruction.queue.Instruction.class, new InstructionKey(id));
     }
 }