Package org.apache.ace.agent

Examples of org.apache.ace.agent.DownloadHandler


        verifyTestMocks();
    }

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


        assertIOException(future);
    }

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

        assertRetryException(handle.start(null));
    }

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

        assertSuccessful(result, m_200digest);
    }

    @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) {
View Full Code Here

        assertSuccessful(handle.start(null), m_200digest);
    }

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

        clearTestMocks();
    }

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

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

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

        assertEquals(getDigest(file), m_digest);
    }

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

TOP

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

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.