Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Aug 3, 2015
1 parent 5c1f700 commit 891dd5a
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.boot.actuate.autoconfigure;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -33,9 +34,10 @@
* @author Stephane Nicoll
* @since 1.3.0
*/
@Conditional(OnEnabledHealthIndicatorCondition.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@Conditional(OnEnabledHealthIndicatorCondition.class)
public @interface ConditionalOnEnablednHealthIndicator {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ private void addEndpointLink(ResourceSupport resource, MvcEndpoint endpoint) {
resource.add(linkTo(type).slash(fullPath).withRel(rel));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,38 @@
* {@link Condition} that checks if a health indicator is enabled.
*
* @author Stephane Nicoll
* @since 1.3.0
*/
class OnEnabledHealthIndicatorCondition extends SpringBootCondition {

private static final String ANNOTATION_CLASS = ConditionalOnEnablednHealthIndicator.class
.getName();

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata
.getAnnotationAttributes(ConditionalOnEnablednHealthIndicator.class.getName()));

.getAnnotationAttributes(ANNOTATION_CLASS));
String endpointName = annotationAttributes.getString("value");
ConditionOutcome outcome = determineHealthIndicatorOutcome(endpointName, context);
ConditionOutcome outcome = getHealthIndicatorOutcome(context, endpointName);
if (outcome != null) {
return outcome;
}
return determineDefaultIndicatorsOutcome(context);
return getDefaultIndicatorsOutcome(context);
}

private ConditionOutcome determineHealthIndicatorOutcome(String endpointName,
ConditionContext context) {
private ConditionOutcome getHealthIndicatorOutcome(ConditionContext context,
String endpointName) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), "management.health." + endpointName + ".");
if (resolver.containsProperty("enabled")) {
boolean match = resolver.getProperty("enabled", Boolean.class,
true);
return new ConditionOutcome(match, "The health indicator " + endpointName +
" is " + (match ? "enabled" : "disabled"));
boolean match = resolver.getProperty("enabled", Boolean.class, true);
return new ConditionOutcome(match, "The health indicator " + endpointName
+ " is " + (match ? "enabled" : "disabled"));
}
return null;
}

