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`**
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.
|
||||
@@ -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) {
|
||||
|
||||
@@ -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