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.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * Test for {@link FlowWriterConcurrent}.
34 @RunWith(MockitoJUnitRunner.class)
35 public class FlowWriterConcurrentTest {
37 private static final Logger LOG = LoggerFactory.getLogger(FlowWriterConcurrentTest.class);
38 private static final int FLOWS_PER_DPN = 100;
41 private DataBroker mockDataBroker;
43 private ExecutorService mockFlowPusher;
45 private WriteTransaction writeTransaction;
47 private Nodes mockNodes;
49 private FlowWriterConcurrent flowWriterConcurrent;
52 public void setUp() throws Exception {
54 doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
55 Mockito.when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
57 Mockito.doAnswer(invocation -> {
58 ((Runnable) invocation.getArguments()[0]).run();
60 }).when(mockFlowPusher).execute(ArgumentMatchers.<Runnable>any());
62 flowWriterConcurrent = new FlowWriterConcurrent(mockDataBroker, mockFlowPusher);
66 public void testAddFlows() throws Exception {
67 flowWriterConcurrent.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short) 0, (short) 1, true);
68 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(ArgumentMatchers.<LogicalDatastoreType>any(),
69 ArgumentMatchers.<InstanceIdentifier<DataObject>>any(), ArgumentMatchers.<DataObject>any(),
70 ArgumentMatchers.anyBoolean());
74 public void testDeleteFlows() throws Exception {
75 flowWriterConcurrent.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
76 Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN))
77 .delete(ArgumentMatchers.<LogicalDatastoreType>any(),
78 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());