|
39 | 39 | import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; |
40 | 40 | import org.testcontainers.lifecycle.Startables; |
41 | 41 |
|
| 42 | +import java.sql.Connection; |
42 | 43 | import java.sql.ResultSet; |
43 | 44 | import java.sql.SQLException; |
44 | 45 | import java.time.Duration; |
@@ -227,6 +228,33 @@ public List<String> fetchTableContent(TableId tableId, int columnCount) throws S |
227 | 228 | return results; |
228 | 229 | } |
229 | 230 |
|
| 231 | + // Starrocks alter column is asynchronous and does not support Light mode. |
| 232 | + public void waitAlterDone(TableId tableId, long timeout) |
| 233 | + throws SQLException, InterruptedException { |
| 234 | + Connection conn = STARROCKS_CONTAINER.createConnection(""); |
| 235 | + conn.createStatement().execute(String.format("USE `%s`", tableId.getSchemaName())); |
| 236 | + long t0 = System.currentTimeMillis(); |
| 237 | + while (System.currentTimeMillis() - t0 < timeout) { |
| 238 | + ResultSet rs = |
| 239 | + conn.createStatement() |
| 240 | + .executeQuery( |
| 241 | + String.format( |
| 242 | + "SHOW ALTER TABLE COLUMN WHERE TableName = '%s' ORDER BY CreateTime DESC LIMIT 1", |
| 243 | + tableId.getTableName())); |
| 244 | + if (rs.next()) { |
| 245 | + String state = rs.getString("State"); |
| 246 | + if ("FINISHED".equals(state)) { |
| 247 | + return; |
| 248 | + } |
| 249 | + if ("CANCELLED".equals(state)) { |
| 250 | + throw new RuntimeException("Alter failed: " + rs.getString("Msg")); |
| 251 | + } |
| 252 | + } |
| 253 | + Thread.sleep(1000L); |
| 254 | + } |
| 255 | + throw new RuntimeException("Alter job timeout"); |
| 256 | + } |
| 257 | + |
230 | 258 | public static <T> void assertEqualsInAnyOrder(List<T> expected, List<T> actual) { |
231 | 259 | Assertions.assertThat(actual).containsExactlyInAnyOrderElementsOf(expected); |
232 | 260 | } |
|
0 commit comments