2323
2424import org .junit .jupiter .api .BeforeEach ;
2525import org .junit .jupiter .api .Test ;
26+ import org .junitpioneer .jupiter .RetryingTest ;
2627
2728import org .springframework .beans .factory .annotation .Autowired ;
2829import org .springframework .jdbc .datasource .DataSourceTransactionManager ;
4041
4142/**
4243 * @author Ruslan Stelmachenko
44+ * @author Artem Bilan
4345 *
4446 * @since 5.3.10
4547 */
@@ -70,17 +72,17 @@ void testNewTransactionIsStartedWhenTransactionIsAlreadyActive() {
7072 TransactionSynchronization transactionSynchronization = spy (TransactionSynchronization .class );
7173 TransactionSynchronizationManager .registerSynchronization (transactionSynchronization );
7274
73- this .client .acquire ("foo " , Duration .ofSeconds (10 )); // 1
74- this .client .renew ("foo " , Duration .ofSeconds (10 )); // 2
75- this .client .delete ("foo " ); // 3
76- this .client .isAcquired ("foo " ); // 4
75+ this .client .acquire ("test " , Duration .ofSeconds (10 )); // 1
76+ this .client .renew ("test " , Duration .ofSeconds (10 )); // 2
77+ this .client .delete ("test " ); // 3
78+ this .client .isAcquired ("test " ); // 4
7779 this .client .deleteExpired (); // 5
7880 this .client .close (); // 6
7981
8082 // Make sure a transaction is still active
8183 assertThat (TransactionSynchronizationManager .isActualTransactionActive ()).isTrue ();
8284 // And was suspended for each invocation of @Transactional methods of DefaultLockRepository,
83- // that confirms that these methods were called in a separate transaction each.
85+ // which confirms that these methods were called in a separate transaction each.
8486 verify (transactionSynchronization , times (6 )).suspend ();
8587 }
8688
@@ -92,26 +94,26 @@ void testIsAcquiredFromRepeatableReadTransaction() {
9294 assertThat (TransactionSynchronizationManager .getCurrentTransactionIsolationLevel ())
9395 .isEqualTo (Connection .TRANSACTION_REPEATABLE_READ );
9496
95- this .client .acquire ("foo " , Duration .ofSeconds (10 ));
96- assertThat (this .client .isAcquired ("foo " )).isTrue ();
97+ this .client .acquire ("test " , Duration .ofSeconds (10 ));
98+ assertThat (this .client .isAcquired ("test " )).isTrue ();
9799
98- this .client .delete ("foo " );
99- assertThat (this .client .isAcquired ("foo " )).isFalse ();
100+ this .client .delete ("test " );
101+ assertThat (this .client .isAcquired ("test " )).isFalse ();
100102 }
101103
102104 @ Test
103105 void testAcquired () {
104- client .acquire ("foo " , Duration .ofMillis (100 ));
105- assertThat (this .client .isAcquired ("foo " )).isTrue ();
106+ client .acquire ("test " , Duration .ofMillis (100 ));
107+ assertThat (this .client .isAcquired ("test " )).isTrue ();
106108 }
107109
108- @ Test
110+ @ RetryingTest ( 10 )
109111 void testAcquireSameLockTwiceAndTtlWillBeUpdated () throws InterruptedException {
110- client .acquire ("foo " , Duration .ofMillis (150 ));
111- Thread .sleep (100 );
112- client .acquire ("foo " , Duration .ofMillis (150 ));
112+ client .acquire ("test " , Duration .ofMillis (150 ));
113+ Thread .sleep (10 );
114+ client .acquire ("test " , Duration .ofMillis (150 ));
113115 Thread .sleep (60 );
114- assertThat (this .client .isAcquired ("foo " )).isTrue ();
116+ assertThat (this .client .isAcquired ("test " )).isTrue ();
115117 }
116118
117119 @ Test
@@ -121,22 +123,22 @@ void testAcquiredLockIsAcquiredByAnotherProcess() {
121123 lockRepositoryOfAnotherProcess .afterSingletonsInstantiated ();
122124 lockRepositoryOfAnotherProcess .afterPropertiesSet ();
123125
124- lockRepositoryOfAnotherProcess .acquire ("foo " , Duration .ofMillis (100 ));
125- assertThat (this .client .acquire ("foo " , Duration .ofMillis (100 ))).isFalse ();
126+ lockRepositoryOfAnotherProcess .acquire ("test " , Duration .ofMillis (100 ));
127+ assertThat (this .client .acquire ("test " , Duration .ofMillis (100 ))).isFalse ();
126128
127129 lockRepositoryOfAnotherProcess .close ();
128130 }
129131
130- @ Test
132+ @ RetryingTest ( 10 )
131133 void testAcquiredLockIsAcquiredByAnotherProcessButExpired () throws InterruptedException {
132134 DefaultLockRepository lockRepositoryOfAnotherProcess = new DefaultLockRepository (dataSource );
133135 lockRepositoryOfAnotherProcess .setTransactionManager (transactionManager );
134136 lockRepositoryOfAnotherProcess .afterSingletonsInstantiated ();
135137 lockRepositoryOfAnotherProcess .afterPropertiesSet ();
136138
137- lockRepositoryOfAnotherProcess .acquire ("foo " , Duration .ofMillis (100 ));
139+ lockRepositoryOfAnotherProcess .acquire ("test " , Duration .ofMillis (100 ));
138140 Thread .sleep (110 );
139- assertThat (this .client .acquire ("foo " , Duration .ofMillis (100 ))).isTrue ();
141+ assertThat (this .client .acquire ("test " , Duration .ofMillis (100 ))).isTrue ();
140142
141143 lockRepositoryOfAnotherProcess .close ();
142144 }
@@ -148,35 +150,35 @@ void testIsAcquiredLockIsAcquiredByAnotherProcess() {
148150 lockRepositoryOfAnotherProcess .afterSingletonsInstantiated ();
149151 lockRepositoryOfAnotherProcess .afterPropertiesSet ();
150152
151- lockRepositoryOfAnotherProcess .acquire ("foo " , Duration .ofMillis (100 ));
152- assertThat (this .client .isAcquired ("foo " )).isFalse ();
153+ lockRepositoryOfAnotherProcess .acquire ("test " , Duration .ofMillis (100 ));
154+ assertThat (this .client .isAcquired ("test " )).isFalse ();
153155
154156 lockRepositoryOfAnotherProcess .close ();
155157 }
156158
157- @ Test
159+ @ RetryingTest ( 10 )
158160 void testIsAcquiredLockIsExpired () throws InterruptedException {
159- client .acquire ("foo " , Duration .ofMillis (100 ));
161+ client .acquire ("test " , Duration .ofMillis (100 ));
160162 Thread .sleep (110 );
161- assertThat (this .client .isAcquired ("foo " )).isFalse ();
163+ assertThat (this .client .isAcquired ("test " )).isFalse ();
162164 }
163165
164- @ Test
166+ @ RetryingTest ( 10 )
165167 void testRenew () throws InterruptedException {
166- client .acquire ("foo " , Duration .ofMillis (150 ));
167- Thread .sleep (100 );
168- assertThat (client .renew ("foo " , Duration .ofMillis (150 ))).isTrue ();
168+ client .acquire ("test " , Duration .ofMillis (150 ));
169+ Thread .sleep (10 );
170+ assertThat (client .renew ("test " , Duration .ofMillis (150 ))).isTrue ();
169171 Thread .sleep (60 );
170- assertThat (this .client .isAcquired ("foo " )).isTrue ();
172+ assertThat (this .client .isAcquired ("test " )).isTrue ();
171173 }
172174
173- @ Test
175+ @ RetryingTest ( 10 )
174176 void testRenewLockIsExpiredAndLockStatusHasBeenCleanUp () throws InterruptedException {
175- client .acquire ("foo " , Duration .ofMillis (100 ));
177+ client .acquire ("test " , Duration .ofMillis (100 ));
176178 Thread .sleep (110 );
177179 client .deleteExpired ();
178180
179- assertThat (this .client .renew ("foo " , Duration .ofMillis (100 ))).isFalse ();
181+ assertThat (this .client .renew ("test " , Duration .ofMillis (100 ))).isFalse ();
180182 }
181183
182184 @ Test
@@ -186,17 +188,17 @@ void testRenewLockIsAcquiredByAnotherProcess() {
186188 lockRepositoryOfAnotherProcess .afterSingletonsInstantiated ();
187189 lockRepositoryOfAnotherProcess .afterPropertiesSet ();
188190
189- lockRepositoryOfAnotherProcess .acquire ("foo " , Duration .ofMillis (100 ));
190- assertThat (this .client .renew ("foo " , Duration .ofMillis (100 ))).isFalse ();
191+ lockRepositoryOfAnotherProcess .acquire ("test " , Duration .ofMillis (100 ));
192+ assertThat (this .client .renew ("test " , Duration .ofMillis (100 ))).isFalse ();
191193
192194 lockRepositoryOfAnotherProcess .close ();
193195 }
194196
195197 @ Test
196198 void testDelete () {
197- this .client .acquire ("foo " , Duration .ofSeconds (10 ));
198- assertThat (this .client .delete ("foo " )).isTrue ();
199- assertThat (this .client .isAcquired ("foo " )).isFalse ();
199+ this .client .acquire ("test " , Duration .ofSeconds (10 ));
200+ assertThat (this .client .delete ("test " )).isTrue ();
201+ assertThat (this .client .isAcquired ("test " )).isFalse ();
200202 }
201203
202204 @ Test
@@ -206,27 +208,28 @@ void testDeleteLockIsAcquiredByAnotherProcess() {
206208 lockRepositoryOfAnotherProcess .afterSingletonsInstantiated ();
207209 lockRepositoryOfAnotherProcess .afterPropertiesSet ();
208210
209- lockRepositoryOfAnotherProcess .acquire ("foo " , Duration .ofSeconds (10 ));
210- assertThat (this .client .delete ("foo " )).isFalse ();
211+ lockRepositoryOfAnotherProcess .acquire ("test " , Duration .ofSeconds (10 ));
212+ assertThat (this .client .delete ("test " )).isFalse ();
211213
212214 lockRepositoryOfAnotherProcess .close ();
213215 }
214216
215- @ Test
217+ @ RetryingTest ( 10 )
216218 void testDeleteAfterLockIsExpiredAndLockStatusHasBeenCleanUp () throws InterruptedException {
217- client .acquire ("foo " , Duration .ofMillis (100 ));
218- Thread .sleep (200 );
219+ client .acquire ("test " , Duration .ofMillis (10 ));
220+ Thread .sleep (50 );
219221 client .deleteExpired ();
220222
221- assertThat (this .client .delete ("foo " )).isFalse ();
223+ assertThat (this .client .delete ("test " )).isFalse ();
222224 }
223225
224- @ Test
226+ @ RetryingTest ( 10 )
225227 void testDeleteExpired () throws InterruptedException {
226- client .acquire ("foo " , Duration .ofMillis (100 ));
227- Thread .sleep (200 );
228+ client .acquire ("test " , Duration .ofMillis (10 ));
229+ Thread .sleep (50 );
228230 client .deleteExpired ();
229231
230- assertThat (this .client .renew ("foo " , Duration .ofMillis (100 ))).isFalse ();
232+ assertThat (this .client .renew ("test " , Duration .ofMillis (100 ))).isFalse ();
231233 }
234+
232235}
0 commit comments