Fix JdbcLockRLeaderInitiatorTests race condition

JIRA: https://jira.spring.io/browse/INT-4247

* Fix `JdbcLockRegistryLeaderInitiatorTests` race condition to assert
the `initiator1` is elected eventually after yielding when the
`initiator2` is stopped
This commit is contained in:
Artem Bilan
2017-07-20 10:51:17 -04:00
parent 31b0f54f4b
commit a81fb6fbbd
2 changed files with 8 additions and 6 deletions

View File

@@ -136,7 +136,7 @@ subprojects { subproject ->
springSecurityVersion = '4.1.4.RELEASE'
springSocialTwitterVersion = '1.1.2.RELEASE'
springRetryVersion = '1.1.3.RELEASE'
springVersion = project.hasProperty('springVersion') ? project.springVersion : '4.3.9.RELEASE'
springVersion = project.hasProperty('springVersion') ? project.springVersion : '4.3.10.RELEASE'
springWsVersion = '2.3.0.RELEASE'
xmlUnitVersion = '1.6'
xstreamVersion = '1.4.7'

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -45,6 +45,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
/**
* @author Artem Bilan
* @author Gary Russell
*
* @since 4.3.1
*/
public class JdbcLockRegistryLeaderInitiatorTests {
@@ -155,15 +156,16 @@ public class JdbcLockRegistryLeaderInitiatorTests {
assertThat(initiator1.getContext().isLeader(), is(true));
assertThat(initiator2.getContext().isLeader(), is(false));
// Stop second initiator, so the first one will be leader even after yield
initiator2.stop();
CountDownLatch revoked11 = new CountDownLatch(1);
initiator1.setLeaderEventPublisher(new CountingPublisher(new CountDownLatch(1), revoked11));
CountDownLatch granted11 = new CountDownLatch(1);
initiator1.setLeaderEventPublisher(new CountingPublisher(granted11));
initiator1.getContext().yield();
assertThat(revoked11.await(10, TimeUnit.SECONDS), is(true));
assertThat(initiator1.getContext().isLeader(), is(false));
assertThat(granted11.await(20, TimeUnit.SECONDS), is(true));
assertThat(initiator1.getContext().isLeader(), is(true));
initiator1.stop();
}