@Test public void updateRouting() throws Exception { final SxpClusterRoute oldRoute = new SxpClusterRouteBuilder().setRoutingDefinition(leftSide).build(); final SxpClusterRoute newRoute = new SxpClusterRouteBuilder().setRoutingDefinition(rightSide).build(); Mockito.when(routingService.addRouteForCurrentService()).thenReturn(true); Mockito.when(routingService.removeRouteForCurrentService()).thenReturn(true); Mockito.when(rTx.read(ArgumentMatchers.any(), ArgumentMatchers.any())) .thenReturn(FluentFutures.immediateFluentFuture(Optional.of(oldRoute))); Mockito.when(wTx.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); Iterables.concat(leftSide, rightSide).forEach(routeDef -> { reactor.getRoutingServiceMap().putIfAbsent(routeDef.getIpAddress(), routingService); }); reactor.updateRouting(oldRoute, newRoute); Mockito.verify(wTx).put(ArgumentMatchers.any(), pathCaptor.capture(), dataCaptor.capture()); Assert.assertEquals(1, pathCaptor.getAllValues().size()); Assert.assertEquals(1, dataCaptor.getAllValues().size()); final List<RoutingDefinition> actual = dataCaptor.getValue().getRoutingDefinition(); Assert.assertEquals(3, actual.size()); Collections.sort(actual, Comparator.comparing(o -> RouteUtil.addressToString(o.getIpAddress()))); int idx = 0; Assert.assertEquals(null, actual.get(idx).getInfo()); Assert.assertNull(actual.get(idx).isConsistent()); Assert.assertEquals("1.2.3.2", RouteUtil.addressToString(actual.get(idx).getIpAddress())); idx++; Assert.assertEquals("updated", actual.get(idx).getInfo()); Assert.assertEquals(true, actual.get(idx).isConsistent()); Assert.assertEquals("1.2.3.3", RouteUtil.addressToString(actual.get(idx).getIpAddress())); idx++; Assert.assertEquals("added", actual.get(idx).getInfo()); Assert.assertEquals(true, actual.get(idx).isConsistent()); Assert.assertEquals("1.2.3.4", RouteUtil.addressToString(actual.get(idx).getIpAddress())); }
@Override public FluentFuture<? extends CommitInfo> updateRouting(@Nullable final SxpClusterRoute oldRoute, @Nullable final SxpClusterRoute newRoute) { final Map<IpAddress, RoutingDefinition> oldDefinitions = new HashMap<>(); final Map<IpAddress, RoutingDefinition> newDefinitions = new HashMap<>(); final List<RoutingDefinition> outcomingRouteDefinitions = new ArrayList<>(); fillDefinitionsSafely(oldRoute, oldDefinitions); fillDefinitionsSafely(newRoute, newDefinitions); final MapDifference<IpAddress, RoutingDefinition> routingDifference = Maps.difference(oldDefinitions, newDefinitions); processDeleted(routingDifference, outcomingRouteDefinitions); processUpdated(routingDifference, outcomingRouteDefinitions); processAdded(routingDifference, outcomingRouteDefinitions); collectUnchanged(routingDifference, outcomingRouteDefinitions); final SxpClusterRoute sxpClusterRoute = new SxpClusterRouteBuilder().setRoutingDefinition(outcomingRouteDefinitions).build(); return datastoreAccess.put(SxpClusterRouteManager.SXP_CLUSTER_ROUTE_CONFIG_PATH, sxpClusterRoute, LogicalDatastoreType.OPERATIONAL); }
RouteReactorImpl implements RouteReactor { @Override public FluentFuture<? extends CommitInfo> updateRouting(@Nullable final SxpClusterRoute oldRoute, @Nullable final SxpClusterRoute newRoute) { final Map<IpAddress, RoutingDefinition> oldDefinitions = new HashMap<>(); final Map<IpAddress, RoutingDefinition> newDefinitions = new HashMap<>(); final List<RoutingDefinition> outcomingRouteDefinitions = new ArrayList<>(); fillDefinitionsSafely(oldRoute, oldDefinitions); fillDefinitionsSafely(newRoute, newDefinitions); final MapDifference<IpAddress, RoutingDefinition> routingDifference = Maps.difference(oldDefinitions, newDefinitions); processDeleted(routingDifference, outcomingRouteDefinitions); processUpdated(routingDifference, outcomingRouteDefinitions); processAdded(routingDifference, outcomingRouteDefinitions); collectUnchanged(routingDifference, outcomingRouteDefinitions); final SxpClusterRoute sxpClusterRoute = new SxpClusterRouteBuilder().setRoutingDefinition(outcomingRouteDefinitions).build(); return datastoreAccess.put(SxpClusterRouteManager.SXP_CLUSTER_ROUTE_CONFIG_PATH, sxpClusterRoute, LogicalDatastoreType.OPERATIONAL); } }
RouteReactorImpl implements RouteReactor { @Override public FluentFuture<? extends CommitInfo> updateRouting(@Nullable final SxpClusterRoute oldRoute, @Nullable final SxpClusterRoute newRoute) { final Map<IpAddress, RoutingDefinition> oldDefinitions = new HashMap<>(); final Map<IpAddress, RoutingDefinition> newDefinitions = new HashMap<>(); final List<RoutingDefinition> outcomingRouteDefinitions = new ArrayList<>(); fillDefinitionsSafely(oldRoute, oldDefinitions); fillDefinitionsSafely(newRoute, newDefinitions); final MapDifference<IpAddress, RoutingDefinition> routingDifference = Maps.difference(oldDefinitions, newDefinitions); processDeleted(routingDifference, outcomingRouteDefinitions); processUpdated(routingDifference, outcomingRouteDefinitions); processAdded(routingDifference, outcomingRouteDefinitions); collectUnchanged(routingDifference, outcomingRouteDefinitions); final SxpClusterRoute sxpClusterRoute = new SxpClusterRouteBuilder().setRoutingDefinition(outcomingRouteDefinitions).build(); return datastoreAccess.put(SxpClusterRouteManager.SXP_CLUSTER_ROUTE_CONFIG_PATH, sxpClusterRoute, LogicalDatastoreType.OPERATIONAL); } RouteReactorImpl(final DataBroker dataBroker, final RoutingServiceFactory routingServiceFactory); }
RouteReactorImpl implements RouteReactor { @Override public FluentFuture<? extends CommitInfo> updateRouting(@Nullable final SxpClusterRoute oldRoute, @Nullable final SxpClusterRoute newRoute) { final Map<IpAddress, RoutingDefinition> oldDefinitions = new HashMap<>(); final Map<IpAddress, RoutingDefinition> newDefinitions = new HashMap<>(); final List<RoutingDefinition> outcomingRouteDefinitions = new ArrayList<>(); fillDefinitionsSafely(oldRoute, oldDefinitions); fillDefinitionsSafely(newRoute, newDefinitions); final MapDifference<IpAddress, RoutingDefinition> routingDifference = Maps.difference(oldDefinitions, newDefinitions); processDeleted(routingDifference, outcomingRouteDefinitions); processUpdated(routingDifference, outcomingRouteDefinitions); processAdded(routingDifference, outcomingRouteDefinitions); collectUnchanged(routingDifference, outcomingRouteDefinitions); final SxpClusterRoute sxpClusterRoute = new SxpClusterRouteBuilder().setRoutingDefinition(outcomingRouteDefinitions).build(); return datastoreAccess.put(SxpClusterRouteManager.SXP_CLUSTER_ROUTE_CONFIG_PATH, sxpClusterRoute, LogicalDatastoreType.OPERATIONAL); } RouteReactorImpl(final DataBroker dataBroker, final RoutingServiceFactory routingServiceFactory); @Override FluentFuture<? extends CommitInfo> updateRouting(@Nullable final SxpClusterRoute oldRoute,
                                                            @Nullable final SxpClusterRoute newRoute); @Override FluentFuture<? extends CommitInfo> wipeRouting(); }
