INT-4357: LeaderInit: Add failed to lock event
JIRA: https://jira.spring.io/browse/INT-4357 Updated based on code review. Updated adocs *Polishing code style, typos * Add protection from NPE when `LockRegistryLeaderInitiator` isn't supplied with the `leaderEventPublisher` * Add `What's New` note
This commit is contained in:
committed by
Artem Bilan
parent
a7eebed252
commit
1979f91cf5
@@ -38,6 +38,7 @@ import org.springframework.integration.support.leader.LockRegistryLeaderInitiato
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @author Glenn Renfro
|
||||
*
|
||||
* @since 4.3.9
|
||||
*/
|
||||
@@ -83,7 +84,10 @@ public class RedisLockRegistryLeaderInitiatorTests extends RedisAvailableTests {
|
||||
final CountDownLatch granted2 = new CountDownLatch(1);
|
||||
CountDownLatch revoked1 = new CountDownLatch(1);
|
||||
CountDownLatch revoked2 = new CountDownLatch(1);
|
||||
initiator1.setLeaderEventPublisher(new CountingPublisher(granted1, revoked1) {
|
||||
CountDownLatch acquireLockFailed1 = new CountDownLatch(1);
|
||||
CountDownLatch acquireLockFailed2 = new CountDownLatch(1);
|
||||
|
||||
initiator1.setLeaderEventPublisher(new CountingPublisher(granted1, revoked1, acquireLockFailed1) {
|
||||
|
||||
@Override
|
||||
public void publishOnRevoked(Object source, Context context, String role) {
|
||||
@@ -99,7 +103,7 @@ public class RedisLockRegistryLeaderInitiatorTests extends RedisAvailableTests {
|
||||
|
||||
});
|
||||
|
||||
initiator2.setLeaderEventPublisher(new CountingPublisher(granted2, revoked2) {
|
||||
initiator2.setLeaderEventPublisher(new CountingPublisher(granted2, revoked2, acquireLockFailed2) {
|
||||
|
||||
@Override
|
||||
public void publishOnRevoked(Object source, Context context, String role) {
|
||||
@@ -132,7 +136,7 @@ public class RedisLockRegistryLeaderInitiatorTests extends RedisAvailableTests {
|
||||
initiator2.stop();
|
||||
|
||||
CountDownLatch revoked11 = new CountDownLatch(1);
|
||||
initiator1.setLeaderEventPublisher(new CountingPublisher(new CountDownLatch(1), revoked11));
|
||||
initiator1.setLeaderEventPublisher(new CountingPublisher(new CountDownLatch(1), revoked11, new CountDownLatch(1)));
|
||||
|
||||
initiator1.getContext().yield();
|
||||
|
||||
@@ -150,13 +154,16 @@ public class RedisLockRegistryLeaderInitiatorTests extends RedisAvailableTests {
|
||||
|
||||
private volatile LockRegistryLeaderInitiator initiator;
|
||||
|
||||
CountingPublisher(CountDownLatch granted, CountDownLatch revoked) {
|
||||
private final CountDownLatch acquireLockFailed;
|
||||
|
||||
CountingPublisher(CountDownLatch granted, CountDownLatch revoked, CountDownLatch acquireLockFailed) {
|
||||
this.granted = granted;
|
||||
this.revoked = revoked;
|
||||
this.acquireLockFailed = acquireLockFailed;
|
||||
}
|
||||
|
||||
CountingPublisher(CountDownLatch granted) {
|
||||
this(granted, new CountDownLatch(1));
|
||||
this(granted, new CountDownLatch(1), new CountDownLatch(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,6 +171,11 @@ public class RedisLockRegistryLeaderInitiatorTests extends RedisAvailableTests {
|
||||
this.revoked.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishOnFailedToAcquire(Object source, Context context, String role) {
|
||||
this.acquireLockFailed.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishOnGranted(Object source, Context context, String role) {
|
||||
this.initiator = (LockRegistryLeaderInitiator) source;
|
||||
|
||||
Reference in New Issue
Block a user