SPR-5256
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.jmx.export.annotation;
|
||||
|
||||
import org.springframework.jmx.IJmxTestBean;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -65,7 +66,7 @@ public class AnnotationTestBean implements IJmxTestBean {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@ManagedAttribute(description = "The Nick Name Attribute")
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
@@ -97,5 +98,16 @@ public class AnnotationTestBean implements IJmxTestBean {
|
||||
public void dontExposeMe() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@ManagedMetric(description="The QueueSize metric", currencyTimeLimit = 20, persistPolicy="OnUpdate", persistPeriod=300,
|
||||
category="utilization", metricType = MetricType.COUNTER, displayName="Queue Size", unit="messages")
|
||||
public long getQueueSize() {
|
||||
return 100l;
|
||||
}
|
||||
|
||||
@ManagedMetric
|
||||
public int getCacheEntries() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ import test.interceptor.NopInterceptor;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemblerTests {
|
||||
|
||||
protected static final String QUEUE_SIZE_METRIC = "QueueSize";
|
||||
|
||||
protected static final String CACHE_ENTRIES_METRIC = "CacheEntries";
|
||||
|
||||
public void testDescription() throws Exception {
|
||||
ModelMBeanInfo info = getMBeanInfoFromAssembler();
|
||||
@@ -165,15 +169,49 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
|
||||
|
||||
assertTrue("Not included in autodetection", assembler.includeBean(proxy.getClass(), "some bean name"));
|
||||
}
|
||||
|
||||
public void testMetricDescription() throws Exception {
|
||||
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
|
||||
ModelMBeanAttributeInfo metric = inf.getAttribute(QUEUE_SIZE_METRIC);
|
||||
ModelMBeanOperationInfo operation = inf.getOperation("getQueueSize");
|
||||
assertEquals("The description for the queue size metric is incorrect",
|
||||
"The QueueSize metric", metric.getDescription());
|
||||
assertEquals("The description for the getter operation of the queue size metric is incorrect",
|
||||
"The QueueSize metric", operation.getDescription());
|
||||
}
|
||||
|
||||
public void testMetricDescriptor() throws Exception {
|
||||
ModelMBeanInfo info = getMBeanInfoFromAssembler();
|
||||
Descriptor desc = info.getAttribute(QUEUE_SIZE_METRIC).getDescriptor();
|
||||
assertEquals("Currency Time Limit should be 20", "20", desc.getFieldValue("currencyTimeLimit"));
|
||||
assertEquals("Persist Policy should be OnUpdate", "OnUpdate", desc.getFieldValue("persistPolicy"));
|
||||
assertEquals("Persist Period should be 300", "300", desc.getFieldValue("persistPeriod"));
|
||||
assertEquals("Unit should be messages", "messages",desc.getFieldValue("units"));
|
||||
assertEquals("Display Name should be Queue Size", "Queue Size",desc.getFieldValue("displayName"));
|
||||
assertEquals("Metric Type should be COUNTER", "COUNTER",desc.getFieldValue("metricType"));
|
||||
assertEquals("Metric Category should be utilization", "utilization",desc.getFieldValue("metricCategory"));
|
||||
}
|
||||
|
||||
public void testMetricDescriptorDefaults() throws Exception {
|
||||
ModelMBeanInfo info = getMBeanInfoFromAssembler();
|
||||
Descriptor desc = info.getAttribute(CACHE_ENTRIES_METRIC).getDescriptor();
|
||||
assertNull("Currency Time Limit should not be populated", desc.getFieldValue("currencyTimeLimit"));
|
||||
assertNull("Persist Policy should not be populated", desc.getFieldValue("persistPolicy"));
|
||||
assertNull("Persist Period should not be populated", desc.getFieldValue("persistPeriod"));
|
||||
assertNull("Unit should not be populated", desc.getFieldValue("units"));
|
||||
assertEquals("Display Name should be populated by default via JMX", CACHE_ENTRIES_METRIC,desc.getFieldValue("displayName"));
|
||||
assertEquals("Metric Type should be GAUGE", "GAUGE",desc.getFieldValue("metricType"));
|
||||
assertNull("Metric Category should not be populated", desc.getFieldValue("metricCategory"));
|
||||
}
|
||||
|
||||
protected abstract String getObjectName();
|
||||
|
||||
protected int getExpectedAttributeCount() {
|
||||
return 4;
|
||||
return 6;
|
||||
}
|
||||
|
||||
protected int getExpectedOperationCount() {
|
||||
return 7;
|
||||
return 9;
|
||||
}
|
||||
|
||||
protected IJmxTestBean createJmxTestBean() {
|
||||
|
||||
Reference in New Issue
Block a user