diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-08-15 10:15:06 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-08-16 05:37:09 +0000 |
commit | b1b07f942fd77b7d987cc44aabd492db5e8c29a0 (patch) | |
tree | bca9afe1e431c7287600c6fd5daa851dc70d3967 /v3po/v3po2vpp/src/test/java/io/fd | |
parent | be31f4746e6ee61dbe448ce0d49b8236bdbcc6f8 (diff) |
HC2VPP-205 / HC2VPP-25 - Sub interface caching improvement
Improves dumping mechanism for sub interfaces in a way
that if full dump was already performed,
it will be used from cache instead of new dump call.
Also prevents creating dump dto's if not necessary
Change-Id: I46a305ec1b325c2d949bff9e2b151752ccd508b6
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd')
12 files changed, 418 insertions, 196 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java index a681706f7..e53fccdab 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java @@ -16,15 +16,20 @@ package io.fd.hc2vpp.v3po.interfacesstate; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; import org.junit.Test; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; @@ -34,18 +39,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.Ethernet; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.EthernetBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; public class EthernetCustomizerTest extends ReaderCustomizerTest<Ethernet, EthernetBuilder> implements - InterfaceDumpHelper { + InterfaceDumpHelper { private static final String IFC_CTX_NAME = "ifc-test-instance"; private static final String IF_NAME = "local0"; private static final int IF_INDEX = 1; private static final InstanceIdentifier<Ethernet> IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(Ethernet.class); + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceStateAugmentation.class).child(Ethernet.class); private NamingContext interfaceContext; + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + public EthernetCustomizerTest() { super(Ethernet.class, VppInterfaceStateAugmentationBuilder.class); } @@ -58,15 +65,16 @@ public class EthernetCustomizerTest extends ReaderCustomizerTest<Ethernet, Ether @Override protected ReaderCustomizer<Ethernet, EthernetBuilder> initCustomizer() { - return new EthernetCustomizer(api, interfaceContext); + return new EthernetCustomizer(dumpCacheManager); } - private void testRead(final int linkDuplex, final EthernetStateAttributes.Duplex duplex) throws ReadFailedException { + private void testRead(final int linkDuplex, final EthernetStateAttributes.Duplex duplex) + throws ReadFailedException { final EthernetBuilder builder = mock(EthernetBuilder.class); final short mtu = 123; - whenSwInterfaceDumpThenReturn(api, ifaceDetails(mtu, linkDuplex)); + when(dumpCacheManager.getInterfaceDetail(any(), any(), any())).thenReturn(ifaceDetails(mtu, linkDuplex)); getCustomizer().readCurrentAttributes(IID, builder, ctx); - verify(builder).setMtu((int)mtu); + verify(builder).setMtu((int) mtu); verify(builder).setDuplex(duplex); } @@ -74,7 +82,7 @@ public class EthernetCustomizerTest extends ReaderCustomizerTest<Ethernet, Ether final SwInterfaceDetails details = new SwInterfaceDetails(); details.swIfIndex = IF_INDEX; details.linkMtu = mtu; - details.linkDuplex = (byte)duplex; + details.linkDuplex = (byte) duplex; return details; } diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java index 76e1b0a3e..806da6858 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java @@ -23,16 +23,23 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; import com.google.common.collect.Lists; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.vpp.jvpp.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.GreTunnelDetails; +import io.fd.vpp.jvpp.core.dto.GreTunnelDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.GreTunnelDump; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Map; import org.junit.Test; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; @@ -41,11 +48,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.Gre; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.GreBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.GreTunnelDetails; -import io.fd.vpp.jvpp.core.dto.GreTunnelDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.GreTunnelDump; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; public class GreCustomizerTest extends ReaderCustomizerTest<Gre, GreBuilder> { @@ -55,23 +57,25 @@ public class GreCustomizerTest extends ReaderCustomizerTest<Gre, GreBuilder> { private NamingContext interfacesContext; static final InstanceIdentifier<Gre> IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(Gre.class); + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceStateAugmentation.class).child(Gre.class); + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; public GreCustomizerTest() { super(Gre.class, VppInterfaceStateAugmentationBuilder.class); } @Override - public void setUp() throws UnknownHostException, VppInvocationException { + public void setUp() throws UnknownHostException, VppInvocationException, ReadFailedException { interfacesContext = new NamingContext("gre-tunnel", IFC_CTX_NAME); defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); final SwInterfaceDetails v = new SwInterfaceDetails(); v.interfaceName = "gre-tunnel4".getBytes(); - final Map<Integer, SwInterfaceDetails> map = new HashMap<>(); - map.put(0, v); - cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map); + + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IFACE_NAME)).thenReturn(v); final GreTunnelDetailsReplyDump value = new GreTunnelDetailsReplyDump(); final GreTunnelDetails greTunnelDetails = new GreTunnelDetails(); @@ -103,29 +107,20 @@ public class GreCustomizerTest extends ReaderCustomizerTest<Gre, GreBuilder> { verify(api).greTunnelDump(any(GreTunnelDump.class)); } - @Test(expected = NullPointerException.class) - public void testReadCurrentAttributesVppNameNotCached() throws Exception { - InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0); - - final GreBuilder builder = getCustomizer().getBuilder(IID); - getCustomizer().readCurrentAttributes(IID, builder, ctx); - } - @Test public void testReadCurrentAttributesWrongType() throws Exception { final SwInterfaceDetails v = new SwInterfaceDetails(); v.interfaceName = "tap-2".getBytes(); - InterfaceCustomizer.getCachedInterfaceDump(cache).put(0, v); + + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IFACE_NAME)).thenReturn(v); final GreBuilder builder = getCustomizer().getBuilder(IID); getCustomizer().readCurrentAttributes(IID, builder, ctx); - - // Should be ignored verifyZeroInteractions(api); } @Override protected ReaderCustomizer<Gre, GreBuilder> initCustomizer() { - return new GreCustomizer(api, interfacesContext); + return new GreCustomizer(api, interfacesContext, dumpCacheManager); } }
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java index 2f8a30b84..d8fa719ff 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java @@ -17,20 +17,24 @@ package io.fd.hc2vpp.v3po.interfacesstate; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDump; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; import org.junit.Test; import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; @@ -39,12 +43,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDump; public class InterfaceCustomizerTest extends ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> - implements InterfaceDataTranslator, InterfaceDumpHelper { + implements InterfaceDataTranslator, InterfaceDumpHelper { private static final String IFC_CTX_NAME = "ifc-test-instance"; private static final String IFACE0_NAME = "eth0"; @@ -57,6 +58,8 @@ public class InterfaceCustomizerTest extends ListReaderCustomizerTest<Interface, private NamingContext interfacesContext; @Mock private DisabledInterfacesManager interfaceDisableContext; + @Mock + private InterfaceCacheDumpManager dumpCacheManager; public InterfaceCustomizerTest() { super(Interface.class, InterfacesStateBuilder.class); @@ -72,16 +75,7 @@ public class InterfaceCustomizerTest extends ListReaderCustomizerTest<Interface, @Override protected ReaderCustomizer<Interface, InterfaceBuilder> initCustomizer() { - return new InterfaceCustomizer(api, interfacesContext, interfaceDisableContext); - } - - private void verifySwInterfaceDumpWasInvoked(final int nameFilterValid, final String ifaceName, - final int dumpIfcsInvocationCount) - throws VppInvocationException { - final SwInterfaceDump expected = new SwInterfaceDump(); - expected.nameFilterValid = (byte) nameFilterValid; - expected.nameFilter = ifaceName.getBytes(); - verify(api, times(dumpIfcsInvocationCount)).swInterfaceDump(expected); + return new InterfaceCustomizer(interfacesContext, interfaceDisableContext, dumpCacheManager); } private void assertIfacesAreEqual(final Interface iface, final SwInterfaceDetails details) { @@ -102,31 +96,16 @@ public class InterfaceCustomizerTest extends ListReaderCustomizerTest<Interface, iface.linkSpeed = 1; iface.l2AddressLength = 6; iface.l2Address = new byte[iface.l2AddressLength]; - whenSwInterfaceDumpThenReturn(api, iface); + when(dumpCacheManager.getInterfaceDetail(id, ctx, IFACE0_NAME)).thenReturn(iface); getCustomizer().readCurrentAttributes(id, builder, ctx); - verifySwInterfaceDumpWasInvoked(1, IFACE0_NAME, 1); - assertIfacesAreEqual(builder.build(), iface); - } + final SwInterfaceDump request = new SwInterfaceDump(); + request.nameFilter = IFACE0_NAME.getBytes(); + request.nameFilterValid = 1; - @Test - public void testReadCurrentAttributesFailed() throws Exception { - final String ifaceName = IFACE0_NAME; - final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(ifaceName)); - final InterfaceBuilder builder = getCustomizer().getBuilder(id); - - whenSwInterfaceDumpThenReturn(api); - - try { - getCustomizer().readCurrentAttributes(id, builder, ctx); - } catch (IllegalArgumentException e) { - verifySwInterfaceDumpWasInvoked(0, ifaceName, 2); - return; - } - - fail("ReadFailedException was expected"); + assertIfacesAreEqual(builder.build(), iface); + verify(dumpCacheManager, times(1)).getInterfaceDetail(id, ctx, IFACE0_NAME); } @Test @@ -140,12 +119,16 @@ public class InterfaceCustomizerTest extends ListReaderCustomizerTest<Interface, iface.swIfIndex = 2; iface.supSwIfIndex = 1; iface.subId = 1; - whenSwInterfaceDumpThenReturn(api, iface); + when(dumpCacheManager.getInterfaceDetail(id, ctx, SUB_IFACE_NAME)).thenReturn(iface); getCustomizer().readCurrentAttributes(id, builder, ctx); - verifySwInterfaceDumpWasInvoked(1, SUB_IFACE_NAME, 1); + final SwInterfaceDump request = new SwInterfaceDump(); + request.nameFilter = SUB_IFACE_NAME.getBytes(); + request.nameFilterValid = 1; + verifyZeroInteractions(builder); + verify(dumpCacheManager, times(1)).getInterfaceDetail(id, ctx, SUB_IFACE_NAME); } @Test @@ -166,16 +149,19 @@ public class InterfaceCustomizerTest extends ListReaderCustomizerTest<Interface, swSubIf1.subId = 1; swSubIf1.supSwIfIndex = 1; swSubIf1.interfaceName = SUB_IFACE_NAME.getBytes(); - whenSwInterfaceDumpThenReturn(api, swIf0, swIf1, swSubIf1); + when(dumpCacheManager.getInterfaces(id, ctx)).thenReturn(Stream.of(swIf0, swIf1, swSubIf1)); final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME), new InterfaceKey( IFACE1_NAME)); final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx); - verifySwInterfaceDumpWasInvoked(0, "", 1); + final SwInterfaceDump request = new SwInterfaceDump(); + request.nameFilter = "".getBytes(); + request.nameFilterValid = 0; // sub-interface should not be on the list assertEquals(expectedIds, actualIds); + verify(dumpCacheManager, times(1)).getInterfaces(id, ctx); } @Test @@ -191,12 +177,13 @@ public class InterfaceCustomizerTest extends ListReaderCustomizerTest<Interface, final SwInterfaceDetails swIf1 = new SwInterfaceDetails(); swIf1.swIfIndex = 1; swIf1.interfaceName = IFACE1_NAME.getBytes(); - whenSwInterfaceDumpThenReturn(api, swIf0, swIf1); + when(dumpCacheManager.getInterfaces(id, ctx)).thenReturn(Stream.of(swIf0, swIf1)); final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME)); final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx); // disabled interface should not be on the list assertEquals(expectedIds, actualIds); + verify(dumpCacheManager, times(1)).getInterfaces(id, ctx); } } diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java index 63cb3d972..53934ff80 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java @@ -23,6 +23,7 @@ import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; @@ -34,6 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.Test; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; @@ -52,6 +54,9 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> { private NamingContext interfaceContext; private NamingContext bridgeDomainContext; + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + public L2CustomizerTest() { super(L2.class, VppInterfaceStateAugmentationBuilder.class); } @@ -64,13 +69,13 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> { @Override protected ReaderCustomizer<L2, L2Builder> initCustomizer() { - return new L2Customizer(api, interfaceContext, bridgeDomainContext); + return new L2Customizer(api, interfaceContext, bridgeDomainContext, dumpCacheManager); } private InstanceIdentifier<L2> getL2Id(final String name) { return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)) - .augmentation( - VppInterfaceStateAugmentation.class).child(L2.class); + .augmentation( + VppInterfaceStateAugmentation.class).child(L2.class); } private void whenBridgeDomainDumpThenReturn(final List<BridgeDomainDetails> bridgeDomainDetails) { @@ -101,7 +106,6 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> { @Test public void testRead() throws Exception { - final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>(); final int ifId = 1; final int bdId = 1; final String bdName = "bd001"; @@ -111,8 +115,6 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> { final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); ifaceDetails.subId = ifId; - cachedInterfaceDump.put(ifId, ifaceDetails); - cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump); // BVIinterfaceContext whenBridgeDomainDumpThenReturn(Collections.singletonList(generateBdDetails(ifId, ifId, bdId))); @@ -124,7 +126,7 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> { // Not BVI whenBridgeDomainDumpThenReturn(Collections - .singletonList(generateBdDetails(ifId, 99 /* Different ifc is marked as BVI in bd details */, bdId))); + .singletonList(generateBdDetails(ifId, 99 /* Different ifc is marked as BVI in bd details */, bdId))); builder = mock(L2Builder.class); getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx); @@ -136,7 +138,7 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> { final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails(); bridgeDomainDetails.bviSwIfIndex = bviSwIfIndex; bridgeDomainDetails.bdId = bdId; - bridgeDomainDetails.swIfDetails = new BridgeDomainSwIf[] {generateBdSwIfDetails(ifId)}; + bridgeDomainDetails.swIfDetails = new BridgeDomainSwIf[]{generateBdSwIfDetails(ifId)}; return bridgeDomainDetails; } }
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java index dc748fe45..887b3e3e6 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java @@ -19,19 +19,20 @@ package io.fd.hc2vpp.v3po.interfacesstate; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.common.translate.util.TagRewriteOperation; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; @@ -40,9 +41,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.interfaces.state._interface.SubInterfaces; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.interfaces.state._interface.sub.interfaces.SubInterface; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.sub._interface.l2.state.attributes.L2Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.rewrite.attributes.Rewrite; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.rewrite.attributes.RewriteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.sub._interface.l2.state.attributes.L2Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.tag.rewrite.PushTags; import org.opendaylight.yangtools.yang.binding.ChildOf; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -60,6 +61,9 @@ public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, Rewrite @Captor private ArgumentCaptor<List<PushTags>> captor; + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + public RewriteCustomizerTest() { super(Rewrite.class, L2Builder.class); } @@ -72,14 +76,15 @@ public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, Rewrite @Override protected ReaderCustomizer<Rewrite, RewriteBuilder> initCustomizer() { - return new RewriteCustomizer(api, interfacesContext); + return new RewriteCustomizer(dumpCacheManager); } private InstanceIdentifier<Rewrite> getVlanTagRewriteId(final String name, final long index) { - final Class<ChildOf<? super SubInterface>> child = (Class)Rewrite.class; + final Class<ChildOf<? super SubInterface>> child = (Class) Rewrite.class; final InstanceIdentifier id = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation( - SubinterfaceStateAugmentation.class).child(SubInterfaces.class) + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)) + .augmentation( + SubinterfaceStateAugmentation.class).child(SubInterfaces.class) .child(SubInterface.class, new SubInterfaceKey(index)) .child(child); return id; @@ -87,8 +92,6 @@ public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, Rewrite @Test public void testRead() throws ReadFailedException { - final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>(); - final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); ifaceDetails.subId = VLAN_ID; ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes(); @@ -97,14 +100,13 @@ public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, Rewrite ifaceDetails.vtrTag1 = 123; ifaceDetails.vtrTag2 = 321; ifaceDetails.vtrPushDot1Q = 1; - ifaceDetails.swIfIndex= VLAN_IF_INDEX; + ifaceDetails.swIfIndex = VLAN_IF_INDEX; ifaceDetails.supSwIfIndex = 2; - cachedInterfaceDump.put(VLAN_IF_INDEX, ifaceDetails); - cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump); final RewriteBuilder builder = mock(RewriteBuilder.class); - - getCustomizer().readCurrentAttributes(getVlanTagRewriteId(IF_NAME, VLAN_ID), builder, ctx); + final InstanceIdentifier<Rewrite> vlanTagRewriteId = getVlanTagRewriteId(IF_NAME, VLAN_ID); + when(dumpCacheManager.getInterfaceDetail(vlanTagRewriteId, ctx, VLAN_IF_NAME)).thenReturn(ifaceDetails); + getCustomizer().readCurrentAttributes(vlanTagRewriteId, builder, ctx); verify(builder).setVlanType(_802dot1q.class); verify(builder).setPopTags((short) 2); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java index 32e351e66..c20e21892 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java @@ -20,18 +20,20 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.stream.Stream; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; @@ -46,8 +48,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.sub._interface.base.attributes.Tags; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -public class SubInterfaceCustomizerTest extends ListReaderCustomizerTest<SubInterface, SubInterfaceKey, SubInterfaceBuilder> implements - InterfaceDumpHelper { +public class SubInterfaceCustomizerTest + extends ListReaderCustomizerTest<SubInterface, SubInterfaceKey, SubInterfaceBuilder> implements + InterfaceDumpHelper { private static final String IFC_CTX_NAME = "ifc-test-instance"; private static final String SUPER_IF_NAME = "local0"; @@ -58,6 +61,9 @@ public class SubInterfaceCustomizerTest extends ListReaderCustomizerTest<SubInte private NamingContext interfacesContext; + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + public SubInterfaceCustomizerTest() { super(SubInterface.class, SubInterfacesBuilder.class); } @@ -71,18 +77,18 @@ public class SubInterfaceCustomizerTest extends ListReaderCustomizerTest<SubInte @Override protected ReaderCustomizer<SubInterface, SubInterfaceBuilder> initCustomizer() { - return new SubInterfaceCustomizer(api, interfacesContext); + return new SubInterfaceCustomizer(api, interfacesContext, dumpCacheManager); } private InstanceIdentifier<SubInterface> getSubInterfaceId(final String name, final long id) { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation( - SubinterfaceStateAugmentation.class).child( - SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(id)); + return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)) + .augmentation( + SubinterfaceStateAugmentation.class).child( + SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(id)); } @Test public void testRead() throws ReadFailedException { - final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>(); final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); ifaceDetails.subId = VLAN_IF_ID; @@ -95,11 +101,12 @@ public class SubInterfaceCustomizerTest extends ListReaderCustomizerTest<SubInte ifaceDetails.subOuterVlanIdAny = 1; ifaceDetails.subInnerVlanIdAny = 1; ifaceDetails.subExactMatch = 1; - cachedInterfaceDump.put(VLAN_IF_INDEX, ifaceDetails); - cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump); final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class); - getCustomizer().readCurrentAttributes(getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID), builder, ctx); + final InstanceIdentifier<SubInterface> subInterfaceId = getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID); + + when(dumpCacheManager.getInterfaceDetail(subInterfaceId, ctx, VLAN_IF_NAME)).thenReturn(ifaceDetails); + getCustomizer().readCurrentAttributes(subInterfaceId, builder, ctx); verify(builder).setIdentifier((long) VLAN_IF_ID); @@ -109,7 +116,7 @@ public class SubInterfaceCustomizerTest extends ListReaderCustomizerTest<SubInte ArgumentCaptor<Match> matchCaptor = ArgumentCaptor.forClass(Match.class); verify(builder).setMatch(matchCaptor.capture()); - final VlanTagged matchType = (VlanTagged)matchCaptor.getValue().getMatchType(); + final VlanTagged matchType = (VlanTagged) matchCaptor.getValue().getMatchType(); assertTrue(matchType.getVlanTagged().isMatchExactTags()); } @@ -120,10 +127,11 @@ public class SubInterfaceCustomizerTest extends ListReaderCustomizerTest<SubInte iface.swIfIndex = VLAN_IF_INDEX; iface.subId = VLAN_IF_ID; iface.supSwIfIndex = SUPER_IF_INDEX; - whenSwInterfaceDumpThenReturn(api, iface); + final InstanceIdentifier<SubInterface> subInterfaceId = getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID); + when(dumpCacheManager.getInterfaces(subInterfaceId, ctx)).thenReturn(Stream.of(iface)); final List<SubInterfaceKey> allIds = - getCustomizer().getAllIds(getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID), ctx); + getCustomizer().getAllIds(subInterfaceId, ctx); assertEquals(1, allIds.size()); } diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java index 39aefb3b3..ebdf30170 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java @@ -22,9 +22,11 @@ import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import org.junit.Test; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; @@ -50,9 +52,13 @@ public class SubInterfaceL2CustomizerTest extends ReaderCustomizerTest<L2, L2Bui private static final long SUB_IF_ID = 1; private static final int SUB_IF_INDEX = 11; private InstanceIdentifier<L2> IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(L2.class); + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceStateAugmentation.class) + .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)) + .child(L2.class); + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; public SubInterfaceL2CustomizerTest() { super(L2.class, SubInterfaceBuilder.class); @@ -68,13 +74,6 @@ public class SubInterfaceL2CustomizerTest extends ReaderCustomizerTest<L2, L2Bui @Override protected ReaderCustomizer<L2, L2Builder> initCustomizer() { - return new SubInterfaceL2Customizer(api, interfaceContext, bridgeDomainContext); - } - - @Test(expected = ReadFailedException.class) - public void testReadFailed() throws ReadFailedException { - final L2Builder builder = mock(L2Builder.class); - when(api.swInterfaceDump(any())).thenReturn(failedFuture()); - getCustomizer().readCurrentAttributes(IID, builder, ctx); + return new SubInterfaceL2Customizer(api, interfaceContext, bridgeDomainContext, dumpCacheManager); } }
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/TapCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/TapCustomizerTest.java index e268f7b15..1fbefd696 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/TapCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/TapCustomizerTest.java @@ -21,12 +21,17 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; +import io.fd.vpp.jvpp.core.dto.SwInterfaceTapDetails; +import io.fd.vpp.jvpp.core.dto.SwInterfaceTapDetailsReplyDump; import org.junit.Test; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; @@ -35,9 +40,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.Tap; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.TapBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; -import io.fd.vpp.jvpp.core.dto.SwInterfaceTapDetails; -import io.fd.vpp.jvpp.core.dto.SwInterfaceTapDetailsReplyDump; public class TapCustomizerTest extends ReaderCustomizerTest<Tap, TapBuilder> implements InterfaceDumpHelper { @@ -46,10 +48,13 @@ public class TapCustomizerTest extends ReaderCustomizerTest<Tap, TapBuilder> imp private static final String TAP_NAME = "testTapName"; private static final int IF_INDEX = 1; private static final InstanceIdentifier<Tap> IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(Tap.class); + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceStateAugmentation.class).child(Tap.class); private NamingContext interfaceContext; + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + public TapCustomizerTest() { super(Tap.class, VppInterfaceStateAugmentationBuilder.class); } @@ -58,7 +63,7 @@ public class TapCustomizerTest extends ReaderCustomizerTest<Tap, TapBuilder> imp protected void setUp() throws Exception { interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - whenSwInterfaceDumpThenReturn(api, ifaceDetails()); + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(ifaceDetails()); } private SwInterfaceDetails ifaceDetails() { @@ -71,7 +76,7 @@ public class TapCustomizerTest extends ReaderCustomizerTest<Tap, TapBuilder> imp @Override protected ReaderCustomizer<Tap, TapBuilder> initCustomizer() { - return new TapCustomizer(api, interfaceContext); + return new TapCustomizer(api, interfaceContext, dumpCacheManager); } @Test diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java index b83b74e2d..e58877eb1 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java @@ -21,13 +21,18 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; +import io.fd.vpp.jvpp.core.dto.SwInterfaceVhostUserDetails; +import io.fd.vpp.jvpp.core.dto.SwInterfaceVhostUserDetailsReplyDump; import java.math.BigInteger; import org.junit.Test; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; @@ -37,21 +42,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.VhostUser; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.VhostUserBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; -import io.fd.vpp.jvpp.core.dto.SwInterfaceVhostUserDetails; -import io.fd.vpp.jvpp.core.dto.SwInterfaceVhostUserDetailsReplyDump; public class VhostUserCustomizerTest extends ReaderCustomizerTest<VhostUser, VhostUserBuilder> implements - InterfaceDumpHelper { + InterfaceDumpHelper { private static final String IFC_CTX_NAME = "ifc-test-instance"; private static final String IF_NAME = "VirtualEthernet1"; private static final int IF_INDEX = 1; private static final InstanceIdentifier<VhostUser> IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(VhostUser.class); + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceStateAugmentation.class).child(VhostUser.class); private NamingContext interfaceContext; + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + public VhostUserCustomizerTest() { super(VhostUser.class, VppInterfaceStateAugmentationBuilder.class); } @@ -60,7 +65,7 @@ public class VhostUserCustomizerTest extends ReaderCustomizerTest<VhostUser, Vho protected void setUp() throws Exception { interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - whenSwInterfaceDumpThenReturn(api, ifaceDetails()); + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(ifaceDetails()); } private SwInterfaceDetails ifaceDetails() { @@ -73,7 +78,7 @@ public class VhostUserCustomizerTest extends ReaderCustomizerTest<VhostUser, Vho @Override protected ReaderCustomizer<VhostUser, VhostUserBuilder> initCustomizer() { - return new VhostUserCustomizer(api, interfaceContext); + return new VhostUserCustomizer(api, interfaceContext, dumpCacheManager); } @Test diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java index f5e659f50..ba0cf2d2d 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java @@ -23,13 +23,23 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; +import com.google.common.collect.Lists; +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.vpp.jvpp.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; +import io.fd.vpp.jvpp.core.dto.VxlanTunnelDetails; +import io.fd.vpp.jvpp.core.dto.VxlanTunnelDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.VxlanTunnelDump; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Map; - import org.junit.Test; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; @@ -40,17 +50,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.VxlanBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import com.google.common.collect.Lists; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; -import io.fd.vpp.jvpp.core.dto.VxlanTunnelDetails; -import io.fd.vpp.jvpp.core.dto.VxlanTunnelDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.VxlanTunnelDump; - public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilder> { private static final String IFC_CTX_NAME = "ifc-test-instance"; @@ -60,22 +59,24 @@ public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilde private NamingContext interfacesContext; static final InstanceIdentifier<Vxlan> IID = InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(Vxlan.class); + .augmentation(VppInterfaceStateAugmentation.class).child(Vxlan.class); + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; public VxlanCustomizerTest() { super(Vxlan.class, VppInterfaceStateAugmentationBuilder.class); } @Override - public void setUp() throws UnknownHostException, VppInvocationException { + public void setUp() throws UnknownHostException, VppInvocationException, ReadFailedException { interfacesContext = new NamingContext("vxlan-tunnel", IFC_CTX_NAME); defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); final SwInterfaceDetails v = new SwInterfaceDetails(); v.interfaceName = "vxlan-tunnel4".getBytes(); - final Map<Integer, SwInterfaceDetails> map = new HashMap<>(); - map.put(0, v); - cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map); + + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(v); final VxlanTunnelDetailsReplyDump value = new VxlanTunnelDetailsReplyDump(); final VxlanTunnelDetails vxlanTunnelDetails = new VxlanTunnelDetails(); @@ -110,9 +111,10 @@ public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilde verify(api).vxlanTunnelDump(any(VxlanTunnelDump.class)); } - @Test(expected = NullPointerException.class) + @Test(expected = IllegalArgumentException.class) public void testReadCurrentAttributesVppNameNotCached() throws Exception { - InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0); + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)) + .thenThrow(new IllegalArgumentException("Detail for interface not found")); final VxlanBuilder builder = getCustomizer().getBuilder(IID); getCustomizer().readCurrentAttributes(IID, builder, ctx); @@ -122,7 +124,8 @@ public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilde public void testReadCurrentAttributesWrongType() throws Exception { final SwInterfaceDetails v = new SwInterfaceDetails(); v.interfaceName = "tap-2".getBytes(); - InterfaceCustomizer.getCachedInterfaceDump(cache).put(0, v); + + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(v); final VxlanBuilder builder = getCustomizer().getBuilder(IID); getCustomizer().readCurrentAttributes(IID, builder, ctx); @@ -133,6 +136,6 @@ public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilde @Override protected ReaderCustomizer<Vxlan, VxlanBuilder> initCustomizer() { - return new VxlanCustomizer(api, interfacesContext); + return new VxlanCustomizer(api, interfacesContext, dumpCacheManager); } }
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java index f8f1e14b6..ce794302b 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java @@ -19,20 +19,28 @@ package io.fd.hc2vpp.v3po.interfacesstate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; import com.google.common.collect.Lists; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; +import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDetails; +import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDump; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Map; import org.junit.Test; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; @@ -41,11 +49,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.VxlanGpe; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces.state._interface.VxlanGpeBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; -import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDetails; -import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDump; public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, VxlanGpeBuilder> { @@ -55,23 +58,25 @@ public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, Vxlan private NamingContext interfacesContext; private static final InstanceIdentifier<VxlanGpe> VXLAN_GPE_ID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(VxlanGpe.class); + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceStateAugmentation.class).child(VxlanGpe.class); + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; public VxlanGpeCustomizerTest() { super(VxlanGpe.class, VppInterfaceStateAugmentationBuilder.class); } @Override - public void setUp() throws UnknownHostException, VppBaseCallException { + public void setUp() throws UnknownHostException, VppBaseCallException, ReadFailedException { interfacesContext = new NamingContext("vxlan_gpe_inf", IFC_CTX_NAME); defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); final SwInterfaceDetails v = new SwInterfaceDetails(); v.interfaceName = "vxlan_gpe_inf2".getBytes(); - final Map<Integer, SwInterfaceDetails> map = new HashMap<>(); - map.put(0, v); - cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map); + + when(dumpCacheManager.getInterfaceDetail(any(), any(), matches(IF_NAME))).thenReturn(v); final VxlanGpeTunnelDetailsReplyDump value = new VxlanGpeTunnelDetailsReplyDump(); final VxlanGpeTunnelDetails vxlanGpeTunnelDetails = new VxlanGpeTunnelDetails(); @@ -108,9 +113,10 @@ public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, Vxlan verify(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class)); } - @Test(expected = NullPointerException.class) + @Test(expected = IllegalArgumentException.class) public void testReadCurrentAttributesVppNameNotCached() throws Exception { - InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0); + when(dumpCacheManager.getInterfaceDetail(VXLAN_GPE_ID, ctx, IF_NAME)) + .thenThrow(new IllegalArgumentException("Detail for interface not found")); final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID); getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx); @@ -120,18 +126,17 @@ public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, Vxlan public void testReadCurrentAttributesWrongType() throws Exception { final SwInterfaceDetails v = new SwInterfaceDetails(); v.interfaceName = "tap-3".getBytes(); - InterfaceCustomizer.getCachedInterfaceDump(cache).put(0, v); + + when(dumpCacheManager.getInterfaceDetail(VXLAN_GPE_ID, ctx, IF_NAME)).thenReturn(v); final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID); getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx); - - // Should be ignored verifyZeroInteractions(api); } @Override protected ReaderCustomizer<VxlanGpe, VxlanGpeBuilder> initCustomizer() { - return new VxlanGpeCustomizer(api, interfacesContext); + return new VxlanGpeCustomizer(api, interfacesContext, dumpCacheManager); } } diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImplTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImplTest.java new file mode 100644 index 000000000..6f47f162d --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImplTest.java @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.interfacesstate.cache; + +import static io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManagerImpl.BY_NAME_INDEX_KEY; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.test.util.FutureProducer; +import io.fd.hc2vpp.common.test.util.NamingContextHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceCacheDumpManagerImplTest implements NamingContextHelper, FutureProducer { + + private static final String IFACE_0 = "iface-0"; + private static final String IFACE_1 = "iface-1"; + private static final String IFACE_2 = "iface-2"; + private static final String IFACE_3 = "iface-3"; + + @Mock + private FutureJVppCore jvpp; + @Mock + private ReadContext ctx; + @Mock + private MappingContext mappingContext; + + private InstanceIdentifier<Interface> identifier; + private InstanceIdentifier<Interface> identifierThree; + private NamingContext namingContext; + private ModificationCache cache; + private InterfaceCacheDumpManagerImpl manager; + + @Before + public void setUp() throws Exception { + initMocks(this); + namingContext = new NamingContext("interface-", "interface-context"); + cache = new ModificationCache(); + manager = new InterfaceCacheDumpManagerImpl(jvpp, namingContext); + when(ctx.getModificationCache()).thenReturn(cache); + when(ctx.getMappingContext()).thenReturn(mappingContext); + identifier = InstanceIdentifier.create(InterfacesState.class) + .child(Interface.class, new InterfaceKey(IFACE_0)); + + identifierThree = InstanceIdentifier.create(InterfacesState.class) + .child(Interface.class, new InterfaceKey(IFACE_3)); + + when(jvpp.swInterfaceDump(fullRequest())).thenReturn(future(fullReply())); + + // this one is not in full dump + when(jvpp.swInterfaceDump(specificRequest(IFACE_3))).thenReturn(future(specificReplyThree())); + defineMapping(mappingContext, IFACE_0, 0, "interface-context"); + defineMapping(mappingContext, IFACE_1, 1, "interface-context"); + defineMapping(mappingContext, IFACE_2, 2, "interface-context"); + defineMapping(mappingContext, IFACE_3, 3, "interface-context"); + } + + @Test + public void getInterfaces() throws Exception { + assertFalse(cache.containsKey(BY_NAME_INDEX_KEY)); + final List<SwInterfaceDetails> interfaces = manager.getInterfaces(identifier, ctx).collect(Collectors.toList()); + assertEquals(3, interfaces.size()); + assertTrue(interfaces.contains(detailZero())); + assertTrue(interfaces.contains(detailOne())); + assertTrue(interfaces.contains(detailTwo())); + + // first request must call jvpp + verify(jvpp, times(1)).swInterfaceDump(fullRequest()); + assertTrue(cache.containsKey(BY_NAME_INDEX_KEY)); + + // then cached value should be returned + final List<SwInterfaceDetails> cachedInterfaces = + manager.getInterfaces(identifier, ctx).collect(Collectors.toList()); + assertEquals(3, cachedInterfaces.size()); + assertTrue(cachedInterfaces.contains(detailZero())); + assertTrue(cachedInterfaces.contains(detailOne())); + assertTrue(cachedInterfaces.contains(detailTwo())); + + //verify that dump wasn't invoked again + verifyNoMoreInteractions(jvpp); + } + + @Test + public void getInterfaceDetailFromCache() throws Exception { + final HashMap<Object, Object> cachedMap = new HashMap<>(); + final SwInterfaceDetails detailZero = detailZero(); + cachedMap.put(IFACE_0, detailZero); + cache.put(BY_NAME_INDEX_KEY, cachedMap); + when(jvpp.swInterfaceDump(specificRequest(IFACE_0))).thenReturn(future(specificReplyZero())); + final SwInterfaceDetails interfaceDetail = manager.getInterfaceDetail(identifier, ctx, IFACE_0); + assertEquals(detailZero, interfaceDetail); + + // must not call jvpp, just get it from cache + verifyZeroInteractions(jvpp); + } + + @Test + public void getInterfaceDetailNotInFullDump() throws Exception { + assertFalse(cache.containsKey(BY_NAME_INDEX_KEY)); + final SwInterfaceDetails specificDetail = manager.getInterfaceDetail(identifierThree, ctx, IFACE_3); + assertEquals(detailThree(), specificDetail); + + verify(jvpp, times(1)).swInterfaceDump(specificRequest(IFACE_3)); + } + + private SwInterfaceDetailsReplyDump fullReply() { + final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); + reply.swInterfaceDetails = Arrays.asList(detailZero(), detailOne(), detailTwo()); + return reply; + } + + private static SwInterfaceDetails detailTwo() { + SwInterfaceDetails detail3 = new SwInterfaceDetails(); + detail3.swIfIndex = 2; + detail3.interfaceName = IFACE_2.getBytes(); + return detail3; + } + + private static SwInterfaceDetails detailOne() { + SwInterfaceDetails detail2 = new SwInterfaceDetails(); + detail2.swIfIndex = 1; + detail2.interfaceName = IFACE_1.getBytes(); + return detail2; + } + + private static SwInterfaceDetails detailThree() { + SwInterfaceDetails detail2 = new SwInterfaceDetails(); + detail2.swIfIndex = 3; + detail2.interfaceName = IFACE_3.getBytes(); + return detail2; + } + + private static SwInterfaceDetails detailZero() { + SwInterfaceDetails detail1 = new SwInterfaceDetails(); + detail1.swIfIndex = 0; + detail1.interfaceName = IFACE_0.getBytes(); + return detail1; + } + + private SwInterfaceDetailsReplyDump specificReplyThree() { + final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); + reply.swInterfaceDetails = Arrays.asList(detailThree()); + return reply; + } + + private SwInterfaceDetailsReplyDump specificReplyZero() { + final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); + reply.swInterfaceDetails = Arrays.asList(detailZero()); + return reply; + } + + private static SwInterfaceDump specificRequest(final String ifaceName) { + final SwInterfaceDump specificRequest = new SwInterfaceDump(); + specificRequest.nameFilterValid = 1; + specificRequest.nameFilter = ifaceName.getBytes(); + return specificRequest; + } + + private static SwInterfaceDump fullRequest() { + final SwInterfaceDump fullRequest = new SwInterfaceDump(); + fullRequest.nameFilterValid = 0; + fullRequest.nameFilter = "".getBytes(); + return fullRequest; + } +}
\ No newline at end of file |