2 * Copyright (c) 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 TableWriterTest {
35 private static final Logger LOG = LoggerFactory.getLogger(TableWriterTest.class);
37 private static final int TABLES_PER_DPN = 100;
38 private static final int DPN_COUNT = 1;
39 private static final short START_TABLE_ID = 0;
40 private static final short END_TABLE_ID = 99;
43 private DataBroker mockDataBroker;
45 private ExecutorService mockTablePusher;
47 private WriteTransaction writeTransaction;
49 private TableWriter tableWriter;
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(mockTablePusher).execute(ArgumentMatchers.<Runnable>any());
62 tableWriter = new TableWriter(mockDataBroker, mockTablePusher);
66 public void testAddTables() throws Exception {
67 tableWriter.addTables(DPN_COUNT, START_TABLE_ID, END_TABLE_ID);
68 Mockito.verify(writeTransaction, Mockito.times(TABLES_PER_DPN))
69 .put(ArgumentMatchers.<LogicalDatastoreType>any(),
70 ArgumentMatchers.<InstanceIdentifier<DataObject>>any(), ArgumentMatchers.<DataObject>any(),
71 ArgumentMatchers.anyBoolean());
75 public void testDeleteTables() throws Exception {
76 tableWriter.deleteTables(DPN_COUNT, START_TABLE_ID, END_TABLE_ID);
77 Mockito.verify(writeTransaction, Mockito.times(TABLES_PER_DPN))
78 .delete(ArgumentMatchers.<LogicalDatastoreType>any(),
79 ArgumentMatchers.<InstanceIdentifier<DataObject>>any());