import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
@Nullable
@Override
public Void apply(@Nullable final Optional<Topology> input) {
- if (input.isPresent()) {
+ if (input != null) {
// clean cache
cachedDao.invalidateCache();
- for (Node node : input.get().getNode()) {
+ final List<Node> nodeList = java.util.Optional.ofNullable(input.orNull())
+ .map(Topology::getNode)
+ .orElseGet(() -> {
+ LOG.warn("failed to update cache of SxpMasterDB - no data");
+ return Collections.emptyList();
+ });
+ for (Node node : nodeList) {
java.util.Optional.ofNullable(node.getAugmentation(SxpNodeIdentity.class))
.map(SxpNodeIdentity::getSxpDomains)
.map(SxpDomains::getSxpDomain)
});
}
} else {
- LOG.warn("failed to update cache of SxpMasterDB - no data");
+ LOG.warn("failed to update cache of SxpMasterDB - null input");
}
return null;
}
final IpPrefix changeKey = changePath.firstKeyOf(EndpointForwardingTemplateBySubnet.class).getIpPrefix();
SxpListenerUtil.updateCachedDao(templateCachedDao, changeKey, change);
+ //TODO: handle removal (now causes NPE)
final EndpointForwardingTemplateBySubnet epForwardingTemplate = change.getRootNode().getDataAfter();
processWithEPTemplates(epForwardingTemplate);
}
Assert.assertFalse(read.get().isPresent());
}
+ @Test
+ public void testRead_absentNull() throws Exception {
+ Mockito.when(cachedDao.find(Matchers.<IpPrefix>any())).thenReturn(Optional.<MasterDatabaseBinding>absent());
+ Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(rTx);
+ Mockito.when(rTx.read(Matchers.eq(LogicalDatastoreType.CONFIGURATION),
+ Matchers.<InstanceIdentifier<Topology>>any())).thenReturn(
+ Futures.<Optional<Topology>, ReadFailedException>immediateCheckedFuture(
+ Optional.of(new TopologyBuilder().build())));
+
+
+ final ListenableFuture<Optional<MasterDatabaseBinding>> read = dao.read(IP_PREFIX);
+ Assert.assertTrue(read.isDone());
+ Assert.assertFalse(read.get().isPresent());
+ }
+
@Test
public void testRead_presentCached() throws Exception {
Mockito.when(cachedDao.find(Matchers.<IpPrefix>any())).thenReturn(Optional.of(MASTER_DB_BINDING_VALUE));