/** * {@inheritDoc} */ @Override public void updateInstrumentation(Collection<Long> updatePlatformIds) { if (CollectionUtils.isEmpty(updatePlatformIds)) { throw new IllegalArgumentException("The collection of platform idents may not be null or empty."); } if (log.isInfoEnabled()) { log.info("Instrumentation updated messages flushed for the agent(s) with ID(s): {}", Arrays.toString(updatePlatformIds.toArray())); } for (long platformId : updatePlatformIds) { messageGate.flush(platformId); } }
@Test public void successful() { instrumentationService.updateInstrumentation(Arrays.asList(10L, 20L)); ArgumentCaptor<Long> platformIdentCaptor = ArgumentCaptor.forClass(Long.class); verify(messageGate, times(2)).flush(platformIdentCaptor.capture()); verifyNoMoreInteractions(messageGate); assertThat(platformIdentCaptor.getAllValues(), contains(10L, 20L)); }
@Test @SuppressWarnings("unchecked") public void unknownPlatformId() throws Exception { when(definition.getClassName()).thenReturn("class.one"); ClassInstrumentationChangedEvent event = new ClassInstrumentationChangedEvent(this, 10L, Arrays.asList(definition)); messageGate.onApplicationEvent(event); when(agentStatusDataProvider.getAgentStatusDataMap()).thenReturn(Collections.EMPTY_MAP); assertThat(getDefinitionBuffer().get(10L).entrySet(), hasSize(1)); messageGate.flush(20L); verifyZeroInteractions(messageProvider); assertThat(getDefinitionBuffer().get(10L).entrySet(), hasSize(1)); } }
@Test @SuppressWarnings("rawtypes") public void successful() throws Exception { when(definition.getClassName()).thenReturn("class.one"); ClassInstrumentationChangedEvent event = new ClassInstrumentationChangedEvent(this, 10L, Arrays.asList(definition)); messageGate.onApplicationEvent(event); when(agentStatusDataProvider.getAgentStatusDataMap()).thenReturn(ImmutableMap.of(10L, statusData)); when(statusData.getInstrumentationStatus()).thenReturn(InstrumentationStatus.PENDING); assertThat(getDefinitionBuffer().get(10L).entrySet(), hasSize(1)); messageGate.flush(10L); ArgumentCaptor<IAgentMessage> messageCaptor = ArgumentCaptor.forClass(IAgentMessage.class); verify(messageProvider).provideMessage(eq(10L), messageCaptor.capture()); verify(statusData).setInstrumentationStatus(InstrumentationStatus.UP_TO_DATE); verifyNoMoreInteractions(statusData, messageProvider); assertThat(((UpdatedInstrumentationMessage) messageCaptor.getValue()).getMessageContent(), contains(definition)); assertThat(getDefinitionBuffer().get(10L).entrySet(), hasSize(0)); }