2 * Copyright (c) 2016 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.Matchers;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.invocation.InvocationOnMock;
22 import org.mockito.runners.MockitoJUnitRunner;
23 import org.mockito.stubbing.Answer;
24 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
25 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
26 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
28 import org.opendaylight.yangtools.yang.binding.DataObject;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * Test for {@link FlowWriterConcurrent}.
36 @RunWith(MockitoJUnitRunner.class)
37 public class FlowWriterConcurrentTest {
39 private static final Logger LOG = LoggerFactory.getLogger(FlowWriterConcurrentTest.class);
40 private static final int FLOWS_PER_DPN = 100;
43 private DataBroker mockDataBroker;
45 private ExecutorService mockFlowPusher;
47 private WriteTransaction wTx;
49 private Nodes mockNodes;
51 private FlowWriterConcurrent flowWriterConcurrent;
54 public void setUp() throws Exception {
56 doReturn(wTx).when(mockDataBroker).newWriteOnlyTransaction();
57 Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
59 Mockito.doAnswer(new Answer<Void>() {
61 public Void answer(InvocationOnMock invocation) throws Throwable {
62 ((Runnable)invocation.getArguments()[0]).run();
65 }).when(mockFlowPusher).execute(Matchers.<Runnable>any());
67 flowWriterConcurrent = new FlowWriterConcurrent(mockDataBroker, mockFlowPusher);
70 public void testAddFlows() throws Exception {
71 flowWriterConcurrent.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short)0, (short)1);
72 Mockito.verify(wTx, Mockito.times(FLOWS_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
76 public void testDeleteFlows() throws Exception {
77 flowWriterConcurrent.deleteFlows(1, FLOWS_PER_DPN, 10, (short)0, (short)1);
78 Mockito.verify(wTx, Mockito.times(FLOWS_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any());