@Test public void testRead_absent() throws Exception { Mockito.when(cachedDao.find(Matchers.<IpPrefix>any())).thenReturn(Optional.<EndpointForwardingTemplateBySubnet>absent()); Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(rTx); Mockito.when(rTx.read(Matchers.eq(LogicalDatastoreType.CONFIGURATION), Matchers.<InstanceIdentifier<SxpEpMapper>>any())).thenReturn( Futures.<Optional<SxpEpMapper>, ReadFailedException>immediateCheckedFuture(Optional.<SxpEpMapper>absent())); final ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> read = dao.read(KEY_1); Assert.assertTrue(read.isDone()); Assert.assertFalse(read.get().isPresent()); }
@Override public ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> read(@Nonnull final IpPrefix key) { final Optional<EndpointForwardingTemplateBySubnet> value = lookup(cachedDao, key); final ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> readResult; if (value.isPresent()) { readResult = Futures.immediateFuture(value); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); final CheckedFuture<Optional<SxpEpMapper>, ReadFailedException> read = rTx.read(LogicalDatastoreType.CONFIGURATION, buildReadPath(key)); Futures.addCallback(read, SxpListenerUtil.createTxCloseCallback(rTx), MoreExecutors.directExecutor()); readResult = Futures.transform(read, new Function<Optional<SxpEpMapper>, Optional<EndpointForwardingTemplateBySubnet>>() { @Nullable @Override public Optional<EndpointForwardingTemplateBySubnet> apply(@Nullable final Optional<SxpEpMapper> input) { if (input!=null && input.isPresent()) { cachedDao.invalidateCache(); final List<EndpointForwardingTemplateBySubnet> templateLot = input.get().getEndpointForwardingTemplateBySubnet(); if (templateLot != null) { for (EndpointForwardingTemplateBySubnet template : templateLot) { cachedDao.update(template.getIpPrefix(), template); } } return lookup(cachedDao, key); } else { return Optional.absent(); } } }, MoreExecutors.directExecutor()); } return readResult; }
EPForwardingTemplateDaoImpl implements DSAsyncDao<IpPrefix, EndpointForwardingTemplateBySubnet> { @Override public ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> read(@Nonnull final IpPrefix key) { final Optional<EndpointForwardingTemplateBySubnet> value = lookup(cachedDao, key); final ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> readResult; if (value.isPresent()) { readResult = Futures.immediateFuture(value); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); final CheckedFuture<Optional<SxpEpMapper>, ReadFailedException> read = rTx.read(LogicalDatastoreType.CONFIGURATION, buildReadPath(key)); Futures.addCallback(read, SxpListenerUtil.createTxCloseCallback(rTx), MoreExecutors.directExecutor()); readResult = Futures.transform(read, new Function<Optional<SxpEpMapper>, Optional<EndpointForwardingTemplateBySubnet>>() { @Nullable @Override public Optional<EndpointForwardingTemplateBySubnet> apply(@Nullable final Optional<SxpEpMapper> input) { if (input!=null && input.isPresent()) { cachedDao.invalidateCache(); final List<EndpointForwardingTemplateBySubnet> templateLot = input.get().getEndpointForwardingTemplateBySubnet(); if (templateLot != null) { for (EndpointForwardingTemplateBySubnet template : templateLot) { cachedDao.update(template.getIpPrefix(), template); } } return lookup(cachedDao, key); } else { return Optional.absent(); } } }, MoreExecutors.directExecutor()); } return readResult; } }
EPForwardingTemplateDaoImpl implements DSAsyncDao<IpPrefix, EndpointForwardingTemplateBySubnet> { @Override public ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> read(@Nonnull final IpPrefix key) { final Optional<EndpointForwardingTemplateBySubnet> value = lookup(cachedDao, key); final ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> readResult; if (value.isPresent()) { readResult = Futures.immediateFuture(value); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); final CheckedFuture<Optional<SxpEpMapper>, ReadFailedException> read = rTx.read(LogicalDatastoreType.CONFIGURATION, buildReadPath(key)); Futures.addCallback(read, SxpListenerUtil.createTxCloseCallback(rTx), MoreExecutors.directExecutor()); readResult = Futures.transform(read, new Function<Optional<SxpEpMapper>, Optional<EndpointForwardingTemplateBySubnet>>() { @Nullable @Override public Optional<EndpointForwardingTemplateBySubnet> apply(@Nullable final Optional<SxpEpMapper> input) { if (input!=null && input.isPresent()) { cachedDao.invalidateCache(); final List<EndpointForwardingTemplateBySubnet> templateLot = input.get().getEndpointForwardingTemplateBySubnet(); if (templateLot != null) { for (EndpointForwardingTemplateBySubnet template : templateLot) { cachedDao.update(template.getIpPrefix(), template); } } return lookup(cachedDao, key); } else { return Optional.absent(); } } }, MoreExecutors.directExecutor()); } return readResult; } EPForwardingTemplateDaoImpl(final DataBroker dataBroker,
                                       final SimpleCachedDao<IpPrefix, EndpointForwardingTemplateBySubnet> cachedDao); }
