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 com.google.common.util.concurrent.Futures;
14 import java.util.concurrent.ExecutorService;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.ArgumentMatchers;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.runners.MockitoJUnitRunner;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Test for {@link FlowWriterSequential}.
33 @RunWith(MockitoJUnitRunner.class)
34 public class FlowWriterSequentialTest {
36 private static final Logger LOG = LoggerFactory.getLogger(FlowWriterSequentialTest.class);
37 private static final int FLOWS_PER_DPN = 100;
40 private DataBroker mockDataBroker;
42 private ExecutorService mockFlowPusher;
44 private WriteTransaction writeTransaction;
46 private FlowWriterSequential flowWriterSequential;
49 public void setUp() throws Exception {
51 doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
52 Mockito.when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
54 Mockito.doAnswer(invocation -> {
55 ((Runnable) invocation.getArguments()[0]).run();
57 }).when(mockFlowPusher).execute(ArgumentMatchers.<Runnable>any());
59 flowWriterSequential = new FlowWriterSequential(mockDataBroker, mockFlowPusher);
63 public void testAddFlows() throws Exception {
64 flowWriterSequential.addFlows(1, FLOWS_PER_DPN, 10, 10, (short) 0, (short) 1, true);
65 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(ArgumentMatchers.<LogicalDatastoreType>any(),
66 ArgumentMatchers.<InstanceIdentifier<DataObject>>any(), ArgumentMatchers.<DataObject>any(),
67 ArgumentMatchers.anyBoolean());
71 public void testDeleteFlows() throws Exception {
72 flowWriterSequential.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
73 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
74 .delete(ArgumentMatchers.<LogicalDatastoreType>any(),
75 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());