GH-3567: JdbcLockRegistry: Retry TransactionSysEx
Fixes https://github.com/spring-projects/spring-integration/issues/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
This commit is contained in:
@@ -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.
|
||||
@@ -31,6 +31,7 @@ import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.dao.TransientDataAccessException;
|
||||
import org.springframework.integration.support.locks.ExpirableLockRegistry;
|
||||
import org.springframework.integration.util.UUIDConverter;
|
||||
import org.springframework.transaction.TransactionSystemException;
|
||||
import org.springframework.transaction.TransactionTimedOutException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -50,6 +51,7 @@ import org.springframework.util.Assert;
|
||||
* @author Gary Russell
|
||||
* @author Alexandre Strubel
|
||||
* @author Olivier Hubaut
|
||||
* @author Fran Aranda
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@@ -134,7 +136,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry {
|
||||
}
|
||||
break;
|
||||
}
|
||||
catch (TransientDataAccessException | TransactionTimedOutException e) {
|
||||
catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) {
|
||||
// try again
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
@@ -168,7 +170,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry {
|
||||
}
|
||||
break;
|
||||
}
|
||||
catch (TransientDataAccessException | TransactionTimedOutException e) {
|
||||
catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) {
|
||||
// try again
|
||||
}
|
||||
catch (InterruptedException ie) {
|
||||
@@ -212,7 +214,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry {
|
||||
}
|
||||
return acquired;
|
||||
}
|
||||
catch (TransientDataAccessException | TransactionTimedOutException e) {
|
||||
catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) {
|
||||
// try again
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -245,7 +247,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry {
|
||||
this.mutex.delete(this.path);
|
||||
return;
|
||||
}
|
||||
catch (TransientDataAccessException | TransactionTimedOutException e) {
|
||||
catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) {
|
||||
// try again
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user