@Test public void testRead_absent() throws Exception { Mockito.when(cachedDao.find(Matchers.<Sgt>any())).thenReturn(Optional.<EndpointPolicyTemplateBySgt>absent()); Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(rTx); Mockito.when(rTx.read(Matchers.eq(LogicalDatastoreType.CONFIGURATION), Matchers.<InstanceIdentifier<EndpointPolicyTemplateBySgt>>any())).thenReturn( Futures.<Optional<EndpointPolicyTemplateBySgt>, ReadFailedException>immediateCheckedFuture( Optional.<EndpointPolicyTemplateBySgt>absent())); final ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> read = dao.read(KEY_1); Assert.assertTrue(read.isDone()); Assert.assertFalse(read.get().isPresent()); }
@Override public ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> read(@Nonnull final Sgt key) { final Optional<EndpointPolicyTemplateBySgt> cachedEndpointPolicyTemplateBySgtValue = lookup(cachedDao, key); if (cachedEndpointPolicyTemplateBySgtValue.isPresent()) { return Futures.immediateFuture(cachedEndpointPolicyTemplateBySgtValue); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); final CheckedFuture<Optional<EndpointPolicyTemplateBySgt>, ReadFailedException> read = rTx.read(LogicalDatastoreType.CONFIGURATION, buildReadPath(key)); Futures.addCallback(read, SxpListenerUtil.createTxCloseCallback(rTx), MoreExecutors.directExecutor()); return Futures.transform(read, new Function<Optional<EndpointPolicyTemplateBySgt>, Optional<EndpointPolicyTemplateBySgt>>() { @Nullable @Override public Optional<EndpointPolicyTemplateBySgt> apply(@Nullable final Optional<EndpointPolicyTemplateBySgt> input) { if (input.isPresent()) { cachedDao.update(key, keyFactory.sortValueKeyLists(input.get())); } return input; } }, MoreExecutors.directExecutor()); } }
EPPolicyTemplateDaoImpl implements DSAsyncDao<Sgt, EndpointPolicyTemplateBySgt>,
        ReadableByKey<EpPolicyTemplateValueKey, EndpointPolicyTemplateBySgt> { @Override public ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> read(@Nonnull final Sgt key) { final Optional<EndpointPolicyTemplateBySgt> cachedEndpointPolicyTemplateBySgtValue = lookup(cachedDao, key); if (cachedEndpointPolicyTemplateBySgtValue.isPresent()) { return Futures.immediateFuture(cachedEndpointPolicyTemplateBySgtValue); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); final CheckedFuture<Optional<EndpointPolicyTemplateBySgt>, ReadFailedException> read = rTx.read(LogicalDatastoreType.CONFIGURATION, buildReadPath(key)); Futures.addCallback(read, SxpListenerUtil.createTxCloseCallback(rTx), MoreExecutors.directExecutor()); return Futures.transform(read, new Function<Optional<EndpointPolicyTemplateBySgt>, Optional<EndpointPolicyTemplateBySgt>>() { @Nullable @Override public Optional<EndpointPolicyTemplateBySgt> apply(@Nullable final Optional<EndpointPolicyTemplateBySgt> input) { if (input.isPresent()) { cachedDao.update(key, keyFactory.sortValueKeyLists(input.get())); } return input; } }, MoreExecutors.directExecutor()); } } }
EPPolicyTemplateDaoImpl implements DSAsyncDao<Sgt, EndpointPolicyTemplateBySgt>,
        ReadableByKey<EpPolicyTemplateValueKey, EndpointPolicyTemplateBySgt> { @Override public ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> read(@Nonnull final Sgt key) { final Optional<EndpointPolicyTemplateBySgt> cachedEndpointPolicyTemplateBySgtValue = lookup(cachedDao, key); if (cachedEndpointPolicyTemplateBySgtValue.isPresent()) { return Futures.immediateFuture(cachedEndpointPolicyTemplateBySgtValue); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); final CheckedFuture<Optional<EndpointPolicyTemplateBySgt>, ReadFailedException> read = rTx.read(LogicalDatastoreType.CONFIGURATION, buildReadPath(key)); Futures.addCallback(read, SxpListenerUtil.createTxCloseCallback(rTx), MoreExecutors.directExecutor()); return Futures.transform(read, new Function<Optional<EndpointPolicyTemplateBySgt>, Optional<EndpointPolicyTemplateBySgt>>() { @Nullable @Override public Optional<EndpointPolicyTemplateBySgt> apply(@Nullable final Optional<EndpointPolicyTemplateBySgt> input) { if (input.isPresent()) { cachedDao.update(key, keyFactory.sortValueKeyLists(input.get())); } return input; } }, MoreExecutors.directExecutor()); } } EPPolicyTemplateDaoImpl(final DataBroker dataBroker,
                                   final SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> cachedDao,
                                   final EpPolicyTemplateValueKeyFactory keyFactory); }
