Search in sources :

Example 36 with DisabledTransferPrompt

use of ch.cyberduck.core.transfer.DisabledTransferPrompt in project cyberduck by iterate-ch.

the class SingleTransferWorkerTest method testUploadPrepareOverrideRootExists.

@Test
public void testUploadPrepareOverrideRootExists() 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 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) {
            if (file.equals(root)) {
                assertTrue(segment.isExists());
            } else {
                assertFalse(segment.isExists());
            }
        }
    };
    final NullSession session = new NullSession(new Host(new TestProtocol())) {

        @Override
        public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
            return new AttributedList<Path>(Collections.singletonList(new Path("/t", EnumSet.of(Path.Type.directory))));
        }
    };
    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(item, action);
            assertFalse(this.getCache().isCached(new TransferItem(child, 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) NullSession(ch.cyberduck.core.NullSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) NullLocal(ch.cyberduck.core.NullLocal) 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) 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 37 with DisabledTransferPrompt

use of ch.cyberduck.core.transfer.DisabledTransferPrompt in project cyberduck by iterate-ch.

the class SingleTransferWorkerTest method testUploadFileNotFound.

@Test(expected = NotfoundException.class)
public void testUploadFileNotFound() throws Exception {
    // #7791
    final Path root = new Path("/t", EnumSet.of(Path.Type.file));
    final Host bookmark = new Host(new TestProtocol());
    final Transfer t = new UploadTransfer(bookmark, root, new NullLocal("l") {

        @Override
        public boolean exists() {
            // Will give a not found failure
            return false;
        }
    });
    final NullSession session = new NullSession(bookmark) {

        @Override
        public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
            return new AttributedList<Path>(Collections.singletonList(new Path("/t", EnumSet.of(Path.Type.directory))));
        }
    };
    try {
        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 file, final TransferAction action) {
                // Expected not found
                fail();
                return null;
            }
        }.run(session);
    } catch (NotfoundException e) {
        // Expected
        assertFalse(t.isComplete());
        throw e;
    }
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) NotfoundException(ch.cyberduck.core.exception.NotfoundException) TestProtocol(ch.cyberduck.core.TestProtocol) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) TransferAction(ch.cyberduck.core.transfer.TransferAction) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) AttributedList(ch.cyberduck.core.AttributedList) NullLocal(ch.cyberduck.core.NullLocal) 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) Future(java.util.concurrent.Future) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) ListProgressListener(ch.cyberduck.core.ListProgressListener) TransferItem(ch.cyberduck.core.transfer.TransferItem) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Test(org.junit.Test)

Example 38 with DisabledTransferPrompt

use of ch.cyberduck.core.transfer.DisabledTransferPrompt in project cyberduck by iterate-ch.

the class ConcurrentTransferWorkerTest method testBorrow.

@Test
public void testBorrow() throws Exception {
    final Host host = new Host(new TestProtocol(), "test.cyberduck.ch");
    final Transfer t = new UploadTransfer(host, new Path("/t", EnumSet.of(Path.Type.directory)), new NullLocal("l"));
    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(), new DisabledTransferErrorCallback(), new DisabledLoginCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledNotificationService());
    assertNotSame(worker.borrow(ConcurrentTransferWorker.Connection.source), worker.borrow(ConcurrentTransferWorker.Connection.source));
    worker.cleanup(true);
}
Also used : DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DefaultSessionPool(ch.cyberduck.core.pool.DefaultSessionPool) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Test(org.junit.Test)

Example 39 with DisabledTransferPrompt

use of ch.cyberduck.core.transfer.DisabledTransferPrompt in project cyberduck by iterate-ch.

the class ConcurrentTransferWorkerTest method testSessionReuse.

