Repository: phoenix Updated Branches: refs/heads/3.0 56390c426 -> 6afce315e
PHOENIX-1036 Fix flapping ContextClassloaderIT (SamarthJain) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/6afce315 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/6afce315 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/6afce315 Branch: refs/heads/3.0 Commit: 6afce315e9a647b637b4e0fe6a21c9c3f19b21c8 Parents: 56390c4 Author: Mujtaba <mujt...@apache.org> Authored: Wed Jun 11 15:43:45 2014 -0700 Committer: Mujtaba <mujt...@apache.org> Committed: Wed Jun 11 15:43:45 2014 -0700 ---------------------------------------------------------------------- .../phoenix/end2end/ContextClassloaderIT.java | 53 +++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/6afce315/phoenix-core/src/it/java/org/apache/phoenix/end2end/ContextClassloaderIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ContextClassloaderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ContextClassloaderIT.java index b131cc9..b35ef20 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ContextClassloaderIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ContextClassloaderIT.java @@ -17,6 +17,14 @@ */ package org.apache.phoenix.end2end; +import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL; +import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR; +import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR; +import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM; +import static org.apache.phoenix.util.TestUtil.LOCALHOST; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.net.URL; import java.net.URLClassLoader; @@ -26,29 +34,38 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.phoenix.jdbc.PhoenixTestDriver; +import org.apache.phoenix.query.BaseTest; import org.apache.phoenix.query.QueryServices; +import org.apache.phoenix.util.ReadOnlyProps; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - @Category(NeedsOwnMiniClusterTest.class) -public class ContextClassloaderIT { +public class ContextClassloaderIT extends BaseTest { private static HBaseTestingUtility hbaseTestUtil; + private static PhoenixTestDriver driver; private static ClassLoader badContextClassloader; - + private static String url; + @BeforeClass public static void setUpBeforeClass() throws Exception { - hbaseTestUtil = new HBaseTestingUtility(); - hbaseTestUtil.getConfiguration().setInt(QueryServices.MASTER_INFO_PORT_ATTRIB, -1); - hbaseTestUtil.getConfiguration().setInt(QueryServices.REGIONSERVER_INFO_PORT_ATTRIB, -1); + Configuration conf = HBaseConfiguration.create(); + setUpConfigForMiniCluster(conf); + hbaseTestUtil = new HBaseTestingUtility(conf); hbaseTestUtil.startMiniCluster(); - Connection conn = DriverManager.getConnection(getUrl()); + String clientPort = hbaseTestUtil.getConfiguration().get(QueryServices.ZOOKEEPER_PORT_ATTRIB); + url = JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + LOCALHOST + JDBC_PROTOCOL_SEPARATOR + clientPort + + JDBC_PROTOCOL_TERMINATOR + PHOENIX_TEST_DRIVER_URL_PARAM; + driver = initAndRegisterDriver(url, ReadOnlyProps.EMPTY_PROPS); + + Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement(); stmt.execute("CREATE TABLE test (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR)"); stmt.execute("UPSERT INTO test VALUES (1, 'name1')"); @@ -60,13 +77,13 @@ public class ContextClassloaderIT { File.createTempFile("invalid", ".jar").toURI().toURL() }, null); } - private static String getUrl() { - return "jdbc:phoenix:localhost:" + hbaseTestUtil.getZkCluster().getClientPort(); - } - @AfterClass - public static void tearDownAfterClass() throws Exception { - hbaseTestUtil.shutdownMiniCluster(); + public static void tearDown() throws Exception { + try { + destroyDriver(driver); + } finally { + hbaseTestUtil.shutdownMiniCluster(); + } } @Test @@ -77,7 +94,7 @@ public class ContextClassloaderIT { @Override public void run() { try { - Connection conn = DriverManager.getConnection(getUrl()); + Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from test where name = 'name2'"); while (rs.next()) { @@ -103,7 +120,7 @@ public class ContextClassloaderIT { @Override public void run() { try { - Connection conn = DriverManager.getConnection(getUrl()); + Connection conn = DriverManager.getConnection(url); ResultSet tablesRs = conn.getMetaData().getTables(null, null, null, null); while (tablesRs.next()) { // Just make sure we run over all records @@ -127,7 +144,7 @@ public class ContextClassloaderIT { @Override public void run() { try { - Connection conn = DriverManager.getConnection(getUrl()); + Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement(); stmt.execute("CREATE TABLE T2 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR)"); stmt.execute("UPSERT INTO T2 VALUES (1, 'name1')");