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