private ConditionOutcome determineDefaultIndicatorsOutcome(ConditionContext context) {
private ConditionOutcome getDefaultIndicatorsOutcome(ConditionContext context) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), "management.health.defaults.");
boolean match = Boolean.valueOf(resolver.getProperty("enabled", "true"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public class SimpleInMemoryRepository<T> {

private final ConcurrentMap<String, Object> locks = new ConcurrentReferenceHashMap<String, Object>();

public interface Callback<T> {
T modify(T current);
}

public T update(String name, Callback<T> callback) {
Object lock = this.locks.putIfAbsent(name, new Object());
if (lock == null) {
Expand Down Expand Up @@ -101,4 +97,8 @@ protected NavigableMap<String, T> getValues() {
return this.values;
}

public interface Callback<T> {
T modify(T current);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure;

import java.util.Map;

import javax.sql.DataSource;

import org.junit.After;
Expand Down Expand Up @@ -105,16 +106,15 @@ public void defaultHealthIndicatorsDisabled() {
@Test
public void defaultHealthIndicatorsDisabledWithCustomOne() {
this.context.register(CustomHealthIndicator.class,
HealthIndicatorAutoConfiguration.class,
ManagementServerProperties.class);
HealthIndicatorAutoConfiguration.class, ManagementServerProperties.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.defaults.enabled:false");
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
assertEquals(1, beans.size());
assertSame(this.context.getBean("customHealthIndicator"), beans.values().
iterator().next());
assertSame(this.context.getBean("customHealthIndicator"), beans.values()
.iterator().next());
}

@Test
Expand Down Expand Up @@ -445,6 +445,7 @@ public Health health() {
}
};
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ private void assertEndpointEnabled(String... pairs) {

@Configuration
protected static class EndpointsConfig extends Config {

@Bean
public EndpointHandlerMapping endpointHandlerMapping(
Collection<? extends MvcEndpoint> endpoints) {
return new EndpointHandlerMapping(endpoints);
}

}

@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static class Listener {
private Integer maxConcurrency;

/**
* Number of messages to be handled in a single request. It should be greater than
* Number of messages to be handled in a single request. It should be greater than
* or equal to the transaction size (if used).
*/
private Integer prefetch;
Expand All @@ -318,7 +318,7 @@ public static class Listener {
private Integer transactionSize;

public boolean isAutoStartup() {
return autoStartup;
return this.autoStartup;
}

public void setAutoStartup(boolean autoStartup) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ enum DatabaseDriver {
/**
* SQL Server
*/
SQLSERVER("com.microsoft.sqlserver.jdbc.SQLServerDriver", "com.microsoft.sqlserver.jdbc.SQLServerXADataSource");
SQLSERVER("com.microsoft.sqlserver.jdbc.SQLServerDriver",
"com.microsoft.sqlserver.jdbc.SQLServerXADataSource");

private final String driverClassName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void setJndiName(String jndiName) {
}

public Listener getListener() {
return listener;
return this.listener;
}

public static class Listener {
Expand All @@ -69,8 +69,8 @@ public static class Listener {
private boolean autoStartup = true;

/**
* Acknowledge mode of the container. By default, the listener is
* transacted with automatic acknowledgment.
* Acknowledge mode of the container. By default, the listener is transacted with
* automatic acknowledgment.
*/
private AcknowledgeMode acknowledgeMode;

Expand All @@ -85,15 +85,15 @@ public static class Listener {
private Integer maxConcurrency;

public boolean isAutoStartup() {
return autoStartup;
return this.autoStartup;
}

public void setAutoStartup(boolean autoStartup) {
this.autoStartup = autoStartup;
}

public AcknowledgeMode getAcknowledgeMode() {
return acknowledgeMode;
return this.acknowledgeMode;
}

public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) {
Expand All @@ -120,16 +120,17 @@ public String formatConcurrency() {
if (this.concurrency == null) {
return (this.maxConcurrency != null ? "1-" + this.maxConcurrency : null);
}
return (this.maxConcurrency != null ? this.concurrency + "-" +
this.maxConcurrency : String.valueOf(this.concurrency));
return (this.maxConcurrency != null ? this.concurrency + "-"
+ this.maxConcurrency : String.valueOf(this.concurrency));
}
}

/**
* Translate the acknowledge modes defined on the {@link javax.jms.Session}.
*
* <p>{@link javax.jms.Session#SESSION_TRANSACTED} is not defined as we take
* care of this already via a call to {@code setSessionTransacted}.
* <p>
* {@link javax.jms.Session#SESSION_TRANSACTED} is not defined as we take care of this
* already via a call to {@code setSessionTransacted}.
*/
public enum AcknowledgeMode {

Expand All @@ -140,8 +141,8 @@ public enum AcknowledgeMode {
AUTO(1),

/**
* Messages are acknowledged once the message listener implementation has
* called {@link javax.jms.Message#acknowledge()}. This mode gives the application
* Messages are acknowledged once the message listener implementation has called
* {@link javax.jms.Message#acknowledge()}. This mode gives the application
* (rather than the JMS provider) complete control over message acknowledgement.
*/
CLIENT(2),
Expand All @@ -160,7 +161,7 @@ public enum AcknowledgeMode {
}

public int getMode() {
return mode;
return this.mode;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public String getKeyUri() {
}
if (ResourceServerProperties.this.tokenInfoUri != null
&& ResourceServerProperties.this.tokenInfoUri
.endsWith("/check_token")) {
.endsWith("/check_token")) {
return ResourceServerProperties.this.userInfoUri.replace("/check_token",
"/token_key");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public class ThymeleafProperties {
private boolean cache = true;

/**
* Order of the template resolver in the chain. By default, the template resolver
* is first in the chain. Order start at 1 and should only be set if you have
* defined additional "TemplateResolver" beans.
* Order of the template resolver in the chain. By default, the template resolver is
* first in the chain. Order start at 1 and should only be set if you have defined
* additional "TemplateResolver" beans.
*/
private Integer templateResolverOrder;

Expand Down Expand Up @@ -160,7 +160,7 @@ public void setCache(boolean cache) {
}

public Integer getTemplateResolverOrder() {
return templateResolverOrder;
return this.templateResolverOrder;
}

public void setTemplateResolverOrder(Integer templateResolverOrder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
Expand Down Expand Up @@ -189,8 +188,7 @@ public void testRabbitListenerContainerFactoryBackOff() {

@Test
public void testRabbitListenerContainerFactoryWithCustomSettings() {
load(TestConfiguration.class,
"spring.rabbitmq.listener.autoStartup:false",
load(TestConfiguration.class, "spring.rabbitmq.listener.autoStartup:false",
"spring.rabbitmq.listener.acknowledgeMode:manual",
"spring.rabbitmq.listener.concurrency:5",
"spring.rabbitmq.listener.maxConcurrency:10",
Expand All @@ -201,8 +199,7 @@ public void testRabbitListenerContainerFactoryWithCustomSettings() {
SimpleRabbitListenerContainerFactory.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitListenerContainerFactory);
assertEquals(false, dfa.getPropertyValue("autoStartup"));
assertEquals(AcknowledgeMode.MANUAL,
dfa.getPropertyValue("acknowledgeMode"));
assertEquals(AcknowledgeMode.MANUAL, dfa.getPropertyValue("acknowledgeMode"));
assertEquals(5, dfa.getPropertyValue("concurrentConsumers"));
assertEquals(10, dfa.getPropertyValue("maxConcurrentConsumers"));
assertEquals(40, dfa.getPropertyValue("prefetchCount"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
*/
public class JacksonAutoConfigurationTests {

AnnotationConfigApplicationContext context;
private AnnotationConfigApplicationContext context;

@Before
public void setUp() {
Expand Down Expand Up @@ -411,8 +411,8 @@ public void customLocale() throws JsonProcessingException {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.date-format:zzzz");
this.context.refresh();
ObjectMapper objectMapper = this.context
.getBean(Jackson2ObjectMapperBuilder.class).build();
ObjectMapper objectMapper = this.context.getBean(
Jackson2ObjectMapperBuilder.class).build();

DateTime dateTime = new DateTime(1436966242231L, DateTimeZone.UTC);
assertEquals("\"Koordinierte Universalzeit\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,19 @@ public void testJmsListenerContainerFactoryBackOff() {

@Test
public void testJmsListenerContainerFactoryWithCustomSettings() {
load(EnableJmsConfiguration.class,
"spring.jms.listener.autoStartup=false",
load(EnableJmsConfiguration.class, "spring.jms.listener.autoStartup=false",
"spring.jms.listener.acknowledgeMode=client",
"spring.jms.listener.concurrency=2",
"spring.jms.listener.maxConcurrency=10");
JmsListenerContainerFactory<?> jmsListenerContainerFactory = this.context
.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
assertEquals(DefaultJmsListenerContainerFactory.class,
jmsListenerContainerFactory.getClass());
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory)
jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class));
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory)
.createListenerContainer(mock(JmsListenerEndpoint.class));
assertEquals(false, listenerContainer.isAutoStartup());
assertEquals(Session.CLIENT_ACKNOWLEDGE, listenerContainer.getSessionAcknowledgeMode());
assertEquals(Session.CLIENT_ACKNOWLEDGE,
listenerContainer.getSessionAcknowledgeMode());
assertEquals(2, listenerContainer.getConcurrentConsumers());
assertEquals(10, listenerContainer.getMaxConcurrentConsumers());
}
Expand Down
Loading

0 comments on commit 891dd5a

Please sign in to comment.