diff --git hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java index bf05ba91650edf40c59382adae66c79ff86e5d4d..3bd8705bcd2466214369febd6a3a4bcd9c15416b 100644 --- hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java +++ hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java @@ -18,7 +18,6 @@ */ package org.apache.hive.hcatalog.templeton; -import junit.framework.Assert; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.NameValuePair; @@ -28,6 +27,8 @@ import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.hadoop.hive.metastore.MetaStoreUtils; import org.apache.hadoop.hive.ql.ErrorMsg; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.type.TypeReference; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Ignore; @@ -35,11 +36,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.eclipse.jetty.http.HttpStatus; + import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; +import junit.framework.Assert; /** * A set of tests exercising e2e WebHCat DDL APIs. These tests are somewhat @@ -64,6 +68,7 @@ private static final String ERROR_CODE = "errorCode"; private static Main templetonServer; private static final String charSet = "UTF-8"; + @BeforeClass public static void startHebHcatInMem() { int webhcatPort = 50111; @@ -81,6 +86,7 @@ public static void startHebHcatInMem() { templetonServer.run(); LOG.info("Main started"); } + @AfterClass public static void stopWebHcatInMem() { if(templetonServer != null) { @@ -89,14 +95,33 @@ public static void stopWebHcatInMem() { LOG.info("Main stopped"); } } + + private static Map jsonStringToSortedMap(String jsonStr) { + Map sortedMap; + try { + sortedMap = (new ObjectMapper()).readValue(jsonStr, + new TypeReference>() {}); + } catch (Exception ex) { + throw new RuntimeException( + "Exception converting json string to sorted map " + ex, ex); + } + + return sortedMap; + } + @Test public void getStatus() throws IOException { LOG.debug("+getStatus()"); MethodCallRetVal p = doHttpCall(templetonBaseUrl + "/status", HTTP_METHOD_TYPE.GET); Assert.assertEquals(p.getAssertMsg(), HttpStatus.OK_200, p.httpStatusCode); - Assert.assertEquals(p.getAssertMsg(), "{\"status\":\"ok\",\"version\":\"v1\"}", p.responseBody); + // Must be deterministic order map for comparison across Java versions + Assert.assertTrue(p.getAssertMsg(), + jsonStringToSortedMap("{\"status\":\"ok\",\"version\":\"v1\"}").equals( + jsonStringToSortedMap(p.responseBody))); + LOG.debug("-getStatus()"); } + @Ignore("not ready due to HIVE-4824") @Test public void listDataBases() throws IOException { @@ -106,6 +131,7 @@ public void listDataBases() throws IOException { Assert.assertEquals(p.getAssertMsg(), "{\"databases\":[\"default\"]}", p.responseBody); LOG.debug("-listDataBases()"); } + /** * Check that we return correct status code when the URL doesn't map to any method * in {@link Server} @@ -118,6 +144,7 @@ public void invalidPath() throws IOException { /** * tries to drop table in a DB that doesn't exist */ + @Ignore("not ready due to HIVE-4824") @Test public void dropTableNoSuchDB() throws IOException { @@ -128,6 +155,7 @@ public void dropTableNoSuchDB() throws IOException { ErrorMsg.DATABASE_NOT_EXISTS.getErrorCode(), getErrorCode(p.responseBody)); } + /** * tries to drop table in a DB that doesn't exist */ @@ -140,6 +168,7 @@ public void dropTableNoSuchDbIfExists() throws IOException { Assert.assertEquals(p.getAssertMsg(), HttpStatus.NOT_FOUND_404, p.httpStatusCode); Assert.assertEquals(p.getAssertMsg(), ErrorMsg.DATABASE_NOT_EXISTS.getErrorCode(), getErrorCode(p.responseBody)); } + /** * tries to drop table that doesn't exist (with ifExists=true) */ @@ -151,6 +180,7 @@ public void dropTableIfExists() throws IOException { {new NameValuePair("ifExists", "true")}); Assert.assertEquals(p.getAssertMsg(), HttpStatus.OK_200, p.httpStatusCode); } + @Ignore("not ready due to HIVE-4824") @Test public void createDataBase() throws IOException { @@ -164,6 +194,7 @@ public void createDataBase() throws IOException { MethodCallRetVal p = doHttpCall(templetonBaseUrl + "/ddl/database/newdb", HTTP_METHOD_TYPE.PUT, props, null); Assert.assertEquals(p.getAssertMsg(), HttpStatus.OK_200, p.httpStatusCode); } + @Ignore("not ready due to HIVE-4824") @Test public void createTable() throws IOException { @@ -186,6 +217,7 @@ public void createTable() throws IOException { MethodCallRetVal descTbl = doHttpCall(templetonBaseUrl + "/ddl/database/default/table/test_table", HTTP_METHOD_TYPE.GET); Assert.assertEquals(descTbl.getAssertMsg(), HttpStatus.OK_200, descTbl.httpStatusCode); } + @Ignore("not ready due to HIVE-4824") @Test public void describeNoSuchTable() throws IOException { @@ -245,6 +277,7 @@ private static int getErrorCode(String jsonErrorObject) throws IOException { } return hiveRetCode; } + /** * Encapsulates information from HTTP method call */ @@ -263,10 +296,12 @@ String getAssertMsg() { return methodName + " " + submittedURL + " " + responseBody; } } + private static enum HTTP_METHOD_TYPE {GET, POST, DELETE, PUT} private static MethodCallRetVal doHttpCall(String uri, HTTP_METHOD_TYPE type) throws IOException { return doHttpCall(uri, type, null, null); } + /** * Does a basic HTTP GET and returns Http Status code + response body * Will add the dummy user query string @@ -321,4 +356,4 @@ private static MethodCallRetVal doHttpCall(String uri, HTTP_METHOD_TYPE type, Ma } return new MethodCallRetVal(-1, "Http " + type + " failed; see log file for details", actualUri, method.getName()); } -} +} \ No newline at end of file