@Test public void testDownloadOk() throws Exception { DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class); DownloadResult downloadResult; Future<DownloadResult> future; final DownloadHandle handle = downloadHandler.getHandle(m_testContentURL); future = handle.start(null); downloadResult = future.get(5, TimeUnit.SECONDS); assertTrue(downloadResult.isComplete()); File file = ((DownloadHandleImpl) handle).getDownloadFile(); long fileLength = file.length(); assertTrue(file.exists(), file.getName() + " does not exist?!"); assertTrue(fileLength > 0 && fileLength == m_contentLength, "Nothing downloaded yet for " + file.getName() + "?"); // Verify the contents of the downloaded file is what we expect... assertEquals(getDigest(file), m_digest); }
@Test public void testRestartDownloadOk() throws Exception { DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class); DownloadResult downloadResult; Future<DownloadResult> future; final DownloadHandle handle = downloadHandler.getHandle(m_testContentURL); future = handle.start(new DownloadProgressListener() { @Override public void progress(long bytesRead) { handle.stop(); } }); assertDownloadStopped(future); File file = ((DownloadHandleImpl) handle).getDownloadFile(); long fileLength = file.length(); // Discard the result... handle.discard(); // Restart & finish the download... DownloadHandle handle2 = downloadHandler.getHandle(m_testContentURL); future = handle2.start(null); downloadResult = future.get(5, TimeUnit.SECONDS); assertTrue(downloadResult.isComplete()); fileLength = file.length(); assertTrue(file.exists(), file.getName() + " does not exist?!"); assertTrue(fileLength == m_contentLength, "Nothing downloaded yet for " + file.getName() + "?"); // Verify the contents of the downloaded file is what we expect... assertEquals(getDigest(file), m_digest); }
assertEquals(getDigest(file), m_digest);