Merge branch '2.2.x'
This commit is contained in:
@@ -31,16 +31,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
/*
|
||||
* @RunWith(SpringRunner.class)
|
||||
*
|
||||
* @SpringBootTest(classes = ConsulPropertySourceLocatorRetryTests.Config.class,
|
||||
* properties = { "spring.application.name=testConsulPropertySourceLocatorRetry",
|
||||
* "spring.cloud.consul.host=53210a7c-4809-42cb-8b30-057d2db85fcc",
|
||||
* "logging.level.org.springframework.retry=TRACE", "spring.cloud.consul.port=65530",
|
||||
* "spring.cloud.consul.retry.maxAttempts=1", "spring.cloud.consul.config.failFast=true"
|
||||
* }, webEnvironment = RANDOM_PORT)
|
||||
*/
|
||||
public class ConsulPropertySourceLocatorRetryTests {
|
||||
|
||||
@Rule
|
||||
@@ -48,7 +38,8 @@ public class ConsulPropertySourceLocatorRetryTests {
|
||||
|
||||
@Test
|
||||
public void testRetry() {
|
||||
Assert.assertThrows(TransportException.class, () -> {
|
||||
//Assert.assertThrows(TransportException.class, () -> {
|
||||
try {
|
||||
new SpringApplicationBuilder(Config.class).properties(
|
||||
"spring.application.name=testConsulPropertySourceLocatorRetry",
|
||||
"spring.cloud.consul.host=53210a7c-4809-42cb-8b30-057d2db85fcc",
|
||||
@@ -56,7 +47,12 @@ public class ConsulPropertySourceLocatorRetryTests {
|
||||
"spring.cloud.consul.port=65530",
|
||||
"spring.cloud.consul.retry.maxAttempts=1",
|
||||
"spring.cloud.consul.config.failFast=true").run();
|
||||
});
|
||||
Assert.fail("Did not throw TransportException");
|
||||
}
|
||||
catch (TransportException e) {
|
||||
// success
|
||||
}
|
||||
//});
|
||||
assertThat(output).contains("RetryContext retrieved");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -51,7 +52,7 @@ public class ConsulDiscoveryProperties {
|
||||
private List<String> tags = new ArrayList<>();
|
||||
|
||||
/** Metadata to use when registering service. */
|
||||
private Map<String, String> metadata;
|
||||
private Map<String, String> metadata = new LinkedHashMap<>();
|
||||
|
||||
/** Enable tag override for the registered service. */
|
||||
private Boolean enableTagOverride;
|
||||
|
||||
@@ -39,6 +39,11 @@ import org.springframework.util.StringUtils;
|
||||
ConfigServerProperties.class })
|
||||
public class ConsulConfigServerAutoConfiguration {
|
||||
|
||||
/**
|
||||
* The metadata key for the path for config server.
|
||||
*/
|
||||
public static final String CONFIG_PATH_KEY = "configPath";
|
||||
|
||||
@Autowired(required = false)
|
||||
private ConsulDiscoveryProperties properties;
|
||||
|
||||
@@ -52,7 +57,12 @@ public class ConsulConfigServerAutoConfiguration {
|
||||
}
|
||||
String prefix = this.server.getPrefix();
|
||||
if (StringUtils.hasText(prefix)) {
|
||||
this.properties.getTags().add("configPath=" + prefix);
|
||||
if (this.properties.isTagsAsMetadata()) {
|
||||
this.properties.getTags().add(CONFIG_PATH_KEY + "=" + prefix);
|
||||
}
|
||||
else {
|
||||
this.properties.getMetadata().put(CONFIG_PATH_KEY, prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,18 @@ public class ConsulConfigServerAutoConfigurationTests {
|
||||
assertThat(properties.getTags()).containsExactly("configPath=/config");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onWhenRequestedMetadata() throws Exception {
|
||||
setup("spring.cloud.config.server.prefix=/config",
|
||||
"spring.cloud.consul.discovery.tags-as-metadata=false");
|
||||
assertThat(
|
||||
this.context.getBeanNamesForType(ConsulDiscoveryProperties.class).length)
|
||||
.isEqualTo(1);
|
||||
ConsulDiscoveryProperties properties = this.context
|
||||
.getBean(ConsulDiscoveryProperties.class);
|
||||
assertThat(properties.getMetadata()).containsEntry("configPath", "/config");
|
||||
}
|
||||
|
||||
private void setup(String... env) {
|
||||
this.context = new SpringApplicationBuilder(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
|
||||
Reference in New Issue
Block a user