Skip to content

Commit 5938ab2

Browse files
culebrasartembilan
authored andcommitted
GH-3567: JdbcLockRegistry: Retry TransactionSysEx
Fixes #3567 * Retry for TransactionSystemException in JdbcLockRegistry * Unit test added for `TransactionSystemException` * Completing author and copyright year information **Cherry-pick to `5.4.x` & `5.3.x`** # Conflicts: # spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java
1 parent de4b8e1 commit 5938ab2

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
3131
import org.springframework.dao.TransientDataAccessException;
3232
import org.springframework.integration.support.locks.ExpirableLockRegistry;
3333
import org.springframework.integration.util.UUIDConverter;
34+
import org.springframework.transaction.TransactionSystemException;
3435
import org.springframework.transaction.TransactionTimedOutException;
3536
import org.springframework.util.Assert;
3637

@@ -50,6 +51,7 @@
5051
* @author Gary Russell
5152
* @author Alexandre Strubel
5253
* @author Olivier Hubaut
54+
* @author Fran Aranda
5355
*
5456
* @since 4.3
5557
*/
@@ -134,7 +136,7 @@ public void lock() {
134136
}
135137
break;
136138
}
137-
catch (TransientDataAccessException | TransactionTimedOutException e) {
139+
catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) {
138140
// try again
139141
}
140142
catch (InterruptedException e) {
@@ -168,7 +170,7 @@ public void lockInterruptibly() throws InterruptedException {
168170
}
169171
break;
170172
}
171-
catch (TransientDataAccessException | TransactionTimedOutException e) {
173+
catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) {
172174
// try again
173175
}
174176
catch (InterruptedException ie) {
@@ -212,7 +214,7 @@ public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
212214
}
213215
return acquired;
214216
}
215-
catch (TransientDataAccessException | TransactionTimedOutException e) {
217+
catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) {
216218
// try again
217219
}
218220
catch (Exception e) {
@@ -245,7 +247,7 @@ public void unlock() {
245247
this.mutex.delete(this.path);
246248
return;
247249
}
248-
catch (TransientDataAccessException | TransactionTimedOutException e) {
250+
catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) {
249251
// try again
250252
}
251253
catch (Exception e) {

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/lock/JdbcLockRegistryDelegateTests.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 the original author or authors.
2+
* Copyright 2020-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,10 +32,12 @@
3232

3333
import org.springframework.dao.TransientDataAccessException;
3434
import org.springframework.integration.test.util.TestUtils;
35+
import org.springframework.transaction.TransactionSystemException;
3536
import org.springframework.transaction.TransactionTimedOutException;
3637

3738
/**
3839
* @author Olivier Hubaut
40+
* @author Fran Aranda
3941
*
4042
* @since 5.2.11
4143
*/
@@ -122,4 +124,22 @@ public void testTransactionTimedOutException() {
122124
assertThat(TestUtils.getPropertyValue(lock, "delegate", ReentrantLock.class).isLocked()).isFalse();
123125
}
124126

127+
@Test
128+
public void testTransactionSystemException() {
129+
final Lock lock = registry.obtain("foo");
130+
lock.tryLock();
131+
132+
final AtomicBoolean shouldThrow = new AtomicBoolean(true);
133+
doAnswer(invocation -> {
134+
if (shouldThrow.getAndSet(false)) {
135+
throw mock(TransactionSystemException.class);
136+
}
137+
return null;
138+
}).when(repository).delete(anyString());
139+
140+
lock.unlock();
141+
142+
assertThat(TestUtils.getPropertyValue(lock, "delegate", ReentrantLock.class).isLocked()).isFalse();
143+
}
144+
125145
}

0 commit comments

Comments
 (0)