From 82a2ccf51a613f2eb6f73e35fce5c721b16711c4 Mon Sep 17 00:00:00 2001 From: Deepesh Khandelwal Date: Tue, 24 Mar 2015 15:02:49 -0700 Subject: [PATCH] HIVE-10074: Ability to run HCat Client Unit tests in a system test setting --- .../apache/hive/hcatalog/api/TestHCatClient.java | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java b/hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java index 321a86d..555e055 100644 --- a/hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java +++ b/hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java @@ -71,6 +71,8 @@ private static final String replicationTargetHCatPort = "20102"; private static HiveConf replicationTargetHCatConf; private static SecurityManager securityManager; + private static boolean useExternalMS = false; + private static boolean useExternalMSForReplication = false; private static class RunMS implements Runnable { @@ -101,14 +103,22 @@ public void run() { @AfterClass public static void tearDown() throws Exception { - LOG.info("Shutting down metastore."); - System.setSecurityManager(securityManager); + if (!useExternalMS) { + LOG.info("Shutting down metastore."); + System.setSecurityManager(securityManager); + } } @BeforeClass public static void startMetaStoreServer() throws Exception { hcatConf = new HiveConf(TestHCatClient.class); + String metastoreUri = System.getProperty(HiveConf.ConfVars.METASTOREURIS.varname); + if (metastoreUri != null) { + hcatConf.setVar(HiveConf.ConfVars.METASTOREURIS, metastoreUri); + useExternalMS = true; + return; + } if (Shell.WINDOWS) { WindowsPathUtil.convertPathsFromWindowsToHdfs(hcatConf); } @@ -162,8 +172,12 @@ public void testBasicDDLCommands() throws Exception { assertTrue(testDb.getProperties().size() == 0); String warehouseDir = System .getProperty("test.warehouse.dir", "/user/hive/warehouse"); - String expectedDir = warehouseDir.replaceFirst("pfile:///", "pfile:/"); - assertEquals(expectedDir + "/" + db + ".db", testDb.getLocation()); + if (useExternalMS) { + assertTrue(testDb.getLocation().matches(".*" + "/" + db + ".db")); + } else { + String expectedDir = warehouseDir.replaceFirst("pfile:///", "pfile:/"); + assertEquals(expectedDir + "/" + db + ".db", testDb.getLocation()); + } ArrayList cols = new ArrayList(); cols.add(new HCatFieldSchema("id", Type.INT, "id comment")); cols.add(new HCatFieldSchema("value", Type.STRING, "value comment")); @@ -213,7 +227,7 @@ public void testBasicDDLCommands() throws Exception { assertEquals("checking " + serdeConstants.SERIALIZATION_NULL_FORMAT, Character.toString('\006'), table2.getSerdeParams().get(serdeConstants.SERIALIZATION_NULL_FORMAT)); - assertEquals((expectedDir + "/" + db + ".db/" + tableTwo).toLowerCase(), table2.getLocation().toLowerCase()); + assertTrue(table2.getLocation().toLowerCase().matches(".*" + ("/" + db + ".db/" + tableTwo).toLowerCase())); HCatCreateTableDesc tableDesc3 = HCatCreateTableDesc.create(db, tableThree, cols).fileFormat("orcfile").build(); @@ -372,7 +386,7 @@ public void testDatabaseLocation() throws Exception { .ifNotExists(true).location("/tmp/" + dbName).build(); client.createDatabase(dbDesc); HCatDatabase newDB = client.getDatabase(dbName); - assertTrue(newDB.getLocation().equalsIgnoreCase("file:/tmp/" + dbName)); + assertTrue(newDB.getLocation().matches(".*/tmp/" + dbName)); client.close(); } -- 1.9.5 (Apple Git-50.3)