Search in sources :

Example 1 with ProgressListener

use of ch.cyberduck.core.ProgressListener in project cyberduck by iterate-ch.

the class SingleTransferWorkerTest method testUploadPrepareOverrideRootDoesNotExist.

@Test
public void testUploadPrepareOverrideRootDoesNotExist() throws Exception {
    final Path child = new Path("/t/c", EnumSet.of(Path.Type.file));
    final Path root = new Path("/t", EnumSet.of(Path.Type.directory)) {

        @Override
        public Path getParent() {
            return new Path("/", EnumSet.of(Path.Type.directory));
        }
    };
    final NullLocal local = new NullLocal("l") {

        @Override
        public AttributedList<Local> list() {
            AttributedList<Local> l = new AttributedList<Local>();
            l.add(new NullLocal(this.getAbsolute(), "c") {

                @Override
                public boolean exists() {
                    return true;
                }
            });
            return l;
        }

        @Override
        public boolean exists() {
            return true;
        }
    };
    final Transfer t = new UploadTransfer(new Host(new TestProtocol()), root, local) {

        @Override
        public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
        // 
        }
    };
    final NullSession session = new NullSession(new Host(new TestProtocol()));
    final SingleTransferWorker worker = new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.overwrite;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {

        @Override
        public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
            if (item.remote.equals(root)) {
                assertTrue(this.getCache().isCached(new TransferItem(root, local)));
            }
            super.transfer(new TransferItem(item.remote, new NullLocal("l") {

                @Override
                public AttributedList<Local> list() {
                    AttributedList<Local> l = new AttributedList<Local>();
                    l.add(new NullLocal(this.getAbsolute(), "c"));
                    return l;
                }
            }), action);
            assertFalse(this.getCache().isCached(new TransferItem(child, local)));
            return null;
        }
    };
    worker.run(session);
    assertFalse(worker.getCache().isCached(new TransferItem(child, local)));
}
Also used : TestProtocol(ch.cyberduck.core.TestProtocol) TransferAction(ch.cyberduck.core.transfer.TransferAction) NullSession(ch.cyberduck.core.NullSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) AttributedList(ch.cyberduck.core.AttributedList) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) ListProgressListener(ch.cyberduck.core.ListProgressListener) ProgressListener(ch.cyberduck.core.ProgressListener) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Example 2 with ProgressListener

use of ch.cyberduck.core.ProgressListener in project cyberduck by iterate-ch.

the class SingleTransferWorkerTest method testDownloadPrepareOverride.

@Test
public void testDownloadPrepareOverride() throws Exception {
    final Path child = new Path("/t/c", EnumSet.of(Path.Type.file));
    final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
    final NullLocal local = new NullLocal("l") {

        @Override
        public boolean exists() {
            return true;
        }

        @Override
        public boolean isDirectory() {
            return true;
        }

        @Override
        public boolean isFile() {
            return false;
        }

        @Override
        public AttributedList<Local> list() {
            return AttributedList.emptyList();
        }
    };
    final Transfer t = new DownloadTransfer(new Host(new TestProtocol()), root, local) {

        @Override
        public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
            if (file.equals(root)) {
                assertTrue(segment.isExists());
            } else {
                assertFalse(segment.isExists());
            }
        }

        @Override
        public AbstractDownloadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
            return super.filter(source, destination, action, listener).withAttributes(new AttributesFinder() {

                @Override
                public PathAttributes find(final Path file, final ListProgressListener listener) {
                    return file.attributes();
                }
            });
        }
    };
    final NullSession session = new NullSession(new Host(new TestProtocol())) {

        @Override
        public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
            final AttributedList<Path> children = new AttributedList<Path>();
            children.add(child);
            return children;
        }
    };
    final SingleTransferWorker worker = new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.overwrite;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {

        @Override
        public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
            if (item.remote.equals(root)) {
                assertTrue(this.getCache().isCached(new TransferItem(root, local)));
            }
            super.transfer(new TransferItem(item.remote, new NullLocal("l")), action);
            if (item.remote.equals(root)) {
                assertFalse(this.getCache().isCached(new TransferItem(root, local)));
            }
            return null;
        }
    };
    worker.run(session);
    assertFalse(worker.getCache().isCached(new TransferItem(child, local)));
    assertTrue(worker.getCache().isEmpty());
}
Also used : TestProtocol(ch.cyberduck.core.TestProtocol) TransferAction(ch.cyberduck.core.transfer.TransferAction) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) NullSession(ch.cyberduck.core.NullSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) NullLocal(ch.cyberduck.core.NullLocal) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) PathAttributes(ch.cyberduck.core.PathAttributes) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) ListProgressListener(ch.cyberduck.core.ListProgressListener) ProgressListener(ch.cyberduck.core.ProgressListener) AttributedList(ch.cyberduck.core.AttributedList) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Example 3 with ProgressListener

use of ch.cyberduck.core.ProgressListener in project cyberduck by iterate-ch.

the class SynchronizationPathFilterTest method testAcceptDirectory.

