HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / hbase-http / src / test / java / org / apache / hadoop / hbase / http / TestHttpServerLifecycle.java
blobce0d6d6bc3272e824f06bd905c65a38c0f83e61d
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.http;
20 import org.apache.hadoop.hbase.HBaseClassTestRule;
21 import org.apache.hadoop.hbase.testclassification.MiscTests;
22 import org.apache.hadoop.hbase.testclassification.SmallTests;
23 import org.junit.ClassRule;
24 import org.junit.Ignore;
25 import org.junit.Test;
26 import org.junit.experimental.categories.Category;
28 @Category({MiscTests.class, SmallTests.class})
29 public class TestHttpServerLifecycle extends HttpServerFunctionalTest {
31 @ClassRule
32 public static final HBaseClassTestRule CLASS_RULE =
33 HBaseClassTestRule.forClass(TestHttpServerLifecycle.class);
35 /**
36 * Check that a server is alive by probing the {@link HttpServer#isAlive()} method
37 * and the text of its toString() description
38 * @param server server
40 private void assertAlive(HttpServer server) {
41 assertTrue("Server is not alive", server.isAlive());
42 assertToStringContains(server, HttpServer.STATE_DESCRIPTION_ALIVE);
45 private void assertNotLive(HttpServer server) {
46 assertTrue("Server should not be live", !server.isAlive());
47 assertToStringContains(server, HttpServer.STATE_DESCRIPTION_NOT_LIVE);
50 /**
51 * Test that the server is alive once started
53 * @throws Throwable on failure
55 @Ignore ("Hangs on occasion; see HBASE-14430") @Test
56 public void testCreatedServerIsNotAlive() throws Throwable {
57 HttpServer server = createTestServer();
58 assertNotLive(server);
61 @Ignore ("Hangs on occasion; see HBASE-14430") @Test
62 public void testStopUnstartedServer() throws Throwable {
63 HttpServer server = createTestServer();
64 stop(server);
67 /**
68 * Test that the server is alive once started
70 * @throws Throwable on failure
72 @Ignore ("Hangs on occasion; see HBASE-14430") @Test
73 public void testStartedServerIsAlive() throws Throwable {
74 HttpServer server = null;
75 server = createTestServer();
76 assertNotLive(server);
77 server.start();
78 assertAlive(server);
79 stop(server);
82 /**
83 * Assert that the result of {@link HttpServer#toString()} contains the specific text
84 * @param server server to examine
85 * @param text text to search for
87 private void assertToStringContains(HttpServer server, String text) {
88 String description = server.toString();
89 assertTrue("Did not find \"" + text + "\" in \"" + description + "\"",
90 description.contains(text));
93 /**
94 * Test that the server is not alive once stopped
96 * @throws Throwable on failure
98 @Ignore ("Hangs on occasion; see HBASE-14430") @Test
99 public void testStoppedServerIsNotAlive() throws Throwable {
100 HttpServer server = createAndStartTestServer();
101 assertAlive(server);
102 stop(server);
103 assertNotLive(server);
107 * Test that the server is not alive once stopped
109 * @throws Throwable on failure
111 @Ignore ("Hangs on occasion; see HBASE-14430") @Test
112 public void testStoppingTwiceServerIsAllowed() throws Throwable {
113 HttpServer server = createAndStartTestServer();
114 assertAlive(server);
115 stop(server);
116 assertNotLive(server);
117 stop(server);
118 assertNotLive(server);
122 * Test that the server is alive once started
124 * @throws Throwable
125 * on failure
127 @Ignore ("Hangs on occasion; see HBASE-14430") @Test
128 public void testWepAppContextAfterServerStop() throws Throwable {
129 HttpServer server = null;
130 String key = "test.attribute.key";
131 String value = "test.attribute.value";
132 server = createTestServer();
133 assertNotLive(server);
134 server.start();
135 server.setAttribute(key, value);
136 assertAlive(server);
137 assertEquals(value, server.getAttribute(key));
138 stop(server);
139 assertNull("Server context should have cleared", server.getAttribute(key));