This is an automated email from the ASF dual-hosted git repository.

nicholasjiang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-webui.git


The following commit(s) were added to refs/heads/main by this push:
     new 0cb137df [Bugfix] Fix condition of listClusters in ClusterMapper.xml 
(#256)
0cb137df is described below

commit 0cb137df0a881af1ec7c7d700f674278493cdeda
Author: s7monk <[email protected]>
AuthorDate: Tue May 28 17:51:16 2024 +0800

    [Bugfix] Fix condition of listClusters in ClusterMapper.xml (#256)
---
 .../src/main/resources/mapper/ClusterMapper.xml    | 50 ++++++++---------
 .../server/controller/ClusterControllerTest.java   | 63 ++++++++++++++--------
 2 files changed, 68 insertions(+), 45 deletions(-)

diff --git a/paimon-web-server/src/main/resources/mapper/ClusterMapper.xml 
b/paimon-web-server/src/main/resources/mapper/ClusterMapper.xml
index 3f4c9cae..65f5c21a 100644
--- a/paimon-web-server/src/main/resources/mapper/ClusterMapper.xml
+++ b/paimon-web-server/src/main/resources/mapper/ClusterMapper.xml
@@ -39,29 +39,31 @@ under the License.
 
     <select id="listClusters" 
parameterType="org.apache.paimon.web.server.data.model.ClusterInfo" 
resultMap="SysClusterResult">
         <include refid="selectClusterVo"/>
-        <if test="cluster.id != null and cluster.id != 0">
-            AND id = #{cluster.id}
-        </if>
-        <if test="cluster.clusterName != null and cluster.clusterName != ''">
-            AND cluser_name like concat('%', #{cluster.clusterName}, '%')
-        </if>
-        <if test="cluster.host != null and cluster.host != ''">
-            AND host = #{cluster.host}
-        </if>
-        <if test="cluster.port != null">
-            AND port = #{cluster.port}
-        </if>
-        <if test="cluster.type != null and cluster.type != ''">
-            AND `type` = #{cluster.type}
-        </if>
-        <if test="cluster.enabled != null">
-            AND enabled = #{cluster.enabled}
-        </if>
-        <if test="cluster.params.beginTime != null and 
cluster.params.beginTime != ''"><!-- Start time search -->
-            AND date_format(create_time,'%y%m%d') &gt;= 
date_format(#{cluster.params.beginTime},'%y%m%d')
-        </if>
-        <if test="cluster.params.endTime != null and cluster.params.endTime != 
''"><!-- End time search -->
-            AND date_format(create_time,'%y%m%d') &lt;= 
date_format(#{cluster.params.endTime},'%y%m%d')
-        </if>
+        <where>
+            <if test="cluster.id != null and cluster.id != 0">
+                AND id = #{cluster.id}
+            </if>
+            <if test="cluster.clusterName != null and cluster.clusterName != 
''">
+                AND cluser_name like concat('%', #{cluster.clusterName}, '%')
+            </if>
+            <if test="cluster.host != null and cluster.host != ''">
+                AND host = #{cluster.host}
+            </if>
+            <if test="cluster.port != null">
+                AND port = #{cluster.port}
+            </if>
+            <if test="cluster.type != null and cluster.type != ''">
+                AND `type` = #{cluster.type}
+            </if>
+            <if test="cluster.enabled != null">
+                AND enabled = #{cluster.enabled}
+            </if>
+            <if test="cluster.params.beginTime != null and 
cluster.params.beginTime != ''"><!-- Start time search -->
+                AND date_format(create_time,'%y%m%d') &gt;= 
date_format(#{cluster.params.beginTime},'%y%m%d')
+            </if>
+            <if test="cluster.params.endTime != null and 
cluster.params.endTime != ''"><!-- End time search -->
+                AND date_format(create_time,'%y%m%d') &lt;= 
date_format(#{cluster.params.endTime},'%y%m%d')
+            </if>
+        </where>
     </select>
 </mapper>
\ No newline at end of file
diff --git 
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/ClusterControllerTest.java
 
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/ClusterControllerTest.java
index 3a816ca2..9154294c 100644
--- 
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/ClusterControllerTest.java
+++ 
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/ClusterControllerTest.java
@@ -35,6 +35,8 @@ import 
org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
 import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
 import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
 
+import java.util.List;
+
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -100,32 +102,26 @@ public class ClusterControllerTest extends 
ControllerTestBase {
     @Test
     @Order(3)
     public void testListClusters() throws Exception {
-        String responseString =
-                mockMvc.perform(
-                                MockMvcRequestBuilders.get(clusterPath + 
"/list")
-                                        .cookie(cookie)
-                                        
.contentType(MediaType.APPLICATION_JSON_VALUE)
-                                        
.accept(MediaType.APPLICATION_JSON_VALUE))
-                        .andExpect(MockMvcResultMatchers.status().isOk())
-                        .andDo(MockMvcResultHandlers.print())
-                        .andReturn()
-                        .getResponse()
-                        .getContentAsString();
-
-        PageR<ClusterInfo> r =
-                ObjectMapperUtils.fromJSON(
-                        responseString, new 
TypeReference<PageR<ClusterInfo>>() {});
-        assertTrue(
-                r.getData() != null
-                        && ((r.getTotal() > 0 && r.getData().size() > 0)
-                                || (r.getTotal() == 0 && r.getData().size() == 
0)));
-
-        ClusterInfo clusterInfo = r.getData().get(0);
+        List<ClusterInfo> clustersWithoutConditions = listClusters("");
+        assertTrue(clustersWithoutConditions.size() > 0);
+        ClusterInfo clusterInfo = clustersWithoutConditions.get(0);
         assertEquals(clusterName, clusterInfo.getClusterName());
         assertEquals("127.0.0.1", clusterInfo.getHost());
         assertEquals(8083, clusterInfo.getPort());
         assertEquals("Flink", clusterInfo.getType());
         assertTrue(clusterInfo.getEnabled());
+
+        List<ClusterInfo> clustersWithConditionsFlink = listClusters("Flink");
+        assertTrue(clustersWithConditionsFlink.size() > 0);
+        ClusterInfo clusterInfo1 = clustersWithConditionsFlink.get(0);
+        assertEquals(clusterName, clusterInfo1.getClusterName());
+        assertEquals("127.0.0.1", clusterInfo1.getHost());
+        assertEquals(8083, clusterInfo1.getPort());
+        assertEquals("Flink", clusterInfo1.getType());
+        assertTrue(clusterInfo1.getEnabled());
+
+        List<ClusterInfo> clustersWithConditionsSpark = listClusters("Spark");
+        assertEquals(0, clustersWithConditionsSpark.size());
     }
 
     @Test
@@ -186,4 +182,29 @@ public class ClusterControllerTest extends 
ControllerTestBase {
         R<?> result = ObjectMapperUtils.fromJSON(delResponseString, R.class);
         assertEquals(200, result.getCode());
     }
+
+    private List<ClusterInfo> listClusters(String params) throws Exception {
+        String responseString =
+                mockMvc.perform(
+                                MockMvcRequestBuilders.get(clusterPath + 
"/list")
+                                        .cookie(cookie)
+                                        .param("type", params)
+                                        
.contentType(MediaType.APPLICATION_JSON_VALUE)
+                                        
.accept(MediaType.APPLICATION_JSON_VALUE))
+                        .andExpect(MockMvcResultMatchers.status().isOk())
+                        .andDo(MockMvcResultHandlers.print())
+                        .andReturn()
+                        .getResponse()
+                        .getContentAsString();
+
+        PageR<ClusterInfo> r =
+                ObjectMapperUtils.fromJSON(
+                        responseString, new 
TypeReference<PageR<ClusterInfo>>() {});
+
+        assertTrue(
+                r.getData() != null
+                        && ((r.getTotal() > 0 && r.getData().size() > 0)
+                                || (r.getTotal() == 0 && r.getData().size() == 
0)));
+        return r.getData();
+    }
 }

Reply via email to