mirror of https://github.com/apache/lucene.git
LockVerifyServer does not need to reuse addresses nor set accept timeout (#12535)
This commit is contained in:
parent
67be0189bc
commit
3c235bb7b4
|
@ -103,8 +103,7 @@ public class LockStressTest {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"Connecting to server " + addr + " and registering as client " + myID + "...");
|
"Connecting to server " + addr + " and registering as client " + myID + "...");
|
||||||
try (Socket socket = new Socket()) {
|
try (Socket socket = new Socket()) {
|
||||||
socket.setReuseAddress(true);
|
socket.connect(addr, 3000); // wait at most 3 seconds to successfully connect, else fail
|
||||||
socket.connect(addr, 500);
|
|
||||||
final OutputStream out = socket.getOutputStream();
|
final OutputStream out = socket.getOutputStream();
|
||||||
final InputStream in = socket.getInputStream();
|
final InputStream in = socket.getInputStream();
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,7 @@ public class LockVerifyServer {
|
||||||
static void run(String hostname, int maxClients, Consumer<InetSocketAddress> startClients)
|
static void run(String hostname, int maxClients, Consumer<InetSocketAddress> startClients)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
try (final ServerSocket s = new ServerSocket()) {
|
try (final ServerSocket s = new ServerSocket()) {
|
||||||
s.setReuseAddress(true);
|
s.setSoTimeout(30000); // give clients at most 30 secs to connect and send bytes
|
||||||
s.setSoTimeout(30000); // initially 30 secs to give clients enough time to startup
|
|
||||||
s.bind(new InetSocketAddress(hostname, 0));
|
s.bind(new InetSocketAddress(hostname, 0));
|
||||||
final InetSocketAddress localAddr = (InetSocketAddress) s.getLocalSocketAddress();
|
final InetSocketAddress localAddr = (InetSocketAddress) s.getLocalSocketAddress();
|
||||||
System.out.println("Listening on " + localAddr + "...");
|
System.out.println("Listening on " + localAddr + "...");
|
||||||
|
|
|
@ -18,6 +18,8 @@ package org.apache.lucene.store;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ProcessBuilder.Redirect;
|
import java.lang.ProcessBuilder.Redirect;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -40,6 +42,22 @@ public class TestStressLockFactories extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String readIfExists(Path path) throws IOException {
|
||||||
|
if (Files.exists(path)) {
|
||||||
|
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readClientStdout(Path dir, int client) throws IOException {
|
||||||
|
return readIfExists(dir.resolve("out-" + client + ".txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readClientStderr(Path dir, int client) throws IOException {
|
||||||
|
return readIfExists(dir.resolve("err-" + client + ".txt"));
|
||||||
|
}
|
||||||
|
|
||||||
private void runImpl(Class<? extends LockFactory> impl) throws Exception {
|
private void runImpl(Class<? extends LockFactory> impl) throws Exception {
|
||||||
final int clients = TEST_NIGHTLY ? 5 : 2;
|
final int clients = TEST_NIGHTLY ? 5 : 2;
|
||||||
final String host = "127.0.0.1";
|
final String host = "127.0.0.1";
|
||||||
|
@ -50,6 +68,7 @@ public class TestStressLockFactories extends LuceneTestCase {
|
||||||
|
|
||||||
final List<Process> processes = new ArrayList<>(clients);
|
final List<Process> processes = new ArrayList<>(clients);
|
||||||
|
|
||||||
|
try {
|
||||||
LockVerifyServer.run(
|
LockVerifyServer.run(
|
||||||
host,
|
host,
|
||||||
clients,
|
clients,
|
||||||
|
@ -78,13 +97,60 @@ public class TestStressLockFactories extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Server failed");
|
||||||
|
int client = 0;
|
||||||
|
for (Process p : processes) {
|
||||||
|
System.err.println("stderr for " + p.pid() + ":\n" + readClientStderr(dir, client));
|
||||||
|
System.err.println("stdout for " + p.pid() + ":\n" + readClientStdout(dir, client));
|
||||||
|
client++;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
// wait for all processes to exit...
|
// wait for all processes to exit...
|
||||||
try {
|
try {
|
||||||
|
int client = 0;
|
||||||
for (Process p : processes) {
|
for (Process p : processes) {
|
||||||
if (p.waitFor(15, TimeUnit.SECONDS)) {
|
int clientTimeoutSeconds = 15;
|
||||||
assertEquals("Process " + p.pid() + " died abnormally?", 0, p.waitFor());
|
|
||||||
|
boolean doFail = false;
|
||||||
|
String reason = null;
|
||||||
|
|
||||||
|
if (p.waitFor(clientTimeoutSeconds, TimeUnit.SECONDS)) {
|
||||||
|
// process finished within our 15 second wait period; get its exit code
|
||||||
|
int exitCode = p.waitFor();
|
||||||
|
if (exitCode != 0) {
|
||||||
|
doFail = true;
|
||||||
|
reason =
|
||||||
|
"Process "
|
||||||
|
+ p.pid()
|
||||||
|
+ " (client "
|
||||||
|
+ client
|
||||||
|
+ ") exited abnormally: exit code "
|
||||||
|
+ exitCode;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
doFail = true;
|
||||||
|
reason =
|
||||||
|
"Process "
|
||||||
|
+ p.pid()
|
||||||
|
+ " (client "
|
||||||
|
+ client
|
||||||
|
+ ") did not finish within "
|
||||||
|
+ clientTimeoutSeconds
|
||||||
|
+ " second timeout";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doFail) {
|
||||||
|
System.err.println(reason);
|
||||||
|
System.err.println("stderr for " + p.pid() + ":\n" + readClientStderr(dir, client));
|
||||||
|
System.err.println("stdout for " + p.pid() + ":\n" + readClientStdout(dir, client));
|
||||||
|
fail(reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
client++;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// kill all processes, which are still alive.
|
// kill all processes, which are still alive.
|
||||||
|
|
Loading…
Reference in New Issue