2 * Copyright (c) 2016 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 com.google.common.util.concurrent.MoreExecutors;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.DependencyQueue;
15 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.DependentJob;
16 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.HwvtepOperationalState;
17 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.McastMacsRemoteUpdateCommand;
18 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.UnMetDependencyGetter;
19 import org.opendaylight.ovsdb.lib.notation.UUID;
20 import org.opendaylight.ovsdb.lib.operations.Operations;
21 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
29 import org.opendaylight.yangtools.yang.binding.Identifiable;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.powermock.core.classloader.annotations.PrepareForTest;
32 import org.powermock.modules.junit4.PowerMockRunner;
33 import org.powermock.reflect.Whitebox;
35 import java.util.List;
37 import java.util.concurrent.CountDownLatch;
39 import static org.junit.Assert.assertEquals;
40 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
42 @RunWith(PowerMockRunner.class)
43 @PrepareForTest({HwvtepConnectionInstance.class, HwvtepConnectionManager.class, Operations.class, DependencyQueue.class})
44 public class DependencyQueueTest extends DataChangeListenerTestBase {
46 String[][] terminationPoints = new String[][]{
51 UnMetDependencyGetter<RemoteMcastMacs> MCAST_MAC_DATA_VALIDATOR;
52 HwvtepOperationalState opState;
54 InstanceIdentifier<RemoteMcastMacs> macIid;
55 InstanceIdentifier<LogicalSwitches> lsIid;
56 Map<Class<? extends Identifiable>, List<InstanceIdentifier>> unMetDependencies;
59 MCAST_MAC_DATA_VALIDATOR = Whitebox.getInternalState(McastMacsRemoteUpdateCommand.class, UnMetDependencyGetter.class);
60 opState = new HwvtepOperationalState(connectionInstance);
61 mac = TestBuilders.buildRemoteMcastMacs(nodeIid,"FF:FF:FF:FF:FF:FF", "ls0",
62 new String[]{"192.168.122.20", "192.168.122.30"});
63 lsIid = nodeIid.augmentation(HwvtepGlobalAugmentation.class).
64 child(LogicalSwitches.class, new LogicalSwitchesKey(new HwvtepNodeName("ls0")));
65 macIid = nodeIid.augmentation(HwvtepGlobalAugmentation.class).
66 child(RemoteMcastMacs.class, new RemoteMcastMacsKey(mac.getKey()));
67 Whitebox.setInternalState(DependencyQueue.class, "executorService", MoreExecutors.sameThreadExecutor());
71 public void testLogicalSwitchConfigDependency() throws Exception {
73 unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getUnMetConfigDependencies(opState, mac);
74 unMetDependencies.remove(TerminationPoint.class);
76 final CountDownLatch latch = new CountDownLatch(1);
77 opState.getDeviceInfo().addJobToQueue(new DependentJob.ConfigWaitingJob(macIid, mac, unMetDependencies) {
79 protected void onDependencyResolved(HwvtepOperationalState operationalState, TransactionBuilder transactionBuilder) {
83 assertEquals(1, latch.getCount());
84 addData(CONFIGURATION, LogicalSwitches.class, new String[]{"ls0", "100"});
85 addData(CONFIGURATION, TerminationPoint.class, terminationPoints);
86 assertEquals(0, latch.getCount());
90 public void testLogicalSwitchInTransitDependency() throws Exception {
92 opState.getDeviceInfo().markKeyAsInTransit(LogicalSwitches.class, lsIid);
93 unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getInTransitDependencies(opState, mac);
95 final CountDownLatch latch = new CountDownLatch(1);
96 opState.getDeviceInfo().addJobToQueue(new DependentJob.OpWaitingJob<RemoteMcastMacs>(macIid, mac, unMetDependencies) {
98 protected void onDependencyResolved(HwvtepOperationalState operationalState, TransactionBuilder transactionBuilder) {
102 opState.getDeviceInfo().onOpDataAvailable();
103 assertEquals(1, latch.getCount());
105 opState.getDeviceInfo().updateDeviceOpData(LogicalSwitches.class, lsIid, new UUID("ls0"), "ls0");
106 opState.getDeviceInfo().onOpDataAvailable();
107 assertEquals(0, latch.getCount());