@Test public void testColumnMutationInParentTableWithExistingTenantTable() throws Exception { Properties props = new Properties(); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(nextTimestamp())); Connection conn = DriverManager.getConnection(getUrl(), props); try { // try adding a PK col try { conn.createStatement() .execute("alter table " + PARENT_TABLE_NAME + " add new_pk varchar primary key"); fail(); } catch (SQLException expected) { assertEquals(CANNOT_MUTATE_TABLE.getErrorCode(), expected.getErrorCode()); } // try adding a non-PK col try { conn.createStatement().execute("alter table " + PARENT_TABLE_NAME + " add new_col char(1)"); fail(); } catch (SQLException expected) { assertEquals(CANNOT_MUTATE_TABLE.getErrorCode(), expected.getErrorCode()); } // try removing a PK col try { conn.createStatement().execute("alter table " + PARENT_TABLE_NAME + " drop column id"); fail(); } catch (SQLException expected) { assertEquals(CANNOT_DROP_PK.getErrorCode(), expected.getErrorCode()); } // try removing a non-PK col try { conn.createStatement().execute("alter table " + PARENT_TABLE_NAME + " drop column user"); fail(); } catch (SQLException expected) { assertEquals(CANNOT_MUTATE_TABLE.getErrorCode(), expected.getErrorCode()); } } finally { conn.close(); } }
@Test public void testColumnMutationInParentTableWithExistingTenantTable() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); try { // try adding a PK col try { conn.createStatement() .execute("alter table " + PARENT_TABLE_NAME + " add new_pk varchar primary key"); fail(); } catch (SQLException expected) { assertEquals(CANNOT_MUTATE_TABLE.getErrorCode(), expected.getErrorCode()); } // try adding a non-PK col try { conn.createStatement().execute("alter table " + PARENT_TABLE_NAME + " add new_col char(1)"); fail(); } catch (SQLException expected) { assertEquals(CANNOT_MUTATE_TABLE.getErrorCode(), expected.getErrorCode()); } // try removing a PK col try { conn.createStatement().execute("alter table " + PARENT_TABLE_NAME + " drop column id"); fail(); } catch (SQLException expected) { assertEquals(CANNOT_DROP_PK.getErrorCode(), expected.getErrorCode()); } // try removing a non-PK col try { conn.createStatement().execute("alter table " + PARENT_TABLE_NAME + " drop column user"); fail(); } catch (SQLException expected) { assertEquals(CANNOT_MUTATE_TABLE.getErrorCode(), expected.getErrorCode()); } } finally { conn.close(); } }
@Test public void testDropParentTableWithExistingTenantTable() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().executeUpdate("drop table " + PARENT_TABLE_NAME); fail( "Should not have been allowed to drop a parent table to which tenant-specific tables still point."); } catch (SQLException expected) { assertEquals(CANNOT_MUTATE_TABLE.getErrorCode(), expected.getErrorCode()); } finally { conn.close(); } }
@Test public void testDisallowDropParentTableWithExistingTenantTable() throws Exception { Properties props = new Properties(); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(nextTimestamp())); Connection conn = DriverManager.getConnection(getUrl(), props); try { conn.createStatement().executeUpdate("drop table " + PARENT_TABLE_NAME); fail( "Should not have been allowed to drop a parent table to which tenant-specific tables still point."); } catch (SQLException expected) { assertEquals(CANNOT_MUTATE_TABLE.getErrorCode(), expected.getErrorCode()); } finally { conn.close(); } }