File tree 2 files changed +19
-3
lines changed
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src
main/java/org/apache/dolphinscheduler/plugin/registry/jdbc
test/java/org/apache/dolphinscheduler/plugin/registry/jdbc
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 27
27
import org .apache .commons .lang3 .StringUtils ;
28
28
29
29
import java .sql .SQLException ;
30
- import java .sql .SQLIntegrityConstraintViolationException ;
31
30
import java .util .Collection ;
32
31
import java .util .Date ;
33
32
import java .util .List ;
@@ -142,7 +141,6 @@ public boolean existKey(String key) {
142
141
/**
143
142
* Try to acquire the target Lock, if cannot acquire, return null.
144
143
*/
145
- @ SuppressWarnings ("checkstyle:IllegalCatch" )
146
144
public JdbcRegistryLock tryToAcquireLock (String key ) {
147
145
JdbcRegistryLock jdbcRegistryLock = JdbcRegistryLock .builder ()
148
146
.lockKey (key )
@@ -154,7 +152,7 @@ public JdbcRegistryLock tryToAcquireLock(String key) {
154
152
jdbcRegistryLockMapper .insert (jdbcRegistryLock );
155
153
return jdbcRegistryLock ;
156
154
} catch (Exception e ) {
157
- if (e instanceof SQLIntegrityConstraintViolationException || e instanceof DuplicateKeyException ) {
155
+ if (e instanceof DuplicateKeyException ) {
158
156
return null ;
159
157
}
160
158
throw e ;
Original file line number Diff line number Diff line change 17
17
18
18
package org .apache .dolphinscheduler .plugin .registry .jdbc ;
19
19
20
+ import static com .google .common .truth .Truth .assertThat ;
21
+
20
22
import org .apache .dolphinscheduler .plugin .registry .RegistryTestCase ;
23
+ import org .apache .dolphinscheduler .plugin .registry .jdbc .model .JdbcRegistryLock ;
24
+
25
+ import lombok .SneakyThrows ;
21
26
27
+ import org .junit .jupiter .api .Test ;
22
28
import org .springframework .beans .factory .annotation .Autowired ;
23
29
import org .springframework .boot .autoconfigure .SpringBootApplication ;
24
30
import org .springframework .boot .test .context .SpringBootTest ;
@@ -33,6 +39,18 @@ public abstract class JdbcRegistryTestCase extends RegistryTestCase<JdbcRegistry
33
39
@ Autowired
34
40
private JdbcOperator jdbcOperator ;
35
41
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
+
36
54
@ Override
37
55
public JdbcRegistry createRegistry () {
38
56
return new JdbcRegistry (jdbcRegistryProperties , jdbcOperator );
You can’t perform that action at this time.
0 commit comments