<artifactId>sal-binding-config</artifactId>
</dependency>
<!-- test dependencies -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testtool-util</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
package org.opendaylight.protocol.bgp.benchmark.app;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Stopwatch;
import com.google.common.net.InetAddresses;
import java.util.Collections;
LOG.info("BGP Application Peer Benchmark Application closed.");
}
+ @VisibleForTesting
+ InstanceIdentifier<Ipv4Routes> getIpv4RoutesIID() {
+ return this.routesIId;
+ }
+
private long addRoute(final Ipv4Prefix ipv4Prefix, final Ipv4Address nextHop, final long count, final long batch) {
final AttributesBuilder attributesBuilder = new AttributesBuilder();
attributesBuilder.setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(
package org.opendaylight.protocol.bgp.benchmark.app;
-import java.util.concurrent.ExecutionException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
+import static org.opendaylight.protocol.util.CheckUtil.readDataConfiguration;
+
import javax.management.MalformedObjectNameException;
-import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.Ipv4Routes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRibKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.OdlBgpAppPeerBenchmarkService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.output.Result;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
public class AppPeerBenchmarkTest extends AbstractDataBrokerTest {
private static final String NH = "127.0.0.1";
private static final String PEER_RIB_ID = "app-peer";
- private static final InstanceIdentifier<ApplicationRib> BASE_IID = KeyedInstanceIdentifier.builder(ApplicationRib.class,
- new ApplicationRibKey(new ApplicationRibId(PEER_RIB_ID))).build();
- private static final InstanceIdentifier tablesIId = BASE_IID
- .child(Tables.class, new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
- private static final InstanceIdentifier<Ipv4Routes> ROUTES = tablesIId.child(Ipv4Routes.class);
-
@Mock
private RpcProviderRegistry rpcRegistry;
@Mock
private RoutedRpcRegistration<OdlBgpAppPeerBenchmarkService> registration;
- private AppPeerBenchmark appPeerBenchmark;
-
@Before
- public void setUp() throws MalformedObjectNameException {
+ public void setUp() throws MalformedObjectNameException, TransactionCommitFailedException {
MockitoAnnotations.initMocks(this);
- Mockito.doReturn(this.registration).when(this.rpcRegistry).addRpcImplementation(Mockito.<Class<OdlBgpAppPeerBenchmarkService>>any(),
+ doReturn(this.registration).when(this.rpcRegistry).addRpcImplementation(Mockito.any(),
Mockito.any(OdlBgpAppPeerBenchmarkService.class));
- Mockito.doNothing().when(this.registration).close();
- this.appPeerBenchmark = new AppPeerBenchmark(getDataBroker(), this.rpcRegistry, PEER_RIB_ID);
+ doNothing().when(this.registration).close();
}
@Test
- public void testRpcs() throws InterruptedException, ExecutionException, ReadFailedException {
- final RpcResult<AddPrefixOutput> addRpcResult = this.appPeerBenchmark.addPrefix(new AddPrefixInputBuilder()
- .setBatchsize(1L)
- .setCount(1L)
- .setNexthop(new Ipv4Address(NH))
- .setPrefix(new Ipv4Prefix(PREFIX)).build()).get();
+ public void testRpcs() throws Exception {
+ final AppPeerBenchmark appPeerBenchmark = new AppPeerBenchmark(getDataBroker(), this.rpcRegistry, PEER_RIB_ID);
+ final InstanceIdentifier<Ipv4Routes> routesIID = appPeerBenchmark.getIpv4RoutesIID();
+
+ final AddPrefixInput addPrefix = new AddPrefixInputBuilder().setBatchsize(1L).setCount(1L)
+ .setNexthop(new Ipv4Address(NH)).setPrefix(new Ipv4Prefix(PREFIX)).build();
+
+ final RpcResult<AddPrefixOutput> addRpcResult = appPeerBenchmark.addPrefix(addPrefix).get();
final Result addResult = addRpcResult.getResult().getResult();
- Assert.assertEquals(1, addResult.getCount().intValue());
- Assert.assertEquals(1, addResult.getRate().intValue());
- final Ipv4Routes routesAfterAdd = getRoutes();
- Assert.assertEquals(1, routesAfterAdd.getIpv4Route().size());
+ checkEquals(()-> assertEquals(1, addResult.getCount().intValue()));
+ checkEquals(()-> assertEquals(1, addResult.getRate().intValue()));
- final RpcResult<DeletePrefixOutput> deleteRpcResult = this.appPeerBenchmark.deletePrefix(new DeletePrefixInputBuilder()
- .setBatchsize(1L)
- .setCount(1L)
- .setPrefix(new Ipv4Prefix(PREFIX)).build()).get();
- final Result deleteResult = deleteRpcResult.getResult().getResult();
- Assert.assertEquals(1, deleteResult.getCount().intValue());
- Assert.assertEquals(1, deleteResult.getRate().intValue());
- final Ipv4Routes routesAfterDelete = getRoutes();
- Assert.assertTrue(routesAfterDelete.getIpv4Route().isEmpty());
- }
+ readDataConfiguration(getDataBroker(), routesIID, routes -> {
+ assertNotNull(routes.getIpv4Route());
+ assertEquals(1, routes.getIpv4Route().size());
+ return routes;
+ });
- @After
- public void tearDown() {
- this.appPeerBenchmark.close();
- }
+ final DeletePrefixInput deletePrefix = new DeletePrefixInputBuilder().setBatchsize(1L).setCount(1L)
+ .setPrefix(new Ipv4Prefix(PREFIX)).build();
+ final RpcResult<DeletePrefixOutput> deleteRpcResult = appPeerBenchmark
+ .deletePrefix(deletePrefix).get();
+ final Result deleteResult = deleteRpcResult.getResult().getResult();
+ checkEquals(()-> assertEquals(1, deleteResult.getCount().intValue()));
+ checkEquals(()-> assertEquals(1, deleteResult.getRate().intValue()));
+ readDataConfiguration(getDataBroker(), routesIID, routes -> {
+ assertNotNull(routes.getIpv4Route());
+ assertTrue(routes.getIpv4Route().isEmpty());
+ return routes;
+ });
- private Ipv4Routes getRoutes() throws ReadFailedException {
- final ReadOnlyTransaction rTx = getDataBroker().newReadOnlyTransaction();
- return rTx.read(LogicalDatastoreType.CONFIGURATION, ROUTES).checkedGet().get();
+ appPeerBenchmark.close();
}
-
}
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
import com.google.common.base.Optional;
MONITOR_ID, new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS), MONITOR_LOCAL_PORT), Optional.of(keys),
this.mappingService.getCodecFactory(), this.moduleInfoBackedContext.getSchemaContext(), null);
- readData(getDataBroker(), BMP_II, monitor -> {
+ readDataOperational(getDataBroker(), BMP_II, monitor -> {
Assert.assertEquals(1, monitor.getMonitor().size());
final Monitor bmpMonitor = monitor.getMonitor().get(0);
Assert.assertEquals(MONITOR_ID, bmpMonitor.getMonitorId());
this.bmpApp.close();
this.mappingService.close();
- readData(getDataBroker(), BMP_II, monitor -> {
+ readDataOperational(getDataBroker(), BMP_II, monitor -> {
assertTrue(monitor.getMonitor().isEmpty());
return monitor;
});
public void testRouterMonitoring() throws Exception {
// first test if a single router monitoring is working
final Channel channel1 = testMonitoringStation(REMOTE_ROUTER_ADDRESS_1);
- readData(getDataBroker(), MONITOR_IID, monitor -> {
+ readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
assertEquals(1, monitor.getRouter().size());
return monitor;
});
final Channel channel2 = testMonitoringStation(REMOTE_ROUTER_ADDRESS_2);
- readData(getDataBroker(), MONITOR_IID, monitor -> {
+ readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
assertEquals(2, monitor.getRouter().size());
return monitor;
});
waitFutureSuccess(channel1.close());
// channel 2 is still open
- readData(getDataBroker(), MONITOR_IID, monitor -> {
+ readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
assertEquals(1, monitor.getRouter().size());
return monitor;
});
final Channel channel4 = testMonitoringStation(REMOTE_ROUTER_ADDRESS_1);
- readData(getDataBroker(), MONITOR_IID, monitor -> {
+ readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
assertEquals(2, monitor.getRouter().size());
return monitor;
});
// sleep for a while to avoid intermittent InMemoryDataTree modification conflict
waitFutureSuccess(channel4.close());
- readData(getDataBroker(), MONITOR_IID, monitor -> {
+ readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
assertEquals(0, monitor.getRouter().size());
return monitor;
});
final Channel channel = connectTestClient(remoteRouterIpAddr, this.msgRegistry);
final RouterId routerId = getRouterId(remoteRouterIpAddr);
try {
- readData(getDataBroker(), MONITOR_IID, monitor -> {
+ readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
assertFalse(monitor.getRouter().isEmpty());
// now find the current router instance
Router router = null;
waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createInitMsg("description", "name", "some info")));
- readData(getDataBroker(), MONITOR_IID, monitor -> {
+ readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
assertFalse(monitor.getRouter().isEmpty());
Router retRouter = null;
for (final Router r : monitor.getRouter()) {
waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createPeerUpNotification(PEER1, true)));
final KeyedInstanceIdentifier<Router, RouterKey> routerIId = MONITOR_IID.child(Router.class, new RouterKey(routerId));
- readData(getDataBroker(), routerIId, router -> {
+ readDataOperational(getDataBroker(), routerIId, router -> {
final List<Peer> peers = router.getPeer();
assertEquals(1, peers.size());
final Peer peer = peers.get(0);
waitWriteAndFlushSuccess(channel.writeAndFlush(statsMsg));
final KeyedInstanceIdentifier<Peer, PeerKey> peerIId = routerIId.child(Peer.class, new PeerKey(PEER_ID));
- readData(getDataBroker(), peerIId.child(Stats.class), peerStats -> {
+ readDataOperational(getDataBroker(), peerIId.child(Stats.class), peerStats -> {
assertNotNull(peerStats.getTimestampSec());
final Tlvs tlvs = statsMsg.getTlvs();
assertEquals(tlvs.getAdjRibsInRoutesTlv().getCount(), peerStats.getAdjRibsInRoutes());
final RouteMirroringMessage routeMirrorMsg = TestUtil.createRouteMirrorMsg(PEER1);
waitWriteAndFlushSuccess(channel.writeAndFlush(routeMirrorMsg));
- readData(getDataBroker(), peerIId.child(Mirrors.class), routeMirrors -> {
+ readDataOperational(getDataBroker(), peerIId.child(Mirrors.class), routeMirrors -> {
assertNotNull(routeMirrors.getTimestampSec());
return routeMirrors;
});
waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createRouteMonitMsg(false, PEER1, AdjRibInType.PrePolicy)));
waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createRouteMonMsgWithEndOfRibMarker(PEER1, AdjRibInType.PrePolicy)));
- readData(getDataBroker(), peerIId.child(PrePolicyRib.class), prePolicyRib -> {
+ readDataOperational(getDataBroker(), peerIId.child(PrePolicyRib.class), prePolicyRib -> {
assertTrue(!prePolicyRib.getTables().isEmpty());
final Tables tables = prePolicyRib.getTables().get(0);
assertTrue(tables.getAttributes().isUptodate());
waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createRouteMonitMsg(false, PEER1, AdjRibInType.PostPolicy)));
waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createRouteMonMsgWithEndOfRibMarker(PEER1, AdjRibInType.PostPolicy)));
- readData(getDataBroker(), peerIId.child(PostPolicyRib.class), postPolicyRib -> {
+ readDataOperational(getDataBroker(), peerIId.child(PostPolicyRib.class), postPolicyRib -> {
assertTrue(!postPolicyRib.getTables().isEmpty());
final Tables tables = postPolicyRib.getTables().get(0);
assertTrue(tables.getAttributes().isUptodate());
waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createPeerDownNotification(PEER1)));
- readData(getDataBroker(), routerIId, router -> {
+ readDataOperational(getDataBroker(), routerIId, router -> {
final List<Peer> peersAfterDown = router.getPeer();
assertTrue(peersAfterDown.isEmpty());
return router;
new MonitorId("monitor2"), new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS_2), MONITOR_LOCAL_PORT), Optional.of(KeyMapping.getKeyMapping()),
this.mappingService.getCodecFactory(), this.moduleInfoBackedContext.getSchemaContext(), null);
- readData(getDataBroker(), BMP_II, monitor -> {
+ readDataOperational(getDataBroker(), BMP_II, monitor -> {
Assert.assertEquals(2, monitor.getMonitor().size());
return monitor;
});
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
import com.google.common.base.Optional;
private void checkLocRib(final int expectedRoutesOnDS) throws Exception {
Thread.sleep(100);
- readData(getDataBroker(), BGP_IID, bgpRib -> {
+ readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
final Ipv4RoutesCase routes = ((Ipv4RoutesCase) bgpRib.getRib().get(0).getLocRib().getTables().get(0)
.getRoutes());
final List<Ipv4Route> routeList = routes.getIpv4Routes().getIpv4Route();
}
void checkPeersPresentOnDataStore(final int numberOfPeers) throws Exception {
- readData(getDataBroker(), BGP_IID, bgpRib -> {
+ readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
Assert.assertEquals(numberOfPeers, bgpRib.getRib().get(0).getPeer().size());
return bgpRib;
});
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
+import static org.opendaylight.protocol.bgp.rib.impl.AbstractAddPathTest.AS_NUMBER;
+import static org.opendaylight.protocol.bgp.rib.impl.AbstractAddPathTest.BGP_ID;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.concurrent.ExecutionException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
import org.opendaylight.controller.md.sal.binding.test.DataBrokerTestCustomizer;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
import org.opendaylight.protocol.bgp.inet.RIBActivator;
import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
import org.opendaylight.protocol.bgp.util.HexDumpBGPFileParser;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6Route;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.LocRib;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
public class ParserToSalTest extends AbstractDataBrokerTest {
private static final String TEST_RIB_ID = "testRib";
+ private static final TablesKey TABLE_KEY = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
+ private static final InstanceIdentifier<BgpRib> BGP_IID = InstanceIdentifier.create(BgpRib.class);
private BGPMock mock;
private AbstractRIBExtensionProviderActivator baseact, lsact;
private RIBExtensionProviderContext ext1, ext2;
- private static final TablesKey TABLE_KEY = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
+
@Mock
- BGPDispatcher dispatcher;
+ private BGPDispatcher dispatcher;
@Mock
private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
private BindingCodecTreeFactory codecFactory;
} catch (final IOException e) {
throw Throwables.propagate(e);
}
- this.mock = new BGPMock(new EventBus("test"), ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry(), Lists.newArrayList(fixMessages(bgpMessages)));
+ this.mock = new BGPMock(new EventBus("test"), ServiceLoaderBGPExtensionProviderContext
+ .getSingletonInstance().getMessageRegistry(), Lists.newArrayList(fixMessages(bgpMessages)));
- Mockito.doReturn(GlobalEventExecutor.INSTANCE.newSucceededFuture(null)).when(this.dispatcher).createReconnectingClient(
- Mockito.any(InetSocketAddress.class), Mockito.any(BGPPeerRegistry.class), Mockito.anyInt(), Mockito.any(Optional.class));
+ Mockito.doReturn(GlobalEventExecutor.INSTANCE.newSucceededFuture(null)).when(this.dispatcher)
+ .createReconnectingClient(Mockito.any(InetSocketAddress.class), Mockito.any(BGPPeerRegistry.class),
+ Mockito.anyInt(), Mockito.any(Optional.class));
this.ext1 = new SimpleRIBExtensionProviderContext();
this.ext2 = new SimpleRIBExtensionProviderContext();
}
@Test
- public void testWithLinkstate() throws InterruptedException, ExecutionException {
- final List<BgpTableType> tables = ImmutableList.of(
- new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
- final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID), new AsNumber(72L), new BgpId("127.0.0.1"),
- null, this.ext2, this.dispatcher, this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
- BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
+ public void testWithLinkstate() throws ReadFailedException {
+ final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(LinkstateAddressFamily.class,
+ LinkstateSubsequentAddressFamily.class));
+ final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID),
+ AS_NUMBER, BGP_ID, null, this.ext2, this.dispatcher,
+ this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
+ BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
+ GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
rib.instantiateServiceInstance();
- assertTablesExists(tables, true);
+ assertTablesExists(tables);
rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
final BGPPeer peer = new BGPPeer("peer-" + this.mock.toString(), rib, PeerRole.Ibgp, null);
peer.instantiateServiceInstance();
}
@Test
- public void testWithoutLinkstate() throws InterruptedException, ExecutionException {
- final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
- final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID), new AsNumber(72L), new BgpId("127.0.0.1"), null,
- this.ext1, this.dispatcher, this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
- BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
+ public void testWithoutLinkstate() throws ReadFailedException {
+ final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class,
+ UnicastSubsequentAddressFamily.class));
+ final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID), AS_NUMBER, BGP_ID, null,
+ this.ext1, this.dispatcher, this.codecFactory, getDomBroker(), tables,
+ Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
+ GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
rib.instantiateServiceInstance();
rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
- assertTablesExists(tables, true);
+ assertTablesExists(tables);
final BGPPeer peer = new BGPPeer("peer-" + this.mock.toString(), rib, PeerRole.Ibgp, null);
peer.instantiateServiceInstance();
final ListenerRegistration<?> reg = this.mock.registerUpdateListener(peer);
});
}
- private void assertTablesExists(final List<BgpTableType> expectedTables, final boolean uptodate) throws InterruptedException, ExecutionException {
- final Optional<LocRib> lockRib = getLocRibTable();
- assertTrue(lockRib.isPresent());
- final List<Tables> tables = lockRib.get().getTables();
- assertFalse(tables.isEmpty());
- for (final BgpTableType tableType : expectedTables) {
- boolean found = false;
- for (final Tables table : tables) {
- if(table.getAfi().equals(tableType.getAfi()) && table.getSafi().equals(tableType.getSafi())) {
- found = true;
- assertTrue(Boolean.valueOf(uptodate).equals(table.getAttributes().isUptodate()));
+ private void assertTablesExists(final List<BgpTableType> expectedTables)
+ throws ReadFailedException {
+ readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
+ final List<Tables> tables = bgpRib.getRib().get(0).getLocRib().getTables();
+ assertFalse(tables.isEmpty());
+
+ for (final BgpTableType tableType : expectedTables) {
+ boolean found = false;
+ for (final Tables table : tables) {
+ if (table.getAfi().equals(tableType.getAfi()) && table.getSafi().equals(tableType.getSafi())) {
+ found = true;
+ assertTrue(Boolean.valueOf(true).equals(table.getAttributes().isUptodate()));
+ }
}
+ assertTrue(found);
}
- assertTrue(found);
- }
- }
-
- private Optional<LocRib> getLocRibTable() throws InterruptedException, ExecutionException {
- return getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId(TEST_RIB_ID))).child(LocRib.class).build()).get();
+ return bgpRib;
+ });
}
}
</dependency>
<!-- Test dependencies -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testtool-util</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
public abstract class AbstractTopologyBuilderTest extends AbstractDataBrokerTest {
- protected static final TopologyId TEST_TOPOLOGY_ID = new TopologyId("test-topo");
- protected static final RibReference LOC_RIB_REF = new DefaultRibReference(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(new RibId("test-rib")))));
+ static final TopologyId TEST_TOPOLOGY_ID = new TopologyId("test-topo");
+ static final RibReference LOC_RIB_REF = new DefaultRibReference(InstanceIdentifier.create(BgpRib.class)
+ .child(Rib.class, new RibKey(Preconditions.checkNotNull(new RibId("test-rib")))));
@Override
protected void setupWithDataBroker(final DataBroker dataBroker) {
package org.opendaylight.bgpcep.bgp.topology.provider;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
-import com.google.common.base.Optional;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@Override
protected void setupWithDataBroker(final DataBroker dataBroker) {
super.setupWithDataBroker(dataBroker);
- this.ipv4TopoBuilder = new Ipv4ReachabilityTopologyBuilder(dataBroker, LOC_RIB_REF, TEST_TOPOLOGY_ID);
+ this.ipv4TopoBuilder = new Ipv4ReachabilityTopologyBuilder(getDataBroker(), LOC_RIB_REF, TEST_TOPOLOGY_ID);
this.ipv4TopoBuilder.start();
- final InstanceIdentifier<Tables> path = this.ipv4TopoBuilder.tableInstanceIdentifier(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
- this.ipv4RouteIID = path.builder().child((Class) Ipv4Routes.class).child(Ipv4Route.class, new Ipv4RouteKey(new PathId(PATH_ID),
- new Ipv4Prefix(ROUTE_IP4PREFIX))).build();
+ final InstanceIdentifier<Tables> path = this.ipv4TopoBuilder.tableInstanceIdentifier(Ipv4AddressFamily.class,
+ UnicastSubsequentAddressFamily.class);
+ this.ipv4RouteIID = path.builder().child((Class) Ipv4Routes.class)
+ .child(Ipv4Route.class, new Ipv4RouteKey(new PathId(PATH_ID),
+ new Ipv4Prefix(ROUTE_IP4PREFIX))).build();
}
@Test
- public void testIpv4ReachabilityTopologyBuilder() throws TransactionCommitFailedException {
+ public void testIpv4ReachabilityTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
// create route
updateIpv4Route(createIpv4Route(NEXT_HOP));
- final Optional<Topology> topologyMaybe = getTopology(this.ipv4TopoBuilder.getInstanceIdentifier());
- assertTrue(topologyMaybe.isPresent());
- final Topology topology = topologyMaybe.get();
- assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
- assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpIpv4ReachabilityTopology());
- assertEquals(1, topology.getNode().size());
- final Node node = topology.getNode().get(0);
- assertEquals(NEXT_HOP, node.getNodeId().getValue());
- assertEquals(ROUTE_IP4PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv4Prefix().getValue());
+
+ readDataOperational(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier(), topology -> {
+ final TopologyTypes1 topologyTypes = topology.getTopologyTypes().getAugmentation(TopologyTypes1.class);
+ assertNotNull(topologyTypes);
+ assertNotNull(topologyTypes.getBgpIpv4ReachabilityTopology());
+ assertEquals(1, topology.getNode().size());
+ final Node node = topology.getNode().get(0);
+ assertEquals(NEXT_HOP, node.getNodeId().getValue());
+ assertEquals(ROUTE_IP4PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0)
+ .getPrefix().getIpv4Prefix().getValue());
+ return topology;
+ });
// update route
updateIpv4Route(createIpv4Route(NEW_NEXT_HOP));
- final Topology topologyUpdated = getTopology(this.ipv4TopoBuilder.getInstanceIdentifier()).get();
- assertEquals(1, topologyUpdated.getNode().size());
- final Node nodeUpdated = topologyUpdated.getNode().get(0);
- assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
- assertEquals(ROUTE_IP4PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv4Prefix().getValue());
+ readDataOperational(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.getNode().size());
+ final Node nodeUpdated = topology.getNode().get(0);
+ assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
+ assertEquals(ROUTE_IP4PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes()
+ .getPrefix().get(0).getPrefix().getIpv4Prefix().getValue());
+ return topology;
+ });
// delete route
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
wTx.delete(LogicalDatastoreType.OPERATIONAL, this.ipv4RouteIID);
wTx.submit();
- final Topology topologyDeleted = getTopology(this.ipv4TopoBuilder.getInstanceIdentifier()).get();
- assertEquals(0, topologyDeleted.getNode().size());
+ readDataOperational(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(0, topology.getNode().size());
+ return topology;
+ });
this.ipv4TopoBuilder.close();
- assertFalse(getTopology(this.ipv4TopoBuilder.getInstanceIdentifier()).isPresent());
+ checkNotPresentOperational(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier());
}
private void updateIpv4Route(final Ipv4Route data) {
package org.opendaylight.bgpcep.bgp.topology.provider;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.opendaylight.bgpcep.bgp.topology.provider.Ipv4ReachabilityTopologyBuilderTest.PATH_ID;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
-import com.google.common.base.Optional;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@Override
protected void setupWithDataBroker(final DataBroker dataBroker) {
super.setupWithDataBroker(dataBroker);
- this.ipv6TopoBuilder = new Ipv6ReachabilityTopologyBuilder(dataBroker, LOC_RIB_REF, TEST_TOPOLOGY_ID);
+ this.ipv6TopoBuilder = new Ipv6ReachabilityTopologyBuilder(getDataBroker(), LOC_RIB_REF, TEST_TOPOLOGY_ID);
this.ipv6TopoBuilder.start();
- final InstanceIdentifier<Tables> path = this.ipv6TopoBuilder.tableInstanceIdentifier(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
- this.ipv6RouteIID = path.builder().child((Class) Ipv6Routes.class).child(Ipv6Route.class, new Ipv6RouteKey(new PathId(PATH_ID),
- new Ipv6Prefix(ROUTE_IP6PREFIX))).build();
+ final InstanceIdentifier<Tables> path = this.ipv6TopoBuilder
+ .tableInstanceIdentifier(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ this.ipv6RouteIID = path.builder().child((Class) Ipv6Routes.class)
+ .child(Ipv6Route.class, new Ipv6RouteKey(new PathId(PATH_ID),
+ new Ipv6Prefix(ROUTE_IP6PREFIX))).build();
}
@Test
- public void testIpv6ReachabilityTopologyBuilder() throws TransactionCommitFailedException {
+ public void testIpv6ReachabilityTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
// create route
updateIpv6Route(createIpv6Route(NEXT_HOP));
- final Optional<Topology> topologyMaybe = getTopology(this.ipv6TopoBuilder.getInstanceIdentifier());
- assertTrue(topologyMaybe.isPresent());
- final Topology topology = topologyMaybe.get();
- assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
- assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpIpv6ReachabilityTopology());
- assertEquals(1, topology.getNode().size());
- final Node node = topology.getNode().get(0);
- assertEquals(NEXT_HOP, node.getNodeId().getValue());
- assertEquals(ROUTE_IP6PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv6Prefix().getValue());
+
+ readDataOperational(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier(), topology -> {
+ final TopologyTypes1 topologyType = topology.getTopologyTypes().getAugmentation(TopologyTypes1.class);
+ assertNotNull(topologyType);
+ assertNotNull(topologyType.getBgpIpv6ReachabilityTopology());
+ assertEquals(1, topology.getNode().size());
+ final Node node = topology.getNode().get(0);
+ assertEquals(NEXT_HOP, node.getNodeId().getValue());
+ assertEquals(ROUTE_IP6PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix()
+ .get(0).getPrefix().getIpv6Prefix().getValue());
+ return topology;
+ });
// update route
updateIpv6Route(createIpv6Route(NEW_NEXT_HOP));
- final Topology topologyUpdated = getTopology(this.ipv6TopoBuilder.getInstanceIdentifier()).get();
- assertEquals(1, topologyUpdated.getNode().size());
- final Node nodeUpdated = topologyUpdated.getNode().get(0);
- assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
- assertEquals(ROUTE_IP6PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv6Prefix().getValue());
+
+ readDataOperational(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.getNode().size());
+ final Node nodeUpdated = topology.getNode().get(0);
+ assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
+ assertEquals(ROUTE_IP6PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix()
+ .get(0).getPrefix().getIpv6Prefix().getValue());
+ return topology;
+ });
// delete route
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
wTx.delete(LogicalDatastoreType.OPERATIONAL, this.ipv6RouteIID);
wTx.submit();
- final Topology topologyDeleted = getTopology(this.ipv6TopoBuilder.getInstanceIdentifier()).get();
- assertEquals(0, topologyDeleted.getNode().size());
+ readDataOperational(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(0, topology.getNode().size());
+ return topology;
+ });
this.ipv6TopoBuilder.close();
- assertFalse(getTopology(this.ipv6TopoBuilder.getInstanceIdentifier()).isPresent());
+ checkNotPresentOperational(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier());
}
private void updateIpv6Route(final Ipv6Route data) {
wTx.submit();
}
- public Ipv6Route createIpv6Route(final String netxHop) {
+ private Ipv6Route createIpv6Route(final String netxHop) {
final Attributes attribute = new AttributesBuilder()
.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
.setCNextHop(new Ipv6NextHopCaseBuilder().setIpv6NextHop(
package org.opendaylight.bgpcep.bgp.topology.provider;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
-import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import io.netty.buffer.Unpooled;
import java.math.BigInteger;
import java.util.Collections;
import java.util.List;
import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
@Override
protected void setupWithDataBroker(final DataBroker dataBroker) {
super.setupWithDataBroker(dataBroker);
- this.linkstateTopoBuilder = new LinkstateTopologyBuilder(dataBroker, LOC_RIB_REF, TEST_TOPOLOGY_ID, LISTENER_RESTART_TIME, LISTENER_ENFORCE_COUNTER);
+ this.linkstateTopoBuilder = new LinkstateTopologyBuilder(getDataBroker(), LOC_RIB_REF, TEST_TOPOLOGY_ID, LISTENER_RESTART_TIME, LISTENER_ENFORCE_COUNTER);
this.linkstateTopoBuilder.start();
final InstanceIdentifier<Tables> path = this.linkstateTopoBuilder.tableInstanceIdentifier(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
- this.linkstateRouteIID = path.builder().child((Class)LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).build();
+ this.linkstateRouteIID = path.builder().child((Class) LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).build();
+
}
@After
public void tearDown() throws Exception {
this.linkstateTopoBuilder.close();
- assertFalse(getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).isPresent());
+ checkNotPresentOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier());
}
@Test
- public void testLinkstateTopologyBuilderTopologyTypes() {
- final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
- assertTrue(topologyMaybe.isPresent());
- final Topology topology = topologyMaybe.get();
- assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
- assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpLinkstateTopology());
+ public void testLinkstateTopologyBuilderTopologyTypes() throws ReadFailedException {
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
+ assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpLinkstateTopology());
+ return topology;
+ });
}
@Test
- public void testIsisLinkstateTopologyBuilder() throws TransactionCommitFailedException {
+ public void testIsisLinkstateTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
// create node
updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.IsisLevel2, "node1", NODE_1_AS, ROUTER_1_ID));
- final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
- assertTrue(topologyMaybe.isPresent());
- final Topology topology1 = topologyMaybe.get();
- assertEquals(1, topology1.getNode().size());
- final Node node1 = topology1.getNode().get(0);
- assertEquals(NODE_1_ISIS_ID, node1.getNodeId().getValue());
- final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
- assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
- assertEquals("node1", igpNode1.getName().getValue());
- final IgpNodeAttributes1 igpNodeAttributes1 = igpNode1.getAugmentation(IgpNodeAttributes1.class);
- assertEquals("0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId().getValue());
- assertEquals(ROUTER_1_ID, igpNodeAttributes1.getIsisNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
- assertEquals("47.0000.0000.0000.0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getNet().get(0).getValue());
- assertNull(igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class));
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.getNode().size());
+ final Node node1 = topology.getNode().get(0);
+ assertEquals(NODE_1_ISIS_ID, node1.getNodeId().getValue());
+ final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
+ assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
+ assertEquals("node1", igpNode1.getName().getValue());
+ final IgpNodeAttributes1 igpNodeAttributes1 = igpNode1.getAugmentation(IgpNodeAttributes1.class);
+ assertEquals("0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId().getValue());
+ assertEquals(ROUTER_1_ID, igpNodeAttributes1.getIsisNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
+ assertEquals("47.0000.0000.0000.0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getNet().get(0).getValue());
+ assertNull(igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class));
+ return topology;
+ });
+
// create link
updateLinkstateRoute(createLinkstateLinkRoute(ProtocolId.IsisLevel2, NODE_1_AS, NODE_2_AS, "link1"));
- final Topology topology2 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
- assertEquals(1, topology2.getLink().size());
- final Link link1 = topology2.getLink().get(0);
- assertEquals(2, topology2.getNode().size());
- assertEquals(1, topology2.getNode().get(0).getTerminationPoint().size());
- assertEquals(1, topology2.getNode().get(1).getTerminationPoint().size());
- assertEquals("bgpls://IsisLevel2:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
- assertEquals(NODE_1_ISIS_ID, link1.getSource().getSourceNode().getValue());
- assertEquals(NODE_2_ISIS_ID, link1.getDestination().getDestNode().getValue());
- final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
- assertEquals("link1", igpLink1.getName());
- assertEquals((short) 1, igpLink1.getAugmentation(IgpLinkAttributes1.class).getIsisLinkAttributes().getMultiTopologyId().shortValue());
- assertNull(igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class));
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.getLink().size());
+ final Link link1 = topology.getLink().get(0);
+ assertEquals(2, topology.getNode().size());
+ assertEquals(1, topology.getNode().get(0).getTerminationPoint().size());
+ assertEquals(1, topology.getNode().get(1).getTerminationPoint().size());
+ assertEquals("bgpls://IsisLevel2:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
+ assertEquals(NODE_1_ISIS_ID, link1.getSource().getSourceNode().getValue());
+ assertEquals(NODE_2_ISIS_ID, link1.getDestination().getDestNode().getValue());
+ final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
+ assertEquals("link1", igpLink1.getName());
+ assertEquals((short) 1, igpLink1.getAugmentation(IgpLinkAttributes1.class).getIsisLinkAttributes().getMultiTopologyId().shortValue());
+ assertNull(igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class));
+ return topology;
+ });
+
// update node
updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.IsisLevel2, "updated-node", NODE_1_AS, ROUTER_2_ID));
- final Topology topology3 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
- final IgpNodeAttributes igpNode2 = topology3.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
- assertEquals(ROUTER_2_ID, igpNode2.getRouterId().get(0).getIpv4Address().getValue());
- assertEquals("updated-node", igpNode2.getName().getValue());
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.getNode().size());
+ final IgpNodeAttributes igpNode2 = topology.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
+ assertEquals(ROUTER_2_ID, igpNode2.getRouterId().get(0).getIpv4Address().getValue());
+ assertEquals("updated-node", igpNode2.getName().getValue());
+ return topology;
+ });
// remove
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
wTx.delete(LogicalDatastoreType.OPERATIONAL, this.linkstateRouteIID);
wTx.submit();
- final Topology topology4 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
- assertEquals(0, topology4.getNode().size());
- assertEquals(0, topology4.getLink().size());
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(0, topology.getNode().size());
+ assertEquals(0, topology.getLink().size());
+ return topology;
+ });
}
@Test
- public void testOspfLinkstateTopologyBuilder() throws TransactionCommitFailedException {
+ public void testOspfLinkstateTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
// create node
updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.Ospf, "node1", NODE_1_AS, ROUTER_1_ID));
- final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
- assertTrue(topologyMaybe.isPresent());
- final Topology topology1 = topologyMaybe.get();
- assertEquals(1, topology1.getNode().size());
- final Node node1 = topology1.getNode().get(0);
- assertEquals(NODE_1_OSPF_ID, node1.getNodeId().getValue());
- final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
- assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
- assertEquals("node1", igpNode1.getName().getValue());
- assertNull(igpNode1.getAugmentation(IgpNodeAttributes1.class));
- assertEquals(ROUTER_1_ID, igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class).getOspfNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.getNode().size());
+ final Node node1 = topology.getNode().get(0);
+ assertEquals(NODE_1_OSPF_ID, node1.getNodeId().getValue());
+ final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
+ assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
+ assertEquals("node1", igpNode1.getName().getValue());
+ assertNull(igpNode1.getAugmentation(IgpNodeAttributes1.class));
+ assertEquals(ROUTER_1_ID, igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class).getOspfNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
+ return topology;
+ });
// update node with prefix
updateLinkstateRoute(createLinkstatePrefixRoute(ProtocolId.Ospf, NODE_1_AS, NODE_1_PREFIX, 500L, ROUTER_1_ID));
- final Topology topology3 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
- final IgpNodeAttributes igpNode2 = topology3.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
- assertEquals(1, igpNode2.getPrefix().size());
- final Prefix prefix = igpNode2.getPrefix().get(0);
- assertEquals(NODE_1_PREFIX, prefix.getPrefix().getIpv4Prefix().getValue());
- assertEquals(500L, prefix.getMetric().longValue());
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ final IgpNodeAttributes igpNode2 = topology.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
+ assertEquals(1, igpNode2.getPrefix().size());
+ final Prefix prefix = igpNode2.getPrefix().get(0);
+ assertEquals(NODE_1_PREFIX, prefix.getPrefix().getIpv4Prefix().getValue());
+ assertEquals(500L, prefix.getMetric().longValue());
+ return topology;
+ });
+
// create link
updateLinkstateRoute(createLinkstateLinkRoute(ProtocolId.Ospf, NODE_1_AS, NODE_2_AS, "link1"));
- final Topology topology2 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
- assertEquals(1, topology2.getLink().size());
- final Link link1 = topology2.getLink().get(0);
- assertEquals(2, topology2.getNode().size());
- assertEquals(1, topology2.getNode().get(0).getTerminationPoint().size());
- assertEquals(1, topology2.getNode().get(1).getTerminationPoint().size());
- assertEquals("bgpls://Ospf:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
- assertEquals(NODE_1_OSPF_ID, link1.getSource().getSourceNode().getValue());
- assertEquals(NODE_2_OSPF_ID, link1.getDestination().getDestNode().getValue());
- final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
- assertEquals("link1", igpLink1.getName());
- assertNull(igpLink1.getAugmentation(IgpLinkAttributes1.class));
- assertEquals((short) 1, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getMultiTopologyId().shortValue());
- assertEquals(2, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getTed().getSrlg().getSrlgValues().size());
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.getLink().size());
+ final Link link1 = topology.getLink().get(0);
+ assertEquals(2, topology.getNode().size());
+ assertEquals(1, topology.getNode().get(0).getTerminationPoint().size());
+ assertEquals(1, topology.getNode().get(1).getTerminationPoint().size());
+ assertEquals("bgpls://Ospf:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
+ assertEquals(NODE_1_OSPF_ID, link1.getSource().getSourceNode().getValue());
+ assertEquals(NODE_2_OSPF_ID, link1.getDestination().getDestNode().getValue());
+ final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
+ assertEquals("link1", igpLink1.getName());
+ assertNull(igpLink1.getAugmentation(IgpLinkAttributes1.class));
+ assertEquals((short) 1, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getMultiTopologyId().shortValue());
+ assertEquals(2, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getTed().getSrlg().getSrlgValues().size());
+ return topology;
+ });
+
+
}
/**
private LinkstateRoute createLinkstateNodeRoute(final ProtocolId protocolId, final String nodeName, final AsNumber asNumber, final String ipv4RouterId) {
return createBaseBuilder(protocolId)
- .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder().setNodeDescriptors(new NodeDescriptorsBuilder().setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{ 0, 0, 1, 2, 3, 4 })).build()).build()).setAsNumber(asNumber).build()).build())
+ .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder().setNodeDescriptors(new NodeDescriptorsBuilder().setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 1, 2, 3, 4})).build()).build()).setAsNumber(asNumber).build()).build())
.setAttributes(new AttributesBuilder()
.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
.addAugmentation(Attributes1.class, new Attributes1Builder().setLinkStateAttribute(new NodeAttributesCaseBuilder().setNodeAttributes(new NodeAttributesBuilder()
.setAttributes(new AttributesBuilder()
.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
.addAugmentation(Attributes1.class, new Attributes1Builder().setLinkStateAttribute(new PrefixAttributesCaseBuilder().setPrefixAttributes(new PrefixAttributesBuilder().setOspfForwardingAddress(new IpAddress(new Ipv4Address(ospfFwdAddress))).setPrefixMetric(new IgpMetric(igpMetric)).build()).build()).build()).build())
- .build();
+ .build();
}
private LinkstateRoute createLinkstateLinkRoute(final ProtocolId protocolId, final AsNumber localAs, final AsNumber remoteAs, final String linkName) {
return createBaseBuilder(protocolId)
.setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCaseBuilder()
- .setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder().setAsNumber(localAs).setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{ 0, 0, 1, 2, 3, 4 })).build()).build()).build())
+ .setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder().setAsNumber(localAs).setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 1, 2, 3, 4})).build()).build()).build())
.setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder().setAsNumber(remoteAs).build())
.setLinkDescriptors(new LinkDescriptorsBuilder().setMultiTopologyId(new TopologyIdentifier(1)).build())
.build())
package org.opendaylight.protocol.data.change.counter;
import static org.junit.Assert.assertEquals;
-import static org.opendaylight.protocol.util.CheckUtil.checkNull;
-import static org.opendaylight.protocol.util.CheckUtil.checkPresent;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.checkPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
@Test
public void testDataChangeCounter() throws Exception {
final TopologyDataChangeCounter counter = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID1);
- readData(getDataBroker(), this.counterInstanceId_1, count -> {
+ readDataOperational(getDataBroker(), this.counterInstanceId_1, count -> {
assertEquals(0, count.getCount().longValue());
return count;
});
counter.onDataTreeChanged(null);
- readData(getDataBroker(), this.counterInstanceId_1, count -> {
+ readDataOperational(getDataBroker(), this.counterInstanceId_1, count -> {
assertEquals(1, count.getCount().longValue());
return count;
});
counter.close();
- checkNull(getDataBroker(), this.counterInstanceId_1);
+ checkNotPresentOperational(getDataBroker(), this.counterInstanceId_1);
}
@Test
public void testDataChangeCounterTwoInstances() throws Exception {
final TopologyDataChangeCounter counter1 = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID1);
- readData(getDataBroker(), this.counterInstanceId_1, count -> {
+ readDataOperational(getDataBroker(), this.counterInstanceId_1, count -> {
assertEquals(0, count.getCount().longValue());
return count;
});
final TopologyDataChangeCounter counter2 = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID2);
- readData(getDataBroker(), this.counterInstanceId_2, count -> {
+ readDataOperational(getDataBroker(), this.counterInstanceId_2, count -> {
assertEquals(0, count.getCount().longValue());
return count;
});
counter1.onDataTreeChanged(null);
- readData(getDataBroker(), this.counterInstanceId_1, count -> {
+ readDataOperational(getDataBroker(), this.counterInstanceId_1, count -> {
assertEquals(1, count.getCount().longValue());
return count;
});
- readData(getDataBroker(), this.counterInstanceId_2, count -> {
+ readDataOperational(getDataBroker(), this.counterInstanceId_2, count -> {
assertEquals(0, count.getCount().longValue());
return count;
});
counter1.close();
- checkNull(getDataBroker(), this.counterInstanceId_1);
+ checkNotPresentOperational(getDataBroker(), this.counterInstanceId_1);
// Check that counter2 does not get deleted
- checkPresent(getDataBroker(), this.counterInstanceId_2);
+ checkPresentOperational(getDataBroker(), this.counterInstanceId_2);
counter2.close();
- checkNull(getDataBroker(), this.counterInstanceId_2);
+ checkNotPresentOperational(getDataBroker(), this.counterInstanceId_2);
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
import com.google.common.collect.Lists;
import java.nio.charset.StandardCharsets;
Pcrpt pcRptMsg = createSrPcRpt("1.1.1.1", "sr-path1", 1L, true);
this.listener.onMessage(this.session, pcRptMsg);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check sr-path
final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
assertNotNull(reportedLsps);
pcRptMsg = createSrPcRpt("1.1.1.3", "sr-path2", 2L, false);
this.listener.onMessage(this.session, pcRptMsg);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check second lsp sr-path
final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
assertNotNull(reportedLsps);
pcRptMsg = createSrPcRpt("1.1.1.2", "sr-path1", 1L, true);
this.listener.onMessage(this.session, pcRptMsg);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check updated sr-path
final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
assertNotNull(reportedLsps);
import static org.junit.Assert.assertFalse;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
import com.google.common.base.Optional;
import java.math.BigInteger;
//report LSP + LSP-DB version number
final Pcrpt pcRpt = getPcrpt(1L, "test");
this.listener.onMessage(session, pcRpt);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertFalse(pcc.getReportedLsp().isEmpty());
return pcc;
});
final LspDbVersion localDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(2L)).build();
session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
this.listener.onSessionUp(session);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - IncrementalSync state
assertEquals(PccSyncState.IncrementalSync, pcc.getStateSync());
//check reported LSP - persisted from previous session
//report LSP2 + LSP-DB version number 2
final Pcrpt pcRpt2 = getPcrpt(2L,"testsecond");
this.listener.onMessage(session, pcRpt2);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - synchronized
assertEquals(PccSyncState.IncrementalSync, pcc.getStateSync());
//check reported LSP is not empty
//sync rpt + LSP-DB
final Pcrpt syncMsg = getSyncPcrt();
this.listener.onMessage(session, syncMsg);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - synchronized
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
//check reported LSP is empty, LSP state from previous session was purged
//report LSP3 + LSP-DB version number 4
final Pcrpt pcRpt3 = getPcrpt(3L,"testthird");
this.listener.onMessage(session, pcRpt3);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - synchronized
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
assertEquals(3,pcc.getReportedLsp().size());
import static org.junit.Assert.assertFalse;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
import com.google.common.base.Optional;
import java.math.BigInteger;
final Pcrpt pcRpt = getPcrt();
this.listener.onMessage(this.session, pcRpt);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
assertFalse(pcc.getReportedLsp().isEmpty());
return pcc;
//PCEP Trigger Full Resync
this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).build());
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertEquals(PccSyncState.PcepTriggeredResync, pcc.getStateSync());
return pcc;
});
//end of sync
final Pcrpt syncMsg = getSyncMsg();
this.listener.onMessage(this.session, syncMsg);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - synchronized
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
return pcc;
});
this.listener.onMessage(this.session, pcRpt);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertEquals(1, pcc.getReportedLsp().size());
return pcc;
});
this.listener.onMessage(this.session, pcRpt);
//end of sync
this.listener.onMessage(this.session, syncMsg);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - synchronized
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
//check reported LSP is not empty, Stale LSP state were purged
//report LSP + LSP-DB version number
final Pcrpt pcRpt = getPcrt();
this.listener.onMessage(this.session, pcRpt);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
final List<ReportedLsp> reportedLspPcc = pcc.getReportedLsp();
assertFalse(reportedLspPcc.isEmpty());
//Trigger Full Resync
this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).setName("test").build());
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertEquals(PccSyncState.PcepTriggeredResync, pcc.getStateSync());
assertFalse(pcc.getReportedLsp().isEmpty());
return pcc;
});
this.listener.onMessage(this.session, pcRpt);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertFalse(pcc.getReportedLsp().isEmpty());
return pcc;
});
//sync rpt + LSP-DB
final Pcrpt syncMsg = getSyncMsg();
this.listener.onMessage(this.session, syncMsg);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - synchronized
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
//check reported LSP
//Trigger Full Resync
this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).setName("test").build());
this.listener.onMessage(this.session, syncMsg);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - synchronized
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
//check reported LSP
import static org.junit.Assert.assertTrue;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
import com.google.common.base.Optional;
import java.math.BigInteger;
final PCEPSession session = getPCEPSession(getOpen(localDbVersion, Boolean.FALSE), getOpen(localDbVersion2, Boolean.FALSE));
this.listener.onSessionUp(session);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - not synchronized and TriggeredInitialSync state
assertEquals(PccSyncState.TriggeredInitialSync, pcc.getStateSync());
return pcc;
//sync rpt + LSP-DB
final Pcrpt syncMsg = getsyncMsg();
this.listener.onMessage(session, syncMsg);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - synchronized
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
//check reported LSP is empty, LSP state from previous session was purged
final Pcrpt pcRpt = getPcrpt();
this.listener.onMessage(session, pcRpt);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertFalse(pcc.getReportedLsp().isEmpty());
return pcc;
});
import static org.junit.Assert.assertTrue;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
import com.google.common.base.Optional;
import java.math.BigInteger;
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build()).build()).build()).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(1L)), null);
this.listener.onMessage(session, pcRpt);
//check topology
- readData(getDataBroker(), this.pathComputationClientIId.builder().augmentation(PathComputationClient1.class)
+ readDataOperational(getDataBroker(), this.pathComputationClientIId.builder().augmentation(PathComputationClient1.class)
.child(LspDbVersion.class).build(), dbVersion -> {
assertEquals(1L, dbVersion.getLspDbVersionValue().longValue());
return dbVersion;
//drop session
this.listener.onSessionDown(session, new IllegalStateException());
- //check topology - node is persisted
- readData(getDataBroker(), TOPO_IID, topology -> {
+ readDataOperational(getDataBroker(), TOPO_IID, topology -> {
assertFalse(topology.getNode().isEmpty());
return topology;
});
+ //check topology - node is persisted
}
@Test
final PCEPSession session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
this.listener.onSessionUp(session);
//check node - synchronized
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
return pcc;
});
.setPlspId(new PlspId(1L)).setSync(true).setRemove(false).setOperational(OperationalStatus.Active)
.build(), Optional.absent(), createPath(Collections.emptyList()));
this.listener.onMessage(session, pcRpt);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertFalse(pcc.getReportedLsp().isEmpty());
return pcc;
});
session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
this.listener.onSessionUp(session);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - not synchronized
assertEquals(PccSyncState.InitialResync, pcc.getStateSync());
//check reported LSP - persisted from previous session
true, false), Optional.absent(),
createPath(Collections.emptyList()));
this.listener.onMessage(session, syncMsg);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
//check node - synchronized
assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
//check reported LSP is empty, LSP state from previous session was purged
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLspTlvs;
-import static org.opendaylight.protocol.util.CheckUtil.checkNull;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(),
Optional.of(MsgBuilderUtil.createSrp(0L)), null);
this.listener.onMessage(this.session, esm);
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertEquals(this.testAddress, pcc.getIpAddress().getIpv4Address().getValue());
// reported lsp so far empty, has not received response (PcRpt) yet
assertTrue(pcc.getReportedLsp().isEmpty());
this.listener.onMessage(this.session, pcRpt);
// check created lsp
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertEquals(1, pcc.getReportedLsp().size());
final ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
assertEquals(this.TUNNEL_NAME, reportedLsp.getName());
this.listener.onMessage(this.session, pcRpt2);
//check updated lsp
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertEquals(1, pcc.getReportedLsp().size());
final ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
assertEquals(this.TUNNEL_NAME, reportedLsp.getName());
this.listener.onMessage(this.session, pcRpt3);
// check if lsp was removed
- readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
assertEquals(0, pcc.getReportedLsp().size());
return pcc;
});
verify(this.listenerReg, times(0)).close();
this.listener.onSessionUp(this.session);
// verify the session was NOT added to topology
- checkNull(getDataBroker(), TOPO_IID);
+ checkNotPresentOperational(getDataBroker(), TOPO_IID);
// still, the session should not be registered and thus close() is never called
verify(this.listenerReg, times(0)).close();
// send request
.setRemove(false).setOperational(OperationalStatus.Active).build(),
Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
this.listener.onMessage(this.session, pcRpt);
- readData(getDataBroker(), TOPO_IID, topology -> {
+ readDataOperational(getDataBroker(), TOPO_IID, topology -> {
assertEquals(1, topology.getNode().size());
return topology;
});
// node should be removed after termination
this.listener.onSessionTerminated(this.session, new PCEPCloseTermination(TerminationReason.UNKNOWN));
verify(this.listenerReg, times(1)).close();
- checkNull(getDataBroker(), this.pathComputationClientIId);
+ checkNotPresentOperational(getDataBroker(), this.pathComputationClientIId);
}
@Test
.build();
this.listener.onSessionUp(this.session);
this.listener.onMessage(this.session, rptmsg);
- readData(getDataBroker(), TOPO_IID, node -> {
+ readDataOperational(getDataBroker(), TOPO_IID, node -> {
assertFalse(node.getNode().isEmpty());
return node;
});
</dependency>
<!-- Testing dependencies -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testtool-util</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
package org.opendaylight.bgpcep.pcep.tunnel.provider;
-import com.google.common.base.Optional;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
+
import com.google.common.collect.Lists;
+import java.util.Collections;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
private static final String LSP2_NAME = "lsp2";
private static final long LSP2_ID = 2;
- private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).build();
- private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).build();
+ private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).build();
+ private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.
+ builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).build();
private ListenerRegistration<NodeChangedListener> listenerRegistration;
@Before
public void setUp() throws TransactionCommitFailedException {
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID, new TopologyBuilder().setKey(new TopologyKey(PCEP_TOPOLOGY_ID)).setNode(Lists.<Node>newArrayList()).setTopologyId(PCEP_TOPOLOGY_ID).build(), true);
- wTx.put(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID, new TopologyBuilder().setKey(new TopologyKey(TUNNEL_TOPOLOGY_ID)).setTopologyId(TUNNEL_TOPOLOGY_ID).build(), true);
+ wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID, new TopologyBuilder()
+ .setKey(new TopologyKey(PCEP_TOPOLOGY_ID)).setNode(Lists.newArrayList())
+ .setTopologyId(PCEP_TOPOLOGY_ID).build(), true);
+ wTx.put(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID, new TopologyBuilder()
+ .setKey(new TopologyKey(TUNNEL_TOPOLOGY_ID)).setTopologyId(TUNNEL_TOPOLOGY_ID).build(), true);
wTx.submit().checkedGet();
- final NodeChangedListener nodeListener = new NodeChangedListener(getDataBroker(), PCEP_TOPOLOGY_ID, TUNNEL_TOPO_IID);
- this.listenerRegistration = getDataBroker().registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.child(Node.class)), nodeListener);
+ final NodeChangedListener nodeListener = new NodeChangedListener(getDataBroker(),
+ PCEP_TOPOLOGY_ID, TUNNEL_TOPO_IID);
+ this.listenerRegistration = getDataBroker().registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.child(Node.class)), nodeListener);
}
@Test
public void testNodeChangedListener() throws ReadFailedException, TransactionCommitFailedException {
// add node -> create two nodes with TPs and link
createNode(NODE1_ID, NODE1_IPV4, LSP1_NAME, LSP1_ID, NODE2_IPV4);
- final Topology tunnelTopo = readTunnelTopology().get();
- Assert.assertEquals(2, tunnelTopo.getNode().size());
+ final Topology tunnelTopo = readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, tunnelTopo1 -> {
+ assertNotNull(tunnelTopo1.getNode());
+ assertEquals(2, tunnelTopo1.getNode().size());
+ return tunnelTopo1;
+ });
final NodeId srcId = new NodeId("ip://" + new IpAddress(new Ipv4Address(NODE1_IPV4)));
final NodeId dstId = new NodeId("ip://" + new IpAddress(new Ipv4Address(NODE2_IPV4)));
- Node dst;
- Node src;
+ final Node dst;
+ final Node src;
if (tunnelTopo.getNode().get(0).getNodeId().equals(srcId)) {
src = tunnelTopo.getNode().get(0);
- dst = tunnelTopo.getNode().get(1);
+ dst = tunnelTopo.getNode().get(1);
} else {
src = tunnelTopo.getNode().get(1);
- dst = tunnelTopo.getNode().get(0);
+ dst = tunnelTopo.getNode().get(0);
}
Assert.assertEquals(srcId, src.getNodeId());
// update second node -> adds supporting node and second link
createNode(NODE2_ID, NODE2_IPV4, LSP2_NAME, LSP2_ID, NODE1_IPV4);
- final Topology updatedNodeTopo = readTunnelTopology().get();
- Assert.assertEquals(2, updatedNodeTopo.getNode().size());
-
- Node updatedNode;
-
- if (updatedNodeTopo.getNode().get(0).getNodeId().equals(srcId)) {
- updatedNode = updatedNodeTopo.getNode().get(1);
- } else {
- updatedNode = updatedNodeTopo.getNode().get(0);
- }
-
- Assert.assertEquals(1, updatedNode.getSupportingNode().size());
- final SupportingNode sNode2 = updatedNode.getSupportingNode().get(0);
- Assert.assertEquals(NODE2_ID, sNode2.getNodeRef());
-
- Assert.assertEquals(2, updatedNodeTopo.getLink().size());
-
- Link link2;
- if (updatedNodeTopo.getLink().get(0).getSource().getSourceNode().equals(srcId)) {
- link2 = updatedNodeTopo.getLink().get(1);
- } else {
- link2 = updatedNodeTopo.getLink().get(0);
- }
-
- Assert.assertEquals(dstId, link2.getSource().getSourceNode());
- Assert.assertEquals(dstNodeTpId, link2.getSource().getSourceTp());
- Assert.assertEquals(srcId, link2.getDestination().getDestNode());
- Assert.assertEquals(srcNodeTpId, link2.getDestination().getDestTp());
+ readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, updatedNodeTopo -> {
+ assertNotNull(updatedNodeTopo.getNode());
+ Assert.assertEquals(2, updatedNodeTopo.getNode().size());
+ final Node updatedNode;
+ if (updatedNodeTopo.getNode().get(0).getNodeId().equals(srcId)) {
+ updatedNode = updatedNodeTopo.getNode().get(1);
+ } else {
+ updatedNode = updatedNodeTopo.getNode().get(0);
+ }
+
+ assertNotNull(updatedNode.getSupportingNode());
+ Assert.assertEquals(1, updatedNode.getSupportingNode().size());
+ final SupportingNode sNode2 = updatedNode.getSupportingNode().get(0);
+ Assert.assertEquals(NODE2_ID, sNode2.getNodeRef());
+ Assert.assertEquals(2, updatedNodeTopo.getLink().size());
+ return updatedNodeTopo;
+
+ });
+
+ readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, updatedNodeTopo -> {
+ final Link link2;
+ if (updatedNodeTopo.getLink().get(0).getSource().getSourceNode().equals(srcId)) {
+ link2 = updatedNodeTopo.getLink().get(1);
+ } else {
+ link2 = updatedNodeTopo.getLink().get(0);
+ }
+ assertEquals(dstId, link2.getSource().getSourceNode());
+ assertEquals(dstNodeTpId, link2.getSource().getSourceTp());
+ assertEquals(srcId, link2.getDestination().getDestNode());
+ assertEquals(srcNodeTpId, link2.getDestination().getDestTp());
+ return updatedNodeTopo;
+ });
// remove nodes -> remove link
removeNode(NODE1_ID);
removeNode(NODE2_ID);
- final Topology removedNodeTopo = readTunnelTopology().get();
- Assert.assertEquals(0, removedNodeTopo.getNode().size());
- Assert.assertEquals(0, removedNodeTopo.getLink().size());
+ readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, removedNodeTopo -> {
+ assertEquals(0, removedNodeTopo.getNode().size());
+ assertEquals(0, removedNodeTopo.getLink().size());
+ return removedNodeTopo;
+ });
}
@After
this.listenerRegistration.close();
}
- private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final long lspId, final String dstIpv4Address) throws TransactionCommitFailedException {
+ private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final long lspId,
+ final String dstIpv4Address) throws TransactionCommitFailedException {
final NodeBuilder nodeBuilder = new NodeBuilder();
nodeBuilder.setKey(new NodeKey(nodeId));
nodeBuilder.setNodeId(nodeId);
final PathBuilder pathBuilder = new PathBuilder();
pathBuilder.setKey(new PathKey(new LspId(lspId)));
- pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(new Bandwidth(new byte[] {0x00, 0x00, (byte) 0xff, (byte) 0xff})).build());
- pathBuilder.addAugmentation(Path1.class, new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4Address(ipv4Address)).setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4Address(dstIpv4Address)).build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
- final ReportedLsp reportedLps = new ReportedLspBuilder().setKey(new ReportedLspKey(lspName)).setPath(Lists.newArrayList(pathBuilder.build())).build();
+ pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(
+ new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0xff})).build());
+ pathBuilder.addAugmentation(Path1.class, new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder()
+ .setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(
+ new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4Address(ipv4Address)).setIpv4ExtendedTunnelId(
+ new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4Address(dstIpv4Address))
+ .build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
+ final ReportedLsp reportedLps = new ReportedLspBuilder().setKey(new ReportedLspKey(lspName)).setPath(
+ Collections.singletonList(pathBuilder.build())).build();
final Node1Builder node1Builder = new Node1Builder();
- node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address))).build());
+ node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized)
+ .setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address)))
+ .build());
nodeBuilder.addAugmentation(Node1.class, node1Builder.build());
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build(), nodeBuilder.build());
+ wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class,
+ new NodeKey(nodeId)).build(), nodeBuilder.build());
wTx.submit().checkedGet();
}
wTx.delete(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build());
wTx.submit().checkedGet();
}
-
- private Optional<Topology> readTunnelTopology() throws ReadFailedException {
- final ReadTransaction rTx = getDataBroker().newReadOnlyTransaction();
- return rTx.read(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID).checkedGet();
- }
}
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.checkPresentOperational;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
import java.util.List;
import java.util.Optional;
-import java.util.concurrent.ExecutionException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.bgpcep.programming.NanotimeUtil;
import org.opendaylight.bgpcep.programming.spi.Instruction;
import org.opendaylight.bgpcep.programming.spi.SchedulerException;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CancelInstructionInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CancelInstructionInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CleanInstructionsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.status.changed.DetailsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepUpdateTunnelInput;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
final SubmitInstructionInput mockedSubmit = getMockedSubmitInstructionInput("mockedSubmit");
this.testedProgrammingService.scheduleInstruction(mockedSubmit);
- checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit.getId())));
+ checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit.getId()));
// assert Schedule to executor
this.mockedExecutorWrapper.assertSubmittedTasksSize(1);
// assert Notification
this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit.getId(), InstructionStatus.Scheduled);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit.getId(),
+ InstructionStatus.Scheduled);
}
@Test
public void testScheduleDependingInstruction() throws Exception {
this.testedProgrammingService.scheduleInstruction(getMockedSubmitInstructionInput("mockedSubmit1"));
- final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+ final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
+ "mockedSubmit1");
this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
this.mockedExecutorWrapper.assertSubmittedTasksSize(2);
@Test
public void testScheduleDependingInstructionToFail() throws Exception {
try {
- this.testedProgrammingService.scheduleInstruction(getMockedSubmitInstructionInput("mockedSubmit", "dep1"));
+ this.testedProgrammingService.scheduleInstruction(getMockedSubmitInstructionInput("mockedSubmit",
+ "dep1"));
} catch (final SchedulerException e) {
assertThat(e.getMessage(), containsString("Unknown dependency ID"));
this.mockedNotificationServiceWrapper.assertNotificationsCount(0);
public void testCancelInstruction() throws Exception {
final SubmitInstructionInput mockedSubmit = getMockedSubmitInstructionInput("mockedSubmit");
this.testedProgrammingService.scheduleInstruction(mockedSubmit);
-
- checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit.getId())));
+ checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit.getId()));
final CancelInstructionInput mockedCancel = getCancelInstruction("mockedSubmit");
this.testedProgrammingService.cancelInstruction(mockedCancel);
- assertTrue(assertInstructionExists(mockedSubmit.getId()));
-
+ checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit.getId()));
this.mockedExecutorWrapper.assertSubmittedTasksSize(2);
this.mockedNotificationServiceWrapper.assertNotificationsCount(2);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit.getId(), InstructionStatus.Cancelled);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit.getId(),
+ InstructionStatus.Cancelled);
}
@Test
public void testCancelDependantInstruction() throws Exception {
final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
- final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+ final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
+ "mockedSubmit1");
this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
- final SubmitInstructionInput mockedSubmit3 = getMockedSubmitInstructionInput("mockedSubmit3", "mockedSubmit1", "mockedSubmit2");
+ final SubmitInstructionInput mockedSubmit3 = getMockedSubmitInstructionInput("mockedSubmit3",
+ "mockedSubmit1", "mockedSubmit2");
this.testedProgrammingService.scheduleInstruction(mockedSubmit3);
this.testedProgrammingService.cancelInstruction(getCancelInstruction("mockedSubmit1"));
this.mockedNotificationServiceWrapper.assertNotificationsCount(1 /*First Scheduled*/+ 3 /*First and all dependencies cancelled*/);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit1.getId(), InstructionStatus.Scheduled);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Cancelled);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit2.getId(), InstructionStatus.Cancelled);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit3.getId(), InstructionStatus.Cancelled);
-
- checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit1.getId())));
- checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit2.getId())));
- checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit3.getId())));
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit1.getId(),
+ InstructionStatus.Scheduled);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+ InstructionStatus.Cancelled);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit2.getId(),
+ InstructionStatus.Cancelled);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit3.getId(),
+ InstructionStatus.Cancelled);
+
+ checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit1.getId()));
+ checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit2.getId()));
+ checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit3.getId()));
}
@Test
public void testCleanInstructions() throws Exception {
final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
- final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+ final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
+ "mockedSubmit1");
this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
final CleanInstructionsInputBuilder cleanInstructionsInputBuilder = new CleanInstructionsInputBuilder();
final CleanInstructionsInput cleanInstructionsInput = cleanInstructionsInputBuilder.setId(
Lists.newArrayList(mockedSubmit1.getId(), mockedSubmit2.getId())).build();
- ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput = this.testedProgrammingService.cleanInstructions(cleanInstructionsInput);
+ ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput = this.testedProgrammingService
+ .cleanInstructions(cleanInstructionsInput);
assertCleanInstructionOutput(cleanedInstructionOutput, 2);
cleanedInstructionOutput = this.testedProgrammingService.cleanInstructions(cleanInstructionsInput);
assertCleanInstructionOutput(cleanedInstructionOutput, 0);
- checkEquals(()-> assertFalse(assertInstructionExists(mockedSubmit1.getId())));
- checkEquals(()-> assertFalse(assertInstructionExists(mockedSubmit2.getId())));
+ checkNotPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit1.getId()));
+ checkNotPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit2.getId()));
}
- private void assertCleanInstructionOutput(final ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput,
- final int unflushedCount) throws InterruptedException, java.util.concurrent.ExecutionException {
+ private void assertCleanInstructionOutput(final ListenableFuture<RpcResult<CleanInstructionsOutput>>
+ cleanedInstructionOutput, final int unflushedCount) throws InterruptedException,
+ java.util.concurrent.ExecutionException {
if (unflushedCount == 0) {
final List<InstructionId> unflushed = cleanedInstructionOutput.get().getResult().getUnflushed();
assertTrue(unflushed == null || unflushed.isEmpty());
public void testCloseProgrammingService() throws Exception {
final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
- final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+ final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
+ "mockedSubmit1");
this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
this.testedProgrammingService.close();
- this.mockedNotificationServiceWrapper.assertNotificationsCount(1/* First scheduled */+ 2/* Both cancelled at close */);
+ this.mockedNotificationServiceWrapper
+ .assertNotificationsCount(1/* First scheduled */+ 2/* Both cancelled at close */);
}
@Test(timeout = 30 * 1000)
public void testTimeoutWhileScheduledTransaction() throws Exception {
- final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
+ final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 *
+ INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
final Nanotime current = NanotimeUtil.currentTime();
final Nanotime deadlineNano = new Nanotime(current.getValue().add(deadlineOffset));
future.get();
- Thread.sleep(2 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS * 1000);
-
this.mockedNotificationServiceWrapper.assertNotificationsCount(2);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Cancelled);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+ InstructionStatus.Cancelled);
}
@Test(timeout = 30 * 1000)
public void testTimeoutWhileSuccessfulTransaction() throws Exception {
- final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
+ final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 *
+ INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
final Nanotime current = NanotimeUtil.currentTime();
final Nanotime deadlineNano = new Nanotime(current.getValue().add(deadlineOffset));
i.checkedExecutionStart();
i.executionCompleted(InstructionStatus.Successful, getDetails());
- Thread.sleep(2 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS * 1000);
-
this.mockedNotificationServiceWrapper.assertNotificationsCount(3);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Executing);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(), InstructionStatus.Successful);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+ InstructionStatus.Executing);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
+ InstructionStatus.Successful);
// Timeout in success should not do anything
}
@Test(timeout = 30 * 1000)
public void testTimeoutWhileExecutingWithDependenciesTransaction() throws Exception {
- final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
+ final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 *
+ INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
final Nanotime current = NanotimeUtil.currentTime();
final Nanotime deadlineNano = new Nanotime(current.getValue().add(deadlineOffset));
final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1", deadline);
final ListenableFuture<Instruction> future = this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
- final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+ final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
+ "mockedSubmit1");
this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
final Instruction i = future.get();
i.checkedExecutionStart();
- Thread.sleep(2 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS * 1000);
-
this.mockedNotificationServiceWrapper.assertNotificationsCount(4);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Executing);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(), InstructionStatus.Unknown);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(), InstructionStatus.Cancelled);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+ InstructionStatus.Executing);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
+ InstructionStatus.Unknown);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(),
+ InstructionStatus.Cancelled);
}
// TODO test deadline with state Queued
i.executionCompleted(InstructionStatus.Successful, getDetails());
this.mockedNotificationServiceWrapper.assertNotificationsCount(4);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Executing);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(), InstructionStatus.Successful);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(), InstructionStatus.Scheduled);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+ InstructionStatus.Executing);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
+ InstructionStatus.Successful);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(),
+ InstructionStatus.Scheduled);
i = future2.get();
i.checkedExecutionStart();
i.executionCompleted(InstructionStatus.Successful, getDetails());
this.mockedNotificationServiceWrapper.assertNotificationsCount(6);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(4, mockedSubmit2.getId(), InstructionStatus.Executing);
- this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(5, mockedSubmit2.getId(), InstructionStatus.Successful);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(4, mockedSubmit2.getId(),
+ InstructionStatus.Executing);
+ this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(5, mockedSubmit2.getId(),
+ InstructionStatus.Successful);
}
private Details getDetails() {
return getMockedSubmitInstructionInput(id, Optional.empty(), dependencyIds);
}
- private SubmitInstructionInput getMockedSubmitInstructionInput(final String id, final Optional<Nanotime> deadline, final String... dependencyIds) {
+ private SubmitInstructionInput getMockedSubmitInstructionInput(final String id, final Optional<Nanotime> deadline,
+ final String... dependencyIds) {
final SubmitInstructionInput mockedSubmitInstruction = mock(SubmitInstructionInput.class);
doReturn(PcepUpdateTunnelInput.class).when(mockedSubmitInstruction).getImplementedInterface();
doReturn(dependencies).when(mockedSubmitInstruction).getPreconditions();
doReturn(getInstructionId(id)).when(mockedSubmitInstruction).getId();
- doReturn(deadline.isPresent() ? deadline.get() : new Nanotime(BigInteger.valueOf(Long.MAX_VALUE))).when(mockedSubmitInstruction).getDeadline();
+ doReturn(deadline.isPresent() ? deadline.get() : new Nanotime(BigInteger.valueOf(Long.MAX_VALUE)))
+ .when(mockedSubmitInstruction).getDeadline();
return mockedSubmitInstruction;
}
return new InstructionId(id);
}
- private boolean assertInstructionExists(final InstructionId id) {
- try {
- return getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL,
- InstanceIdentifier.builder(InstructionsQueue.class, new InstructionsQueueKey(INSTRUCTIONS_QUEUE_KEY))
- .build().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.queue.Instruction.class,
- new InstructionKey(id))).get().isPresent();
- } catch (InterruptedException | ExecutionException e) {
- return false;
- }
+ private KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.
+ rev150720.instruction.queue.Instruction, InstructionKey> buildInstructionIID(final InstructionId id) {
+ return InstanceIdentifier.builder(InstructionsQueue.class, new InstructionsQueueKey(INSTRUCTIONS_QUEUE_KEY))
+ .build().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720
+ .instruction.queue.Instruction.class, new InstructionKey(id));
}
}
*/
package org.opendaylight.protocol.util;
+import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
+import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
+
import com.google.common.base.Optional;
import com.google.common.base.Stopwatch;
import com.google.common.base.Verify;
Verify.verify(future.isSuccess());
}
- public static <R, T extends DataObject> R readData(final DataBroker dataBroker, final InstanceIdentifier<T> iid,
+ public static <R, T extends DataObject> R readDataOperational(final DataBroker dataBroker, final InstanceIdentifier<T> iid,
+ final Function<T, R> function) throws ReadFailedException {
+ return readData(dataBroker, OPERATIONAL, iid, function);
+ }
+
+ public static <R, T extends DataObject> R readDataConfiguration(final DataBroker dataBroker, final InstanceIdentifier<T> iid,
final Function<T, R> function) throws ReadFailedException {
+ return readData(dataBroker, CONFIGURATION, iid, function);
+ }
+
+ private static <R, T extends DataObject> R readData(final DataBroker dataBroker, final LogicalDatastoreType ldt,
+ final InstanceIdentifier<T> iid, final Function<T, R> function) throws ReadFailedException {
AssertionError lastError = null;
final Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= TIMEOUT) {
try (final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
- final Optional<T> data = tx.read(LogicalDatastoreType.OPERATIONAL, iid).checkedGet();
+ final Optional<T> data = tx.read(ldt, iid).checkedGet();
if (data.isPresent()) {
try {
return function.apply(data.get());
throw lastError;
}
- public static <T extends DataObject> T checkPresent(final DataBroker dataBroker, final InstanceIdentifier<T> iid)
+ public static <T extends DataObject> T checkPresentOperational(final DataBroker dataBroker, final InstanceIdentifier<T> iid)
throws ReadFailedException {
- return readData(dataBroker, iid, bgpRib -> bgpRib);
+ return readData(dataBroker, OPERATIONAL, iid, bgpRib -> bgpRib);
}
- public static <T extends DataObject> void checkNull(final DataBroker dataBroker, final InstanceIdentifier<T> iid)
- throws ReadFailedException {
+ public static <T extends DataObject> T checkPresentConfiguration(final DataBroker dataBroker,
+ final InstanceIdentifier<T> iid) throws ReadFailedException {
+ return readData(dataBroker, CONFIGURATION, iid, bgpRib -> bgpRib);
+ }
+
+ public static <T extends DataObject> void checkNotPresentOperational(final DataBroker dataBroker,
+ final InstanceIdentifier<T> iid) throws ReadFailedException {
+ checkNotPresent(dataBroker, OPERATIONAL, iid);
+ }
+
+ public static <T extends DataObject> void checkNotPresentConfiguration(final DataBroker dataBroker,
+ final InstanceIdentifier<T> iid) throws ReadFailedException {
+ checkNotPresent(dataBroker, CONFIGURATION, iid);
+ }
+
+ private static <T extends DataObject> void checkNotPresent(final DataBroker dataBroker,
+ final LogicalDatastoreType ldt, final InstanceIdentifier<T> iid) throws ReadFailedException {
AssertionError lastError = null;
final Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
try (final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
- final com.google.common.base.Optional<T> data = tx.read(LogicalDatastoreType.OPERATIONAL, iid).checkedGet();
+ final com.google.common.base.Optional<T> data = tx.read(ldt, iid).checkedGet();
try {
assert !data.isPresent();
return;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
+import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.checkReceivedMessages;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
+import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
import com.google.common.base.Optional;
import com.google.common.base.VerifyException;
}
@Test(expected = VerifyException.class)
- public void waitFutureSuccessFail() throws Exception {
+ public void testWaitFutureSuccessFail() throws Exception {
when(this.future.isDone()).thenReturn(false);
doReturn(this.future).when(this.future).addListener(any());
- CheckUtil.waitFutureSuccess(this.future);
+ waitFutureSuccess(this.future);
}
@Test
- public void waitFutureSuccess() throws Exception {
+ public void testWaitFutureSuccess() throws Exception {
when(this.future.isSuccess()).thenReturn(true);
doAnswer(invocation -> {
invocation.getArgumentAt(0, GenericFutureListener.class).operationComplete(CheckUtilTest.this.future);
return CheckUtilTest.this.future;
}).when(this.future).addListener(any());
- CheckUtil.waitFutureSuccess(this.future);
+ waitFutureSuccess(this.future);
}
@Test(expected = NullPointerException.class)
- public void readDataNull() throws Exception {
+ public void testReadDataNull() throws Exception {
doReturn(false).when(this.opt).isPresent();
final InstanceIdentifier instanceIdentifier = null;
- CheckUtil.readData(this.dataBroker, instanceIdentifier, test -> false);
+ readDataOperational(this.dataBroker, instanceIdentifier, test -> false);
}
@Test(expected = AssertionError.class)
- public void readDataNotEquall() throws Exception {
+ public void testReadDataNotEquall() throws Exception {
doReturn(true).when(this.opt).isPresent();
doReturn(false).when(this.mockInterface).getResult();
- CheckUtil.readData(this.dataBroker, this.instanceIdentifier, test -> {
+ readDataOperational(this.dataBroker, this.instanceIdentifier, test -> {
assertTrue(test.getResult());
return test;
});
}
@Test(expected = AssertionError.class)
- public void checkNull() throws Exception {
+ public void testCheckNotPresent() throws Exception {
doReturn(true).when(this.opt).isPresent();
- CheckUtil.checkNull(this.dataBroker, this.instanceIdentifier);
+ checkNotPresentOperational(this.dataBroker, this.instanceIdentifier);
}
@Test(expected = AssertionError.class)
- public void checkEquals() throws Exception {
- CheckUtil.checkEquals(()-> assertTrue(false));
+ public void testCheckEquals() throws Exception {
+ checkEquals(()-> assertTrue(false));
}
@Test(expected = AssertionError.class)
- public void checkReceivedMessagesNotEqual() throws Exception {
+ public void testCheckReceivedMessagesNotEqual() throws Exception {
doReturn(0).when(this.listenerCheck).getListMessageSize();
- CheckUtil.checkReceivedMessages(this.listenerCheck, 1);
+ checkReceivedMessages(this.listenerCheck, 1);
}
@Test
- public void checkReceivedMessagesEqual() throws Exception {
+ public void testCheckReceivedMessagesEqual() throws Exception {
doReturn(1).when(this.listenerCheck).getListMessageSize();
- CheckUtil.checkReceivedMessages(this.listenerCheck, 1);
+ checkReceivedMessages(this.listenerCheck, 1);
}
private interface MockInterface extends DataObject {