comparison test/org/tmatesoft/hg/test/HgServer.java @ 653:629a7370554c

Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 03 Jul 2013 14:38:30 +0200
parents
children
comparison
equal deleted inserted replaced
652:cd77bf51b562 653:629a7370554c
1 /*
2 * Copyright (c) 2013 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.test;
18
19 import java.io.File;
20 import java.io.IOException;
21 import java.net.MalformedURLException;
22 import java.net.URL;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 /**
27 * Wraps hg server
28 *
29 * @author Artem Tikhomirov
30 * @author TMate Software Ltd.
31 */
32 class HgServer {
33 private Process serverProcess;
34 private boolean publish = true;
35
36 public HgServer publishing(boolean pub) {
37 publish = pub;
38 return this;
39 }
40
41 public HgServer start(File dir) throws IOException, InterruptedException {
42 if (serverProcess != null) {
43 stop();
44 }
45 List<String> cmdline = new ArrayList<String>();
46 cmdline.add("hg");
47 cmdline.add("--config");
48 cmdline.add("web.allow_push=*");
49 cmdline.add("--config");
50 cmdline.add("web.push_ssl=False");
51 cmdline.add("--config");
52 cmdline.add("server.validate=True");
53 cmdline.add("--config");
54 cmdline.add(String.format("web.port=%d", port()));
55 if (!publish) {
56 cmdline.add("--config");
57 cmdline.add("phases.publish=False");
58 }
59 cmdline.add("serve");
60 serverProcess = new ProcessBuilder(cmdline).directory(dir).start();
61 Thread.sleep(500);
62 return this;
63 }
64
65 public URL getURL() throws MalformedURLException {
66 return new URL(String.format("http://localhost:%d/", port()));
67 }
68
69 public int port() {
70 return 9090;
71 }
72
73 public void stop() {
74 if (serverProcess == null) {
75 return;
76 }
77 // if Process#destroy() doesn't perform well with scripts and child processes
78 // may need to write server pid to a file and send a kill <pid> here
79 serverProcess.destroy();
80 serverProcess = null;
81 }
82 }