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:
Culebras
2021-05-26 15:54:50 +02:00
committed by GitHub
parent b2e0635ce2
commit b7cc2a162d
2 changed files with 29 additions and 7 deletions

View File

@@ -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();
}
}