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