PHOENIX-4073 Disallow operations on a closed Connection
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/82ab8b91 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/82ab8b91 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/82ab8b91 Branch: refs/heads/4.x-HBase-1.1 Commit: 82ab8b9117a7ce14c41f367a48e3abecd9759bab Parents: ce4b111 Author: James Taylor <[email protected]> Authored: Mon Aug 7 11:59:31 2017 -0700 Committer: James Taylor <[email protected]> Committed: Mon Aug 7 23:05:01 2017 -0700 ---------------------------------------------------------------------- .../org/apache/phoenix/end2end/AggregateIT.java | 1 - .../apache/phoenix/end2end/AlterTableIT.java | 1 - .../phoenix/end2end/LikeExpressionIT.java | 13 +++---- .../phoenix/end2end/PointInTimeQueryIT.java | 3 +- .../org/apache/phoenix/end2end/SequenceIT.java | 1 + .../apache/phoenix/end2end/StoreNullsIT.java | 2 +- .../end2end/TenantSpecificTablesDDLIT.java | 1 - .../phoenix/end2end/UpsertBigValuesIT.java | 8 ++-- .../apache/phoenix/end2end/UpsertSelectIT.java | 2 - .../phoenix/tx/FlappingTransactionIT.java | 2 - .../phoenix/exception/SQLExceptionCode.java | 1 + .../apache/phoenix/jdbc/PhoenixConnection.java | 39 +++++++++++++++++--- .../phoenix/compile/QueryCompilerTest.java | 19 +++++++++- .../phoenix/compile/WhereOptimizerTest.java | 3 +- .../apache/phoenix/schema/RowKeySchemaTest.java | 2 +- .../phoenix/schema/RowKeyValueAccessorTest.java | 2 +- 16 files changed, 68 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateIT.java index 3098b88..67a468a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateIT.java @@ -63,7 +63,6 @@ public class AggregateIT extends ParallelStatsDisabledIT { insertRow(conn, tableName, "SOQL3", 30, 7); insertRow(conn, tableName, "SOQL4", 30, 8); conn.commit(); - conn.close(); } private static void insertRow(Connection conn, String tableName, String uri, int appcpu, int id) throws SQLException { http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java index 2cad013..fbdc82e 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java @@ -997,7 +997,6 @@ public class AlterTableIT extends ParallelStatsDisabledIT { stmtInsert1.execute(); conn1.commit(); stmtInsert1.close(); - conn1.close(); // Do the alter through a separate client. conn3.createStatement().execute("alter table " + dataTableFullName + " add field2 BIGINT"); http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java index df59485..c2198cc 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java @@ -46,16 +46,15 @@ public class LikeExpressionIT extends ParallelStatsDisabledIT { String ddl; ddl = "CREATE TABLE " + tableName + " (k VARCHAR NOT NULL PRIMARY KEY, i INTEGER)"; conn.createStatement().execute(ddl); - conn.commit(); + insertRow(conn, "123n7-app-2-", 1); + insertRow(conn, "132n7-App-2-", 2); + insertRow(conn, "213n7-app-2-", 4); + insertRow(conn, "231n7-App-2-", 8); + insertRow(conn, "312n7-app-2-", 16); + insertRow(conn, "321n7-App-2-", 32); } finally { closeStmtAndConn(stmt, conn); } - insertRow(conn, "123n7-app-2-", 1); - insertRow(conn, "132n7-App-2-", 2); - insertRow(conn, "213n7-app-2-", 4); - insertRow(conn, "231n7-App-2-", 8); - insertRow(conn, "312n7-app-2-", 16); - insertRow(conn, "321n7-App-2-", 32); } private void insertRow(Connection conn, String k, int i) throws SQLException { http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/it/java/org/apache/phoenix/end2end/PointInTimeQueryIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PointInTimeQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PointInTimeQueryIT.java index 2b7eea9..61153e1 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PointInTimeQueryIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PointInTimeQueryIT.java @@ -82,8 +82,7 @@ public class PointInTimeQueryIT extends BaseQueryIT { try { rs = conn.createStatement().executeQuery("SELECT next value for " + seqName + " FROM " + tableName + " LIMIT 1"); fail(); - } catch (SequenceNotFoundException e) { - conn.close(); + } catch (SequenceNotFoundException e) { // expected } conn.createStatement().execute("CREATE SEQUENCE " + seqName); http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java index eec567e..2a3dd54 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java @@ -1367,6 +1367,7 @@ public class SequenceIT extends BaseClientManagedTimeIT { assertFalse(rs.next()); conn.close(); + nextConnection(); // verify that calling close() does not return sequence values back to the server query = "SELECT CURRENT_VALUE FROM \"SYSTEM\".\"SEQUENCE\" WHERE SEQUENCE_SCHEMA='ALPHA' AND SEQUENCE_NAME='ZETA'"; rs = conn.prepareStatement(query).executeQuery(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java index 120e25d..49aef9b 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java @@ -315,7 +315,6 @@ public class StoreNullsIT extends ParallelStatsDisabledIT { long count2 = getRowCount(conn, indexName); assertEquals("Table should have 1 row", 1, count1); assertEquals("Index should have 1 row", 1, count2); - conn.close(); ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ ts,v FROM " + tableName); assertTrue(rs.next()); @@ -328,6 +327,7 @@ public class StoreNullsIT extends ParallelStatsDisabledIT { assertEquals(expectedTimestamp, rs.getTimestamp(1)); assertEquals(null, rs.getString(2)); assertFalse(rs.next()); + conn.close(); } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLIT.java index e4479ac..f8dfd65 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLIT.java @@ -471,7 +471,6 @@ public class TenantSpecificTablesDDLIT extends BaseTenantSpecificTablesIT { assertEquals(tenantTable2, rs.getString(PhoenixDatabaseMetaData.TABLE_NAME)); assertEquals(PARENT_TABLE_NAME, rs.getString(PhoenixDatabaseMetaData.SUPERTABLE_NAME)); assertFalse(rs.next()); - conn.close(); Set<String> sortedCatalogs = new HashSet<>(Arrays.asList(TENANT_ID, tenantId2)); rs = conn.getMetaData().getCatalogs(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBigValuesIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBigValuesIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBigValuesIT.java index 0f97a94..ceb76d0 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBigValuesIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBigValuesIT.java @@ -50,7 +50,6 @@ public class UpsertBigValuesIT extends ParallelStatsDisabledIT { stmt.execute(); } conn.commit(); - conn.close(); String select = "SELECT COUNT(*) from " + tableName ; ResultSet rs = conn.createStatement().executeQuery(select); @@ -117,6 +116,7 @@ public class UpsertBigValuesIT extends ParallelStatsDisabledIT { assertEquals(testNumbers[i], rs.getInt(1)); } assertFalse(rs.next()); + conn.close(); } @Test @@ -137,7 +137,6 @@ public class UpsertBigValuesIT extends ParallelStatsDisabledIT { stmt.execute(); } conn.commit(); - conn.close(); String select = "SELECT COUNT(*) from " + tableName ; ResultSet rs = conn.createStatement().executeQuery(select); @@ -204,6 +203,7 @@ public class UpsertBigValuesIT extends ParallelStatsDisabledIT { } assertFalse(rs.next()); */ + conn.close(); } @Test @@ -222,7 +222,6 @@ public class UpsertBigValuesIT extends ParallelStatsDisabledIT { stmt.execute(); } conn.commit(); - conn.close(); String select = "SELECT COUNT(*) from " + tableName ; ResultSet rs = conn.createStatement().executeQuery(select); @@ -285,6 +284,7 @@ public class UpsertBigValuesIT extends ParallelStatsDisabledIT { assertEquals(testNumbers[i], rs.getInt(1)); } assertFalse(rs.next()); + conn.close(); } @Test @@ -306,7 +306,6 @@ public class UpsertBigValuesIT extends ParallelStatsDisabledIT { stmt.execute(); } conn.commit(); - conn.close(); String select = "SELECT COUNT(*) from " + tableName ; ResultSet rs = conn.createStatement().executeQuery(select); @@ -373,5 +372,6 @@ public class UpsertBigValuesIT extends ParallelStatsDisabledIT { } assertFalse(rs.next()); */ + conn.close(); } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java index 55d9d7a..eb8df18 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java @@ -19,7 +19,6 @@ package org.apache.phoenix.end2end; import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB; import static org.apache.phoenix.util.PhoenixRuntime.UPSERT_BATCH_SIZE_ATTRIB; -import static org.apache.phoenix.util.TestUtil.ATABLE_NAME; import static org.apache.phoenix.util.TestUtil.A_VALUE; import static org.apache.phoenix.util.TestUtil.B_VALUE; import static org.apache.phoenix.util.TestUtil.CUSTOM_ENTITY_DATA_FULL_NAME; @@ -817,7 +816,6 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT { assertTrue(rs.next()); assertEquals(numOfRecords, rs.getLong(1)); - conn.close(); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 25)); ResultSet rs2 = conn.createStatement().executeQuery( http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/it/java/org/apache/phoenix/tx/FlappingTransactionIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/FlappingTransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/FlappingTransactionIT.java index 06eac6c..301768b 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/tx/FlappingTransactionIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/FlappingTransactionIT.java @@ -266,8 +266,6 @@ public class FlappingTransactionIT extends ParallelStatsDisabledIT { fail(); } catch (SQLException e) { assertEquals(SQLExceptionCode.TRANSACTION_CONFLICT_EXCEPTION.getErrorCode(), e.getErrorCode()); - } finally { - connWithConflict.close(); } // New connection should now see data as it has been committed http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java index d6297bb..de45000 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java @@ -362,6 +362,7 @@ public enum SQLExceptionCode { }), CANNOT_SPLIT_LOCAL_INDEX(1109,"XCL09", "Local index may not be pre-split."), CANNOT_SALT_LOCAL_INDEX(1110,"XCL10", "Local index may not be salted."), + CONNECTION_CLOSED(1111, "XCL11", "Connectioin is closed."), INDEX_FAILURE_BLOCK_WRITE(1120, "XCL20", "Writes to table blocked until index can be updated."), http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java index a57e017..ed67fe7 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java @@ -534,6 +534,12 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea } } + private void checkOpen() throws SQLException { + if (isClosed) { + throw new SQLExceptionInfo.Builder(SQLExceptionCode.CONNECTION_CLOSED).build().buildException(); + } + } + @Override public void close() throws SQLException { if (isClosed) { @@ -560,6 +566,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea CallRunner.run(new CallRunner.CallableThrowable<Void, SQLException>() { @Override public Void call() throws SQLException { + checkOpen(); mutationState.commit(); return null; } @@ -569,6 +576,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public Array createArrayOf(String typeName, Object[] elements) throws SQLException { + checkOpen(); PDataType arrayPrimitiveType = PDataType.fromSqlTypeName(typeName); return PArrayDataType.instantiatePhoenixArray(arrayPrimitiveType, elements); } @@ -599,6 +607,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public Statement createStatement() throws SQLException { + checkOpen(); PhoenixStatement statement = new PhoenixStatement(this); statements.add(statement); return statement; @@ -618,6 +627,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { + checkOpen(); if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) { throw new SQLFeatureNotSupportedException(); } @@ -627,6 +637,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { + checkOpen(); if (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) { throw new SQLFeatureNotSupportedException(); } @@ -678,7 +689,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public String getCatalog() throws SQLException { - return ""; + return tenantId == null ? "" : tenantId.getString(); } @Override @@ -699,6 +710,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public DatabaseMetaData getMetaData() throws SQLException { + checkOpen(); return new PhoenixDatabaseMetaData(this); } @@ -759,6 +771,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public PreparedStatement prepareStatement(String sql) throws SQLException { + checkOpen(); PhoenixPreparedStatement statement = new PhoenixPreparedStatement(this, sql); statements.add(statement); return statement; @@ -766,18 +779,21 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { + checkOpen(); // Ignore autoGeneratedKeys, and just execute the statement. return prepareStatement(sql); } @Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { + checkOpen(); // Ignore columnIndexes, and just execute the statement. return prepareStatement(sql); } @Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { + checkOpen(); // Ignore columnNames, and just execute the statement. return prepareStatement(sql); } @@ -785,6 +801,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { + checkOpen(); if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) { throw new SQLFeatureNotSupportedException(); } @@ -794,6 +811,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { + checkOpen(); if (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) { throw new SQLFeatureNotSupportedException(); } @@ -810,6 +828,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea CallRunner.run(new CallRunner.CallableThrowable<Void, SQLException>() { @Override public Void call() throws SQLException { + checkOpen(); mutationState.rollback(); return null; } @@ -824,6 +843,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public void setAutoCommit(boolean isAutoCommit) throws SQLException { + checkOpen(); this.isAutoCommit = isAutoCommit; } @@ -833,10 +853,17 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public void setCatalog(String catalog) throws SQLException { + checkOpen(); if (!this.getCatalog().equalsIgnoreCase(catalog)) { // allow noop calls to pass through. throw new SQLFeatureNotSupportedException(); } + // TODO: +// if (catalog == null) { +// tenantId = null; +// } else { +// tenantId = PNameFactory.newName(catalog); +// } } @Override @@ -856,6 +883,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public void setReadOnly(boolean readOnly) throws SQLException { + checkOpen(); this.readOnly=readOnly; } @@ -871,6 +899,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public void setTransactionIsolation(int level) throws SQLException { + checkOpen(); boolean transactionsEnabled = getQueryServices().getProps().getBoolean(QueryServices.TRANSACTIONS_ENABLED, QueryServicesOptions.DEFAULT_TRANSACTIONS_ENABLED); if (level == Connection.TRANSACTION_SERIALIZABLE) { @@ -905,8 +934,8 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public void setSchema(String schema) throws SQLException { + checkOpen(); this.schema = schema; - } @Override @@ -920,14 +949,12 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea @Override public void abort(Executor executor) throws SQLException { - // TODO Auto-generated method stub - + checkOpen(); } @Override public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { - // TODO Auto-generated method stub - + checkOpen(); } @Override http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java index 6c7978a..a45a035 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java @@ -1469,7 +1469,6 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest { } catch (SQLException e) { assertEquals(SQLExceptionCode.EXECUTE_UPDATE_WITH_NON_EMPTY_BATCH.getErrorCode(), e.getErrorCode()); } - conn.close(); try { PreparedStatement stmt = conn.prepareStatement("UPSERT INTO atable VALUES('000000000000000','000000000000000')"); stmt.addBatch(); @@ -4194,4 +4193,22 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest { conn.close(); } } + + @Test + public void testCannotCreateStatementOnClosedConnection() throws Exception { + Connection conn = DriverManager.getConnection(getUrl()); + conn.close(); + try { + conn.createStatement(); + fail(); + } catch (SQLException e) { + assertEquals(e.getErrorCode(), SQLExceptionCode.CONNECTION_CLOSED.getErrorCode()); + } + try { + conn.prepareStatement("SELECT * FROM SYSTEM.CATALOG"); + fail(); + } catch (SQLException e) { + assertEquals(e.getErrorCode(), SQLExceptionCode.CONNECTION_CLOSED.getErrorCode()); + } + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java index 7aec357..b37312b 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java @@ -2043,7 +2043,6 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest { ddl = "create table t (a integer not null, b integer not null, c integer constraint pk primary key (a,b))"; conn.createStatement().execute(ddl); - conn.close(); query = "select c from t where (a,b) in ( (1,2) , (1,3) ) and b = 4"; context = compileStatement(query, Collections.<Object>emptyList()); @@ -2062,12 +2061,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest { // Test with RVC occurring later in the PK ddl = "create table t1 (d varchar, e char(3) not null, a integer not null, b integer not null, c integer constraint pk primary key (d, e, a,b))"; conn.createStatement().execute(ddl); - conn.close(); query = "select c from t1 where d = 'a' and e = 'foo' and a in (1,2) and b = 3 and (a,b) in ( (1,2) , (1,3))"; context = compileStatement(query, Collections.<Object>emptyList()); assertArrayEquals(ByteUtil.concat(PVarchar.INSTANCE.toBytes("a"), QueryConstants.SEPARATOR_BYTE_ARRAY, PChar.INSTANCE.toBytes("foo"), PInteger.INSTANCE.toBytes(1), PInteger.INSTANCE.toBytes(3)), context.getScan().getStartRow()); assertArrayEquals(ByteUtil.concat(PVarchar.INSTANCE.toBytes("a"), QueryConstants.SEPARATOR_BYTE_ARRAY, PChar.INSTANCE.toBytes("foo"), PInteger.INSTANCE.toBytes(1), ByteUtil.nextKey(PInteger.INSTANCE.toBytes(3))), context.getScan().getStopRow()); + conn.close(); } @Test http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeySchemaTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeySchemaTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeySchemaTest.java index 6977103..a435ba6 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeySchemaTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeySchemaTest.java @@ -57,7 +57,6 @@ public class RowKeySchemaTest extends BaseConnectionlessQueryTest { conn.createStatement().execute("CREATE TABLE " + fullTableName + "(" + dataColumns + " CONSTRAINT pk PRIMARY KEY (" + pk + ")) " + (dataProps.isEmpty() ? "" : dataProps) ); PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); PTable table = pconn.getTable(new PTableKey(pconn.getTenantId(), fullTableName)); - conn.close(); StringBuilder buf = new StringBuilder("UPSERT INTO " + fullTableName + " VALUES("); for (int i = 0; i < values.length; i++) { buf.append("?,"); @@ -116,6 +115,7 @@ public class RowKeySchemaTest extends BaseConnectionlessQueryTest { } assertEquals(-1, i); assertNull(schema.previous(ptr, i, minOffset)); + conn.close(); } @Test http://git-wip-us.apache.org/repos/asf/phoenix/blob/82ab8b91/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeyValueAccessorTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeyValueAccessorTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeyValueAccessorTest.java index 7ab72d6..928eb70 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeyValueAccessorTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeyValueAccessorTest.java @@ -53,7 +53,6 @@ public class RowKeyValueAccessorTest extends BaseConnectionlessQueryTest { conn.createStatement().execute("CREATE TABLE " + fullTableName + "(" + dataColumns + " CONSTRAINT pk PRIMARY KEY (" + pk + ")) " + (dataProps.isEmpty() ? "" : dataProps) ); PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); PTable table = pconn.getTable(new PTableKey(pconn.getTenantId(), fullTableName)); - conn.close(); StringBuilder buf = new StringBuilder("UPSERT INTO " + fullTableName + " VALUES("); for (int i = 0; i < values.length; i++) { buf.append("?,"); @@ -79,6 +78,7 @@ public class RowKeyValueAccessorTest extends BaseConnectionlessQueryTest { dataType.coerceBytes(ptr, dataType, pkColumns.get(index).getSortOrder(), SortOrder.getDefault()); Object actualObject = dataType.toObject(ptr); assertEquals(expectedObject, actualObject); + conn.close(); } @Test
