Source:
public void testConcurrentViewCreationWithNewColParentColAddition() throws Exception { try (Connection conn = DriverManager.getConnection(getUrl()); Statement stmt = conn.createStatement()) { String fullTableName = SchemaUtil.getTableName(SCHEMA1, generateUniqueName()); String fullViewName1 = SLOW_VIEWNAME_PREFIX + "_" + generateUniqueName(); String tableDdl = "CREATE TABLE " + fullTableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 INTEGER)" + tableDDLOptions; stmt.execute(tableDdl); latch1 = new CountDownLatch(1); latch2 = new CountDownLatch(1); ExecutorService executorService = Executors.newFixedThreadPool( 1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory() .newThread(r); t.setDaemon(true); t.setPriority(Thread.MIN_PRIORITY); return t; } }); Future<Exception> future = executorService.submit( new CreateViewRunnable(fullTableName, fullViewName1)); boolean result = latch1.await(20, TimeUnit.MINUTES); if (!result) { fail("The create view rpc look too long"); } tableDdl = "ALTER TABLE " + fullTableName + " ADD new_col INTEGER"; try { stmt.execute(tableDdl); fail("Adding a column to a base table should fail when a" + " child view is concurrently being created that" + " has that new column"); } catch (ConcurrentTableMutationException ignored) { } latch2.countDown(); Exception e = future.get(); assertNull(e); try { stmt.execute(tableDdl); fail("Adding a column to a parent that its child view already " + "contains should fail"); } catch (SQLException sqlE) { assertEquals("Expected a different SQLException", CANNOT_MUTATE_TABLE.getErrorCode(),sqlE.getErrorCode()); } } }

Target:
public void testConcurrentViewCreationWithNewColParentColAddition() throws Exception { try (Connection conn = DriverManager.getConnection(getUrl()); Statement stmt = conn.createStatement()) { String fullTableName = SchemaUtil.getTableName(SCHEMA1, generateUniqueName()); String fullViewName1 = SLOW_VIEWNAME_PREFIX + "_" + generateUniqueName(); String tableDdl = "CREATE TABLE " + fullTableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 INTEGER)" + tableDDLOptions; stmt.execute(tableDdl); latch1 = new CountDownLatch(1); latch2 = new CountDownLatch(1); ExecutorService executorService = newSingleThreadExecutor( new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory() .newThread(r); t.setDaemon(true); t.setPriority(Thread.MIN_PRIORITY); return t; } }); Future<Exception> future = executorService.submit( new CreateViewRunnable(fullTableName, fullViewName1)); boolean result = latch1.await(20, TimeUnit.MINUTES); if (!result) { fail("The create view rpc look too long"); } tableDdl = "ALTER TABLE " + fullTableName + " ADD new_col INTEGER"; try { stmt.execute(tableDdl); fail("Adding a column to a base table should fail when a" + " child view is concurrently being created that" + " has that new column"); } catch (ConcurrentTableMutationException ignored) { } latch2.countDown(); Exception e = future.get(); assertNull(e); try { stmt.execute(tableDdl); fail("Adding a column to a parent that its child view already " + "contains should fail"); } catch (SQLException sqlE) { assertEquals("Expected a different SQLException", CANNOT_MUTATE_TABLE.getErrorCode(),sqlE.getErrorCode()); } } }