Skip to content

Commit 7e118a0

Browse files
committed
Merge pull request #16733 from Johnny Lim
* gh-16733: Polish "Remove unnecessary latches in tests" Remove unnecessary latches in tests Closes gh-16733
2 parents bd5f099 + ef11af8 commit 7e118a0

File tree

5 files changed

+2
-19
lines changed

5 files changed

+2
-19
lines changed

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/AbstractDevToolsDataSourceAutoConfigurationTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.sql.SQLException;
2121
import java.sql.Statement;
2222
import java.util.Collection;
23-
import java.util.concurrent.CountDownLatch;
2423
import java.util.concurrent.atomic.AtomicReference;
2524
import java.util.function.Supplier;
2625

@@ -95,11 +94,9 @@ protected final Statement configureDataSourceBehavior(DataSource dataSource)
9594

9695
protected ConfigurableApplicationContext getContext(
9796
Supplier<ConfigurableApplicationContext> supplier) throws Exception {
98-
CountDownLatch latch = new CountDownLatch(1);
9997
AtomicReference<ConfigurableApplicationContext> atomicReference = new AtomicReference<>();
10098
Thread thread = new Thread(() -> {
10199
ConfigurableApplicationContext context = supplier.get();
102-
latch.countDown();
103100
atomicReference.getAndSet(context);
104101
});
105102
thread.start();

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Collections;
2222
import java.util.HashMap;
2323
import java.util.Map;
24-
import java.util.concurrent.CountDownLatch;
2524
import java.util.concurrent.atomic.AtomicReference;
2625
import java.util.function.Supplier;
2726

@@ -253,11 +252,9 @@ public void devToolsSwitchesJspServletToDevelopmentMode() throws Exception {
253252

254253
private ConfigurableApplicationContext getContext(
255254
Supplier<ConfigurableApplicationContext> supplier) throws Exception {
256-
CountDownLatch latch = new CountDownLatch(1);
257255
AtomicReference<ConfigurableApplicationContext> atomicReference = new AtomicReference<>();
258256
Thread thread = new Thread(() -> {
259257
ConfigurableApplicationContext context = supplier.get();
260-
latch.countDown();
261258
atomicReference.getAndSet(context);
262259
});
263260
thread.start();

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfigurationTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.boot.devtools.autoconfigure;
1818

19-
import java.util.concurrent.CountDownLatch;
2019
import java.util.concurrent.atomic.AtomicReference;
2120
import java.util.function.Supplier;
2221

@@ -183,11 +182,9 @@ public void devToolsHealthWithCustomServerContextPathReturns200() throws Excepti
183182
private AnnotationConfigServletWebApplicationContext getContext(
184183
Supplier<AnnotationConfigServletWebApplicationContext> supplier)
185184
throws Exception {
186-
CountDownLatch latch = new CountDownLatch(1);
187185
AtomicReference<AnnotationConfigServletWebApplicationContext> atomicReference = new AtomicReference<>();
188186
Thread thread = new Thread(() -> {
189187
AnnotationConfigServletWebApplicationContext context = supplier.get();
190-
latch.countDown();
191188
atomicReference.getAndSet(context);
192189
});
193190
thread.start();

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolPropertiesIntegrationTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.net.URL;
2020
import java.util.Collections;
21-
import java.util.concurrent.CountDownLatch;
2221
import java.util.concurrent.atomic.AtomicReference;
2322
import java.util.function.Supplier;
2423

@@ -122,11 +121,9 @@ public void postProcessEnablesIncludeStackTraceProperty() throws Exception {
122121

123122
protected ConfigurableApplicationContext getContext(
124123
Supplier<ConfigurableApplicationContext> supplier) throws Exception {
125-
CountDownLatch latch = new CountDownLatch(1);
126124
AtomicReference<ConfigurableApplicationContext> atomicReference = new AtomicReference<>();
127125
Thread thread = new Thread(() -> {
128126
ConfigurableApplicationContext context = supplier.get();
129-
latch.countDown();
130127
atomicReference.getAndSet(context);
131128
});
132129
thread.start();

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolsHomePropertiesPostProcessorTests.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import java.io.IOException;
2222
import java.io.OutputStream;
2323
import java.util.Properties;
24-
import java.util.concurrent.CountDownLatch;
2524

2625
import org.junit.Before;
2726
import org.junit.Rule;
@@ -74,11 +73,7 @@ public void ignoresMissingHomeProperties() throws Exception {
7473
}
7574

7675
protected void runPostProcessor(Runnable runnable) throws Exception {
77-
CountDownLatch latch = new CountDownLatch(1);
78-
Thread thread = new Thread(() -> {
79-
runnable.run();
80-
latch.countDown();
81-
});
76+
Thread thread = new Thread(runnable);
8277
thread.start();
8378
thread.join();
8479
}

0 commit comments

Comments
 (0)