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
8 package org.opendaylight.openflowplugin.applications.bulk.o.matic;
10 import static org.mockito.Mockito.doReturn;
12 import java.util.concurrent.ExecutorService;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.ArgumentMatchers;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.junit.MockitoJUnitRunner;
20 import org.opendaylight.mdsal.binding.api.DataBroker;
21 import org.opendaylight.mdsal.binding.api.WriteTransaction;
22 import org.opendaylight.mdsal.common.api.CommitInfo;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 * Test for {@link FlowWriterConcurrent}.
30 @RunWith(MockitoJUnitRunner.class)
31 public class FlowWriterConcurrentTest {
32 private static final int FLOWS_PER_DPN = 100;
35 private DataBroker mockDataBroker;
37 private ExecutorService mockFlowPusher;
39 private WriteTransaction writeTransaction;
41 private Nodes mockNodes;
43 private FlowWriterConcurrent flowWriterConcurrent;
48 doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
49 doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
51 Mockito.doAnswer(invocation -> {
52 ((Runnable) invocation.getArguments()[0]).run();
54 }).when(mockFlowPusher).execute(ArgumentMatchers.any());
56 flowWriterConcurrent = new FlowWriterConcurrent(mockDataBroker, mockFlowPusher);
60 public void testAddFlows() {
61 flowWriterConcurrent.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short) 0, (short) 1, true);
62 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).mergeParentStructurePut(ArgumentMatchers.any(),
63 ArgumentMatchers.any(), ArgumentMatchers.any());
67 public void testDeleteFlows() {
68 flowWriterConcurrent.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
69 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
70 .delete(ArgumentMatchers.any(),
71 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());