diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java index d5aa450142..1a50141350 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import org.springframework.dao.TransientDataAccessException; import org.springframework.integration.support.locks.ExpirableLockRegistry; import org.springframework.integration.support.locks.RenewableLockRegistry; import org.springframework.integration.util.UUIDConverter; +import org.springframework.transaction.TransactionSystemException; import org.springframework.transaction.TransactionTimedOutException; import org.springframework.util.Assert; @@ -52,6 +53,7 @@ import org.springframework.util.Assert; * @author Alexandre Strubel * @author Stefan Vassilev * @author Olivier Hubaut + * @author Fran Aranda * * @since 4.3 */ @@ -149,7 +151,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry, RenewableLockReg } break; } - catch (TransientDataAccessException | TransactionTimedOutException e) { + catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) { // try again } catch (InterruptedException e) { @@ -183,7 +185,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry, RenewableLockReg } break; } - catch (TransientDataAccessException | TransactionTimedOutException e) { + catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) { // try again } catch (InterruptedException ie) { @@ -227,7 +229,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry, RenewableLockReg } return acquired; } - catch (TransientDataAccessException | TransactionTimedOutException e) { + catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) { // try again } catch (Exception e) { @@ -260,7 +262,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry, RenewableLockReg this.mutex.delete(this.path); return; } - catch (TransientDataAccessException | TransactionTimedOutException e) { + catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) { // try again } catch (Exception e) { @@ -294,7 +296,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry, RenewableLockReg } return renewed; } - catch (TransientDataAccessException | TransactionTimedOutException e) { + catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) { // try again } catch (Exception e) { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/lock/JdbcLockRegistryDelegateTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/lock/JdbcLockRegistryDelegateTests.java index 0efebb97f6..e525d19aa3 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/lock/JdbcLockRegistryDelegateTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/lock/JdbcLockRegistryDelegateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,10 +32,12 @@ import org.junit.jupiter.api.Test; import org.springframework.dao.TransientDataAccessException; import org.springframework.integration.test.util.TestUtils; +import org.springframework.transaction.TransactionSystemException; import org.springframework.transaction.TransactionTimedOutException; /** * @author Olivier Hubaut + * @author Fran Aranda * * @since 5.2.11 */ @@ -122,4 +124,22 @@ public class JdbcLockRegistryDelegateTests { assertThat(TestUtils.getPropertyValue(lock, "delegate", ReentrantLock.class).isLocked()).isFalse(); } + @Test + public void testTransactionSystemException() { + final Lock lock = registry.obtain("foo"); + lock.tryLock(); + + final AtomicBoolean shouldThrow = new AtomicBoolean(true); + doAnswer(invocation -> { + if (shouldThrow.getAndSet(false)) { + throw mock(TransactionSystemException.class); + } + return null; + }).when(repository).delete(anyString()); + + lock.unlock(); + + assertThat(TestUtils.getPropertyValue(lock, "delegate", ReentrantLock.class).isLocked()).isFalse(); + } + }