@Test public void testReadBy() throws Exception { Mockito.when(cachedDao.isEmpty()).thenReturn(false); Mockito.when(cachedDao.values()).thenReturn(Collections.singleton(MASTER_DB_BINDING_VALUE)); final ListenableFuture<Collection<MasterDatabaseBinding>> readByFt = dao.readBy(KEY_1); Assert.assertTrue(readByFt.isDone()); Assert.assertEquals(1, readByFt.get().size()); }
@Override public ListenableFuture<Collection<MasterDatabaseBinding>> readBy(@Nonnull final Sgt specialKey) { final ListenableFuture<Void> cacheUpdatedFt; if (!cachedDao.isEmpty()) { cacheUpdatedFt = Futures.immediateFuture(null); } else { cacheUpdatedFt = updateCache(); } return Futures.transform(cacheUpdatedFt, new Function<Void, Collection<MasterDatabaseBinding>>() { @Nullable @Override public Collection<MasterDatabaseBinding> apply(@Nullable final Void input) { final Collection<MasterDatabaseBinding> foundGroups = new ArrayList<>(); for (MasterDatabaseBinding masterDBItem : cachedDao.values()) { if (masterDBItem.getSecurityGroupTag().equals(specialKey)) { foundGroups.add(masterDBItem); } } return foundGroups; } }, MoreExecutors.directExecutor()); }
MasterDatabaseBindingDaoImpl implements DSAsyncDao<IpPrefix, MasterDatabaseBinding>,
        ReadableAsyncByKey<Sgt, MasterDatabaseBinding> { @Override public ListenableFuture<Collection<MasterDatabaseBinding>> readBy(@Nonnull final Sgt specialKey) { final ListenableFuture<Void> cacheUpdatedFt; if (!cachedDao.isEmpty()) { cacheUpdatedFt = Futures.immediateFuture(null); } else { cacheUpdatedFt = updateCache(); } return Futures.transform(cacheUpdatedFt, new Function<Void, Collection<MasterDatabaseBinding>>() { @Nullable @Override public Collection<MasterDatabaseBinding> apply(@Nullable final Void input) { final Collection<MasterDatabaseBinding> foundGroups = new ArrayList<>(); for (MasterDatabaseBinding masterDBItem : cachedDao.values()) { if (masterDBItem.getSecurityGroupTag().equals(specialKey)) { foundGroups.add(masterDBItem); } } return foundGroups; } }, MoreExecutors.directExecutor()); } }
MasterDatabaseBindingDaoImpl implements DSAsyncDao<IpPrefix, MasterDatabaseBinding>,
        ReadableAsyncByKey<Sgt, MasterDatabaseBinding> { @Override public ListenableFuture<Collection<MasterDatabaseBinding>> readBy(@Nonnull final Sgt specialKey) { final ListenableFuture<Void> cacheUpdatedFt; if (!cachedDao.isEmpty()) { cacheUpdatedFt = Futures.immediateFuture(null); } else { cacheUpdatedFt = updateCache(); } return Futures.transform(cacheUpdatedFt, new Function<Void, Collection<MasterDatabaseBinding>>() { @Nullable @Override public Collection<MasterDatabaseBinding> apply(@Nullable final Void input) { final Collection<MasterDatabaseBinding> foundGroups = new ArrayList<>(); for (MasterDatabaseBinding masterDBItem : cachedDao.values()) { if (masterDBItem.getSecurityGroupTag().equals(specialKey)) { foundGroups.add(masterDBItem); } } return foundGroups; } }, MoreExecutors.directExecutor()); } MasterDatabaseBindingDaoImpl(final DataBroker dataBroker,
                              final SimpleCachedDao<IpPrefix, MasterDatabaseBinding> cachedDao); }
MasterDatabaseBindingDaoImpl implements DSAsyncDao<IpPrefix, MasterDatabaseBinding>,
        ReadableAsyncByKey<Sgt, MasterDatabaseBinding> { @Override public ListenableFuture<Collection<MasterDatabaseBinding>> readBy(@Nonnull final Sgt specialKey) { final ListenableFuture<Void> cacheUpdatedFt; if (!cachedDao.isEmpty()) { cacheUpdatedFt = Futures.immediateFuture(null); } else { cacheUpdatedFt = updateCache(); } return Futures.transform(cacheUpdatedFt, new Function<Void, Collection<MasterDatabaseBinding>>() { @Nullable @Override public Collection<MasterDatabaseBinding> apply(@Nullable final Void input) { final Collection<MasterDatabaseBinding> foundGroups = new ArrayList<>(); for (MasterDatabaseBinding masterDBItem : cachedDao.values()) { if (masterDBItem.getSecurityGroupTag().equals(specialKey)) { foundGroups.add(masterDBItem); } } return foundGroups; } }, MoreExecutors.directExecutor()); } MasterDatabaseBindingDaoImpl(final DataBroker dataBroker,
                              final SimpleCachedDao<IpPrefix, MasterDatabaseBinding> cachedDao); @Override ListenableFuture<Optional<MasterDatabaseBinding>> read(@Nonnull final IpPrefix key); @Override ListenableFuture<Collection<MasterDatabaseBinding>> readBy(@Nonnull final Sgt specialKey); }
MasterDatabaseBindingDaoImpl implements DSAsyncDao<IpPrefix, MasterDatabaseBinding>,
        ReadableAsyncByKey<Sgt, MasterDatabaseBinding> { @Override public ListenableFuture<Collection<MasterDatabaseBinding>> readBy(@Nonnull final Sgt specialKey) { final ListenableFuture<Void> cacheUpdatedFt; if (!cachedDao.isEmpty()) { cacheUpdatedFt = Futures.immediateFuture(null); } else { cacheUpdatedFt = updateCache(); } return Futures.transform(cacheUpdatedFt, new Function<Void, Collection<MasterDatabaseBinding>>() { @Nullable @Override public Collection<MasterDatabaseBinding> apply(@Nullable final Void input) { final Collection<MasterDatabaseBinding> foundGroups = new ArrayList<>(); for (MasterDatabaseBinding masterDBItem : cachedDao.values()) { if (masterDBItem.getSecurityGroupTag().equals(specialKey)) { foundGroups.add(masterDBItem); } } return foundGroups; } }, MoreExecutors.directExecutor()); } MasterDatabaseBindingDaoImpl(final DataBroker dataBroker,
                              final SimpleCachedDao<IpPrefix, MasterDatabaseBinding> cachedDao); @Override ListenableFuture<Optional<MasterDatabaseBinding>> read(@Nonnull final IpPrefix key); @Override ListenableFuture<Collection<MasterDatabaseBinding>> readBy(@Nonnull final Sgt specialKey);  }