1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.http;
19
20 import org.apache.log4j.Logger;
21 import org.junit.Test;
22 import org.junit.Ignore;
23 import org.apache.hadoop.hbase.testclassification.SmallTests;
24 import org.junit.experimental.categories.Category;
25
26 @Category(SmallTests.class)
27 public class TestHttpServerLifecycle extends HttpServerFunctionalTest {
28
29
30
31
32
33
34 private void assertAlive(HttpServer server) {
35 assertTrue("Server is not alive", server.isAlive());
36 assertToStringContains(server, HttpServer.STATE_DESCRIPTION_ALIVE);
37 }
38
39 private void assertNotLive(HttpServer server) {
40 assertTrue("Server should not be live", !server.isAlive());
41 assertToStringContains(server, HttpServer.STATE_DESCRIPTION_NOT_LIVE);
42 }
43
44
45
46
47
48
49 @Ignore ("Hangs on occasion; see HBASE-14430") @Test(timeout=60000)
50 public void testCreatedServerIsNotAlive() throws Throwable {
51 HttpServer server = createTestServer();
52 assertNotLive(server);
53 }
54
55 @Ignore ("Hangs on occasion; see HBASE-14430") @Test(timeout=60000)
56 public void testStopUnstartedServer() throws Throwable {
57 HttpServer server = createTestServer();
58 stop(server);
59 }
60
61
62
63
64
65
66 @Ignore ("Hangs on occasion; see HBASE-14430") @Test(timeout=60000)
67 public void testStartedServerIsAlive() throws Throwable {
68 HttpServer server = null;
69 server = createTestServer();
70 assertNotLive(server);
71 server.start();
72 assertAlive(server);
73 stop(server);
74 }
75
76
77
78
79
80
81 private void assertToStringContains(HttpServer server, String text) {
82 String description = server.toString();
83 assertTrue("Did not find \"" + text + "\" in \"" + description + "\"",
84 description.contains(text));
85 }
86
87
88
89
90
91
92 @Ignore ("Hangs on occasion; see HBASE-14430") @Test(timeout=60000)
93 public void testStoppedServerIsNotAlive() throws Throwable {
94 HttpServer server = createAndStartTestServer();
95 assertAlive(server);
96 stop(server);
97 assertNotLive(server);
98 }
99
100
101
102
103
104
105 @Ignore ("Hangs on occasion; see HBASE-14430") @Test(timeout=60000)
106 public void testStoppingTwiceServerIsAllowed() throws Throwable {
107 HttpServer server = createAndStartTestServer();
108 assertAlive(server);
109 stop(server);
110 assertNotLive(server);
111 stop(server);
112 assertNotLive(server);
113 }
114
115
116
117
118
119
120
121 @Ignore ("Hangs on occasion; see HBASE-14430") @Test(timeout=60000)
122 public void testWepAppContextAfterServerStop() throws Throwable {
123 HttpServer server = null;
124 String key = "test.attribute.key";
125 String value = "test.attribute.value";
126 server = createTestServer();
127 assertNotLive(server);
128 server.start();
129 server.setAttribute(key, value);
130 assertAlive(server);
131 assertEquals(value, server.getAttribute(key));
132 stop(server);
133 assertNull("Server context should have cleared", server.getAttribute(key));
134 }
135 }