/** * {@inheritDoc} */ @Override @MethodLog public InstrumentationDefinition analyze(long platformIdent, String hash, Type sentType) throws BusinessException { return nextGenInstrumentationManager.analyze(platformIdent, hash, sentType); }
@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 emptyCacheMap() { eventListener.onApplicationEvent(event); verify(nextGenInstrumentationManager).getAgentCacheMap(); verifyNoMoreInteractions(nextGenInstrumentationManager); verifyZeroInteractions(nextGenInstrumentationManager, cacheEntry, configurationHolder, environment, event, objectFactory, updateJob, executor, future); }
@Test public void existingNonClassType() 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); ImmutableType typeFromClassCache = mock(ImmutableType.class); when(typeFromClassCache.isClass()).thenReturn(false); when(lookupService.findByHash(HASH)).thenReturn(typeFromClassCache); InstrumentationDefinition result = manager.analyze(ID, HASH, type); assertThat(result, is(nullValue())); verifyZeroInteractions(modificationService, instrumentationService); }
/** * {@inheritDoc} */ @Override @MethodLog public AgentConfig register(List<String> definedIPs, String agentName, String version) throws BusinessException { return nextGenInstrumentationManager.register(definedIPs, agentName, version); }
/** * {@inheritDoc} */ @Override @MethodLog public Collection<JmxAttributeDescriptor> analyzeJmxAttributes(long platformIdent, Collection<JmxAttributeDescriptor> attributeDescriptors) throws BusinessException { return nextGenInstrumentationManager.analyzeJmxAttributes(platformIdent, attributeDescriptors); }
/** * {@inheritDoc} */ @Override @MethodLog public void unregister(long platformIdent) throws BusinessException { nextGenInstrumentationManager.unregister(platformIdent); }
/** * {@inheritDoc} */ @Override @MethodLog public void instrumentationApplied(long platformId, Map<Long, long[]> methodToSensorMap) { nextGenInstrumentationManager.instrumentationApplied(platformId, methodToSensorMap); }
AgentCacheEntry agentCacheEntry = getAgentCacheEntry(id); ClassCache classCache = agentCacheEntry.getClassCache(); ConfigurationHolder configurationHolder = agentCacheEntry.getConfigurationHolder();
@Test public void nonExistingNonClassType() 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); ImmutableType typeFromClassCache = mock(ImmutableType.class); when(typeFromClassCache.isClass()).thenReturn(false); when(lookupService.findByHash(HASH)).thenReturn(null, typeFromClassCache); InstrumentationDefinition result = manager.analyze(ID, HASH, type); assertThat(result, is(nullValue())); verify(modificationService).merge(type); verifyNoMoreInteractions(modificationService); verifyZeroInteractions(instrumentationService); }
@Test @SuppressWarnings("unchecked") public void successful() throws Exception { List<String> definedIPs = mock(List.class); when(instrumentationManager.register(any(List.class), any(String.class), any(String.class))).thenReturn(agentConfig); when(agentConfig.getPlatformId()).thenReturn(10L); agentService.register(definedIPs, "name", "version"); verify(instrumentationManager).register(definedIPs, "name", "version"); verifyNoMoreInteractions(instrumentationManager, messageProvider); verifyZeroInteractions(messageProvider, definedIPs); } }
@Test(expectedExceptions = { BusinessException.class }) public void businessTransactionShouldBeThrownIfNoClassCacheIsAvailable() throws BusinessException { manager.analyzeJmxAttributes(ID, Collections.singleton(descriptor)); } }
@Test public void unregister() throws Exception { long platformId = 10L; manager.unregister(platformId); verify(registrationService).unregisterPlatformIdent(platformId); } }
@Test @SuppressWarnings("unchecked") public void successful() throws Exception { Map<Long, long[]> methodSensorMap = mock(Map.class); agentService.instrumentationApplied(10L, methodSensorMap); verify(instrumentationManager).instrumentationApplied(10L, methodSensorMap); verifyNoMoreInteractions(instrumentationManager); verifyZeroInteractions(messageProvider, methodSensorMap); } }
@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 emptyCacheMap() { eventListener.onApplicationEvent(event); verify(nextGenInstrumentationManager).getAgentCacheMap(); verifyNoMoreInteractions(nextGenInstrumentationManager); verifyZeroInteractions(cacheEntry, configurationHolder, platformIdentDao, platformIdent, configurationResolver, cachedEnvironment, newEnvironment, event, objectFactory, updateJob, executor, future); }
@Test public void existingClassTypeConfigurationNotInitialized() 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); ClassType classType = mock(ClassType.class); when(classType.isClass()).thenReturn(true); when(classType.castToClass()).thenReturn(classType); when(lookupService.findByHash(HASH)).thenReturn(classType); when(configurationHolder.isInitialized()).thenReturn(false); InstrumentationDefinition result = manager.analyze(ID, HASH, type); assertThat(result, is(nullValue())); verifyZeroInteractions(modificationService, instrumentationService); }
@Test(expectedExceptions = BusinessException.class) public void noMappingsForAgent() throws BusinessException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(configurationResolver.getEnvironmentForAgent(definedIPs, agentName)).thenThrow(new BusinessException(null)); manager.register(definedIPs, agentName, version); }
@Test(expectedExceptions = BusinessException.class) public void agentNotRegistered() throws BusinessException { manager.analyzeJmxAttributes(ID, Collections.singleton(descriptor)); }
@Test(expectedExceptions = BusinessException.class) public void agentNotRegistered() throws BusinessException { manager.analyze(ID, HASH, type); }