[TRAFODION-2704]reslove the random schema not exist issue
Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/1ade4208 Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/1ade4208 Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/1ade4208 Branch: refs/heads/master Commit: 1ade4208f1e3551fa4ce2c7cbfda29a4c8c68b15 Parents: 835a489 Author: Weiqing Xu <weiqing...@esgyn.cn> Authored: Sat Sep 23 17:48:39 2017 +0000 Committer: Weiqing Xu <weiqing...@esgyn.cn> Committed: Sun Sep 24 03:43:10 2017 +0000 ---------------------------------------------------------------------- .../org/trafodion/jdbc/t4/T4DriverTest.java | 28 ------------- .../java/org/trafodion/jdbc_test/PropTest.java | 9 +++- .../java/org/trafodion/jdbc_test/TestBlob.java | 16 +++++--- .../org/trafodion/jdbc_test/TestBlobBatch.java | 12 ++++-- .../java/org/trafodion/jdbc_test/TestClob.java | 17 ++++++-- .../org/trafodion/jdbc_test/TestClobBatch.java | 15 ++++--- .../org/trafodion/jdbc_test/TestForeignKey.java | 43 ++++++++++---------- .../trafodion/jdbc_test/TestGetIndexInfo.java | 24 +++++++---- 8 files changed, 88 insertions(+), 76 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/1ade4208/core/conn/jdbcT4/src/test/java/org/trafodion/jdbc/t4/T4DriverTest.java ---------------------------------------------------------------------- diff --git a/core/conn/jdbcT4/src/test/java/org/trafodion/jdbc/t4/T4DriverTest.java b/core/conn/jdbcT4/src/test/java/org/trafodion/jdbc/t4/T4DriverTest.java index e158e7b..e44c97a 100644 --- a/core/conn/jdbcT4/src/test/java/org/trafodion/jdbc/t4/T4DriverTest.java +++ b/core/conn/jdbcT4/src/test/java/org/trafodion/jdbc/t4/T4DriverTest.java @@ -23,12 +23,7 @@ package org.trafodion.jdbc.t4; -import java.sql.Blob; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Statement; import org.junit.Assert; import org.junit.BeforeClass; @@ -44,29 +39,6 @@ public class T4DriverTest { @Test - public void readLob() throws SQLException { - Connection conn = null; - try { - conn = DriverManager.getConnection("jdbc:t4jdbc://192.168.0.36:23400/:", "zz", "zz"); - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("select c2 from tlob"); - while (rs.next()) { - Blob blob = rs.getBlob(1); - System.out.println("LOB length " + blob.length()); - System.out.println(new String(blob.getBytes(1, (int)blob.length()))); - } - conn.close(); - conn = null; - } - catch (SQLException se) { - System.out.println(se.getMessage()); - } - finally { - if (conn != null) - conn.close(); - } - } - @Test public void acceptsURL() throws SQLException { String url = "jdbc:t4jdbc://localhost:23400/:"; Assert.assertTrue(driver.acceptsURL(url)); http://git-wip-us.apache.org/repos/asf/trafodion/blob/1ade4208/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/PropTest.java ---------------------------------------------------------------------- diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/PropTest.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/PropTest.java index a4a269e..47bd5ca 100644 --- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/PropTest.java +++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/PropTest.java @@ -41,6 +41,7 @@ import java.io.*; import org.junit.Test; import static org.junit.Assert.*; +import static org.junit.Assert.fail; /* The test case is added for bug #1452993; * T2 don't read the property file from System Properties but T4 do it. @@ -54,10 +55,14 @@ public class PropTest public void testDefaultPropertiesConnection() throws SQLException { Connection conn = null; try { + conn = Utils.getUserConnection(); + } + catch (Exception e) { + fail("failed to create connection" + e.getMessage()); + } + try { // The option -Dproperties=propFile can be used to instead of System.setProperty() System.setProperty("properties", System.getProperty("trafjdbc.properties")); - - conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd); System.out.println("Catalog : " + conn.getCatalog()); assertEquals("Catalog should be the same as the properties file defined",Utils.catalog, conn.getCatalog()); System.out.println("testDefaultPropertiesConnection : PASS"); http://git-wip-us.apache.org/repos/asf/trafodion/blob/1ade4208/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlob.java ---------------------------------------------------------------------- diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlob.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlob.java index ff7c398..283555c 100644 --- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlob.java +++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlob.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.InputStream; import java.io.OutputStream; @@ -38,7 +39,8 @@ import org.junit.Test; public class TestBlob { private static final String tableName = "BLOBTEST"; - private static final String strCreateTable = "CREATE TABLE " + Utils.schema + "." + tableName + "(C1 int, c2 BLOB);"; + private static final String strCreateTable = "CREATE TABLE if not exists " + Utils.schema + "." + tableName + + "(C1 int, c2 BLOB);"; private static final String strDropTable = "DROP TABLE " + Utils.schema + "." + tableName; private static Connection _conn = null; @@ -46,15 +48,19 @@ public class TestBlob { @BeforeClass public static void doTestSuiteSetup() throws Exception { try { - _conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd); + _conn = Utils.getUserConnection(); + } + catch (Exception e) { + fail("failed to create connection" + e.getMessage()); + } + try ( Statement stmt = _conn.createStatement(); - + ) { // use CQD to enable BLOB support stmt.execute("CQD TRAF_BLOB_AS_VARCHAR 'OFF'"); stmt.execute(strCreateTable); } catch (Exception e) { - System.out.println(e.getMessage()); - e.printStackTrace(); + fail("failed to set CQDs for Blob : " + e.getMessage()); } } http://git-wip-us.apache.org/repos/asf/trafodion/blob/1ade4208/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlobBatch.java ---------------------------------------------------------------------- diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlobBatch.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlobBatch.java index b3acb5e..ee7f44c 100644 --- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlobBatch.java +++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBlobBatch.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -165,15 +166,18 @@ public class TestBlobBatch { @BeforeClass public static void doTestSuiteSetup() throws Exception { try { - _conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd); + _conn = Utils.getUserConnection(); + } catch (Exception e) { + fail("failed to create connection" + e.getMessage()); + } + try ( Statement stmt = _conn.createStatement(); - + ) { // use CQD to enable BLOB support stmt.execute("CQD TRAF_BLOB_AS_VARCHAR 'OFF'"); stmt.execute(strCreateTable); } catch (Exception e) { - System.out.println(e.getMessage()); - e.printStackTrace(); + fail("failed to set CQD : " + e.getMessage()); } } http://git-wip-us.apache.org/repos/asf/trafodion/blob/1ade4208/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java ---------------------------------------------------------------------- diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java index 51a7cf5..1919c53 100644 --- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java +++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.IOException; import java.io.InputStream; @@ -51,10 +52,17 @@ public class TestClob { @BeforeClass public static void doTestSuiteSetup() throws Exception { - try { - _conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd); - Statement stmt = _conn.createStatement(); - + try { + _conn = Utils.getUserConnection(); + } + catch (SQLException se) { + se.printStackTrace(); + fail("failed to create connection : " + se.getMessage()); + } + try ( + Statement stmt = _conn.createStatement(); + ) + { // use CQD to enable CLOB support stmt.execute("CQD TRAF_CLOB_AS_VARCHAR 'OFF'"); // stmt.execute(strDropTable); @@ -62,6 +70,7 @@ public class TestClob { } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); + fail("failed to set CQD for CLOB"); } } http://git-wip-us.apache.org/repos/asf/trafodion/blob/1ade4208/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClobBatch.java ---------------------------------------------------------------------- diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClobBatch.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClobBatch.java index d729dbe..b5ea1d0 100644 --- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClobBatch.java +++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClobBatch.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.Reader; import java.io.StringReader; @@ -200,16 +201,20 @@ public class TestClobBatch { @BeforeClass public static void doTestSuiteSetup() throws Exception { - try { - _conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd); - Statement stmt = _conn.createStatement(); + try { + _conn = Utils.getUserConnection(); + } catch (Exception e) { + fail("failed to create connection" + e.getMessage()); + } + try ( + Statement stmt = _conn.createStatement(); + ) { // use CQD to enable BLOB support stmt.execute("CQD TRAF_CLOB_AS_VARCHAR 'OFF'"); stmt.execute(strCreateTable); } catch (Exception e) { - System.out.println(e.getMessage()); - e.printStackTrace(); + fail("failed to set CQD : " + e.getMessage()); } } http://git-wip-us.apache.org/repos/asf/trafodion/blob/1ade4208/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java ---------------------------------------------------------------------- diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java index 9c87e9e..90c19c4 100644 --- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java +++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java @@ -26,8 +26,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; -import javax.swing.text.Utilities; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -46,22 +44,26 @@ public class TestForeignKey { private static final String FK21 = "FK21"; private static final String FK22 = "FK22"; - private static final String strCreatePKTABLE1Query = "CREATE TABLE " + Utils.schema + "." + PKTABLE1 + "( " + private static final String strCreatePKTABLE1Query = "CREATE TABLE IF NOT EXISTS " + Utils.schema + "." + PKTABLE1 + + "( " + PK1 + " INT NOT NULL PRIMARY KEY)"; private static final String strDropPKTABLE1Query = "DROP TABLE " + Utils.schema + "." + PKTABLE1; - private static final String strCreatePKTABLE2Query = "CREATE TABLE " + Utils.schema + "." + PKTABLE2 + "( " + private static final String strCreatePKTABLE2Query = "CREATE TABLE IF NOT EXISTS " + Utils.schema + "." + PKTABLE2 + + "( " + PK2 + " INT NOT NULL PRIMARY KEY)"; private static final String strDropPKTABLE2Query = "DROP TABLE " + Utils.schema + "." + PKTABLE2; - private static final String strCreateFKTABLE1Query = "CREATE TABLE " + Utils.schema + "." + FKTABLE1 + "( " + private static final String strCreateFKTABLE1Query = "CREATE TABLE IF NOT EXISTS " + Utils.schema + "." + FKTABLE1 + + "( " + FK1 + " INT NOT NULL, " + FK2 + " INT NOT NULL, " + "FOREIGN KEY (" + FK1 + ") REFERENCES " + Utils.schema + "." + PKTABLE1 + "(" + PK1 + "), " + "FOREIGN KEY (" + FK2 + ") REFERENCES " + Utils.schema + "." + PKTABLE2 + "(" + PK2 + "))"; private static final String strDropFKTABLE1Query = "DROP TABLE " + Utils.schema + "." + FKTABLE1; - private static final String strCreateFKTABLE2Query = "CREATE TABLE " + Utils.schema + "." + FKTABLE2 + "( " + private static final String strCreateFKTABLE2Query = "CREATE TABLE IF NOT EXISTS " + Utils.schema + "." + FKTABLE2 + + "( " + FK21 + " INT NOT NULL, " + FK22 + " INT NOT NULL, " + "FOREIGN KEY (" + FK21 + ") REFERENCES " + Utils.schema + "." + PKTABLE1 + "(" + PK1 + "), " @@ -69,24 +71,23 @@ public class TestForeignKey { private static final String strDropFKTABLE2Query = "DROP TABLE " + Utils.schema + "." + FKTABLE2; private static Connection _conn; - + @BeforeClass public static void doTestSuiteSetup() throws Exception { - try{ - _conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd); - try ( - Statement stmt = _conn.createStatement(); - ) - { - stmt.execute(strCreatePKTABLE1Query); - stmt.execute(strCreatePKTABLE2Query); - stmt.execute(strCreateFKTABLE1Query); - stmt.execute(strCreateFKTABLE2Query); - } - } + try { + _conn = Utils.getUserConnection(); + } catch (Exception e) { + fail("failed to create connection" + e.getMessage()); + } + + try (Statement stmt = _conn.createStatement();) { + stmt.execute(strCreatePKTABLE1Query); + stmt.execute(strCreatePKTABLE2Query); + stmt.execute(strCreateFKTABLE1Query); + stmt.execute(strCreateFKTABLE2Query); + } catch (Exception e) { - System.out.println(e.getMessage()); - e.printStackTrace(); + fail("failed to create table: " + e.getMessage()); } } http://git-wip-us.apache.org/repos/asf/trafodion/blob/1ade4208/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestGetIndexInfo.java ---------------------------------------------------------------------- diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestGetIndexInfo.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestGetIndexInfo.java index 1cab0b0..9789ced 100644 --- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestGetIndexInfo.java +++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestGetIndexInfo.java @@ -47,12 +47,23 @@ public class TestGetIndexInfo { @BeforeClass public static void doTestSuiteSetup() throws Exception { - try { - _conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd); + try { + _conn = Utils.getUserConnection(); + } catch (Exception e) { + fail("failed to create connection" + e.getMessage()); + } + + try (Statement stmt = _conn.createStatement() + ) { + stmt.execute(strCreateTableQuery); + } + catch (Exception e) { + fail("failed to create the table : " + e.getMessage()); + } + try ( Statement stmt = _conn.createStatement(); - stmt.execute(strCreateTableQuery); - - PreparedStatement pstmt = _conn.prepareStatement(strInsertQuery); + PreparedStatement pstmt = _conn.prepareStatement(strInsertQuery); + ) { int[][] testValues = { {1, 2}, {10, 3}, @@ -65,8 +76,7 @@ public class TestGetIndexInfo { pstmt.addBatch(); } pstmt.executeBatch(); - pstmt.close(); - + // create index stmt.execute(strCreateIndexQuery);