Commit b1f8a692 authored by Phillip Webb's avatar Phillip Webb

Merge branch '1.2.x'

parents d61c3816 04dfac1c
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/> <setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/> <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/> <setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="8"/> <setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/> <setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/> <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/> <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
......
...@@ -184,7 +184,7 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true ...@@ -184,7 +184,7 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
org.eclipse.jdt.core.formatter.indentation.size=8 org.eclipse.jdt.core.formatter.indentation.size=4
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
......
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2015 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.
...@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.metrics.writer; ...@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.metrics.writer;
import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
/** /**
* A {@link MetricWriter} that publishes the metric updates on a {@link MessageChannel}. * A {@link MetricWriter} that publishes the metric updates on a {@link MessageChannel}.
...@@ -26,13 +25,10 @@ import org.springframework.messaging.support.MessageBuilder; ...@@ -26,13 +25,10 @@ import org.springframework.messaging.support.MessageBuilder;
* carry an additional header "metricName" with the name of the metric in it. * carry an additional header "metricName" with the name of the metric in it.
* *
* @author Dave Syer * @author Dave Syer
* @see MetricWriterMessageHandler
*/ */
public class MessageChannelMetricWriter implements MetricWriter { public class MessageChannelMetricWriter implements MetricWriter {
private static final String METRIC_NAME = "metricName";
private final String DELETE = "delete";
private final MessageChannel channel; private final MessageChannel channel;
public MessageChannelMetricWriter(MessageChannel channel) { public MessageChannelMetricWriter(MessageChannel channel) {
...@@ -41,20 +37,17 @@ public class MessageChannelMetricWriter implements MetricWriter { ...@@ -41,20 +37,17 @@ public class MessageChannelMetricWriter implements MetricWriter {
@Override @Override
public void increment(Delta<?> delta) { public void increment(Delta<?> delta) {
this.channel.send(MessageBuilder.withPayload(delta) this.channel.send(MetricMessage.forIncrement(delta));
.setHeader(METRIC_NAME, delta.getName()).build());
} }
@Override @Override
public void set(Metric<?> value) { public void set(Metric<?> value) {
this.channel.send(MessageBuilder.withPayload(value) this.channel.send(MetricMessage.forSet(value));
.setHeader(METRIC_NAME, value.getName()).build());
} }
@Override @Override
public void reset(String metricName) { public void reset(String metricName) {
this.channel.send(MessageBuilder.withPayload(this.DELETE) this.channel.send(MetricMessage.forReset(metricName));
.setHeader(METRIC_NAME, metricName).build());
} }
} }
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.metrics.writer;
import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
/**
* A metric message sent via Spring Integration.
*
* @author Phillip Webb
*/
class MetricMessage {
private static final String METRIC_NAME = "metricName";
private static final String DELETE = "delete";
private final Message<?> message;
public MetricMessage(Message<?> message) {
this.message = message;
}
public boolean isReset() {
return DELETE.equals(getPayload());
}
public Object getPayload() {
return this.message.getPayload();
}
public String getMetricName() {
return this.message.getHeaders().get(METRIC_NAME, String.class);
}
public static Message<?> forIncrement(Delta<?> delta) {
return forPayload(delta.getName(), delta);
}
public static Message<?> forSet(Metric<?> value) {
return forPayload(value.getName(), value);
}
public static Message<?> forReset(String metricName) {
return forPayload(metricName, DELETE);
}
private static Message<?> forPayload(String metricName, Object payload) {
MessageBuilder<Object> builder = MessageBuilder.withPayload(payload);
builder.setHeader(METRIC_NAME, metricName);
return builder.build();
}
}
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2015 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.
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package org.springframework.boot.actuate.metrics.writer; package org.springframework.boot.actuate.metrics.writer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessageHandler;
...@@ -26,9 +28,12 @@ import org.springframework.messaging.MessagingException; ...@@ -26,9 +28,12 @@ import org.springframework.messaging.MessagingException;
* {@link MetricWriter}. * {@link MetricWriter}.
* *
* @author Dave Syer * @author Dave Syer
* @see MessageChannelMetricWriter
*/ */
public final class MetricWriterMessageHandler implements MessageHandler { public final class MetricWriterMessageHandler implements MessageHandler {
private static final Log logger = LogFactory.getLog(MetricWriterMessageHandler.class);
private final MetricWriter observer; private final MetricWriter observer;
public MetricWriterMessageHandler(MetricWriter observer) { public MetricWriterMessageHandler(MetricWriter observer) {
...@@ -37,14 +42,28 @@ public final class MetricWriterMessageHandler implements MessageHandler { ...@@ -37,14 +42,28 @@ public final class MetricWriterMessageHandler implements MessageHandler {
@Override @Override
public void handleMessage(Message<?> message) throws MessagingException { public void handleMessage(Message<?> message) throws MessagingException {
handleMessage(new MetricMessage(message));
}
private void handleMessage(MetricMessage message) {
Object payload = message.getPayload(); Object payload = message.getPayload();
if (payload instanceof Delta) { if (message.isReset()) {
this.observer.reset(message.getMetricName());
}
else if (payload instanceof Delta) {
Delta<?> value = (Delta<?>) payload; Delta<?> value = (Delta<?>) payload;
this.observer.increment(value); this.observer.increment(value);
} }
else { else if (payload instanceof Metric) {
Metric<?> value = (Metric<?>) payload; Metric<?> value = (Metric<?>) payload;
this.observer.set(value); this.observer.set(value);
} }
else {
if (logger.isWarnEnabled()) {
logger.warn("Unsupported metric payload "
+ (payload == null ? "null" : payload.getClass().getName()));
}
} }
}
} }
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2015 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.
...@@ -16,35 +16,73 @@ ...@@ -16,35 +16,73 @@
package org.springframework.boot.actuate.metrics.writer; package org.springframework.boot.actuate.metrics.writer;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageChannel;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
* Tests for {@link MessageChannelMetricWriter} and {@link MetricWriterMessageHandler}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class MessageChannelMetricWriterTests { public class MessageChannelMetricWriterTests {
private final MessageChannel channel = mock(MessageChannel.class); @Mock
private MessageChannel channel;
@Mock
private MetricWriter observer;
private MessageChannelMetricWriter writer;
private MetricWriterMessageHandler handler;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
given(this.channel.send(any(Message.class))).willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
MessageChannelMetricWriterTests.this.handler.handleMessage(invocation
.getArgumentAt(0, Message.class));
return true;
}
private final MessageChannelMetricWriter observer = new MessageChannelMetricWriter( });
this.channel); this.writer = new MessageChannelMetricWriter(this.channel);
this.handler = new MetricWriterMessageHandler(this.observer);
}
@Test @Test
public void messageSentOnAdd() { public void messageSentOnAdd() {
this.observer.increment(new Delta<Integer>("foo", 1)); this.writer.increment(new Delta<Integer>("foo", 1));
verify(this.channel).send(any(Message.class)); verify(this.channel).send(any(Message.class));
verify(this.observer).increment(any(Delta.class));
} }
@Test @Test
public void messageSentOnSet() { public void messageSentOnSet() {
this.observer.set(new Metric<Double>("foo", 1d)); this.writer.set(new Metric<Double>("foo", 1d));
verify(this.channel).send(any(Message.class));
verify(this.observer).set(any(Metric.class));
}
@Test
public void messageSentOnReset() throws Exception {
this.writer.reset("foo");
verify(this.channel).send(any(Message.class)); verify(this.channel).send(any(Message.class));
verify(this.observer).reset("foo");
} }
} }
...@@ -54,6 +54,7 @@ import static org.mockito.Mockito.mock; ...@@ -54,6 +54,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link JmsAutoConfiguration}. * Tests for {@link JmsAutoConfiguration}.
* *
* @author Greg Turnquist * @author Greg Turnquist
* @author Stephane Nicoll
*/ */
public class JmsAutoConfigurationTests { public class JmsAutoConfigurationTests {
...@@ -150,11 +151,13 @@ public class JmsAutoConfigurationTests { ...@@ -150,11 +151,13 @@ public class JmsAutoConfigurationTests {
.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class); .getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
assertEquals(DefaultJmsListenerContainerFactory.class, assertEquals(DefaultJmsListenerContainerFactory.class,
jmsListenerContainerFactory.getClass()); jmsListenerContainerFactory.getClass());
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory)
jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class)); .createListenerContainer(mock(JmsListenerEndpoint.class));
assertFalse("wrong session transacted flag with JTA transactions", listenerContainer.isSessionTransacted()); assertFalse("wrong session transacted flag with JTA transactions",
listenerContainer.isSessionTransacted());
assertSame(this.context.getBean(JtaTransactionManager.class), assertSame(this.context.getBean(JtaTransactionManager.class),
new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager")); new DirectFieldAccessor(listenerContainer)
.getPropertyValue("transactionManager"));
} }
@Test @Test
...@@ -165,10 +168,12 @@ public class JmsAutoConfigurationTests { ...@@ -165,10 +168,12 @@ public class JmsAutoConfigurationTests {
.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class); .getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
assertEquals(DefaultJmsListenerContainerFactory.class, assertEquals(DefaultJmsListenerContainerFactory.class,
jmsListenerContainerFactory.getClass()); jmsListenerContainerFactory.getClass());
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory)
jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class)); .createListenerContainer(mock(JmsListenerEndpoint.class));
assertTrue("wrong session transacted flag with no tx manager", listenerContainer.isSessionTransacted()); assertTrue("wrong session transacted flag with no tx manager",
assertNull(new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager")); listenerContainer.isSessionTransacted());
assertNull(new DirectFieldAccessor(listenerContainer)
.getPropertyValue("transactionManager"));
} }
@Test @Test
...@@ -178,10 +183,12 @@ public class JmsAutoConfigurationTests { ...@@ -178,10 +183,12 @@ public class JmsAutoConfigurationTests {
.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class); .getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
assertEquals(DefaultJmsListenerContainerFactory.class, assertEquals(DefaultJmsListenerContainerFactory.class,
jmsListenerContainerFactory.getClass()); jmsListenerContainerFactory.getClass());
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory)
jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class)); .createListenerContainer(mock(JmsListenerEndpoint.class));
assertTrue("wrong session transacted flag with no tx manager", listenerContainer.isSessionTransacted()); assertTrue("wrong session transacted flag with no tx manager",
assertNull(new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager")); listenerContainer.isSessionTransacted());
assertNull(new DirectFieldAccessor(listenerContainer)
.getPropertyValue("transactionManager"));
} }
@Test @Test
......
...@@ -54,20 +54,19 @@ import org.springframework.boot.loader.util.SystemPropertyUtils; ...@@ -54,20 +54,19 @@ import org.springframework.boot.loader.util.SystemPropertyUtils;
* Looks in various places for a properties file to extract loader settings, defaulting to * Looks in various places for a properties file to extract loader settings, defaulting to
* {@code application.properties} either on the current classpath or in the current * {@code application.properties} either on the current classpath or in the current
* working directory. The name of the properties file can be changed by setting a System * working directory. The name of the properties file can be changed by setting a System
* property {@code loader.config.name} (e.g. {@code -Dloader.config.name=foo} * property {@code loader.config.name} (e.g. {@code -Dloader.config.name=foo} will look
* will look for {@code foo.properties}. If that file doesn't exist then tries * for {@code foo.properties}. If that file doesn't exist then tries
* {@code loader.config.location} (with allowed prefixes {@code classpath:} and * {@code loader.config.location} (with allowed prefixes {@code classpath:} and
* {@code file:} or any valid URL). Once that file is located turns it into * {@code file:} or any valid URL). Once that file is located turns it into Properties and
* Properties and extracts optional values (which can also be provided overridden as * extracts optional values (which can also be provided overridden as System properties in
* System properties in case the file doesn't exist): * case the file doesn't exist):
* <ul> * <ul>
* <li>{@code loader.path}: a comma-separated list of directories to append to the * <li>{@code loader.path}: a comma-separated list of directories to append to the
* classpath (containing file resources and/or nested archives in *.jar or *.zip). * classpath (containing file resources and/or nested archives in *.jar or *.zip).
* Defaults to {@code lib} (i.e. a directory in the current working directory)</li> * Defaults to {@code lib} in your application archive</li>
* <li>{@code loader.main}: the main method to delegate execution to once the class * <li>{@code loader.main}: the main method to delegate execution to once the class loader
* loader is set up. No default, but will fall back to looking for a * is set up. No default, but will fall back to looking for a {@code Start-Class} in a
* {@code Start-Class} in a {@code MANIFEST.MF}, if there is one in * {@code MANIFEST.MF}, if there is one in <code>${loader.home}/META-INF</code>.</li>
* <code>${loader.home}/META-INF</code>.</li>
* </ul> * </ul>
* *
* @author Dave Syer * @author Dave Syer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment