use of ch.cyberduck.core.ProgressListener 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.ProgressListener 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.ProgressListener in project cyberduck by iterate-ch.
the class SynchronizationPathFilterTest method testAcceptDirectory.
@Test
public void testAcceptDirectory() throws Exception {
Session session = new NullSession(new Host(new TestProtocol()));
final SynchronizationPathFilter mirror = new SynchronizationPathFilter(new ComparePathFilter() {
@Override
public Comparison compare(Path file, Local local, final ProgressListener listener) {
return Comparison.equal;
}
}, new OverwriteFilter(new DownloadSymlinkResolver(Collections.<TransferItem>emptyList()), session), new ch.cyberduck.core.transfer.upload.OverwriteFilter(new UploadSymlinkResolver(null, Collections.<TransferItem>emptyList()), session), TransferAction.mirror);
assertTrue(mirror.accept(new Path("/p", EnumSet.of(Path.Type.directory)), null, new TransferStatus().exists(true)));
}
use of ch.cyberduck.core.ProgressListener in project cyberduck by iterate-ch.
the class CompareFilterTest method testAcceptDirectory.
@Test
public void testAcceptDirectory() throws Exception {
final Host host = new Host(new TestProtocol());
final CompareFilter filter = new CompareFilter(new DisabledUploadSymlinkResolver(), new NullSession(host), new UploadFilterOptions(host), new DisabledProgressListener(), new DefaultComparePathFilter(new NullSession(host), null) {
@Override
public Comparison compare(final Path file, final Local local, final ProgressListener listener) {
return Comparison.equal;
}
});
assertTrue(filter.accept(new Path("/n", EnumSet.of(Path.Type.directory)), new NullLocal("/n") {
@Override
public boolean exists() {
return true;
}
}, new TransferStatus().exists(true)));
}
use of ch.cyberduck.core.ProgressListener in project cyberduck by iterate-ch.
the class SegmentRetryCallableTest method testRetry.
@Test
public void testRetry() throws Exception {
final AtomicInteger count = new AtomicInteger();
final SegmentRetryCallable<Void> c = new SegmentRetryCallable<Void>(new Host(new TestProtocol()), 2, 0, new BackgroundExceptionCallable<Void>() {
@Override
public Void call() throws BackgroundException {
throw new ConnectionRefusedException("d", new SocketException());
}
}, new TransferStatus(), new BytecountStreamListener()) {
@Override
public boolean retry(final BackgroundException failure, final ProgressListener progress, final BackgroundActionState cancel) {
count.incrementAndGet();
return super.retry(failure, progress, cancel);
}
};
try {
c.call();
fail();
} catch (ConnectionRefusedException e) {
// Expected
}
assertEquals(3, count.get());
}
Aggregations