@Test public void consumerIsUsedOnAllReturnedEntities() { List<String> fullList = generateList(4); List<String> batch = generateList(1); final BatchProcessor sut = makeSut(batch, 1); Consumer<String> consumerMock = mock(Consumer.class); sut.process("Some collection", b -> "", fullList, String.class, consumerMock); verify(consumerMock, times(fullList.size())).accept(anyString()); }
public <T> void process(final String collectionName, final Function<List<String>, String> batchQueryFn, final Collection<String> primaryEntries, final Class<T> resultClass, final Consumer<T> consumer) { List<String> asList = new ArrayList<>(); asList.addAll(primaryEntries); final List<List<String>> batches = splitList(this.batchSize, asList); batches.forEach(batch -> { final List<T> dbEntry = repoHandler.getListByQuery(collectionName, batchQueryFn.apply(batch), resultClass); if(dbEntry.size() < batch.size()) { LOG.warn(String.format("Got fewer results %s < %s", dbEntry.size(), batch.size())); LOG.warn("There are referred dependencies not related to known artifacts"); } dbEntry.forEach(consumer); }); }
BatchProcessor { public <T> void process(final String collectionName, final Function<List<String>, String> batchQueryFn, final Collection<String> primaryEntries, final Class<T> resultClass, final Consumer<T> consumer) { List<String> asList = new ArrayList<>(); asList.addAll(primaryEntries); final List<List<String>> batches = splitList(this.batchSize, asList); batches.forEach(batch -> { final List<T> dbEntry = repoHandler.getListByQuery(collectionName, batchQueryFn.apply(batch), resultClass); if(dbEntry.size() < batch.size()) { LOG.warn(String.format("Got fewer results %s < %s", dbEntry.size(), batch.size())); LOG.warn("There are referred dependencies not related to known artifacts"); } dbEntry.forEach(consumer); }); } }
BatchProcessor { public <T> void process(final String collectionName, final Function<List<String>, String> batchQueryFn, final Collection<String> primaryEntries, final Class<T> resultClass, final Consumer<T> consumer) { List<String> asList = new ArrayList<>(); asList.addAll(primaryEntries); final List<List<String>> batches = splitList(this.batchSize, asList); batches.forEach(batch -> { final List<T> dbEntry = repoHandler.getListByQuery(collectionName, batchQueryFn.apply(batch), resultClass); if(dbEntry.size() < batch.size()) { LOG.warn(String.format("Got fewer results %s < %s", dbEntry.size(), batch.size())); LOG.warn("There are referred dependencies not related to known artifacts"); } dbEntry.forEach(consumer); }); } BatchProcessor(RepositoryHandler handler); }
BatchProcessor { public <T> void process(final String collectionName, final Function<List<String>, String> batchQueryFn, final Collection<String> primaryEntries, final Class<T> resultClass, final Consumer<T> consumer) { List<String> asList = new ArrayList<>(); asList.addAll(primaryEntries); final List<List<String>> batches = splitList(this.batchSize, asList); batches.forEach(batch -> { final List<T> dbEntry = repoHandler.getListByQuery(collectionName, batchQueryFn.apply(batch), resultClass); if(dbEntry.size() < batch.size()) { LOG.warn(String.format("Got fewer results %s < %s", dbEntry.size(), batch.size())); LOG.warn("There are referred dependencies not related to known artifacts"); } dbEntry.forEach(consumer); }); } BatchProcessor(RepositoryHandler handler); void process(final String collectionName,
                            final Function<List<String>, String> batchQueryFn,
                            final Collection<String> primaryEntries,
                            final Class<T> resultClass,
                            final Consumer<T> consumer); void setBatchSize(int value); }
BatchProcessor { public <T> void process(final String collectionName, final Function<List<String>, String> batchQueryFn, final Collection<String> primaryEntries, final Class<T> resultClass, final Consumer<T> consumer) { List<String> asList = new ArrayList<>(); asList.addAll(primaryEntries); final List<List<String>> batches = splitList(this.batchSize, asList); batches.forEach(batch -> { final List<T> dbEntry = repoHandler.getListByQuery(collectionName, batchQueryFn.apply(batch), resultClass); if(dbEntry.size() < batch.size()) { LOG.warn(String.format("Got fewer results %s < %s", dbEntry.size(), batch.size())); LOG.warn("There are referred dependencies not related to known artifacts"); } dbEntry.forEach(consumer); }); } BatchProcessor(RepositoryHandler handler); void process(final String collectionName,
                            final Function<List<String>, String> batchQueryFn,
                            final Collection<String> primaryEntries,
                            final Class<T> resultClass,
                            final Consumer<T> consumer); void setBatchSize(int value);  }