This is an automated email from the ASF dual-hosted git repository.
xincheng pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new f69e06408f Remove unused SQLIntegrityConstraintViolationException in
JdbcOperator (#16200)
f69e06408f is described below
commit f69e06408f3a1c808bea4823fc839e43242e2694
Author: Wenjun Ruan <[email protected]>
AuthorDate: Tue Jun 25 10:18:42 2024 +0800
Remove unused SQLIntegrityConstraintViolationException in JdbcOperator
(#16200)
Co-authored-by: xiangzihao <[email protected]>
---
.../plugin/registry/jdbc/JdbcOperator.java | 4 +---
.../plugin/registry/jdbc/JdbcRegistryTestCase.java | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git
a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcOperator.java
b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcOperator.java
index 95f58a4a20..46ba84db8a 100644
---
a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcOperator.java
+++
b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcOperator.java
@@ -27,7 +27,6 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.sql.SQLException;
-import java.sql.SQLIntegrityConstraintViolationException;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -142,7 +141,6 @@ public final class JdbcOperator {
/**
* Try to acquire the target Lock, if cannot acquire, return null.
*/
- @SuppressWarnings("checkstyle:IllegalCatch")
public JdbcRegistryLock tryToAcquireLock(String key) {
JdbcRegistryLock jdbcRegistryLock = JdbcRegistryLock.builder()
.lockKey(key)
@@ -154,7 +152,7 @@ public final class JdbcOperator {
jdbcRegistryLockMapper.insert(jdbcRegistryLock);
return jdbcRegistryLock;
} catch (Exception e) {
- if (e instanceof SQLIntegrityConstraintViolationException || e
instanceof DuplicateKeyException) {
+ if (e instanceof DuplicateKeyException) {
return null;
}
throw e;
diff --git
a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/test/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistryTestCase.java
b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/test/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistryTestCase.java
index 8dbf7a844e..c5c83b62e4 100644
---
a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/test/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistryTestCase.java
+++
b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/test/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistryTestCase.java
@@ -17,8 +17,14 @@
package org.apache.dolphinscheduler.plugin.registry.jdbc;
+import static com.google.common.truth.Truth.assertThat;
+
import org.apache.dolphinscheduler.plugin.registry.RegistryTestCase;
+import org.apache.dolphinscheduler.plugin.registry.jdbc.model.JdbcRegistryLock;
+
+import lombok.SneakyThrows;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
@@ -33,6 +39,18 @@ public abstract class JdbcRegistryTestCase extends
RegistryTestCase<JdbcRegistry
@Autowired
private JdbcOperator jdbcOperator;
+ @Test
+ @SneakyThrows
+ public void testTryToAcquireLock_lockIsAlreadyBeenAcquired() {
+ final String lockKey =
"testTryToAcquireLock_lockIsAlreadyBeenAcquired";
+ // acquire success
+ JdbcRegistryLock jdbcRegistryLock =
jdbcOperator.tryToAcquireLock(lockKey);
+ // acquire failed
+ assertThat(jdbcOperator.tryToAcquireLock(lockKey)).isNull();
+ // release
+ jdbcOperator.releaseLock(jdbcRegistryLock.getId());
+ }
+
@Override
public JdbcRegistry createRegistry() {
return new JdbcRegistry(jdbcRegistryProperties, jdbcOperator);