Make sure bootstrap sources are ordered before use.

Make call to sort() before setting on builder.sources().

fixes gh-176

(cherry picked from commit 6dc35d1)
This commit is contained in:
Spencer Gibb
2017-02-14 16:17:05 -07:00
parent 710080cd47
commit 5b8ae3a96a
5 changed files with 76 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
package org.springframework.cloud.bootstrap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.bootstrap.BootstrapOrderingSpringApplicationJsonIntegrationTests.Application;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration.firstToBeCreated;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class BootstrapSourcesOrderingTests {
@Autowired
private ConfigurableEnvironment environment;
@Test
public void sourcesAreOrderedCorrectly() {
Class<?> firstConstructedClass = firstToBeCreated.get();
assertThat(firstConstructedClass).as("bootstrap sources not ordered correctly").isEqualTo(TestHigherPriorityBootstrapConfiguration.class);
}
@EnableAutoConfiguration
@Configuration
protected static class Application {
}
}

View File

@@ -0,0 +1,17 @@
package org.springframework.cloud.bootstrap;
import org.springframework.core.annotation.Order;
import static org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration.firstToBeCreated;
/**
* @author Spencer Gibb
*/
@Order(0)
public class TestBootstrapConfiguration {
public TestBootstrapConfiguration() {
firstToBeCreated.compareAndSet(null, TestBootstrapConfiguration.class);
}
}

View File

@@ -0,0 +1,20 @@
package org.springframework.cloud.bootstrap;
import java.util.concurrent.atomic.AtomicReference;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
/**
* @author Spencer Gibb
*/
@Order(Ordered.HIGHEST_PRECEDENCE)
public class TestHigherPriorityBootstrapConfiguration {
static final AtomicReference<Class<?>> firstToBeCreated = new AtomicReference<>();
public TestHigherPriorityBootstrapConfiguration() {
firstToBeCreated.compareAndSet(null, TestHigherPriorityBootstrapConfiguration.class);
}
}