EPForwardingTemplateDaoImpl implements DSAsyncDao<IpPrefix, EndpointForwardingTemplateBySubnet> { @Override public ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> read(@Nonnull final IpPrefix key) { final Optional<EndpointForwardingTemplateBySubnet> value = lookup(cachedDao, key); final ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> readResult; if (value.isPresent()) { readResult = Futures.immediateFuture(value); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); final CheckedFuture<Optional<SxpEpMapper>, ReadFailedException> read = rTx.read(LogicalDatastoreType.CONFIGURATION, buildReadPath(key)); Futures.addCallback(read, SxpListenerUtil.createTxCloseCallback(rTx), MoreExecutors.directExecutor()); readResult = Futures.transform(read, new Function<Optional<SxpEpMapper>, Optional<EndpointForwardingTemplateBySubnet>>() { @Nullable @Override public Optional<EndpointForwardingTemplateBySubnet> apply(@Nullable final Optional<SxpEpMapper> input) { if (input!=null && input.isPresent()) { cachedDao.invalidateCache(); final List<EndpointForwardingTemplateBySubnet> templateLot = input.get().getEndpointForwardingTemplateBySubnet(); if (templateLot != null) { for (EndpointForwardingTemplateBySubnet template : templateLot) { cachedDao.update(template.getIpPrefix(), template); } } return lookup(cachedDao, key); } else { return Optional.absent(); } } }, MoreExecutors.directExecutor()); } return readResult; } EPForwardingTemplateDaoImpl(final DataBroker dataBroker,
                                       final SimpleCachedDao<IpPrefix, EndpointForwardingTemplateBySubnet> cachedDao); @Override ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> read(@Nonnull final IpPrefix key); }
EPForwardingTemplateDaoImpl implements DSAsyncDao<IpPrefix, EndpointForwardingTemplateBySubnet> { @Override public ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> read(@Nonnull final IpPrefix key) { final Optional<EndpointForwardingTemplateBySubnet> value = lookup(cachedDao, key); final ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> readResult; if (value.isPresent()) { readResult = Futures.immediateFuture(value); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); final CheckedFuture<Optional<SxpEpMapper>, ReadFailedException> read = rTx.read(LogicalDatastoreType.CONFIGURATION, buildReadPath(key)); Futures.addCallback(read, SxpListenerUtil.createTxCloseCallback(rTx), MoreExecutors.directExecutor()); readResult = Futures.transform(read, new Function<Optional<SxpEpMapper>, Optional<EndpointForwardingTemplateBySubnet>>() { @Nullable @Override public Optional<EndpointForwardingTemplateBySubnet> apply(@Nullable final Optional<SxpEpMapper> input) { if (input!=null && input.isPresent()) { cachedDao.invalidateCache(); final List<EndpointForwardingTemplateBySubnet> templateLot = input.get().getEndpointForwardingTemplateBySubnet(); if (templateLot != null) { for (EndpointForwardingTemplateBySubnet template : templateLot) { cachedDao.update(template.getIpPrefix(), template); } } return lookup(cachedDao, key); } else { return Optional.absent(); } } }, MoreExecutors.directExecutor()); } return readResult; } EPForwardingTemplateDaoImpl(final DataBroker dataBroker,
                                       final SimpleCachedDao<IpPrefix, EndpointForwardingTemplateBySubnet> cachedDao); @Override ListenableFuture<Optional<EndpointForwardingTemplateBySubnet>> read(@Nonnull final IpPrefix key);  }