use of ch.cyberduck.core.TestLoginConnectionService in project cyberduck by iterate-ch.
the class TransferBackgroundActionTest method testResumeOnRetryWithException.
@Test
public void testResumeOnRetryWithException() {
final AtomicBoolean alert = new AtomicBoolean();
final AbstractController controller = new AbstractController() {
@Override
public void invoke(final MainAction runnable, final boolean wait) {
runnable.run();
}
};
final Host host = new Host(new TestProtocol(), "test.cyberduck.ch");
final TransferOptions options = new TransferOptions();
final TransferBackgroundAction action = new TransferBackgroundAction(controller, new DefaultSessionPool(new TestLoginConnectionService(), new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), host) {
@Override
public Session<?> borrow(final BackgroundActionState callback) throws BackgroundException {
throw new ConnectionRefusedException("d", new SocketException());
}
}, SessionPool.DISCONNECTED, new TransferAdapter(), new DownloadTransfer(host, Collections.singletonList(new TransferItem(new Path("/home/test", EnumSet.of(Path.Type.file)), new NullLocal("/t")))), options) {
@Override
public boolean alert(final BackgroundException failure) {
final boolean alerted = alert.get();
alert.set(true);
return !alerted;
}
};
assertFalse(alert.get());
// Connect, prepare and run
new BackgroundCallable<Boolean>(action, controller).call();
assertTrue(alert.get());
assertTrue(action.hasFailed());
// assertTrue(options.resumeRequested);
}
use of ch.cyberduck.core.TestLoginConnectionService in project cyberduck by iterate-ch.
the class TransferBackgroundActionTest method testCopyBetweenHosts.
@Test
public void testCopyBetweenHosts() throws Exception {
final Session session = new NullTransferSession(new Host(new TestProtocol(), "test.cyberduck.ch"));
final Session destination = new NullTransferSession(new Host(new TestProtocol(), "test.cyberduck.ch"));
final Path directory = new Path("/home/jenkins/transfer", EnumSet.of(Path.Type.directory));
final Path test = new Path(directory, "test", EnumSet.of(Path.Type.file));
test.attributes().setSize(0L);
final Path copy = new Path(new Path("/transfer", EnumSet.of(Path.Type.directory)), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
final Transfer t = new CopyTransfer(session.getHost(), destination.getHost(), Collections.singletonMap(test, copy)) {
@Override
public TransferAction action(final Session<?> source, final Session<?> destination, final boolean resumeRequested, final boolean reloadRequested, final TransferPrompt prompt, final ListProgressListener listener) {
return TransferAction.overwrite;
}
};
final AbstractController controller = new AbstractController() {
@Override
public void invoke(final MainAction runnable, final boolean wait) {
runnable.run();
}
};
final AtomicBoolean start = new AtomicBoolean();
final AtomicBoolean stop = new AtomicBoolean();
final TransferBackgroundAction action = new TransferBackgroundAction(controller, new StatelessSessionPool(new TestLoginConnectionService(), session, new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())), new StatelessSessionPool(new TestLoginConnectionService(), destination, new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())), new TransferListener() {
@Override
public void transferDidStart(final Transfer transfer) {
assertEquals(t, transfer);
start.set(true);
}
@Override
public void transferDidStop(final Transfer transfer) {
assertEquals(t, transfer);
stop.set(true);
}
@Override
public void transferDidProgress(final Transfer transfer, final TransferProgress status) {
//
}
}, t, new TransferOptions());
action.prepare();
action.call();
action.finish();
assertFalse(action.hasFailed());
assertTrue(start.get());
assertTrue(stop.get());
assertTrue(t.isComplete());
assertNotNull(t.getTimestamp());
}
use of ch.cyberduck.core.TestLoginConnectionService in project cyberduck by iterate-ch.
the class DefaultSessionPoolTest method testShutdown.
@Test(expected = ConnectionCanceledException.class)
public void testShutdown() throws Exception {
final DefaultSessionPool pool = new DefaultSessionPool(new TestLoginConnectionService(), new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), new Host(new TestProtocol()));
pool.shutdown();
pool.borrow(BackgroundActionState.running);
}
use of ch.cyberduck.core.TestLoginConnectionService in project cyberduck by iterate-ch.
the class StatelessSessionPoolTest method testCheckReconnectApplicationFailure.
@Test
public void testCheckReconnectApplicationFailure() throws Exception {
final AtomicBoolean interrupt = new AtomicBoolean();
final StatelessSessionPool pool = new StatelessSessionPool(new TestLoginConnectionService() {
@Override
public boolean check(final Session<?> session, final CancelCallback callback) {
return true;
}
}, new NullSession(new Host(new TestProtocol())) {
@Override
public void interrupt() throws BackgroundException {
interrupt.set(true);
super.interrupt();
}
}, new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback()));
final Session<?> session = pool.borrow(BackgroundActionState.running);
pool.release(session, new BackgroundException("m", "d"));
assertFalse(interrupt.get());
}
use of ch.cyberduck.core.TestLoginConnectionService in project cyberduck by iterate-ch.
the class SessionBackgroundActionTest method testGetExceptionLoginCanceledException.
@Test
public void testGetExceptionLoginCanceledException() {
final BackgroundException failure = new LoginCanceledException();
SessionBackgroundAction<Void> a = new SessionBackgroundAction<Void>(new StatelessSessionPool(new TestLoginConnectionService(), new NullSession(new Host(new TestProtocol(), "t")), new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())), new AlertCallback() {
@Override
public boolean alert(final Host repeatableBackgroundAction, final BackgroundException f, final StringBuilder transcript) {
assertEquals(failure, f);
return false;
}
}, new DisabledProgressListener()) {
@Override
public Void run(final Session<?> session) throws BackgroundException {
throw failure;
}
};
try {
a.call();
fail();
} catch (BackgroundException e) {
// Ignore
}
assertFalse(a.hasFailed());
}
Aggregations