@Test public void agentRegisteredEvent() throws Exception { when(definitionOne.getClassName()).thenReturn("class.one"); ClassInstrumentationChangedEvent event = new ClassInstrumentationChangedEvent(this, 10L, Collections.singletonList(definitionOne)); messageGate.onApplicationEvent(event); AgentRegisteredEvent registeredEvent = new AgentRegisteredEvent(this, 10L); messageGate.onApplicationEvent(registeredEvent); assertThat(getDefinitionBuffer().get(10L).entrySet(), hasSize(0)); }
@Test public void agentDeletedEvent() throws Exception { when(definitionOne.getClassName()).thenReturn("class.one"); ClassInstrumentationChangedEvent event = new ClassInstrumentationChangedEvent(this, 10L, Collections.singletonList(definitionOne)); messageGate.onApplicationEvent(event); AgentDeletedEvent deletedEvent = new AgentDeletedEvent(this, 10L); messageGate.onApplicationEvent(deletedEvent); assertThat(getDefinitionBuffer().get(10L).entrySet(), hasSize(0)); }
@Test @SuppressWarnings("unchecked") public void changeEventReplaceInstrumentationDefinition() throws Exception { when(definitionOne.getClassName()).thenReturn("class.one"); when(definitionTwo.getClassName()).thenReturn("class.two"); when(definitionThree.getClassName()).thenReturn("class.one"); ClassInstrumentationChangedEvent eventOne = new ClassInstrumentationChangedEvent(this, 10L, Arrays.asList(definitionOne, definitionTwo)); ClassInstrumentationChangedEvent eventTwo = new ClassInstrumentationChangedEvent(this, 10L, Arrays.asList(definitionThree)); when(agentStatusDataProvider.getAgentStatusDataMap()).thenReturn(Collections.EMPTY_MAP); when(statusData.getInstrumentationStatus()).thenReturn(InstrumentationStatus.UP_TO_DATE, InstrumentationStatus.PENDING); messageGate.onApplicationEvent(eventOne); messageGate.onApplicationEvent(eventTwo); assertThat(getDefinitionBuffer().entrySet(), hasSize(1)); assertThat(getDefinitionBuffer().get(10L).entrySet(), hasSize(2)); assertThat(getDefinitionBuffer().get(10L), hasEntry("class.one", definitionThree)); assertThat(getDefinitionBuffer().get(10L), hasEntry("class.two", definitionTwo)); }
@Test public void changeEventAddInstrumentationDefinitions() throws Exception { when(definitionOne.getClassName()).thenReturn("class.one"); when(definitionTwo.getClassName()).thenReturn("class.two"); when(definitionThree.getClassName()).thenReturn("class.three"); ClassInstrumentationChangedEvent eventOne = new ClassInstrumentationChangedEvent(this, 10L, Arrays.asList(definitionOne, definitionTwo)); ClassInstrumentationChangedEvent eventTwo = new ClassInstrumentationChangedEvent(this, 10L, Arrays.asList(definitionThree)); when(agentStatusDataProvider.getAgentStatusDataMap()).thenReturn(ImmutableMap.of(10L, statusData)); when(statusData.getInstrumentationStatus()).thenReturn(InstrumentationStatus.UP_TO_DATE, InstrumentationStatus.PENDING); long currentTime = System.currentTimeMillis(); messageGate.onApplicationEvent(eventOne); messageGate.onApplicationEvent(eventTwo); verify(definitionOne).getClassName(); verify(definitionTwo).getClassName(); verify(definitionThree).getClassName(); verify(agentStatusDataProvider, times(2)).getAgentStatusDataMap(); verify(statusData, times(2)).getInstrumentationStatus(); verify(statusData).setInstrumentationStatus(InstrumentationStatus.PENDING); ArgumentCaptor<Long> timeCaptor = ArgumentCaptor.forClass(Long.class); verify(statusData).setPendingSinceTime(timeCaptor.capture()); verifyNoMoreInteractions(definitionOne, definitionTwo, definitionThree, agentStatusDataProvider, statusData); verifyZeroInteractions(messageProvider); assertThat(timeCaptor.getValue(), greaterThanOrEqualTo(currentTime)); assertThat(getDefinitionBuffer().entrySet(), hasSize(1)); assertThat(getDefinitionBuffer().get(10L).entrySet(), hasSize(3)); assertThat(getDefinitionBuffer().get(10L), hasEntry("class.one", definitionOne)); assertThat(getDefinitionBuffer().get(10L), hasEntry("class.two", definitionTwo)); assertThat(getDefinitionBuffer().get(10L), hasEntry("class.three", definitionThree)); }
@Test @SuppressWarnings("unchecked") public void changeEventAddInstrumentationDefinitionForDiffrentAgents() throws Exception { when(definitionOne.getClassName()).thenReturn("class.one"); when(definitionTwo.getClassName()).thenReturn("class.two"); when(definitionThree.getClassName()).thenReturn("class.one"); ClassInstrumentationChangedEvent eventOne = new ClassInstrumentationChangedEvent(this, 10L, Arrays.asList(definitionOne, definitionTwo)); ClassInstrumentationChangedEvent eventTwo = new ClassInstrumentationChangedEvent(this, 20L, Arrays.asList(definitionThree)); when(agentStatusDataProvider.getAgentStatusDataMap()).thenReturn(Collections.EMPTY_MAP); when(statusData.getInstrumentationStatus()).thenReturn(InstrumentationStatus.UP_TO_DATE, InstrumentationStatus.PENDING); messageGate.onApplicationEvent(eventOne); messageGate.onApplicationEvent(eventTwo); assertThat(getDefinitionBuffer().entrySet(), hasSize(2)); assertThat(getDefinitionBuffer().get(10L).entrySet(), hasSize(2)); assertThat(getDefinitionBuffer().get(10L), hasEntry("class.one", definitionOne)); assertThat(getDefinitionBuffer().get(10L), hasEntry("class.two", definitionTwo)); assertThat(getDefinitionBuffer().get(20L).entrySet(), hasSize(1)); assertThat(getDefinitionBuffer().get(20L), hasEntry("class.one", definitionThree)); }