@Test public void testFor500Pages() throws InterruptedException, CancelledExecutionException { when(pageSpread.getTotalPages()).thenReturn(500); HttpDownloadWorker test = new HttpDownloadWorker(pageSpread, "", "some directory", "test", downloader, new ArrayList<PageSpread.Page>(), downloadObserver, dliDownloader, appContext, logWindow); test.call(); verify(downloadObserver).update(dliDownloader); }
@Override public Void call() throws InterruptedException, CancelledExecutionException { Page page = queue.poll(); int updateInterval = queue.getTotalPages() / 100; if (updateInterval < 1) updateInterval = 1; while (page != null && !Thread.currentThread().isInterrupted()) { appContext.getTap().await(); if (page.canDownload(appContext.getMaxRetryCount())) { boolean status = downloader.download(rootUrl, page.getAndIncrement(), outputDir, appContext, false, simpleLogger, 1 << 22, true); if (!status) { queue.offer(page); } downloads.incrementAndGet(); appContext.incrementPages(); } else { failedDownloads.add(page); } if (queue.getCounter() % updateInterval == 0) { updateProgress(); } page = queue.poll(); } updateProgress(); return null; }
HttpDownloadWorker implements Callable { @Override public Void call() throws InterruptedException, CancelledExecutionException { Page page = queue.poll(); int updateInterval = queue.getTotalPages() / 100; if (updateInterval < 1) updateInterval = 1; while (page != null && !Thread.currentThread().isInterrupted()) { appContext.getTap().await(); if (page.canDownload(appContext.getMaxRetryCount())) { boolean status = downloader.download(rootUrl, page.getAndIncrement(), outputDir, appContext, false, simpleLogger, 1 << 22, true); if (!status) { queue.offer(page); } downloads.incrementAndGet(); appContext.incrementPages(); } else { failedDownloads.add(page); } if (queue.getCounter() % updateInterval == 0) { updateProgress(); } page = queue.poll(); } updateProgress(); return null; } }
HttpDownloadWorker implements Callable { @Override public Void call() throws InterruptedException, CancelledExecutionException { Page page = queue.poll(); int updateInterval = queue.getTotalPages() / 100; if (updateInterval < 1) updateInterval = 1; while (page != null && !Thread.currentThread().isInterrupted()) { appContext.getTap().await(); if (page.canDownload(appContext.getMaxRetryCount())) { boolean status = downloader.download(rootUrl, page.getAndIncrement(), outputDir, appContext, false, simpleLogger, 1 << 22, true); if (!status) { queue.offer(page); } downloads.incrementAndGet(); appContext.incrementPages(); } else { failedDownloads.add(page); } if (queue.getCounter() % updateInterval == 0) { updateProgress(); } page = queue.poll(); } updateProgress(); return null; } HttpDownloadWorker(PageSpread queue, String serverHost, String rootUrl, String outputDir, Downloader downloader, List<Page> failedDownloads, DownloadObserver observer, DLIDownloader dliDownloader, AppContext appContext, LogWindow simpleLogger); }
HttpDownloadWorker implements Callable { @Override public Void call() throws InterruptedException, CancelledExecutionException { Page page = queue.poll(); int updateInterval = queue.getTotalPages() / 100; if (updateInterval < 1) updateInterval = 1; while (page != null && !Thread.currentThread().isInterrupted()) { appContext.getTap().await(); if (page.canDownload(appContext.getMaxRetryCount())) { boolean status = downloader.download(rootUrl, page.getAndIncrement(), outputDir, appContext, false, simpleLogger, 1 << 22, true); if (!status) { queue.offer(page); } downloads.incrementAndGet(); appContext.incrementPages(); } else { failedDownloads.add(page); } if (queue.getCounter() % updateInterval == 0) { updateProgress(); } page = queue.poll(); } updateProgress(); return null; } HttpDownloadWorker(PageSpread queue, String serverHost, String rootUrl, String outputDir, Downloader downloader, List<Page> failedDownloads, DownloadObserver observer, DLIDownloader dliDownloader, AppContext appContext, LogWindow simpleLogger); @Override Void call(); void updateProgress(); int getTotalDownloads(); String getRootUrl(); @Override String toString(); }
HttpDownloadWorker implements Callable { @Override public Void call() throws InterruptedException, CancelledExecutionException { Page page = queue.poll(); int updateInterval = queue.getTotalPages() / 100; if (updateInterval < 1) updateInterval = 1; while (page != null && !Thread.currentThread().isInterrupted()) { appContext.getTap().await(); if (page.canDownload(appContext.getMaxRetryCount())) { boolean status = downloader.download(rootUrl, page.getAndIncrement(), outputDir, appContext, false, simpleLogger, 1 << 22, true); if (!status) { queue.offer(page); } downloads.incrementAndGet(); appContext.incrementPages(); } else { failedDownloads.add(page); } if (queue.getCounter() % updateInterval == 0) { updateProgress(); } page = queue.poll(); } updateProgress(); return null; } HttpDownloadWorker(PageSpread queue, String serverHost, String rootUrl, String outputDir, Downloader downloader, List<Page> failedDownloads, DownloadObserver observer, DLIDownloader dliDownloader, AppContext appContext, LogWindow simpleLogger); @Override Void call(); void updateProgress(); int getTotalDownloads(); String getRootUrl(); @Override String toString();  }