featzhang commented on code in PR #28145:
URL: https://github.com/apache/flink/pull/28145#discussion_r3228517340


##########
flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/parser/SqlClientSyntaxHighlighterTest.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.client.cli.parser;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.api.ResultKind;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.client.cli.CliClient;
+import org.apache.flink.table.client.config.SqlClientOptions;
+import org.apache.flink.table.client.gateway.Executor;
+import org.apache.flink.table.client.gateway.StatementResult;
+import org.apache.flink.util.CloseableIterator;
+
+import org.jline.reader.Parser;
+import org.junit.jupiter.api.Test;
+
+import javax.annotation.Nullable;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.flink.table.client.cli.parser.SyntaxHighlightStyle.BuiltInStyle.DARK;
+import static 
org.apache.flink.table.client.cli.parser.SyntaxHighlightStyle.BuiltInStyle.LIGHT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link SqlClientSyntaxHighlighter}. */
+class SqlClientSyntaxHighlighterTest {
+
+    private static final String SQL = "select * from t";
+    private static final String SET_COLOR_SCHEMA =
+            "SET 'sql-client.display.color-schema' = 'light';";
+
+    @Test
+    void refreshesConfigurationAfterAcceptedStatement() {
+        TestingExecutor executor = new TestingExecutor();
+        executor.setColorSchema(DARK);
+
+        SqlClientSyntaxHighlighter highlighter = new 
SqlClientSyntaxHighlighter(executor);
+        SqlMultiLineParser parser =
+                new SqlMultiLineParser(
+                        new SqlCommandParserImpl(),
+                        executor,
+                        CliClient.ExecutionMode.INTERACTIVE_EXECUTION,
+                        highlighter::updateSessionConfig);
+
+        assertHighlightedAs(highlighter, DARK);
+        assertThat(executor.getSessionConfigCalls).isEqualTo(1);
+
+        executor.setColorSchemaAfterExecute(LIGHT);
+
+        assertHighlightedAs(highlighter, DARK);
+        assertThat(executor.getSessionConfigCalls).isEqualTo(1);
+
+        parser.parse(SET_COLOR_SCHEMA, SET_COLOR_SCHEMA.length(), 
Parser.ParseContext.ACCEPT_LINE);
+
+        assertThat(executor.executedStatement).isEqualTo(SET_COLOR_SCHEMA);
+        assertHighlightedAs(highlighter, LIGHT);
+        assertThat(executor.getSessionConfigCalls).isEqualTo(3);
+    }
+
+    @Test
+    void ignoresNullConfigurationRefreshes() {
+        TestingExecutor executor = new TestingExecutor();
+        executor.setColorSchema(DARK);
+
+        SqlClientSyntaxHighlighter highlighter = new 
SqlClientSyntaxHighlighter(executor);
+

Review Comment:
   The test verifies that `getSessionConfigCalls` doesn't increase during 
repeated highlighting, which confirms the caching fix.
   
   One edge case: what if `executor.getSessionConfig()` returns null after 
`executeStatement()`? The `updateSessionConfig(null)` call would be silently 
ignored, leaving the highlighter with stale config.
   
   Might be worth a test:
   ```java
   executor.setColorSchemaAfterExecute(null);  // simulate transient failure
   parser.parse(SET_COLOR_SCHEMA, ...);
   // Verify highlighter keeps old config instead of failing
   ```
   
   Not critical if the executor contract guarantees non-null.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to