Search in sources :

Example 1 with AbstractDownloadFilter

use of ch.cyberduck.core.transfer.download.AbstractDownloadFilter 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)

Aggregations

DisabledStreamListener (ch.cyberduck.core.io.DisabledStreamListener)1 StreamListener (ch.cyberduck.core.io.StreamListener)1 DisabledNotificationService (ch.cyberduck.core.notification.DisabledNotificationService)1 DefaultSessionPool (ch.cyberduck.core.pool.DefaultSessionPool)1 DefaultX509KeyManager (ch.cyberduck.core.ssl.DefaultX509KeyManager)1 DisabledX509TrustManager (ch.cyberduck.core.ssl.DisabledX509TrustManager)1 DisabledTransferErrorCallback (ch.cyberduck.core.transfer.DisabledTransferErrorCallback)1 DisabledTransferPrompt (ch.cyberduck.core.transfer.DisabledTransferPrompt)1 DownloadTransfer (ch.cyberduck.core.transfer.DownloadTransfer)1 Transfer (ch.cyberduck.core.transfer.Transfer)1 TransferAction (ch.cyberduck.core.transfer.TransferAction)1 TransferItem (ch.cyberduck.core.transfer.TransferItem)1 TransferOptions (ch.cyberduck.core.transfer.TransferOptions)1 TransferSpeedometer (ch.cyberduck.core.transfer.TransferSpeedometer)1 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)1 UploadTransfer (ch.cyberduck.core.transfer.UploadTransfer)1 AbstractDownloadFilter (ch.cyberduck.core.transfer.download.AbstractDownloadFilter)1 DisabledDownloadSymlinkResolver (ch.cyberduck.core.transfer.symlink.DisabledDownloadSymlinkResolver)1 DefaultVaultRegistry (ch.cyberduck.core.vault.DefaultVaultRegistry)1 ArrayList (java.util.ArrayList)1