/** * Notifies listeners about mappings update. */ private void publishAgentMappingsUpdateEvent() { AgentMappingsUpdateEvent event = new AgentMappingsUpdateEvent(this); eventPublisher.publishEvent(event); }
/** * Returns all {@link AbstractClassSensorAssignment} that are contained in the removed profiles. * Only active profiles are taken into account. Also includes the functional assignments that * might be removed as the result of changes in the environment. * * @param functionalAssignmentFactory * SpecialMethodSensorAssignmentFactory for resolving functional assignment updates. * * @return Returns all {@link AbstractClassSensorAssignment} that are "removed". */ public Collection<AbstractClassSensorAssignment<?>> getRemovedSensorAssignments(SpecialMethodSensorAssignmentFactory functionalAssignmentFactory) { Collection<AbstractClassSensorAssignment<?>> removedAssignments = getSensorAssignments(removedProfiles); removedAssignments.addAll(getFunctionalAssignmentsDifference(functionalAssignmentFactory, before, after)); return removedAssignments; }
/** * Notifies listeners about profile update. * * @param old * Old profile instance. * @param updated * Updated profile instance. */ private void publishProfileUpdateEvent(Profile old, Profile updated) { ProfileUpdateEvent profileUpdateEvent = new ProfileUpdateEvent(this, old, updated); eventPublisher.publishEvent(profileUpdateEvent); }
/** * Returns all {@link AbstractClassSensorAssignment} that are "added" as result of this update. * If profile was activated then it means that all assignments after the update are considered * for adding. * * @return Returns all {@link AbstractClassSensorAssignment} that are "removed". */ public Collection<AbstractClassSensorAssignment<?>> getAddedSensorAssignments() { if (isProfileDeactivated()) { // if it was deactivated then nothing is for adding return Collections.emptyList(); } else if (isProfileActivated()) { // if activated then we consider all new assignment to be for adding return getAllSensorAssignments(after); } else { // otherwise find the difference return getAssignmentsDifference(after, before); } }
@Test public void successful() { List<InstrumentationDefinition> instrumentationDefinitions = Arrays.asList(mock(InstrumentationDefinition.class)); ClassInstrumentationChangedEvent event = new ClassInstrumentationChangedEvent(this, 10L, instrumentationDefinitions); assertThat(event.getAgentId(), is(equalTo(10L))); assertThat(instrumentationDefinitions, is(equalTo(event.getInstrumentationDefinitions()))); }
@Test public void deletedEvent() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); assertThat(getAlertingStates(), hasSize(1)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionDeletedEvent(this, definitionOne); when(definitionOne.getId()).thenReturn("id"); alertingScheduler.onApplicationEvent(event); verify(definitionOne, times(2)).getId(); verifyNoMoreInteractions(definitionOne); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(0)); }
@Test public void profileNotActive() { cacheMap.put(1L, cacheEntry); eventListener.onApplicationEvent(event); verify(event).isProfileActive(); verify(event).isProfileDeactivated(); verifyNoMoreInteractions(event); verifyZeroInteractions(cacheEntry, configurationHolder, environment, updateJob, future, nextGenInstrumentationManager, objectFactory, executor); }
@Test public void emptyCacheMap() { when(event.isProfileActive()).thenReturn(true); when(event.getProfileId()).thenReturn("id_1"); eventListener.onApplicationEvent(event); verify(event).isProfileActive(); verify(nextGenInstrumentationManager).getAgentCacheMap(); verifyNoMoreInteractions(event, nextGenInstrumentationManager); verifyZeroInteractions(cacheEntry, configurationHolder, environment, updateJob, future, objectFactory, executor); }
@Test(expectedExceptions = IllegalArgumentException.class) @SuppressWarnings("unchecked") public void emptyDefinitions() { new ClassInstrumentationChangedEvent(this, 10L, Collections.EMPTY_LIST); } }
/** * Notifies listeners about environment update. * * @param old * Old environment instance. * @param updated * Updated environment instance. */ private void publishEnvironmentUpdateEvent(Environment old, Environment updated) { Collection<Profile> removedProfiles = getProfileDifference(old, updated); Collection<Profile> addedProfiles = getProfileDifference(updated, old); EnvironmentUpdateEvent event = new EnvironmentUpdateEvent(this, old, updated, addedProfiles, removedProfiles); eventPublisher.publishEvent(event); }
/** * Finds {@link AbstractClassSensorAssignment}s that exists in first profile and not in the * second one. * * @param p1 * First profile * @param p2 * Second profile * @return {@link AbstractClassSensorAssignment}s that exists in first profile and not in the * second one. */ private Collection<AbstractClassSensorAssignment<?>> getAssignmentsDifference(Profile p1, Profile p2) { Collection<AbstractClassSensorAssignment<?>> results1 = getAllSensorAssignments(p1); Collection<AbstractClassSensorAssignment<?>> results2 = getAllSensorAssignments(p2); return CollectionSubtractUtils.subtractSafe(results1, results2); }
/** * Handle the {@link AbstractAlertingDefinitionEvent}. * * @param event * the received {@link AbstractAlertingDefinitionEvent} */ private void loadedAlertingDefinitions(AbstractAlertingDefinitionEvent event) { alertingStates.clear(); for (AlertingDefinition definition : event.getAlertingDefinitions()) { alertingStates.add(new AlertingState(definition)); } }
/** * Handle the {@link AbstractAlertingDefinitionEvent}. * * @param event * the received {@link AbstractAlertingDefinitionEvent} */ private void createdAlertingDefinition(AbstractAlertingDefinitionEvent event) { alertingStates.add(new AlertingState(event.getFirst())); }
/** * {@inheritDoc} */ @Override public void onApplicationEvent(AbstractAlertingDefinitionEvent event) { if (event == null) { return; } switch (event.getType()) { case LOADED: loadedAlertingDefinitions(event); break; case ADDED: createdAlertingDefinition(event); break; case REMOVED: deletedAlertingDefinition(event); break; case UPDATE: updatedAlertingDefinition(event); break; default: break; } }
/** * Returns all {@link AbstractClassSensorAssignment} that are "removed" as result of this * update. If profile was deactivated then it means that all assignments before the update are * considered for removal. * * @return Returns all {@link AbstractClassSensorAssignment} that are "removed". */ public Collection<AbstractClassSensorAssignment<?>> getRemovedSensorAssignments() { if (isProfileDeactivated()) { // if deactivated then we consider all old assignment to be for removal return getAllSensorAssignments(before); } else if (isProfileActivated()) { // if it was activated then nothing is for removal return Collections.emptyList(); } else { // otherwise find the difference return getAssignmentsDifference(before, after); } }
@Test public void deletedUnknownEvent() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); assertThat(getAlertingStates(), hasSize(1)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionDeletedEvent(this, definitionTwo); when(definitionOne.getId()).thenReturn("id"); alertingScheduler.onApplicationEvent(event); verify(definitionOne).getId(); verify(definitionTwo).getId(); verifyNoMoreInteractions(definitionOne, definitionTwo); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(1)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void nullDefinitions() { new ClassInstrumentationChangedEvent(this, 10L, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void idsNotMatching() { when(updated.getId()).thenReturn(ID); when(old.getId()).thenReturn("smth"); new ProfileUpdateEvent(this, old, updated); } }
/** * Returns all {@link AbstractClassSensorAssignment} that are contained in the added profiles. * Only active profiles are taken into account. Also includes the functional assignments that * might be added as the result of changes in the environment. * * @param functionalAssignmentFactory * SpecialMethodSensorAssignmentFactory for resolving functional assignment updates. * * @return Returns all {@link AbstractClassSensorAssignment} that are "added". */ public Collection<AbstractClassSensorAssignment<?>> getAddedSensorAssignments(SpecialMethodSensorAssignmentFactory functionalAssignmentFactory) { Collection<AbstractClassSensorAssignment<?>> addedAssignments = getSensorAssignments(addedProfiles); addedAssignments.addAll(getFunctionalAssignmentsDifference(functionalAssignmentFactory, after, before)); return addedAssignments; }
@Test(expectedExceptions = IllegalArgumentException.class) public void idsNotMatching() { when(updated.getId()).thenReturn(ID); when(old.getId()).thenReturn("smth"); new EnvironmentUpdateEvent(this, old, updated, null, null); } }