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.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 * Test for {@link FlowWriterSequential}.
30 @RunWith(MockitoJUnitRunner.class)
31 public class FlowWriterSequentialTest {
32 private static final int FLOWS_PER_DPN = 100;
35 private DataBroker mockDataBroker;
37 private ExecutorService mockFlowPusher;
39 private WriteTransaction writeTransaction;
41 private FlowWriterSequential flowWriterSequential;
46 doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
47 doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
49 Mockito.doAnswer(invocation -> {
50 ((Runnable) invocation.getArguments()[0]).run();
52 }).when(mockFlowPusher).execute(ArgumentMatchers.any());
54 flowWriterSequential = new FlowWriterSequential(mockDataBroker, mockFlowPusher);
58 public void testAddFlows() {
59 flowWriterSequential.addFlows(1, FLOWS_PER_DPN, 10, 10, (short) 0, (short) 1, true);
60 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).mergeParentStructurePut(ArgumentMatchers.any(),
61 ArgumentMatchers.any(), ArgumentMatchers.any());
65 public void testDeleteFlows() {
66 flowWriterSequential.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
67 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
68 .delete(ArgumentMatchers.any(),
69 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());