@Test
public void testKillServerProcess() throws IOException {
File dir = Files.createTempDir();
RepositoryConfiguration repoConfig = new RepositoryConfiguration();
repoConfig.addExtension(JavaHgTestExtension.class);
Repository repo = Repository.create(repoConfig, dir);
Process process = getFirstServer(repo).getProcess();
process.destroy();
// Process is dead and we can't send command
try {
VersionCommand cmd = VersionCommand.on(repo);
cmd.execute();
assertFailedExecution(cmd);
} catch (UnexpectedServerTerminationException e) {
// success
}
repo.close();
repo = Repository.open(repoConfig, dir);
String longStringThatDoesntFitInBuffers = Strings.repeat("x", 10 * 1000 * 1000);
GenericCommand cmd = new GenericCommand(repo, "javahg-write");
HgInputStream stream = cmd.launchStream("o", longStringThatDoesntFitInBuffers);
boolean killed = killProcess(process);
if (killed) {
// Command is now sent, but we can't read output
try {
// String s =
Utils.readStream(stream, repo.getServerPool().newDecoder());
// TODO This doesn't work on Linux, why?
// Assert.fail("Exception expected. Read " +
// s.length() + " bytes");
} catch (UnexpectedServerTerminationException e) {
System.err.println("Exit value in testKillServerProcess: " + e.getExitValue());
// success
}
}
repo.close();
deleteTempDir(dir);
}