protected DownloadHandle getDownloadHandle(URL packageURL) { return getDownloadHandler().getHandle(packageURL); }
@Test public void testCreateDownloadHandleGeneratesSameTemporaryFilenameOk() throws Exception { DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class); DownloadHandleImpl handle; handle = (DownloadHandleImpl) downloadHandler.getHandle(m_testContentURL); String tempFilename = handle.getDownloadFile().getAbsolutePath(); handle = (DownloadHandleImpl) downloadHandler.getHandle(m_testContentURL); assertEquals(handle.getDownloadFile().getAbsolutePath(), tempFilename); handle = (DownloadHandleImpl) downloadHandler.getHandle(m_testContentURL); assertEquals(handle.getDownloadFile().getAbsolutePath(), tempFilename); }
@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 testFailed404_noresume_result() throws Exception { DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class); DownloadHandle handle = downloadHandler.getHandle(m_404url); Future<DownloadResult> future = handle.start(null); assertIOException(future); }
@Test public void testSuccessful_noresume_result() throws Exception { DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class); DownloadHandle handle = downloadHandler.getHandle(m_200url); handle.discard(); Future<DownloadResult> result = handle.start(null); assertSuccessful(result, m_200digest); }
@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); }
Future<DownloadResult> future; final DownloadHandle handle = downloadHandler.getHandle(m_testContentURL); assertTrue(firstFileLength < m_contentLength, "Everything downloaded for " + file.getName() + "?"); final DownloadHandle handle2 = downloadHandler.getHandle(m_testContentURL); assertTrue(secondFileLength < m_contentLength, "Everything downloaded for " + file.getName() + "?"); DownloadHandle handle3 = downloadHandler.getHandle(m_testContentURL);
@Test public void testSuccessfulResumeAfterCompleteDownload() throws Exception { DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class); final DownloadHandle handle = downloadHandler.getHandle(m_200url); handle.discard(); Future<DownloadResult> future = handle.start(null); DownloadResult result = future.get(); assertNotNull(result); assertTrue(result.isComplete()); assertEquals(m_200digest, getDigest(result.getInputStream())); Future<DownloadResult> future2 = handle.start(null); DownloadResult result2 = future2.get(); assertNotNull(result2); assertTrue(result2.isComplete()); assertEquals(m_200digest, getDigest(result2.getInputStream())); }
@Test public void testFailed503_noresume_result() throws Exception { DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class); DownloadHandle handle = downloadHandler.getHandle(m_503url); assertRetryException(handle.start(null)); assertRetryException(handle.start(null)); }
@Test public void testSuccessful_resume_result() throws Exception { DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class); final DownloadHandle handle = downloadHandler.getHandle(m_200url); handle.discard(); Future<DownloadResult> future = handle.start(new DownloadProgressListener() { @Override public void progress(long read) { Thread.currentThread().interrupt(); } }); assertStopped(future); assertSuccessful(handle.start(null), m_200digest); }