private void assertSuccessful(Future<DownloadResult> future, String digest) throws Exception { DownloadResult result = future.get(5, TimeUnit.SECONDS); assertTrue(result.isComplete(), "Expected state SUCCESSFUL after succesful completion"); assertNotNull(result.getInputStream(), "Expected non null file after successful completion"); assertEquals(getDigest(result.getInputStream()), digest, "Expected same digest after successful completion"); }
@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())); }
delegate.install(downloadResult.getInputStream());
@BeforeMethod public void setUpAgain() throws Exception { m_dummyInputStream = new FileInputStream(m_dummyFile); DownloadResult downloadResult = addTestMock(DownloadResult.class); expect(downloadResult.isComplete()).andReturn(true).anyTimes(); expect(downloadResult.getInputStream()).andReturn(m_dummyInputStream).anyTimes(); Future<DownloadResult> future = addTestMock(Future.class); expect(future.get()).andReturn(downloadResult).anyTimes(); DownloadHandle downloadHandle = addTestMock(DownloadHandle.class); expect(downloadHandle.start(isNull(DownloadProgressListener.class))).andReturn(future).anyTimes(); DeploymentHandler deploymentHandler = addTestMock(DeploymentHandler.class); expect(deploymentHandler.getInstalledVersion()).andReturn(m_version2).anyTimes(); expect(deploymentHandler.getAvailableVersions()).andReturn(m_availableVersions).anyTimes(); expect(deploymentHandler.getDownloadHandle(eq(m_version3), eq(true))).andReturn(downloadHandle).once(); deploymentHandler.install(notNull(InputStream.class)); expectLastCall().once(); m_agentContext = mockAgentContext(); m_agentContext.setHandler(DeploymentHandler.class, deploymentHandler); replayTestMocks(); m_agentContext.start(); m_agentControl = new AgentControlImpl(m_agentContext); }
@Test public void testDownloading() throws Exception { Version current = m_agentControl.getDeploymentHandler().getInstalledVersion(); Version highest = m_agentControl.getDeploymentHandler().getAvailableVersions().last(); if (highest.compareTo(current) > 0) { DownloadHandle handle = m_agentControl.getDeploymentHandler().getDownloadHandle(highest, true); Future<DownloadResult> future = handle.start(null); DownloadResult result = future.get(); if (result.isComplete()) { InputStream inputStream = result.getInputStream(); try { m_agentControl.getDeploymentHandler().install(inputStream); } finally { inputStream.close(); } } } } }