@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 retrievePlatformId() throws Exception { long fakePlatformId = 3L; when(connection.isConnected()).thenReturn(true); when(configurationStorage.getAgentName()).thenReturn("testAgent"); when(versionService.getVersionAsString()).thenReturn("dummyVersion"); when(connection.register("testAgent", "dummyVersion")).thenReturn(agentConfiguration); when(agentConfiguration.getPlatformId()).thenReturn(fakePlatformId); platformManager.afterPropertiesSet(); long platformId = platformManager.getPlatformId(); assertThat(platformId, is(equalTo(fakePlatformId))); verify(connection, times(0)).connect(anyString(), anyInt()); }
/** * Registers method to the registration service. * * @param agentConfiguration * {@link AgentConfig} to read platform id. * @param methodType * {@link MethodType} in question. * @param methodInstrumentationConfig * {@link MethodInstrumentationConfig}. * @return Id of the method. */ private long registerMethod(AgentConfig agentConfiguration, MethodType methodType, MethodInstrumentationConfig methodInstrumentationConfig) { // extract package and class name String fqn = methodInstrumentationConfig.getTargetClassFqn(); int index = fqn.lastIndexOf('.'); String packageName = index >= 0 ? fqn.substring(0, index) : ""; String className = fqn.substring(index + 1); return registrationService.registerMethodIdent(agentConfiguration.getPlatformId(), packageName, className, methodType.getName(), methodType.getParameters(), methodType.getReturnType(), methodType.getModifiers()); }
/** * Registers the platform at the CMR. * * @throws ServerUnavailableException * If the sending wasn't successful in any way, a {@link ServerUnavailableException} * exception is thrown. * @throws RegistrationException * This exception is thrown when a problem with the registration process appears. * @throws StorageException * If setting configuration to the {@link #configurationStorage} fails. */ private void register() throws ServerUnavailableException, RegistrationException, StorageException { try { AgentConfig agentConfiguration = connection.register(configurationStorage.getAgentName(), versionService.getVersionAsString()); platformId = agentConfiguration.getPlatformId(); configurationStorage.setAgentConfiguration(agentConfiguration); if (log.isDebugEnabled()) { log.debug("Received platform ID: " + platformId); } } catch (BusinessException exception) { log.error("The agent was not able to get configuration from the server. " + exception.getMessage()); throw new BeanInitializationException("The agent was not able to get configuration from the server.", exception); } }
@Test public void connectAndRetrievePlatformId() throws Exception { String host = "localhost"; int port = 1099; RepositoryConfig repositoryConfig = mock(RepositoryConfig.class); when(repositoryConfig.getHost()).thenReturn(host); when(repositoryConfig.getPort()).thenReturn(port); when(configurationStorage.getRepositoryConfig()).thenReturn(repositoryConfig); when(configurationStorage.getAgentName()).thenReturn("testAgent"); when(versionService.getVersionAsString()).thenReturn("dummyVersion"); long fakePlatformId = 7L; when(connection.isConnected()).thenReturn(false); when(connection.register("testAgent", "dummyVersion")).thenReturn(agentConfiguration); when(agentConfiguration.getPlatformId()).thenReturn(fakePlatformId); platformManager.afterPropertiesSet(); long platformId = platformManager.getPlatformId(); assertThat(platformId, is(equalTo(fakePlatformId))); verify(connection, times(1)).connect(host, port); }
@Test public void configureAgent() throws Exception { long agentId = 13L; AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); assertThat(agentConfiguration.getPlatformId(), is(agentId)); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); }
@Test public void instrumentationExist() throws Exception { long agentId = 13L; long sensorId = 15L; String sensorClassName = "sensorClassName"; MethodSensorTypeConfig methodSensorTypeConfig = mock(MethodSensorTypeConfig.class); when(methodSensorTypeConfig.getId()).thenReturn(sensorId); when(methodSensorTypeConfig.getPriority()).thenReturn(PriorityEnum.NORMAL); AgentConfig agentConfiguration = mock(AgentConfig.class); when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig); Map<String, Object> settings = Collections.<String, Object> singletonMap("key", "value"); when(assignment.getSettings()).thenReturn(settings); IMethodSensorConfig methodSensorConfig = mock(IMethodSensorConfig.class); when(methodSensorConfig.getClassName()).thenReturn(sensorClassName); when(environment.getMethodSensorTypeConfig(Matchers.<Class<? extends IMethodSensorConfig>> any())).thenReturn(methodSensorConfig); SensorInstrumentationPoint rsc = mock(SensorInstrumentationPoint.class); when(rsc.getSensorIds()).thenReturn(new long[] { sensorId }); MethodInstrumentationConfig instrumentationConfig = mock(MethodInstrumentationConfig.class); when(instrumentationConfig.getSensorInstrumentationPoint()).thenReturn(rsc); when(methodType.getMethodInstrumentationConfig()).thenReturn(instrumentationConfig); boolean changed = applier.addInstrumentationPoints(agentConfiguration, classType); // verify results assertThat(changed, is(true)); // verify no interaction verifyZeroInteractions(registrationService); verify(instrumentationConfig, times(0)).setSensorInstrumentationPoint(Matchers.<SensorInstrumentationPoint> any()); verify(methodType, times(0)).setMethodInstrumentationConfig(Matchers.<MethodInstrumentationConfig> any()); }
/** * Tests that unregister of platform is executed if connection to the server is established * and registration is performed. */ @Test public void unregisterPlatform() throws Exception { // first simulate connect long fakePlatformId = 3L; when(connection.isConnected()).thenReturn(true); when(configurationStorage.getAgentName()).thenReturn("testAgent"); when(versionService.getVersionAsString()).thenReturn("dummyVersion"); when(connection.register("testAgent", "dummyVersion")).thenReturn(agentConfiguration); when(agentConfiguration.getPlatformId()).thenReturn(fakePlatformId); platformManager.afterPropertiesSet(); platformManager.getPlatformId(); platformManager.unregisterPlatform(); verify(connection, times(1)).unregister(fakePlatformId); verify(connection, times(1)).disconnect(); }
@Test public void add() { long platformId = 7L; String attributeName = "attributeName"; String objectName = "objectname"; long attributeId = 13L; String attributeType = "type"; String attributeDecs = "desc"; boolean isIs = false; boolean readable = true; boolean writable = false; when(filter.matches(assignment, descriptor)).thenReturn(true); when(agentConfig.getPlatformId()).thenReturn(platformId); when(descriptor.getAttributeName()).thenReturn(attributeName); when(descriptor.getmBeanAttributeDescription()).thenReturn(attributeDecs); when(descriptor.getmBeanObjectName()).thenReturn(objectName); when(descriptor.getmBeanAttributeId()).thenReturn(attributeId); when(descriptor.getmBeanAttributeType()).thenReturn(attributeType); when(descriptor.ismBeanAttributeIsIs()).thenReturn(isIs); when(descriptor.ismBeanAttributeIsReadable()).thenReturn(readable); when(descriptor.ismBeanAttributeIsWritable()).thenReturn(writable); boolean added = applier.addMonitoringPoint(agentConfig, descriptor); assertThat(added, is(true)); verify(registrationService).registerJmxSensorDefinitionDataIdent(platformId, objectName, attributeName, attributeDecs, attributeType, isIs, readable, writable); }
when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig);
when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig);
when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig); when(agentConfiguration.getMethodSensorTypeConfig(invocClassName)).thenReturn(invocSensorTypeConfig);
when(agentConfiguration.getPlatformId()).thenReturn(agentId);
when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig);
when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getSpecialMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig);
when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig); when(agentConfiguration.getMethodSensorTypeConfig(invocClassName)).thenReturn(invocSensorTypeConfig);
long id = registrationService.registerJmxSensorDefinitionDataIdent(agentConfiguration.getPlatformId(), objectName, attributeName, description, type, isIs, readable, writable); jmxAttributeDescriptor.setId(id);