Package org.apache.ace.agent

Examples of org.apache.ace.agent.DownloadResult


    @BeforeMethod
    @SuppressWarnings("unchecked")
    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);
View Full Code Here


        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();
View Full Code Here

        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()));
    }
View Full Code Here

        assertTrue(future.isDone());
    }

    private void assertStopped(Future<DownloadResult> future) throws Exception {
        try {
            DownloadResult result = future.get(5, TimeUnit.SECONDS);
            assertFalse(result.isComplete());
        }
        catch (CancellationException exception) {
            // Ok; also fine...
            assertTrue(future.isCancelled());
        }
View Full Code Here

            assertTrue(cause instanceof InterruptedIOException, "Expected InterruptedIOException, but got: " + cause);
        }
    }

    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");
    }
View Full Code Here

    @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?!");
View Full Code Here

    @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() + "?");
View Full Code Here

    @Test
    public void testResumeDownloadOk() throws Exception {
        DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class);

        DownloadResult downloadResult;
        Future<DownloadResult> future;

        final DownloadHandle handle = downloadHandler.getHandle(m_testContentURL);
        // Start the download, but interrupt it after reading the first chunk of data...
        future = handle.start(new DownloadProgressListener() {
            @Override
            public void progress(long bytesRead) {
                System.out.printf("Downloaded %d bytes, interrupting download...%n", bytesRead);
                Thread.currentThread().interrupt();
            }
        });

        assertDownloadStopped(future);

        File file = ((DownloadHandleImpl) handle).getDownloadFile();
        long firstFileLength = file.length();

        assertTrue(file.exists(), file.getName() + " does not exist?!");
        assertTrue(firstFileLength > 0, "Nothing downloaded yet for " + file.getName() + "?");
        assertTrue(firstFileLength < m_contentLength, "Everything downloaded for " + file.getName() + "?");

        final DownloadHandle handle2 = downloadHandler.getHandle(m_testContentURL);
        // Resume the download, but stop it after reading the first chunk of data...
        future = handle2.start(new DownloadProgressListener() {
            private int m_count = 5;

            @Override
            public void progress(long bytesRead) {
                if (--m_count == 0) {
                    System.out.printf("Downloaded %d bytes, stopping download...%n", bytesRead);
                    handle2.stop();
                }
            }
        });

        assertDownloadStopped(future);

        long secondFileLength = file.length();

        System.out.printf("First size: %d, second size: %d; total = %d.%n", firstFileLength, secondFileLength, m_contentLength);

        assertTrue(secondFileLength >= firstFileLength, "Downloaded restarted for " + file.getName() + "?");
        assertTrue(secondFileLength < m_contentLength, "Everything downloaded for " + file.getName() + "?");

        DownloadHandle handle3 = downloadHandler.getHandle(m_testContentURL);
        // Resume the download, and finish it...
        future = handle3.start(null);

        downloadResult = future.get(5, TimeUnit.SECONDS);
        assertTrue(downloadResult.isComplete());

        assertEquals(file.length(), m_contentLength, "Not all content downloaded for " + file.getName() + "?");

        // Verify the contents of the downloaded file is what we expect...
        assertEquals(getDigest(file), m_digest);
View Full Code Here

        assertEquals(getDigest(file), m_digest);
    }

    private void assertDownloadStopped(Future<DownloadResult> future) throws Exception {
        try {
            DownloadResult result = future.get(5, TimeUnit.SECONDS);
            assertFalse(result.isComplete());
        }
        catch (CancellationException exception) {
            // Ok; also fine...
            assertTrue(future.isCancelled());
        }
View Full Code Here

            try {
                DownloadHandle downloadHandle = delegate.getDownloadHandle(updateInfo.m_to, updateInfo.m_fixPackage);

                try {
                    Future<DownloadResult> future = downloadHandle.start(this);
                    DownloadResult downloadResult = future.get();

                    if (downloadResult.isComplete()) {
                        controller.logInfo("Installing %s update %s => %s...", m_type, updateInfo.m_from, updateInfo.m_to);

                        startInstallation(updateInfo);

                        delegate.install(downloadResult.getInputStream());

                        installationSuccess(updateInfo);

                        // Clean up any temporary files...
                        downloadHandle.discard();
View Full Code Here

TOP

Related Classes of org.apache.ace.agent.DownloadResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.