2 * Copyright (c) 2016, 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.applications.bulk.o.matic;
11 import static org.mockito.Mockito.doReturn;
13 import java.util.concurrent.ExecutorService;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.ArgumentMatchers;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.mdsal.binding.api.DataBroker;
22 import org.opendaylight.mdsal.binding.api.WriteTransaction;
23 import org.opendaylight.mdsal.common.api.CommitInfo;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 * Test for {@link FlowWriterSequential}.
31 @RunWith(MockitoJUnitRunner.class)
32 public class FlowWriterSequentialTest {
33 private static final int FLOWS_PER_DPN = 100;
36 private DataBroker mockDataBroker;
38 private ExecutorService mockFlowPusher;
40 private WriteTransaction writeTransaction;
42 private FlowWriterSequential flowWriterSequential;
45 public void setUp() throws Exception {
47 doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
48 doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
50 Mockito.doAnswer(invocation -> {
51 ((Runnable) invocation.getArguments()[0]).run();
53 }).when(mockFlowPusher).execute(ArgumentMatchers.<Runnable>any());
55 flowWriterSequential = new FlowWriterSequential(mockDataBroker, mockFlowPusher);
59 public void testAddFlows() throws Exception {
60 flowWriterSequential.addFlows(1, FLOWS_PER_DPN, 10, 10, (short) 0, (short) 1, true);
61 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(ArgumentMatchers.<LogicalDatastoreType>any(),
62 ArgumentMatchers.<InstanceIdentifier<DataObject>>any(), ArgumentMatchers.<DataObject>any(),
63 ArgumentMatchers.anyBoolean());
67 public void testDeleteFlows() throws Exception {
68 flowWriterSequential.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
69 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
70 .delete(ArgumentMatchers.<LogicalDatastoreType>any(),
71 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());