EPPolicyTemplateDaoImpl implements DSAsyncDao<Sgt, EndpointPolicyTemplateBySgt>,
        ReadableByKey<EpPolicyTemplateValueKey, EndpointPolicyTemplateBySgt> { @Override public ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> read(@Nonnull final Sgt key) { final Optional<EndpointPolicyTemplateBySgt> cachedEndpointPolicyTemplateBySgtValue = lookup(cachedDao, key); if (cachedEndpointPolicyTemplateBySgtValue.isPresent()) { return Futures.immediateFuture(cachedEndpointPolicyTemplateBySgtValue); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); final CheckedFuture<Optional<EndpointPolicyTemplateBySgt>, ReadFailedException> read = rTx.read(LogicalDatastoreType.CONFIGURATION, buildReadPath(key)); Futures.addCallback(read, SxpListenerUtil.createTxCloseCallback(rTx), MoreExecutors.directExecutor()); return Futures.transform(read, new Function<Optional<EndpointPolicyTemplateBySgt>, Optional<EndpointPolicyTemplateBySgt>>() { @Nullable @Override public Optional<EndpointPolicyTemplateBySgt> apply(@Nullable final Optional<EndpointPolicyTemplateBySgt> input) { if (input.isPresent()) { cachedDao.update(key, keyFactory.sortValueKeyLists(input.get())); } return input; } }, MoreExecutors.directExecutor()); } } EPPolicyTemplateDaoImpl(final DataBroker dataBroker,
                                   final SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> cachedDao,
                                   final EpPolicyTemplateValueKeyFactory keyFactory); @Override ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> read(@Nonnull final Sgt key); @Override Collection<EndpointPolicyTemplateBySgt> readBy(@Nonnull final EpPolicyTemplateValueKey specialKey); }
EPPolicyTemplateDaoImpl implements DSAsyncDao<Sgt, EndpointPolicyTemplateBySgt>,
        ReadableByKey<EpPolicyTemplateValueKey, EndpointPolicyTemplateBySgt> { @Override public ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> read(@Nonnull final Sgt key) { final Optional<EndpointPolicyTemplateBySgt> cachedEndpointPolicyTemplateBySgtValue = lookup(cachedDao, key); if (cachedEndpointPolicyTemplateBySgtValue.isPresent()) { return Futures.immediateFuture(cachedEndpointPolicyTemplateBySgtValue); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction(); final CheckedFuture<Optional<EndpointPolicyTemplateBySgt>, ReadFailedException> read = rTx.read(LogicalDatastoreType.CONFIGURATION, buildReadPath(key)); Futures.addCallback(read, SxpListenerUtil.createTxCloseCallback(rTx), MoreExecutors.directExecutor()); return Futures.transform(read, new Function<Optional<EndpointPolicyTemplateBySgt>, Optional<EndpointPolicyTemplateBySgt>>() { @Nullable @Override public Optional<EndpointPolicyTemplateBySgt> apply(@Nullable final Optional<EndpointPolicyTemplateBySgt> input) { if (input.isPresent()) { cachedDao.update(key, keyFactory.sortValueKeyLists(input.get())); } return input; } }, MoreExecutors.directExecutor()); } } EPPolicyTemplateDaoImpl(final DataBroker dataBroker,
                                   final SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> cachedDao,
                                   final EpPolicyTemplateValueKeyFactory keyFactory); @Override ListenableFuture<Optional<EndpointPolicyTemplateBySgt>> read(@Nonnull final Sgt key); @Override Collection<EndpointPolicyTemplateBySgt> readBy(@Nonnull final EpPolicyTemplateValueKey specialKey);  }