* 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();
<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>
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;
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;
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")
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);
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);
cancelTimeout();
// We reuse the preconditions set down in this class
- result = new ExecutionResult<Details>(status, details);
+ result = new ExecutionResult<>(status, details);
setStatus(status, details);
}
}
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();
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;
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;
});
}
- 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
}
}
- 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);
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"/>
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());
}
}
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;
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;
}
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);
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;
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;
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";
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);
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);
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
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,
}
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 + "]";
}
}
}
public final Failure getFailure() {
- return failure;
+ return this.failure;
}
}
}
public static <T> SuccessfulRpcResult<T> create(final T value) {
- return new SuccessfulRpcResult<T>(value);
+ return new SuccessfulRpcResult<>(value);
}
@Override
@Override
public T getResult() {
- return value;
+ return this.value;
}
@Override