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 bd46a3cf9fd Add more test cases on ResourceDataSource (#33092)
bd46a3cf9fd is described below

commit bd46a3cf9fdc2c395a3ead3c71a57d3ea49e4555
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Oct 2 00:06:47 2024 +0800

    Add more test cases on ResourceDataSource (#33092)
---
 .../transaction/core/ResourceDataSourceTest.java   | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git 
a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
 
b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
index c23fc945c65..8964b0f485d 100644
--- 
a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
+++ 
b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.transaction.core;
 
 import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
+import 
org.apache.shardingsphere.transaction.exception.ResourceNameLengthExceededException;
 import org.junit.jupiter.api.Test;
 
 import java.util.regex.Pattern;
@@ -25,32 +26,27 @@ import java.util.regex.Pattern;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.matchesPattern;
 import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class ResourceDataSourceTest {
     
-    private static final String DATABASE_NAME = "sharding_db";
-    
-    private static final String DATA_SOURCE_NAME = "fooDataSource";
-    
     @Test
     void assertNewInstance() {
-        String originalName = DATABASE_NAME + "." + DATA_SOURCE_NAME;
+        String originalName = "foo_db.foo_ds";
         ResourceDataSource actual = new ResourceDataSource(originalName, new 
MockedDataSource());
         assertThat(actual.getOriginalName(), is(originalName));
         assertThat(actual.getDataSource(), instanceOf(MockedDataSource.class));
-        assertTrue(isStartWithNumber(actual.getUniqueResourceName()));
-        assertTrue(actual.getUniqueResourceName().endsWith(DATA_SOURCE_NAME));
+        assertThat(actual.getUniqueResourceName(), 
matchesPattern(Pattern.compile("\\d+-foo_ds")));
     }
     
-    private boolean isStartWithNumber(final String resourceId) {
-        Pattern pattern = Pattern.compile("[0-9]+-.*");
-        return pattern.matcher(resourceId).matches();
+    @Test
+    void assertNewInstanceFailureWithInvalidFormat() {
+        assertThrows(IllegalStateException.class, () -> new 
ResourceDataSource("invalid", new MockedDataSource()));
     }
     
     @Test
-    void assertDataSourceNameOnlyFailure() {
-        assertThrows(IllegalStateException.class, () -> new 
ResourceDataSource(DATA_SOURCE_NAME, new MockedDataSource()));
+    void assertNewInstanceFailureWithTooLongUniqueResourceName() {
+        assertThrows(ResourceNameLengthExceededException.class, () -> new 
ResourceDataSource("foo_db.foo_ds_00000000000000000000000000000000000000000000000000",
 new MockedDataSource()));
     }
 }

Reply via email to