@Test
public void testSessionReuse() throws Exception {
    final Host host = new Host(new TestProtocol(), "test.cyberduck.ch");
    final Transfer t = new UploadTransfer(host, new Path("/t", EnumSet.of(Path.Type.directory)), new NullLocal("l"));
    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.withMaxTotal(1), SessionPool.DISCONNECTED, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt(), new DisabledTransferErrorCallback(), new DisabledLoginCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledNotificationService());
    // Override default transfer queue size
    pool.withMaxTotal(1);
    final Session<?> session = worker.borrow(ConcurrentTransferWorker.Connection.source);
    worker.release(session, ConcurrentTransferWorker.Connection.source, null);
    assertEquals(Session.State.closed, session.getState());
    final Session<?> reuse = worker.borrow(ConcurrentTransferWorker.Connection.source);
    assertSame(session, reuse);
    final CyclicBarrier lock = new CyclicBarrier(2);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                assertSame(session, worker.borrow(ConcurrentTransferWorker.Connection.source));
                try {
                    lock.await(1, TimeUnit.MINUTES);
                } catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
                    fail();
                }
            } catch (BackgroundException e) {
                fail();
            }
        }
    }).start();
    worker.release(reuse, ConcurrentTransferWorker.Connection.source, null);
    lock.await(1, TimeUnit.MINUTES);
    worker.cleanup(true);
}
Also used : DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) DefaultSessionPool(ch.cyberduck.core.pool.DefaultSessionPool) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) TimeoutException(java.util.concurrent.TimeoutException) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) CyclicBarrier(java.util.concurrent.CyclicBarrier) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) BackgroundException(ch.cyberduck.core.exception.BackgroundException) Test(org.junit.Test)

Example 40 with DisabledTransferPrompt

use of ch.cyberduck.core.transfer.DisabledTransferPrompt in project cyberduck by iterate-ch.

the class FTPConcurrentTransferWorkerTest method testConcurrentSessions.

@Test
public void testConcurrentSessions() throws Exception {
    final int files = 20;
    final int connections = 2;
    final List<TransferItem> list = new ArrayList<>();
    final Local file = new Local(File.createTempFile(new AlphanumericRandomStringService().random(), "t").getAbsolutePath());
    for (int i = 1; i <= files; i++) {
        list.add(new TransferItem(new Path(String.format("/t%d", i), EnumSet.of(Path.Type.file)), file));
    }
    final Transfer transfer = new UploadTransfer(session.getHost(), list);
    final DefaultSessionPool pool = new DefaultSessionPool(new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String username, final String title, final String reason, final LoginOptions options) {
            return new Credentials(username, "test");
        }

        @Override
        public void warn(final Host bookmark, final String title, final String message, final String continueButton, final String disconnectButton, final String preference) {
        // 
        }
    }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()), new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), session.getHost());
    final ConcurrentTransferWorker worker = new ConcurrentTransferWorker(pool.withMaxTotal(connections), SessionPool.DISCONNECTED, transfer, new TransferOptions(), new TransferSpeedometer(transfer), 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);
    assertEquals(0L, transfer.getTransferred(), 0L);
    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) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) 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) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) Test(org.junit.Test) AbstractFTPTest(ch.cyberduck.core.ftp.AbstractFTPTest)

Aggregations

DisabledTransferPrompt (ch.cyberduck.core.transfer.DisabledTransferPrompt)42 TransferOptions (ch.cyberduck.core.transfer.TransferOptions)40 TransferSpeedometer (ch.cyberduck.core.transfer.TransferSpeedometer)40 DisabledTransferErrorCallback (ch.cyberduck.core.transfer.DisabledTransferErrorCallback)38 Transfer (ch.cyberduck.core.transfer.Transfer)38 DisabledNotificationService (ch.cyberduck.core.notification.DisabledNotificationService)37 Test (org.junit.Test)37 UploadTransfer (ch.cyberduck.core.transfer.UploadTransfer)36 TransferItem (ch.cyberduck.core.transfer.TransferItem)34 TransferAction (ch.cyberduck.core.transfer.TransferAction)33 DisabledStreamListener (ch.cyberduck.core.io.DisabledStreamListener)31 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)27 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)27 Path (ch.cyberduck.core.Path)26 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)25 Delete (ch.cyberduck.core.features.Delete)25 Local (ch.cyberduck.core.Local)24 IntegrationTest (ch.cyberduck.test.IntegrationTest)23 Host (ch.cyberduck.core.Host)22 DownloadTransfer (ch.cyberduck.core.transfer.DownloadTransfer)22