RouteReactorImpl implements RouteReactor { @Override public FluentFuture<? extends CommitInfo> updateRouting(@Nullable final SxpClusterRoute oldRoute, @Nullable final SxpClusterRoute newRoute) { final Map<IpAddress, RoutingDefinition> oldDefinitions = new HashMap<>(); final Map<IpAddress, RoutingDefinition> newDefinitions = new HashMap<>(); final List<RoutingDefinition> outcomingRouteDefinitions = new ArrayList<>(); fillDefinitionsSafely(oldRoute, oldDefinitions); fillDefinitionsSafely(newRoute, newDefinitions); final MapDifference<IpAddress, RoutingDefinition> routingDifference = Maps.difference(oldDefinitions, newDefinitions); processDeleted(routingDifference, outcomingRouteDefinitions); processUpdated(routingDifference, outcomingRouteDefinitions); processAdded(routingDifference, outcomingRouteDefinitions); collectUnchanged(routingDifference, outcomingRouteDefinitions); final SxpClusterRoute sxpClusterRoute = new SxpClusterRouteBuilder().setRoutingDefinition(outcomingRouteDefinitions).build(); return datastoreAccess.put(SxpClusterRouteManager.SXP_CLUSTER_ROUTE_CONFIG_PATH, sxpClusterRoute, LogicalDatastoreType.OPERATIONAL); } RouteReactorImpl(final DataBroker dataBroker, final RoutingServiceFactory routingServiceFactory); @Override FluentFuture<? extends CommitInfo> updateRouting(@Nullable final SxpClusterRoute oldRoute,
                                                            @Nullable final SxpClusterRoute newRoute); @Override FluentFuture<? extends CommitInfo> wipeRouting();  }