Search in sources :

Example 1 with StreamListener

use of ch.cyberduck.core.io.StreamListener 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 StreamListener

use of ch.cyberduck.core.io.StreamListener 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 StreamListener

use of ch.cyberduck.core.io.StreamListener in project cyberduck by iterate-ch.

the class ConcurrentTransferWorkerTest method testConcurrentSessions.

@Test
public void testConcurrentSessions() throws Exception {
    final int files = 20;
    final int connections = 3;
    final Set<Path> transferred = ConcurrentHashMap.newKeySet();
    final List<TransferItem> list = new ArrayList<TransferItem>();
    for (int i = 1; i <= files; i++) {
        list.add(new TransferItem(new Path("/t" + i, EnumSet.of(Path.Type.file)), new NullLocal("/t" + i)));
    }
    final Host host = new Host(new TestProtocol(), "test.cyberduck.ch");
    final Transfer t = new DownloadTransfer(host, list) {

        @Override
        public void transfer(final Session<?> source, final Session<?> destination, final Path file, final Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
            assertNotNull(source);
            transferred.add(file);
        }

        @Override
        public AbstractDownloadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
            return new AbstractDownloadFilter(new DisabledDownloadSymlinkResolver(), source, null) {

                @Override
                public boolean accept(final Path file, final Local local, final TransferStatus parent) {
                    assertFalse(transferred.contains(file));
                    return true;
                }

                @Override
                public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) {
                    assertFalse(transferred.contains(file));
                    return new TransferStatus();
                }

                @Override
                public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) {
                    assertFalse(transferred.contains(file));
                }

                @Override
                public void complete(final Path file, final Local local, final TransferOptions options, final TransferStatus status, final ProgressListener listener) {
                    assertTrue(transferred.contains(file));
                }
            };
        }
    };
    final LoginConnectionService connection = new TestLoginConnectionService();
    final DefaultSessionPool pool = new DefaultSessionPool(connection, new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), host);
    final ConcurrentTransferWorker worker = new ConcurrentTransferWorker(pool, SessionPool.DISCONNECTED, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.overwrite;
        }
    }, new DisabledTransferErrorCallback(), new DisabledLoginCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledNotificationService());
    pool.withMaxTotal(connections);
    final Session<?> session = worker.borrow(ConcurrentTransferWorker.Connection.source);
    assertTrue(worker.run(session));
    worker.release(session, ConcurrentTransferWorker.Connection.source, null);
    for (int i = 1; i <= files; i++) {
        assertTrue(transferred.contains(new Path("/t" + i, EnumSet.of(Path.Type.file))));
    }
    worker.cleanup(true);
}
Also used : DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) TransferAction(ch.cyberduck.core.transfer.TransferAction) ArrayList(java.util.ArrayList) DefaultSessionPool(ch.cyberduck.core.pool.DefaultSessionPool) DisabledDownloadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledDownloadSymlinkResolver) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) AbstractDownloadFilter(ch.cyberduck.core.transfer.download.AbstractDownloadFilter) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) Test(org.junit.Test)

Example 4 with StreamListener

use of ch.cyberduck.core.io.StreamListener in project cyberduck by iterate-ch.

the class UploadTransferTest method testCacheRename.

@Test
public void testCacheRename() throws Exception {
    final AtomicInteger c = new AtomicInteger();
    final NullLocal local = new NullLocal("t") {

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

                @Override
                public boolean exists() {
                    return true;
                }
            });
            l.add(new NullLocal(this.getAbsolute(), "b") {

                @Override
                public boolean exists() {
                    return true;
                }
            });
            l.add(new NullLocal(this.getAbsolute(), "c") {

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

        @Override
        public boolean exists() {
            return true;
        }
    };
    final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
    final NullSession session = new NullSession(new Host(new TestProtocol())) {

        @Override
        public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws ConnectionCanceledException {
            c.incrementAndGet();
            listener.chunk(folder, AttributedList.emptyList());
            return AttributedList.emptyList();
        }
    };
    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) {
        // 
        }
    };
    new SingleTransferWorker(session, null, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.rename;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()).run(session);
    assertEquals(1, c.get());
}
Also used : SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 5 with StreamListener

use of ch.cyberduck.core.io.StreamListener in project cyberduck by iterate-ch.

the class UploadTransferTest method testCacheResume.

@Test
public void testCacheResume() throws Exception {
    final AtomicInteger c = new AtomicInteger();
    final NullLocal local = new NullLocal("t") {

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

                @Override
                public boolean exists() {
                    return true;
                }
            });
            l.add(new NullLocal(this.getAbsolute(), "b") {

                @Override
                public boolean exists() {
                    return true;
                }
            });
            l.add(new NullLocal(this.getAbsolute(), "c") {

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

        @Override
        public boolean exists() {
            return true;
        }
    };
    final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
    final NullSession session = new NullSession(new Host(new TestProtocol())) {

        @Override
        public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws ConnectionCanceledException {
            if (folder.equals(root.getParent())) {
                c.incrementAndGet();
            }
            listener.chunk(folder, AttributedList.emptyList());
            return AttributedList.emptyList();
        }
    };
    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) {
            assertTrue(options.resumeRequested);
        }
    };
    final TransferOptions options = new TransferOptions();
    options.resumeRequested = true;
    new SingleTransferWorker(session, null, t, options, new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            fail();
            return null;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()).run(session);
    assertEquals(1, c.get());
}
Also used : SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

DisabledStreamListener (ch.cyberduck.core.io.DisabledStreamListener)7 StreamListener (ch.cyberduck.core.io.StreamListener)7 DisabledNotificationService (ch.cyberduck.core.notification.DisabledNotificationService)7 Test (org.junit.Test)7 DisabledTransferErrorCallback (ch.cyberduck.core.transfer.DisabledTransferErrorCallback)4 DisabledTransferPrompt (ch.cyberduck.core.transfer.DisabledTransferPrompt)4 DownloadTransfer (ch.cyberduck.core.transfer.DownloadTransfer)4 Transfer (ch.cyberduck.core.transfer.Transfer)4 TransferAction (ch.cyberduck.core.transfer.TransferAction)4 TransferItem (ch.cyberduck.core.transfer.TransferItem)4 TransferOptions (ch.cyberduck.core.transfer.TransferOptions)4 TransferSpeedometer (ch.cyberduck.core.transfer.TransferSpeedometer)4 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)4 UploadTransfer (ch.cyberduck.core.transfer.UploadTransfer)4 AttributedList (ch.cyberduck.core.AttributedList)3 ConnectionCallback (ch.cyberduck.core.ConnectionCallback)3 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)3 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)3 Host (ch.cyberduck.core.Host)3 ListProgressListener (ch.cyberduck.core.ListProgressListener)3