1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.transport;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertTrue;
15
16 import java.net.InetSocketAddress;
17
18 import org.junit.Test;
19
20
21
22
23 public class DaemonTest {
24
25 @Test
26 public void testDaemonStop() throws Exception {
27 Daemon d = new Daemon();
28 d.start();
29 InetSocketAddress address = d.getAddress();
30 assertTrue("Port should be allocated", address.getPort() > 0);
31 assertTrue("Daemon should be running", d.isRunning());
32 Thread.sleep(1000);
33 d.stopAndWait();
34
35 d = new Daemon(address);
36 d.start();
37 InetSocketAddress newAddress = d.getAddress();
38 assertEquals("New daemon should run on the same port", address,
39 newAddress);
40 assertTrue("Daemon should be running", d.isRunning());
41 Thread.sleep(1000);
42 d.stopAndWait();
43 }
44
45 @Test
46 public void testDaemonRestart() throws Exception {
47 Daemon d = new Daemon();
48 d.start();
49 InetSocketAddress address = d.getAddress();
50 assertTrue("Port should be allocated", address.getPort() > 0);
51 assertTrue("Daemon should be running", d.isRunning());
52 Thread.sleep(1000);
53 d.stopAndWait();
54
55 d.start();
56 InetSocketAddress newAddress = d.getAddress();
57 assertEquals("Daemon should again run on the same port", address,
58 newAddress);
59 assertTrue("Daemon should be running", d.isRunning());
60 Thread.sleep(1000);
61 d.stopAndWait();
62 }
63 }