Skip to content

Commit 0dd8ebb

Browse files
committed
Remove unused SQLIntegrityConstraintViolationException in JdbcOperator
1 parent 9a823c4 commit 0dd8ebb

File tree

2 files changed

+19
-3
lines changed
  • dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src

2 files changed

+19
-3
lines changed

dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcOperator.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.commons.lang3.StringUtils;
2828

2929
import java.sql.SQLException;
30-
import java.sql.SQLIntegrityConstraintViolationException;
3130
import java.util.Collection;
3231
import java.util.Date;
3332
import java.util.List;
@@ -142,7 +141,6 @@ public boolean existKey(String key) {
142141
/**
143142
* Try to acquire the target Lock, if cannot acquire, return null.
144143
*/
145-
@SuppressWarnings("checkstyle:IllegalCatch")
146144
public JdbcRegistryLock tryToAcquireLock(String key) {
147145
JdbcRegistryLock jdbcRegistryLock = JdbcRegistryLock.builder()
148146
.lockKey(key)
@@ -154,7 +152,7 @@ public JdbcRegistryLock tryToAcquireLock(String key) {
154152
jdbcRegistryLockMapper.insert(jdbcRegistryLock);
155153
return jdbcRegistryLock;
156154
} catch (Exception e) {
157-
if (e instanceof SQLIntegrityConstraintViolationException || e instanceof DuplicateKeyException) {
155+
if (e instanceof DuplicateKeyException) {
158156
return null;
159157
}
160158
throw e;

dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/test/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistryTestCase.java

+18
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717

1818
package org.apache.dolphinscheduler.plugin.registry.jdbc;
1919

20+
import static com.google.common.truth.Truth.assertThat;
21+
2022
import org.apache.dolphinscheduler.plugin.registry.RegistryTestCase;
23+
import org.apache.dolphinscheduler.plugin.registry.jdbc.model.JdbcRegistryLock;
24+
25+
import lombok.SneakyThrows;
2126

27+
import org.junit.jupiter.api.Test;
2228
import org.springframework.beans.factory.annotation.Autowired;
2329
import org.springframework.boot.autoconfigure.SpringBootApplication;
2430
import org.springframework.boot.test.context.SpringBootTest;
@@ -33,6 +39,18 @@ public abstract class JdbcRegistryTestCase extends RegistryTestCase<JdbcRegistry
3339
@Autowired
3440
private JdbcOperator jdbcOperator;
3541

42+
@Test
43+
@SneakyThrows
44+
public void testTryToAcquireLock_lockIsAlreadyBeenAcquired() {
45+
final String lockKey = "testTryToAcquireLock_lockIsAlreadyBeenAcquired";
46+
// acquire success
47+
JdbcRegistryLock jdbcRegistryLock = jdbcOperator.tryToAcquireLock(lockKey);
48+
// acquire failed
49+
assertThat(jdbcOperator.tryToAcquireLock(lockKey)).isNull();
50+
// release
51+
jdbcOperator.releaseLock(jdbcRegistryLock.getId());
52+
}
53+
3654
@Override
3755
public JdbcRegistry createRegistry() {
3856
return new JdbcRegistry(jdbcRegistryProperties, jdbcOperator);

0 commit comments

Comments
 (0)