use of java.sql.SQLException in project hive by apache.
the class TestCustomAuthentication method testCustomAuthentication.
@Test
public void testCustomAuthentication() throws Exception {
String url = "jdbc:hive2://localhost:10000/default";
Class.forName("org.apache.hive.jdbc.HiveDriver");
try {
DriverManager.getConnection(url, "wronguser", "pwd");
Assert.fail("Expected Exception");
} catch (SQLException e) {
Assert.assertNotNull(e.getMessage());
Assert.assertTrue(e.getMessage(), e.getMessage().contains("Peer indicated failure: Error validating the login"));
}
Connection connection = DriverManager.getConnection(url, "hiveuser", "hive");
connection.close();
System.out.println(">>> PASSED testCustomAuthentication");
}
use of java.sql.SQLException in project hive by apache.
the class cbo_rp_TestJdbcDriver2 method testErrorDiag.
@Test
public void testErrorDiag() throws SQLException {
Statement stmt = con.createStatement();
// verify syntax error
try {
stmt.executeQuery("select from " + dataTypeTableName);
fail("SQLException is expected");
} catch (SQLException e) {
assertEquals("42000", e.getSQLState());
}
// verify table not fuond error
try {
stmt.executeQuery("select * from nonTable");
fail("SQLException is expected");
} catch (SQLException e) {
assertEquals("42S02", e.getSQLState());
}
// verify invalid column error
try {
stmt.executeQuery("select zzzz from " + dataTypeTableName);
fail("SQLException is expected");
} catch (SQLException e) {
assertEquals("42000", e.getSQLState());
}
}
use of java.sql.SQLException in project hive by apache.
the class cbo_rp_TestJdbcDriver2 method testPostClose.
/**
* Validate error on closed resultset
* @throws SQLException
*/
@Test
public void testPostClose() throws SQLException {
Statement stmt = con.createStatement();
ResultSet res = stmt.executeQuery("select * from " + tableName);
assertNotNull("ResultSet is null", res);
res.close();
try {
res.getInt(1);
fail("Expected SQLException");
} catch (SQLException e) {
}
try {
res.getMetaData();
fail("Expected SQLException");
} catch (SQLException e) {
}
try {
res.setFetchSize(10);
fail("Expected SQLException");
} catch (SQLException e) {
}
}
use of java.sql.SQLException in project hive by apache.
the class cbo_rp_TestJdbcDriver2 method doTestErrorCase.
private void doTestErrorCase(String sql, String expectedMessage, String expectedSQLState, int expectedErrorCode) throws SQLException {
Statement stmt = con.createStatement();
boolean exceptionFound = false;
try {
stmt.execute(sql);
} catch (SQLException e) {
assertTrue("Adequate error messaging not found for '" + sql + "': " + e.getMessage(), e.getMessage().contains(expectedMessage));
assertEquals("Expected SQLState not found for '" + sql + "'", expectedSQLState, e.getSQLState());
assertEquals("Expected error code not found for '" + sql + "'", expectedErrorCode, e.getErrorCode());
exceptionFound = true;
}
assertNotNull("Exception should have been thrown for query: " + sql, exceptionFound);
}
use of java.sql.SQLException in project hive by apache.
the class cbo_rp_TestJdbcDriver2 method testNullResultSet.
@Test
public void testNullResultSet() throws Exception {
List<String> setupQueries = new ArrayList<String>();
String testQuery;
Statement stmt = con.createStatement();
// -select- should return a ResultSet
try {
stmt.executeQuery("select * from " + tableName);
System.out.println("select: success");
} catch (SQLException e) {
failWithExceptionMsg(e);
}
// -create- should not return a ResultSet
setupQueries.add("drop table test_t1");
testQuery = "create table test_t1 (under_col int, value string)";
checkResultSetExpected(stmt, setupQueries, testQuery, false);
setupQueries.clear();
// -create table as select- should not return a ResultSet
setupQueries.add("drop table test_t1");
testQuery = "create table test_t1 as select * from " + tableName;
checkResultSetExpected(stmt, setupQueries, testQuery, false);
setupQueries.clear();
// -insert table as select- should not return a ResultSet
setupQueries.add("drop table test_t1");
setupQueries.add("create table test_t1 (under_col int, value string)");
testQuery = "insert into table test_t1 select under_col, value from " + tableName;
checkResultSetExpected(stmt, setupQueries, testQuery, false);
setupQueries.clear();
stmt.close();
}
Aggregations