leonardBang commented on a change in pull request #12431:
URL: https://github.com/apache/flink/pull/12431#discussion_r433762047
##########
File path:
flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientTest.java
##########
@@ -166,6 +167,64 @@ public void write(int b) throws IOException {
}
}
+ @Test
+ public void testUseCatalog() throws Exception {
+ TestingExecutor executor = new TestingExecutorBuilder()
+ .setUseCatalogConsumer((ignored1, catalogName)
-> {
+ if (!catalogName.equals("cat")) {
+ throw new
SqlExecutionException("unexpected catalog name: " + catalogName);
+ }
+ })
+ .build();
+
+ InputStream inputStream = new ByteArrayInputStream("use catalog
cat;\n".getBytes());
+ ByteArrayOutputStream outputStream = new
ByteArrayOutputStream(256);
+ CliClient cliClient = null;
+ SessionContext sessionContext = new
SessionContext("test-session", new Environment());
+ String sessionId = executor.openSession(sessionContext);
+
+ try (Terminal terminal = new DumbTerminal(inputStream,
outputStream)) {
+ cliClient = new CliClient(terminal, sessionId,
executor, File.createTempFile("history", "tmp").toPath());
+ cliClient.open();
+ assertThat(executor.getNumUseCatalogCalls(), is(1));
+ String output = new String(outputStream.toByteArray());
+ assertFalse(output.contains("unexpected catalog name"));
+ } finally {
+ if (cliClient != null) {
+ cliClient.close();
+ }
+ }
+ }
+
+ @Test
+ public void testUseDatabase() throws Exception {
+ TestingExecutor executor = new TestingExecutorBuilder()
+ .setUseDatabaseConsumer((ignored1,
databaseName) -> {
+ if (!databaseName.equals("db")) {
+ throw new
SqlExecutionException("unexpected database name: " + databaseName);
+ }
+ })
+ .build();
+
+ InputStream inputStream = new ByteArrayInputStream("use
db;\n".getBytes());
+ ByteArrayOutputStream outputStream = new
ByteArrayOutputStream(256);
+ CliClient cliClient = null;
+ SessionContext sessionContext = new
SessionContext("test-session", new Environment());
+ String sessionId = executor.openSession(sessionContext);
Review comment:
Could we extract this code to a function for reuse purpose?
##########
File path:
flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientTest.java
##########
@@ -166,6 +167,64 @@ public void write(int b) throws IOException {
}
}
+ @Test
+ public void testUseCatalog() throws Exception {
+ TestingExecutor executor = new TestingExecutorBuilder()
+ .setUseCatalogConsumer((ignored1, catalogName)
-> {
+ if (!catalogName.equals("cat")) {
+ throw new
SqlExecutionException("unexpected catalog name: " + catalogName);
+ }
+ })
+ .build();
+
+ InputStream inputStream = new ByteArrayInputStream("use catalog
cat;\n".getBytes());
+ ByteArrayOutputStream outputStream = new
ByteArrayOutputStream(256);
+ CliClient cliClient = null;
+ SessionContext sessionContext = new
SessionContext("test-session", new Environment());
+ String sessionId = executor.openSession(sessionContext);
+
+ try (Terminal terminal = new DumbTerminal(inputStream,
outputStream)) {
Review comment:
we can use try(resources) to avoid call finally here?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]