You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/08/17 22:33:46 UTC

(shardingsphere) branch master updated: Fixes sonar issues (#36328)

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

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 8ff263e7979 Fixes sonar issues (#36328)
8ff263e7979 is described below

commit 8ff263e7979f968baa29a7ef25cd52977036bdb0
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Aug 18 06:33:40 2025 +0800

    Fixes sonar issues (#36328)
---
 .../FirebirdInt16BinaryProtocolValueTest.java      |  3 +-
 .../RowNumberDecoratorMergedResultTest.java        | 44 +++++-----------------
 .../shardingsphere/infra/datanode/DataNode.java    |  4 --
 3 files changed, 11 insertions(+), 40 deletions(-)

diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt16BinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt16BinaryProtocolValueTest.java
index 5e077d1979c..51115eb39fa 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt16BinaryProtocolValueTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt16BinaryProtocolValueTest.java
@@ -28,7 +28,6 @@ import java.math.BigDecimal;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -64,6 +63,6 @@ class FirebirdInt16BinaryProtocolValueTest {
         when(payload.getByteBuf()).thenReturn(byteBuf);
         new FirebirdInt16BinaryProtocolValue().write(payload, BigDecimal.ONE);
         verify(byteBuf).writeZero(15);
-        verify(byteBuf).writeBytes(eq(new byte[]{1}));
+        verify(byteBuf).writeBytes(new byte[]{1});
     }
 }
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
index eb67722c0b2..4c8dc6e7de5 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
@@ -104,47 +104,23 @@ class RowNumberDecoratorMergedResultTest {
     }
     
     @Test
-    void assertNextForRowCountBoundOpenedFalse() throws SQLException {
-        SelectStatement selectStatement = new SelectStatement(databaseType);
-        selectStatement.setProjections(new ProjectionsSegment(0, 0));
-        WhereSegment whereSegment = mock(WhereSegment.class);
-        BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class);
-        when(binaryOperationExpression.getLeft()).thenReturn(new ColumnSegment(0, 0, new IdentifierValue("row_id")));
-        when(binaryOperationExpression.getRight()).thenReturn(new LiteralExpressionSegment(0, 0, 2));
-        when(binaryOperationExpression.getOperator()).thenReturn(">=");
-        when(binaryOperationExpression.getText()).thenReturn("");
-        when(whereSegment.getExpr()).thenReturn(binaryOperationExpression);
-        SubqueryTableSegment subqueryTableSegment = mock(SubqueryTableSegment.class);
-        SubquerySegment subquerySegment = mock(SubquerySegment.class);
-        SelectStatement subSelectStatement = mock(SelectStatement.class);
-        when(subSelectStatement.getDatabaseType()).thenReturn(databaseType);
-        ProjectionsSegment subProjectionsSegment = mock(ProjectionsSegment.class);
-        when(subSelectStatement.getProjections()).thenReturn(subProjectionsSegment);
-        when(subquerySegment.getSelect()).thenReturn(subSelectStatement);
-        when(subqueryTableSegment.getSubquery()).thenReturn(subquerySegment);
-        selectStatement.setFrom(subqueryTableSegment);
-        selectStatement.setWhere(whereSegment);
-        ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(databaseType);
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
-        when(database.getName()).thenReturn("foo_db");
-        SelectStatementContext selectStatementContext = new SelectStatementContext(selectStatement, null, createShardingSphereMetaData(database), "foo_db", Collections.emptyList());
-        MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
-                mock(ConnectionContext.class));
-        for (int i = 0; i < 8; i++) {
-            assertTrue(actual.next());
-        }
-        assertFalse(actual.next());
+    void assertNextForRowCountWithOpenInterval() throws SQLException {
+        assertNextForRowCountWithInterval(true);
     }
     
     @Test
-    void assertNextForRowCountBoundOpenedTrue() throws SQLException {
+    void assertNextForRowCountWithClosedInterval() throws SQLException {
+        assertNextForRowCountWithInterval(false);
+    }
+    
+    private void assertNextForRowCountWithInterval(final boolean isOpenInterval) throws SQLException {
         SelectStatement selectStatement = new SelectStatement(databaseType);
         selectStatement.setProjections(new ProjectionsSegment(0, 0));
         WhereSegment whereSegment = mock(WhereSegment.class);
         BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class);
         when(binaryOperationExpression.getLeft()).thenReturn(new ColumnSegment(0, 0, new IdentifierValue("row_id")));
         when(binaryOperationExpression.getRight()).thenReturn(new LiteralExpressionSegment(0, 0, 2));
-        when(binaryOperationExpression.getOperator()).thenReturn(">=");
+        when(binaryOperationExpression.getOperator()).thenReturn(isOpenInterval ? ">" : ">=");
         when(binaryOperationExpression.getText()).thenReturn("");
         when(whereSegment.getExpr()).thenReturn(binaryOperationExpression);
         SubqueryTableSegment subqueryTableSegment = mock(SubqueryTableSegment.class);
@@ -161,8 +137,8 @@ class RowNumberDecoratorMergedResultTest {
         ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
         when(database.getName()).thenReturn("foo_db");
         SelectStatementContext selectStatementContext = new SelectStatementContext(selectStatement, null, createShardingSphereMetaData(database), "foo_db", Collections.emptyList());
-        MergedResult actual =
-                resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database, mock(ConnectionContext.class));
+        MergedResult actual = resultMerger.merge(
+                Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database, mock(ConnectionContext.class));
         for (int i = 0; i < 8; i++) {
             assertTrue(actual.next());
         }
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java
index 021064cde52..5626c85b9f3 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java
@@ -129,10 +129,6 @@ public final class DataNode {
         return tier == segments.size();
     }
     
-    private boolean isActualDataNodesIncludedDataSourceInstance(final String actualDataNodes) {
-        return isValidDataNode(actualDataNodes, 3);
-    }
-    
     /**
      * Validates the data node format based on its structure.
      *