2 * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. 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.ovsdb.hwvtepsouthbound;
11 import static org.junit.Assert.assertEquals;
13 import java.util.List;
15 import java.util.concurrent.CountDownLatch;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mockito;
19 import org.mockito.junit.MockitoJUnitRunner;
20 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
21 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.DependencyQueue;
22 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.DependentJob;
23 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.HwvtepOperationalState;
24 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.McastMacsRemoteUpdateCommand;
25 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.UnMetDependencyGetter;
26 import org.opendaylight.ovsdb.lib.notation.UUID;
27 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey;
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
35 import org.opendaylight.yangtools.yang.binding.Identifiable;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.powermock.reflect.Whitebox;
39 @RunWith(MockitoJUnitRunner.Silent.class)
40 public class DependencyQueueTest extends DataChangeListenerTestBase {
42 String[][] terminationPoints = new String[][]{
47 UnMetDependencyGetter<RemoteMcastMacs> mcastMacDataValidator;
48 HwvtepOperationalState opState;
50 InstanceIdentifier<RemoteMcastMacs> macIid;
51 InstanceIdentifier<LogicalSwitches> lsIid;
52 Map<Class<? extends Identifiable>, List<InstanceIdentifier>> unMetDependencies;
54 void setupForTest() throws Exception {
55 mcastMacDataValidator = Whitebox.getInternalState(McastMacsRemoteUpdateCommand.class,
56 UnMetDependencyGetter.class);
57 opState = new HwvtepOperationalState(connectionInstance);
58 mac = TestBuilders.buildRemoteMcastMacs(nodeIid,"FF:FF:FF:FF:FF:FF", "ls0",
59 new String[]{"192.168.122.20", "192.168.122.30"});
60 lsIid = nodeIid.augmentation(HwvtepGlobalAugmentation.class)
61 .child(LogicalSwitches.class, new LogicalSwitchesKey(new HwvtepNodeName("ls0")));
62 macIid = nodeIid.augmentation(HwvtepGlobalAugmentation.class)
63 .child(RemoteMcastMacs.class, new RemoteMcastMacsKey(mac.key()));
64 setFinalStatic(DependencyQueue.class, "EXECUTOR_SERVICE", Mockito.mock(SameThreadScheduledExecutor.class,
65 Mockito.CALLS_REAL_METHODS));
69 public void testLogicalSwitchConfigDependency() throws Exception {
71 unMetDependencies = mcastMacDataValidator.getUnMetConfigDependencies(opState, mac);
72 unMetDependencies.remove(TerminationPoint.class);
74 final CountDownLatch latch = new CountDownLatch(1);
75 opState.getDeviceInfo().addJobToQueue(new DependentJob.ConfigWaitingJob(macIid, mac, unMetDependencies) {
77 protected void onDependencyResolved(HwvtepOperationalState operationalState,
78 TransactionBuilder transactionBuilder) {
82 assertEquals(1, latch.getCount());
83 addData(LogicalDatastoreType.CONFIGURATION, LogicalSwitches.class, new String[]{"ls0", "100"});
84 addData(LogicalDatastoreType.CONFIGURATION, TerminationPoint.class, terminationPoints);
85 assertEquals(0, latch.getCount());
89 public void testLogicalSwitchInTransitDependency() throws Exception {
91 opState.getDeviceInfo().markKeyAsInTransit(LogicalSwitches.class, lsIid);
92 unMetDependencies = mcastMacDataValidator.getInTransitDependencies(opState, mac);
94 final CountDownLatch latch = new CountDownLatch(1);
95 opState.getDeviceInfo().addJobToQueue(new DependentJob.OpWaitingJob<RemoteMcastMacs>(
96 macIid, mac, (Map)unMetDependencies, 0) {
98 protected void onDependencyResolved(HwvtepOperationalState operationalState,
99 TransactionBuilder transactionBuilder) {
103 opState.getDeviceInfo().onOperDataAvailable();
104 assertEquals(1, latch.getCount());
106 opState.getDeviceInfo().updateDeviceOperData(LogicalSwitches.class, lsIid, new UUID("ls0"), "ls0");
107 opState.getDeviceInfo().onOperDataAvailable();
108 //wait for sometime so that the onDependencyResolved is triggered
110 assertEquals(0, latch.getCount());