@Test
public void testJmxOperationPolledForSensor() throws Exception {
final int opReturnVal = 123;
final AtomicInteger invocationCount = new AtomicInteger();
MBeanOperationInfo opInfo = new MBeanOperationInfo(opName, "my descr", new MBeanParameterInfo[0], Integer.class.getName(), MBeanOperationInfo.ACTION);
GeneralisedDynamicMBean mbean = jmxService.registerMBean(
Collections.emptyMap(),
ImmutableMap.of(opInfo, new Function<Object[], Integer>() {
@Override
public Integer apply(Object[] args) {
invocationCount.incrementAndGet(); return opReturnVal;
}}),
objectName);
feed = JmxFeed.builder()
.entity(entity)
.pollOperation(new JmxOperationPollConfig<Integer>(intAttribute)
.objectName(objectName)
.operationName(opName))
.build();
Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
@Override
public void run() {
assertTrue(invocationCount.get() > 0, "invocationCount="+invocationCount);
assertEquals(entity.getAttribute(intAttribute), (Integer)opReturnVal);
}});
}