@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { jmxObjectName = new ObjectName(objectName); jmxObjectNameWithWildcard = new ObjectName(objectNameWithWildcard); jmxService = newJmxServiceRetrying(LOCALHOST_NAME, 5); jmxHelper = new JmxHelper(jmxService.getUrl()); jmxHelper.setMinTimeBetweenReconnectAttempts(0); jmxHelper.connect(TIMEOUT_MS); }
@Test public void testSubscribeToJmxNotificationsDirectlyWithJmxHelper() throws Exception { StandardEmitterMBean mbean = jmxService.registerMBean(ImmutableList.of("one"), objectName); int sequence = 0; final List<Notification> received = Lists.newArrayList(); jmxHelper.addNotificationListener(jmxObjectName, new NotificationListener() { @Override public void handleNotification(Notification notif, Object callback) { received.add(notif); }}); final Notification notif = sendNotification(mbean, "one", sequence++, "abc"); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { assertEquals(received.size(), 1); assertNotificationsEqual(received.get(0), notif); }}); }
@Test public void testMBeanNotFoundLoggedOnlyOncePerUrl() throws Exception { ObjectName wrongObjectName = new ObjectName("DoesNotExist:type=DoesNotExist"); // Expect just one log message about: // JMX object DoesNotExist:type=DoesNotExist not found at service:jmx:rmi://localhost:1099/jndi/rmi://localhost:9001/jmxrmi" for (int i = 0; i < 10; i++) { jmxHelper.findMBean(wrongObjectName); } jmxService.shutdown(); jmxHelper.disconnect(); jmxService = newJmxServiceRetrying(LOCALHOST_NAME, 5); jmxHelper = new JmxHelper(jmxService.getUrl()); jmxHelper.connect(); // Expect just one log message about: // JMX object DoesNotExist:type=DoesNotExist not found at service:jmx:rmi://localhost:1099/jndi/rmi://localhost:9001/jmxrmi" for (int i = 0; i < 10; i++) { jmxHelper.findMBean(wrongObjectName); } }