-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02cc4d6
commit 8501c77
Showing
2 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...roject/hadoop-common/src/test/java/org/apache/hadoop/http/TestDisabledProfileServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.http; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Small test to cover default disabled prof endpoint. | ||
*/ | ||
public class TestDisabledProfileServlet extends HttpServerFunctionalTest { | ||
|
||
private static HttpServer2 server; | ||
private static URL baseUrl; | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
server = createTestServer(); | ||
server.start(); | ||
baseUrl = getServerURL(server); | ||
} | ||
|
||
@AfterClass | ||
public static void cleanup() throws Exception { | ||
server.stop(); | ||
} | ||
|
||
@Test | ||
public void testQuery() throws Exception { | ||
try { | ||
readOutput(new URL(baseUrl, "/prof")); | ||
throw new IllegalStateException("Should not reach here"); | ||
} catch (IOException e) { | ||
assertTrue(e.getMessage() | ||
.contains(HttpServletResponse.SC_INTERNAL_SERVER_ERROR + " for URL: " + baseUrl)); | ||
} | ||
|
||
// CORS headers | ||
HttpURLConnection conn = | ||
(HttpURLConnection) new URL(baseUrl, "/prof").openConnection(); | ||
assertEquals("GET", conn.getHeaderField(ProfileServlet.ACCESS_CONTROL_ALLOW_METHODS)); | ||
assertNotNull(conn.getHeaderField(ProfileServlet.ACCESS_CONTROL_ALLOW_ORIGIN)); | ||
} | ||
|
||
@Test | ||
public void testRequestMethods() throws IOException { | ||
assertEquals("Unexpected response code", HttpServletResponse.SC_METHOD_NOT_ALLOWED, | ||
getConnection("PUT").getResponseCode()); | ||
assertEquals("Unexpected response code", HttpServletResponse.SC_METHOD_NOT_ALLOWED, | ||
getConnection("POST").getResponseCode()); | ||
assertEquals("Unexpected response code", HttpServletResponse.SC_METHOD_NOT_ALLOWED, | ||
getConnection("DELETE").getResponseCode()); | ||
assertEquals("Unexpected response code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, | ||
getConnection("GET").getResponseCode()); | ||
} | ||
|
||
private HttpURLConnection getConnection(final String method) throws IOException { | ||
URL url = new URL(baseUrl, "/prof"); | ||
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | ||
conn.setRequestMethod(method); | ||
return conn; | ||
} | ||
|
||
} |