Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;

import org.apache.camel.spi.annotations.InfraService;
Expand Down Expand Up @@ -136,6 +138,23 @@ public void setUpServer() throws Exception {
sshd.start();

port = ((InetSocketAddress) sshd.getBoundAddresses().iterator().next()).getPort();

waitForServerReady();
}

private void waitForServerReady() throws IOException {
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(30);
IOException lastException = null;
while (System.nanoTime() < deadline) {
try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress("localhost", port), 1000);
return;
} catch (IOException e) {
lastException = e;
Thread.onSpinWait();
}
}
throw new IOException("SFTP server not ready after 30 seconds on port " + port, lastException);
}

protected PublickeyAuthenticator getPublickeyAuthenticator() {
Expand Down
Loading