Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] Remove unused SQLIntegrityConstraintViolationException in JdbcOperator #16200

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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;
Expand Down Expand Up @@ -142,7 +141,6 @@ public boolean existKey(String key) {
/**
* 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)
Expand All @@ -154,7 +152,7 @@ public JdbcRegistryLock tryToAcquireLock(String key) {
jdbcRegistryLockMapper.insert(jdbcRegistryLock);
return jdbcRegistryLock;
} catch (Exception e) {
if (e instanceof SQLIntegrityConstraintViolationException || e instanceof DuplicateKeyException) {
if (e instanceof DuplicateKeyException) {
return null;
}
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Loading