/** * {@inheritDoc} */ @Override @MethodLog public AgentConfig register(List<String> definedIPs, String agentName, String version) throws BusinessException { return nextGenInstrumentationManager.register(definedIPs, agentName, version); }
@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 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(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 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 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); }
@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 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 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 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); }
@Test public void existingClassTypeInstrumented() 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(true); AgentConfig configuration = mock(AgentConfig.class); Collection<IInstrumentationApplier> appliers = mock(Collection.class); InstrumentationDefinition instrumentationResult = mock(InstrumentationDefinition.class); when(configurationHolder.getAgentConfiguration()).thenReturn(configuration); when(configurationHolder.getInstrumentationAppliers()).thenReturn(appliers); when(instrumentationService.addAndGetInstrumentationResult(classType, configuration, appliers)).thenReturn(instrumentationResult); InstrumentationDefinition result = manager.analyze(ID, HASH, type); assertThat(result, is(instrumentationResult)); verify(instrumentationService).addAndGetInstrumentationResult(classType, configuration, appliers); verifyNoMoreInteractions(instrumentationService); verifyZeroInteractions(modificationService); }
AgentConfig result = manager.register(definedIPs, agentName, version);
AgentConfig result = manager.register(definedIPs, agentName, version);
@Test public void existingAgent() throws BusinessException { long id = 10; List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; final AgentConfig configuration = mock(AgentConfig.class); Environment environment = mock(Environment.class); when(configurationResolver.getEnvironmentForAgent(definedIPs, agentName)).thenReturn(environment); when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(id); when(configurationHolder.isInitialized()).thenReturn(true); when(configurationHolder.getEnvironment()).thenReturn(environment); when(configurationHolder.getAgentConfiguration()).thenReturn(configuration); Map<Collection<String>, InstrumentationDefinition> initialInstrumentations = mock(Map.class); when(instrumentationService.getInstrumentationResultsWithHashes()).thenReturn(initialInstrumentations); AgentConfig result = manager.register(definedIPs, agentName, version); assertThat(result, is(configuration)); verify(configurationResolver).getEnvironmentForAgent(definedIPs, agentName); verify(registrationService).registerPlatformIdent(definedIPs, agentName, version); verify(configurationHolder).getEnvironment(); verify(configurationHolder).getAgentConfiguration(); verify(configurationHolder).isInitialized(); verify(configuration).setInitialInstrumentationResults(initialInstrumentations); verify(configuration).setClassCacheExistsOnCmr(true); verify(classCache).getInstrumentationService(); verify(instrumentationService).getInstrumentationResultsWithHashes(); verifyNoMoreInteractions(configurationResolver, registrationService, configurationHolder, instrumentationService, classCache); }
@Test public void existingAgentNoEnvironment() throws BusinessException { long id = 10; List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; final AgentConfig configuration = mock(AgentConfig.class); Environment environment = mock(Environment.class); when(configurationResolver.getEnvironmentForAgent(definedIPs, agentName)).thenReturn(environment); when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(id); when(configurationHolder.isInitialized()).thenReturn(false); when(configurationHolder.getEnvironment()).thenReturn(environment); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { when(configurationHolder.getAgentConfiguration()).thenReturn(configuration); return null; } }).when(configurationHolder).update(environment, id); AgentConfig result = manager.register(definedIPs, agentName, version); assertThat(result, is(configuration)); verify(configurationResolver).getEnvironmentForAgent(definedIPs, agentName); verify(registrationService).registerPlatformIdent(definedIPs, agentName, version); verify(configurationHolder).update(environment, id); verify(configurationHolder).getEnvironment(); verify(configurationHolder).getAgentConfiguration(); verify(configurationHolder).isInitialized(); verifyNoMoreInteractions(configurationResolver, registrationService, configurationHolder); verifyZeroInteractions(classCache); }