/** * {@inheritDoc} */ @Override public boolean shouldAnalyzeOnStartup(String className) { if ((null != classHashHelper) && classHashHelper.isAnalyzed(className)) { InstrumentationDefinition instrumentationDefinition = classHashHelper.getInstrumentationDefinition(className); return (null != instrumentationDefinition) && !instrumentationDefinition.isEmpty(); } return true; }
@Test public void notRegistered() throws Exception { helper.afterPropertiesSet(); String fqn = "fqn"; InstrumentationDefinition definition = helper.getInstrumentationDefinition(fqn); assertThat(definition, is(nullValue())); }
@Test public void register() throws Exception { helper.afterPropertiesSet(); String fqn = "fqn"; InstrumentationDefinition definition = mock(InstrumentationDefinition.class); helper.registerInstrumentationDefinition(fqn, definition); InstrumentationDefinition fromCache = helper.getInstrumentationDefinition(fqn); assertThat(fromCache, is(definition)); }
@Test public void saveAndLoad() throws Exception { String fqn = "fqn"; InstrumentationDefinition definition = mock(InstrumentationDefinition.class); helper.registerInstrumentationDefinition(fqn, definition); helper.destroy(); helper.afterPropertiesSet(); InstrumentationDefinition fromCache = helper.getInstrumentationDefinition(fqn); assertThat(fromCache, is(nullValue())); } }
@Test public void initialInstrumentationPoints() throws Exception { String fqn = "fqn"; String hash = "hash"; InstrumentationDefinition instrumentationResult = mock(InstrumentationDefinition.class); Map<Collection<String>, InstrumentationDefinition> initInstrumentations = Collections.<Collection<String>, InstrumentationDefinition> singletonMap(Collections.singleton(hash), instrumentationResult); when(instrumentationResult.getClassName()).thenReturn(fqn); when(configurationStorage.getInitialInstrumentationResults()).thenReturn(initInstrumentations); helper.afterPropertiesSet(); assertThat(helper.isEmpty(), is(false)); assertThat(helper.isSent(fqn, hash), is(true)); assertThat(helper.getInstrumentationDefinition(fqn), is(instrumentationResult)); }
@Test public void notToBeSentNoInstrumentation() throws IOException { String className = TestClass.class.getName(); ClassLoader classLoader = TestClass.class.getClassLoader(); byte[] byteCode = getByteCode(className); ArgumentCaptor<String> fqnCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<String> hashCaptor = ArgumentCaptor.forClass(String.class); when(classHashHelper.isSent(fqnCaptor.capture(), hashCaptor.capture())).thenReturn(true); when(classHashHelper.getInstrumentationDefinition(fqnCaptor.capture())).thenReturn(null); byte[] instrumentedByteCode = byteCodeAnalyzer.analyzeAndInstrument(byteCode, className, classLoader); // we did not send the class type assertThat(instrumentedByteCode, is(nullValue())); verify(classHashHelper, times(1)).registerAnalyzed(fqnCaptor.getValue()); verify(classHashHelper, times(1)).isSent(fqnCaptor.getValue(), hashCaptor.getValue()); // but we asked for the instrumentation result verify(classHashHelper, times(1)).getInstrumentationDefinition(fqnCaptor.getValue()); verifyNoMoreInteractions(classHashHelper); verifyZeroInteractions(platformManager, connection, hookDispatcherMapper); }
if (classHashHelper.isSent(className, hash)) { instrumentationResult = classHashHelper.getInstrumentationDefinition(className); } else {
ArgumentCaptor<String> hashCaptor = ArgumentCaptor.forClass(String.class); when(classHashHelper.isSent(fqnCaptor.capture(), hashCaptor.capture())).thenReturn(true); when(classHashHelper.getInstrumentationDefinition(fqnCaptor.capture())).thenReturn(instrumentationResult); verify(classHashHelper, times(1)).registerAnalyzed(fqnCaptor.getValue()); verify(classHashHelper, times(1)).getInstrumentationDefinition(fqnCaptor.getValue()); ArgumentCaptor<RegisteredSensorConfig> rscCaptor = ArgumentCaptor.forClass(RegisteredSensorConfig.class); verify(hookDispatcherMapper, times(1)).addMapping(eq(rscId), rscCaptor.capture());