/** * {@inheritDoc} */ @Override @MethodLog public Collection<JmxAttributeDescriptor> analyzeJmxAttributes(long platformIdent, Collection<JmxAttributeDescriptor> attributeDescriptors) throws BusinessException { return nextGenInstrumentationManager.analyzeJmxAttributes(platformIdent, attributeDescriptors); }
@Test(expectedExceptions = { BusinessException.class }) public void businessTransactionShouldBeThrownIfNoClassCacheIsAvailable() throws BusinessException { manager.analyzeJmxAttributes(ID, Collections.singleton(descriptor)); } }
@Test(expectedExceptions = BusinessException.class) public void agentNotRegistered() throws BusinessException { manager.analyzeJmxAttributes(ID, Collections.singleton(descriptor)); }
@Test @SuppressWarnings("unchecked") public void successful() throws Exception { List<JmxAttributeDescriptor> attributeDescriptors = mock(List.class); agentService.analyzeJmxAttributes(10L, attributeDescriptors); verify(instrumentationManager).analyzeJmxAttributes(10L, attributeDescriptors); verifyNoMoreInteractions(instrumentationManager); verifyZeroInteractions(messageProvider, attributeDescriptors); } }
@Test public void nothingSent() throws BusinessException, ClassCacheModificationException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(ID); manager.register(definedIPs, agentName, version); Collection<JmxAttributeDescriptor> toMonitor = manager.analyzeJmxAttributes(ID, Collections.<JmxAttributeDescriptor> emptyList()); assertThat(toMonitor, is(empty())); }
@Test public void configurationHolderNotInitialized() throws BusinessException, ClassCacheModificationException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(ID); manager.register(definedIPs, agentName, version); when(configurationHolder.isInitialized()).thenReturn(false); Collection<JmxAttributeDescriptor> toMonitor = manager.analyzeJmxAttributes(ID, Collections.singleton(descriptor)); assertThat(toMonitor, is(empty())); }
@Test public void configurationHolderHasNoAppliers() throws BusinessException, ClassCacheModificationException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(ID); manager.register(definedIPs, agentName, version); when(configurationHolder.isInitialized()).thenReturn(true); when(configurationHolder.getJmxMonitoringAppliers()).thenReturn(null); Collection<JmxAttributeDescriptor> toMonitor = manager.analyzeJmxAttributes(ID, Collections.singleton(descriptor)); assertThat(toMonitor, is(empty())); }
@Test public void applierDoesNothing() throws BusinessException, ClassCacheModificationException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(ID); manager.register(definedIPs, agentName, version); AgentConfig configuration = mock(AgentConfig.class); when(configurationHolder.isInitialized()).thenReturn(true); when(configurationHolder.getAgentConfiguration()).thenReturn(configuration); when(configurationHolder.getJmxMonitoringAppliers()).thenReturn(Collections.singleton(applier)); when(applier.addMonitoringPoint(configuration, descriptor)).thenReturn(false); Collection<JmxAttributeDescriptor> toMonitor = manager.analyzeJmxAttributes(ID, Collections.singleton(descriptor)); assertThat(toMonitor, is(empty())); verify(applier).addMonitoringPoint(configuration, descriptor); }
@Test public void applierAddsMonitoringPoint() throws BusinessException, ClassCacheModificationException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(ID); manager.register(definedIPs, agentName, version); AgentConfig configuration = mock(AgentConfig.class); when(configurationHolder.isInitialized()).thenReturn(true); when(configurationHolder.getAgentConfiguration()).thenReturn(configuration); when(configurationHolder.getJmxMonitoringAppliers()).thenReturn(Collections.singleton(applier)); when(applier.addMonitoringPoint(configuration, descriptor)).thenReturn(true); Collection<JmxAttributeDescriptor> toMonitor = manager.analyzeJmxAttributes(ID, Collections.singleton(descriptor)); assertThat(toMonitor, hasSize(1)); assertThat(toMonitor, hasItem(descriptor)); verify(applier).addMonitoringPoint(configuration, descriptor); }
@Test public void ensureNoDoubleRegistration() throws BusinessException, ClassCacheModificationException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(ID); manager.register(definedIPs, agentName, version); AgentConfig configuration = mock(AgentConfig.class); when(configurationHolder.isInitialized()).thenReturn(true); when(configurationHolder.getAgentConfiguration()).thenReturn(configuration); List<JmxMonitoringApplier> appliers = new ArrayList<>(); appliers.add(applier); appliers.add(applier); when(configurationHolder.getJmxMonitoringAppliers()).thenReturn(appliers); when(applier.addMonitoringPoint(configuration, descriptor)).thenReturn(true); Collection<JmxAttributeDescriptor> toMonitor = manager.analyzeJmxAttributes(ID, Collections.singleton(descriptor)); assertThat(toMonitor, hasSize(1)); assertThat(toMonitor, hasItem(descriptor)); verify(applier).addMonitoringPoint(configuration, descriptor); }