Browse Source

Merge pull request #16733 from Johnny Lim

* gh-16733:
  Polish "Remove unnecessary latches in tests"
  Remove unnecessary latches in tests

Closes gh-16733
pull/16815/head
Andy Wilkinson 7 years ago
parent
commit
7e118a02ca
  1. 3
      spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/AbstractDevToolsDataSourceAutoConfigurationTests.java
  2. 3
      spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java
  3. 3
      spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfigurationTests.java
  4. 3
      spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolPropertiesIntegrationTests.java
  5. 9
      spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolsHomePropertiesPostProcessorTests.java

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

@ -20,7 +20,6 @@ import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -95,11 +94,9 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
protected ConfigurableApplicationContext getContext( protected ConfigurableApplicationContext getContext(
Supplier<ConfigurableApplicationContext> supplier) throws Exception { Supplier<ConfigurableApplicationContext> supplier) throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<ConfigurableApplicationContext> atomicReference = new AtomicReference<>(); AtomicReference<ConfigurableApplicationContext> atomicReference = new AtomicReference<>();
Thread thread = new Thread(() -> { Thread thread = new Thread(() -> {
ConfigurableApplicationContext context = supplier.get(); ConfigurableApplicationContext context = supplier.get();
latch.countDown();
atomicReference.getAndSet(context); atomicReference.getAndSet(context);
}); });
thread.start(); thread.start();

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

@ -21,7 +21,6 @@ import java.time.Duration;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -253,11 +252,9 @@ public class LocalDevToolsAutoConfigurationTests {
private ConfigurableApplicationContext getContext( private ConfigurableApplicationContext getContext(
Supplier<ConfigurableApplicationContext> supplier) throws Exception { Supplier<ConfigurableApplicationContext> supplier) throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<ConfigurableApplicationContext> atomicReference = new AtomicReference<>(); AtomicReference<ConfigurableApplicationContext> atomicReference = new AtomicReference<>();
Thread thread = new Thread(() -> { Thread thread = new Thread(() -> {
ConfigurableApplicationContext context = supplier.get(); ConfigurableApplicationContext context = supplier.get();
latch.countDown();
atomicReference.getAndSet(context); atomicReference.getAndSet(context);
}); });
thread.start(); thread.start();

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

@ -16,7 +16,6 @@
package org.springframework.boot.devtools.autoconfigure; package org.springframework.boot.devtools.autoconfigure;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -183,11 +182,9 @@ public class RemoteDevToolsAutoConfigurationTests {
private AnnotationConfigServletWebApplicationContext getContext( private AnnotationConfigServletWebApplicationContext getContext(
Supplier<AnnotationConfigServletWebApplicationContext> supplier) Supplier<AnnotationConfigServletWebApplicationContext> supplier)
throws Exception { throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<AnnotationConfigServletWebApplicationContext> atomicReference = new AtomicReference<>(); AtomicReference<AnnotationConfigServletWebApplicationContext> atomicReference = new AtomicReference<>();
Thread thread = new Thread(() -> { Thread thread = new Thread(() -> {
AnnotationConfigServletWebApplicationContext context = supplier.get(); AnnotationConfigServletWebApplicationContext context = supplier.get();
latch.countDown();
atomicReference.getAndSet(context); atomicReference.getAndSet(context);
}); });
thread.start(); thread.start();

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

@ -18,7 +18,6 @@ package org.springframework.boot.devtools.env;
import java.net.URL; import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -122,11 +121,9 @@ public class DevToolPropertiesIntegrationTests {
protected ConfigurableApplicationContext getContext( protected ConfigurableApplicationContext getContext(
Supplier<ConfigurableApplicationContext> supplier) throws Exception { Supplier<ConfigurableApplicationContext> supplier) throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<ConfigurableApplicationContext> atomicReference = new AtomicReference<>(); AtomicReference<ConfigurableApplicationContext> atomicReference = new AtomicReference<>();
Thread thread = new Thread(() -> { Thread thread = new Thread(() -> {
ConfigurableApplicationContext context = supplier.get(); ConfigurableApplicationContext context = supplier.get();
latch.countDown();
atomicReference.getAndSet(context); atomicReference.getAndSet(context);
}); });
thread.start(); thread.start();

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,7 +21,6 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -74,11 +73,7 @@ public class DevToolsHomePropertiesPostProcessorTests {
} }
protected void runPostProcessor(Runnable runnable) throws Exception { protected void runPostProcessor(Runnable runnable) throws Exception {
CountDownLatch latch = new CountDownLatch(1); Thread thread = new Thread(runnable);
Thread thread = new Thread(() -> {
runnable.run();
latch.countDown();
});
thread.start(); thread.start();
thread.join(); thread.join();
} }

Loading…
Cancel
Save