@Test
public void testAcceptDirectory() throws Exception {
    Session session = new NullSession(new Host(new TestProtocol()));
    final SynchronizationPathFilter mirror = new SynchronizationPathFilter(new ComparePathFilter() {

        @Override
        public Comparison compare(Path file, Local local, final ProgressListener listener) {
            return Comparison.equal;
        }
    }, new OverwriteFilter(new DownloadSymlinkResolver(Collections.<TransferItem>emptyList()), session), new ch.cyberduck.core.transfer.upload.OverwriteFilter(new UploadSymlinkResolver(null, Collections.<TransferItem>emptyList()), session), TransferAction.mirror);
    assertTrue(mirror.accept(new Path("/p", EnumSet.of(Path.Type.directory)), null, new TransferStatus().exists(true)));
}
Also used : Path(ch.cyberduck.core.Path) ComparePathFilter(ch.cyberduck.core.synchronization.ComparePathFilter) DefaultComparePathFilter(ch.cyberduck.core.synchronization.DefaultComparePathFilter) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DownloadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DownloadSymlinkResolver) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) ProgressListener(ch.cyberduck.core.ProgressListener) Comparison(ch.cyberduck.core.synchronization.Comparison) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) UploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.UploadSymlinkResolver) OverwriteFilter(ch.cyberduck.core.transfer.download.OverwriteFilter) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Example 4 with ProgressListener

use of ch.cyberduck.core.ProgressListener in project cyberduck by iterate-ch.

the class CompareFilterTest method testAcceptDirectory.

@Test
public void testAcceptDirectory() throws Exception {
    final Host host = new Host(new TestProtocol());
    final CompareFilter filter = new CompareFilter(new DisabledUploadSymlinkResolver(), new NullSession(host), new UploadFilterOptions(host), new DisabledProgressListener(), new DefaultComparePathFilter(new NullSession(host), null) {

        @Override
        public Comparison compare(final Path file, final Local local, final ProgressListener listener) {
            return Comparison.equal;
        }
    });
    assertTrue(filter.accept(new Path("/n", EnumSet.of(Path.Type.directory)), new NullLocal("/n") {

        @Override
        public boolean exists() {
            return true;
        }
    }, new TransferStatus().exists(true)));
}
Also used : DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) Path(ch.cyberduck.core.Path) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DefaultComparePathFilter(ch.cyberduck.core.synchronization.DefaultComparePathFilter) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) ProgressListener(ch.cyberduck.core.ProgressListener) Comparison(ch.cyberduck.core.synchronization.Comparison) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Test(org.junit.Test)

Example 5 with ProgressListener

use of ch.cyberduck.core.ProgressListener in project cyberduck by iterate-ch.

the class SegmentRetryCallableTest method testRetry.

@Test
public void testRetry() throws Exception {
    final AtomicInteger count = new AtomicInteger();
    final SegmentRetryCallable<Void> c = new SegmentRetryCallable<Void>(new Host(new TestProtocol()), 2, 0, new BackgroundExceptionCallable<Void>() {

        @Override
        public Void call() throws BackgroundException {
            throw new ConnectionRefusedException("d", new SocketException());
        }
    }, new TransferStatus(), new BytecountStreamListener()) {

        @Override
        public boolean retry(final BackgroundException failure, final ProgressListener progress, final BackgroundActionState cancel) {
            count.incrementAndGet();
            return super.retry(failure, progress, cancel);
        }
    };
    try {
        c.call();
        fail();
    } catch (ConnectionRefusedException e) {
    // Expected
    }
    assertEquals(3, count.get());
}
Also used : SocketException(java.net.SocketException) TestProtocol(ch.cyberduck.core.TestProtocol) BackgroundActionState(ch.cyberduck.core.threading.BackgroundActionState) Host(ch.cyberduck.core.Host) ConnectionRefusedException(ch.cyberduck.core.exception.ConnectionRefusedException) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) ProgressListener(ch.cyberduck.core.ProgressListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BackgroundException(ch.cyberduck.core.exception.BackgroundException) Test(org.junit.Test)

Aggregations

ProgressListener (ch.cyberduck.core.ProgressListener)12 Test (org.junit.Test)12 Host (ch.cyberduck.core.Host)9 Path (ch.cyberduck.core.Path)9 TestProtocol (ch.cyberduck.core.TestProtocol)9 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)9 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)8 Local (ch.cyberduck.core.Local)8 NullLocal (ch.cyberduck.core.NullLocal)8 NullSession (ch.cyberduck.core.NullSession)8 Comparison (ch.cyberduck.core.synchronization.Comparison)5 DefaultComparePathFilter (ch.cyberduck.core.synchronization.DefaultComparePathFilter)5 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)4 Session (ch.cyberduck.core.Session)4 AttributedList (ch.cyberduck.core.AttributedList)3 ConnectionCallback (ch.cyberduck.core.ConnectionCallback)3 ListProgressListener (ch.cyberduck.core.ListProgressListener)3 DisabledStreamListener (ch.cyberduck.core.io.DisabledStreamListener)3 StreamListener (ch.cyberduck.core.io.StreamListener)3 DisabledNotificationService (ch.cyberduck.core.notification.DisabledNotificationService)3