Source:
<code>public void testDroppingColumnWhileCreatingIndex() throws Exception { String schemaName = "S1"; String tableName = generateUniqueName(); String viewSchemaName = "S1"; String fullTableName = SchemaUtil.getTableName(schemaName, tableName); String indexName = "IND_" + generateUniqueName(); String viewName = "VIEW_" + generateUniqueName(); String fullViewName = SchemaUtil.getTableName(viewSchemaName, viewName); createBaseTable(schemaName, tableName, false, null, null, true); try (Connection conn = getConnection()) { conn.setAutoCommit(true); conn.createStatement().execute("CREATE VIEW " + fullViewName + " AS SELECT * FROM " + fullTableName); conn.commit(); <START> final int[] exceptionCode = new int[1]; <END> final CountDownLatch doneSignal = new CountDownLatch(2); Runnable r1 = new Runnable() { @Override public void run() { try { conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullViewName + " (v1)"); } catch (SQLException e) { exceptionCode[0] = e.getErrorCode(); throw new RuntimeException(e); } finally { doneSignal.countDown(); } } }; Runnable r2 = new Runnable() { @Override public void run() { try { conn.createStatement().execute("ALTER TABLE " + fullTableName + " DROP COLUMN v1"); } catch (SQLException e) { exceptionCode[0] = e.getErrorCode(); throw new RuntimeException(e); } finally { doneSignal.countDown(); } } }; Thread t1 = new Thread(r1); t1.start(); Thread t2 = new Thread(r2); t2.start(); t1.join(); t2.join(); doneSignal.await(60, TimeUnit.SECONDS); assertEquals(exceptionCode[0], 301); } }</code><technical_language>a strong opinion want threads mutate exceptionCode, AtomicInteger for exceptionCode array size 1, threads set values finally assert assertEquals(exceptionCode.get(), 301) if prefer :)</technical_language>

Target:
public void testDroppingColumnWhileCreatingIndex() throws Exception { String schemaName = "S1"; String tableName = generateUniqueName(); String viewSchemaName = "S1"; String fullTableName = SchemaUtil.getTableName(schemaName, tableName); String indexName = "IND_" + generateUniqueName(); String viewName = "VIEW_" + generateUniqueName(); String fullViewName = SchemaUtil.getTableName(viewSchemaName, viewName); createBaseTable(schemaName, tableName, false, null, null, true); try (Connection conn = getConnection()) { conn.setAutoCommit(true); conn.createStatement().execute("CREATE VIEW " + fullViewName + " AS SELECT * FROM " + fullTableName); conn.commit(); final AtomicInteger exceptionCode = new AtomicInteger(); final CountDownLatch doneSignal = new CountDownLatch(2); Runnable r1 = new Runnable() { @Override public void run() { try { conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullViewName + " (v1)"); } catch (SQLException e) { exceptionCode.set(e.getErrorCode()); throw new RuntimeException(e); } finally { doneSignal.countDown(); } } }; Runnable r2 = new Runnable() { @Override public void run() { try { conn.createStatement().execute("ALTER TABLE " + fullTableName + " DROP COLUMN v1"); } catch (SQLException e) { exceptionCode.set(e.getErrorCode()); throw new RuntimeException(e); } finally { doneSignal.countDown(); } } }; Thread t1 = new Thread(r1); t1.start(); Thread t2 = new Thread(r2); t2.start(); t1.join(); t2.join(); doneSignal.await(60, TimeUnit.SECONDS); assertEquals(exceptionCode.get(), 301); } }