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);
}
Aggregations