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 2024/10/19 15:13:53 UTC

(shardingsphere) branch master updated: Add test cases on PipelineContextKey (#33323)

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 aa6da27c558 Add test cases on PipelineContextKey (#33323)
aa6da27c558 is described below

commit aa6da27c5586a9a0931390d0f7589f572c401960
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Oct 19 23:13:47 2024 +0800

    Add test cases on PipelineContextKey (#33323)
    
    * Add test cases on PipelineElasticJobListener
    
    * Add test cases on PipelineContextKey
---
 .../pipeline/core/context/PipelineContextKey.java  | 16 +++----
 .../core/context/PipelineContextKeyTest.java       | 51 +++++++++++++++++-----
 2 files changed, 49 insertions(+), 18 deletions(-)

diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/context/PipelineContextKey.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/context/PipelineContextKey.java
index 958ad54d04e..176ab986e52 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/context/PipelineContextKey.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/context/PipelineContextKey.java
@@ -39,23 +39,23 @@ public final class PipelineContextKey {
     }
     
     @Override
-    public boolean equals(final Object o) {
-        if (this == o) {
+    public boolean equals(final Object obj) {
+        if (this == obj) {
             return true;
         }
-        if (null == o || getClass() != o.getClass()) {
+        if (null == obj || getClass() != obj.getClass()) {
             return false;
         }
-        final PipelineContextKey that = (PipelineContextKey) o;
+        PipelineContextKey that = (PipelineContextKey) obj;
         return instanceType == that.instanceType && Objects.equals(filterDatabaseName(this), filterDatabaseName(that));
     }
     
-    private String filterDatabaseName(final PipelineContextKey contextKey) {
-        return InstanceType.PROXY == contextKey.getInstanceType() ? "" : contextKey.getDatabaseName();
-    }
-    
     @Override
     public int hashCode() {
         return Objects.hash(instanceType, filterDatabaseName(this));
     }
+    
+    private String filterDatabaseName(final PipelineContextKey contextKey) {
+        return InstanceType.PROXY == contextKey.getInstanceType() ? "" : contextKey.getDatabaseName();
+    }
 }
diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/context/PipelineContextKeyTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/context/PipelineContextKeyTest.java
index 0964ed1f331..9590145b8eb 100644
--- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/context/PipelineContextKeyTest.java
+++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/context/PipelineContextKeyTest.java
@@ -23,22 +23,53 @@ import org.junit.jupiter.api.Test;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
 
 class PipelineContextKeyTest {
     
     @Test
-    void assertHashCodeEqualsForProxyMode() {
-        PipelineContextKey contextKey1 = new PipelineContextKey(null, InstanceType.PROXY);
-        PipelineContextKey contextKey2 = new PipelineContextKey("sharding_db", InstanceType.PROXY);
-        assertThat(contextKey1.hashCode(), is(contextKey2.hashCode()));
-        assertThat(contextKey1, is(contextKey2));
+    void assertEqualsWithSameObject() {
+        PipelineContextKey pipelineContextKey = new PipelineContextKey(InstanceType.JDBC);
+        assertThat(pipelineContextKey, is(pipelineContextKey));
     }
     
     @Test
-    void assertHashCodeEqualsForJdbcMode() {
-        PipelineContextKey contextKey1 = new PipelineContextKey("logic_db", InstanceType.JDBC);
-        PipelineContextKey contextKey2 = new PipelineContextKey("sharding_db", InstanceType.JDBC);
-        assertThat(contextKey1.hashCode(), not(contextKey2.hashCode()));
-        assertThat(contextKey1, not(contextKey2));
+    void assertEqualsWithNull() {
+        assertNotEquals(null, new PipelineContextKey(InstanceType.JDBC));
+    }
+    
+    @Test
+    void assertEqualsWithDifferentClassTypes() {
+        assertThat(new PipelineContextKey(InstanceType.JDBC), not(new Object()));
+    }
+    
+    @Test
+    void assertEqualsWithDifferentInstanceTypes() {
+        assertThat(new PipelineContextKey(InstanceType.JDBC), not(new PipelineContextKey(InstanceType.PROXY)));
+    }
+    
+    @Test
+    void assertEqualsWithProxyMode() {
+        assertThat(new PipelineContextKey(null, InstanceType.PROXY), is(new PipelineContextKey("foo_db", InstanceType.PROXY)));
+    }
+    
+    @Test
+    void assertEqualsWithJDBCMode() {
+        assertThat(new PipelineContextKey("foo_db", InstanceType.JDBC), is(new PipelineContextKey("foo_db", InstanceType.JDBC)));
+    }
+    
+    @Test
+    void assertNotEqualsWithJDBCMode() {
+        assertThat(new PipelineContextKey("foo_db", InstanceType.JDBC), not(new PipelineContextKey("bar_db", InstanceType.JDBC)));
+    }
+    
+    @Test
+    void assertHashCodeWithProxyMode() {
+        assertThat(new PipelineContextKey(InstanceType.PROXY).hashCode(), is(new PipelineContextKey("foo_db", InstanceType.PROXY).hashCode()));
+    }
+    
+    @Test
+    void assertHashCodeWithJDBCMode() {
+        assertThat(new PipelineContextKey("foo_db", InstanceType.JDBC).hashCode(), not(new PipelineContextKey("bar_db", InstanceType.JDBC).hashCode()));
     }
 }