From 72c43ebf83582de6f22138f235b0049fb55609d2 Mon Sep 17 00:00:00 2001 From: Marius Oehler Date: Thu, 23 Dec 2021 12:00:30 +0100 Subject: [PATCH 1/5] Prevent recursive method hook execution --- .../instrumentation/hook/HookManager.java | 29 ++++++++++--------- .../core/instrumentation/hook/MethodHook.java | 12 +++++--- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java index 1c3d0a63ce..c7b85211e8 100644 --- a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java +++ b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java @@ -49,6 +49,8 @@ public class HookManager { */ private volatile Map, Map> hooks = Collections.emptyMap(); + public static ThreadLocal hookGate = ThreadLocal.withInitial(() -> false); + @PostConstruct void init() { Instances.hookManager = this::getHook; @@ -64,16 +66,20 @@ void destroy() { * * @param clazz the name of the class to which the method to query the hook for belongs * @param methodSignature the signature of the method in the form of name(parametertype,parametertype,..) + * * @return */ private IMethodHook getHook(Class clazz, String methodSignature) { - Map methodHooks = hooks.get(clazz); - if (methodHooks != null) { - MethodHook hook = methodHooks.get(methodSignature); - if (hook != null) { - return hook; + if (!hookGate.get() ) { + Map methodHooks = hooks.get(clazz); + if (methodHooks != null) { + MethodHook hook = methodHooks.get(methodSignature); + if (hook != null) { + return hook; + } } } + return NoopMethodHook.INSTANCE; } @@ -88,7 +94,6 @@ public HookUpdate startUpdate() { return new HookUpdate(); } - /** * A {@link HookUpdate} instance represents a (potential) change to apply to the {@link HookManager}. * Hooks for any class can be updated by calling {@link #updateHooksForClass(Class)}. This updates @@ -120,7 +125,8 @@ private HookUpdate() { newHooks = new WeakHashMap<>(); for (Map.Entry, Map> existingMethodHooks : hooks.entrySet()) { HashMap newMethodHooks = new HashMap<>(); - existingMethodHooks.getValue().forEach((signature, hook) -> newMethodHooks.put(signature, hook.getResettedCopy())); + existingMethodHooks.getValue() + .forEach((signature, hook) -> newMethodHooks.put(signature, hook.getResettedCopy())); newHooks.put(existingMethodHooks.getKey(), newMethodHooks); } } @@ -159,13 +165,11 @@ private void ensureNotCommitted() { private Optional getCurrentHook(Class declaringClass, String methodSignature) { Map methodHooks = newHooks.get(declaringClass); - return Optional.ofNullable(methodHooks) - .map(myHooks -> myHooks.get(methodSignature)); + return Optional.ofNullable(methodHooks).map(myHooks -> myHooks.get(methodSignature)); } private void setHook(Class declaringClass, String methodSignature, MethodHook newHook) { - newHooks.computeIfAbsent(declaringClass, (v) -> new HashMap<>()) - .put(methodSignature, newHook); + newHooks.computeIfAbsent(declaringClass, (v) -> new HashMap<>()).put(methodSignature, newHook); } private void removeHook(Class declaringClass, String methodSignature) { @@ -193,8 +197,7 @@ private void removeHook(Class declaringClass, String methodSignature) { private void addOrReplaceHooks(Class clazz, Map hookConfigs) { hookConfigs.forEach((method, newConfig) -> { String signature = CoreUtils.getSignature(method); - MethodHookConfiguration oldConfig = getCurrentHook(clazz, signature) - .map(MethodHook::getSourceConfiguration) + MethodHookConfiguration oldConfig = getCurrentHook(clazz, signature).map(MethodHook::getSourceConfiguration) .orElse(null); if (!Objects.equals(newConfig, oldConfig)) { if (log.isDebugEnabled()) { diff --git a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHook.java b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHook.java index a8173c0318..262a961a9d 100644 --- a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHook.java +++ b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHook.java @@ -98,10 +98,12 @@ public InternalInspectitContext onEnter(Object[] args, Object thiz) { log.error("Entry action {} executed for method {} threw an exception and from now on is disabled!", action, methodInformation.getMethodFQN(), t); activeEntryActions.remove(action); } - } - inspectitContext.makeActive(); - return inspectitContext; + inspectitContext.makeActive(); + return inspectitContext; + } finally { + HookManager.hookGate.set(false); + } } @Override @@ -114,8 +116,10 @@ public void onExit(Object[] args, Object thiz, Object returnValue, Throwable thr log.error("Exit action {} executed for method {} threw an exception and from now on is disabled!", action, methodInformation.getMethodFQN(), t); activeExitActions.remove(action); } + context.close(); + } finally { + HookManager.hookGate.set(false); } - context.close(); } /** From 7eb46b3dee3dfec419705ff55d82735203cab953 Mon Sep 17 00:00:00 2001 From: Marius Oehler Date: Thu, 20 Jan 2022 11:19:23 +0100 Subject: [PATCH 2/5] Introducing recursion gate thread local for preventing action recursion --- .../instrumentation/hook/HookManager.java | 19 ++-- .../core/instrumentation/hook/MethodHook.java | 50 ++++++----- .../instrumentation/hook/HookManagerTest.java | 86 +++++++++++++++++++ .../instrumentation/hook/MethodHookTest.java | 43 ++++++++-- 4 files changed, 164 insertions(+), 34 deletions(-) create mode 100644 inspectit-ocelot-core/src/test/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManagerTest.java diff --git a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java index c7b85211e8..2bad3baada 100644 --- a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java +++ b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java @@ -1,5 +1,6 @@ package rocks.inspectit.ocelot.core.instrumentation.hook; +import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import lombok.val; import net.bytebuddy.description.method.MethodDescription; @@ -29,6 +30,13 @@ @Service public class HookManager { + /** + * Thread local flag for marking the current thread that it is currently in the execution/scope of agent actions. + * This is used to prevent a endless action recursion in case an instrumented action is invoked within another + * action. In that case, the instrumentation has to be suppressed. + */ + public static final ThreadLocal RECURSION_GATE = ThreadLocal.withInitial(() -> false); + @Autowired private InstrumentationConfigurationResolver configResolver; @@ -49,8 +57,6 @@ public class HookManager { */ private volatile Map, Map> hooks = Collections.emptyMap(); - public static ThreadLocal hookGate = ThreadLocal.withInitial(() -> false); - @PostConstruct void init() { Instances.hookManager = this::getHook; @@ -65,12 +71,13 @@ void destroy() { * Actual implementation for {@link IHookManager#getHook(Class, String)}. * * @param clazz the name of the class to which the method to query the hook for belongs - * @param methodSignature the signature of the method in the form of name(parametertype,parametertype,..) + * @param methodSignature the signature of the method in the form of name(parametertype, parametertype,..) * - * @return + * @return the method hook for the specified method */ - private IMethodHook getHook(Class clazz, String methodSignature) { - if (!hookGate.get() ) { + @VisibleForTesting + IMethodHook getHook(Class clazz, String methodSignature) { + if (!RECURSION_GATE.get()) { Map methodHooks = hooks.get(clazz); if (methodHooks != null) { MethodHook hook = methodHooks.get(methodSignature); diff --git a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHook.java b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHook.java index 262a961a9d..58775734a6 100644 --- a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHook.java +++ b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHook.java @@ -13,7 +13,6 @@ import rocks.inspectit.ocelot.core.selfmonitoring.ActionScopeFactory; import rocks.inspectit.ocelot.core.selfmonitoring.IActionScope; -import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -65,7 +64,6 @@ public class MethodHook implements IMethodHook { */ private final MethodReflectionInformation methodInformation; - /** * The factory that creates/spawns new scopes for an {@link IHookAction} */ @@ -88,37 +86,49 @@ public MethodHook(MethodHookConfiguration sourceConfiguration, ContextManager in @Override public InternalInspectitContext onEnter(Object[] args, Object thiz) { - InspectitContextImpl inspectitContext = inspectitContextManager.enterNewContext(); - IHookAction.ExecutionContext executionContext = new IHookAction.ExecutionContext(args, thiz, null, null, this, inspectitContext); - - for (IHookAction action : activeEntryActions) { - try (IActionScope scope = actionScopeFactory.createScope(action)) { - action.execute(executionContext); - } catch (Throwable t) { - log.error("Entry action {} executed for method {} threw an exception and from now on is disabled!", action, methodInformation.getMethodFQN(), t); - activeEntryActions.remove(action); + try { + // flags the thread that it is now in action execution + HookManager.RECURSION_GATE.set(true); + + InspectitContextImpl inspectitContext = inspectitContextManager.enterNewContext(); + IHookAction.ExecutionContext executionContext = new IHookAction.ExecutionContext(args, thiz, null, null, this, inspectitContext); + + for (IHookAction action : activeEntryActions) { + try (IActionScope scope = actionScopeFactory.createScope(action)) { + action.execute(executionContext); + } catch (Throwable t) { + log.error("Entry action {} executed for method {} threw an exception and from now on is disabled!", action, methodInformation + .getMethodFQN(), t); + activeEntryActions.remove(action); + } } inspectitContext.makeActive(); return inspectitContext; } finally { - HookManager.hookGate.set(false); + HookManager.RECURSION_GATE.set(false); } } @Override public void onExit(Object[] args, Object thiz, Object returnValue, Throwable thrown, InternalInspectitContext context) { - IHookAction.ExecutionContext executionContext = new IHookAction.ExecutionContext(args, thiz, returnValue, thrown, this, (InspectitContextImpl) context); - for (IHookAction action : activeExitActions) { - try (IActionScope scope = actionScopeFactory.createScope(action)) { - action.execute(executionContext); - } catch (Throwable t) { - log.error("Exit action {} executed for method {} threw an exception and from now on is disabled!", action, methodInformation.getMethodFQN(), t); - activeExitActions.remove(action); + try { + // flags the thread that it is now in action execution + HookManager.RECURSION_GATE.set(true); + + IHookAction.ExecutionContext executionContext = new IHookAction.ExecutionContext(args, thiz, returnValue, thrown, this, (InspectitContextImpl) context); + for (IHookAction action : activeExitActions) { + try (IActionScope scope = actionScopeFactory.createScope(action)) { + action.execute(executionContext); + } catch (Throwable t) { + log.error("Exit action {} executed for method {} threw an exception and from now on is disabled!", action, methodInformation + .getMethodFQN(), t); + activeExitActions.remove(action); + } } context.close(); } finally { - HookManager.hookGate.set(false); + HookManager.RECURSION_GATE.set(false); } } diff --git a/inspectit-ocelot-core/src/test/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManagerTest.java b/inspectit-ocelot-core/src/test/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManagerTest.java new file mode 100644 index 0000000000..90c493470a --- /dev/null +++ b/inspectit-ocelot-core/src/test/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManagerTest.java @@ -0,0 +1,86 @@ +package rocks.inspectit.ocelot.core.instrumentation.hook; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.util.ReflectionTestUtils; +import rocks.inspectit.ocelot.bootstrap.instrumentation.IMethodHook; +import rocks.inspectit.ocelot.bootstrap.instrumentation.noop.NoopMethodHook; +import rocks.inspectit.ocelot.core.instrumentation.config.InstrumentationConfigurationResolver; +import rocks.inspectit.ocelot.core.selfmonitoring.ActionScopeFactory; +import rocks.inspectit.ocelot.core.selfmonitoring.SelfMonitoringService; + +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +@ExtendWith(MockitoExtension.class) +public class HookManagerTest { + + @InjectMocks + private HookManager manager; + + @Mock + private InstrumentationConfigurationResolver configResolver; + + @Mock + private SelfMonitoringService selfMonitoring; + + @Mock + private MethodHookGenerator hookGenerator; + + @Nested + public class GetHook { + + @Test + public void hookNotExisting() { + IMethodHook result = manager.getHook(HookManagerTest.class, "stark"); + + assertThat(result).isSameAs(NoopMethodHook.INSTANCE); + } + + @Test + public void hookExisting() { + // create map with mock hook + MethodHook hook = MethodHook.builder().actionScopeFactory(mock(ActionScopeFactory.class)).build(); + Map methodHookMap = new HashMap<>(); + methodHookMap.put("lannister", hook); + Map, Map> hooks = new HashMap<>(); + hooks.put(HookManagerTest.class, methodHookMap); + + // inject map + ReflectionTestUtils.setField(manager, "hooks", hooks); + + IMethodHook result = manager.getHook(HookManagerTest.class, "lannister"); + + assertThat(result).isSameAs(hook); + } + + @Test + public void preventRecursion() { + // create map with mock hook + MethodHook hook = MethodHook.builder().actionScopeFactory(mock(ActionScopeFactory.class)).build(); + Map methodHookMap = new HashMap<>(); + methodHookMap.put("lannister", hook); + Map, Map> hooks = new HashMap<>(); + hooks.put(HookManagerTest.class, methodHookMap); + + // inject map + ReflectionTestUtils.setField(manager, "hooks", hooks); + + IMethodHook resultFirst = manager.getHook(HookManagerTest.class, "lannister"); + assertThat(resultFirst).isSameAs(hook); + + // set recursion gate + HookManager.RECURSION_GATE.set(true); + + IMethodHook resultSecond = manager.getHook(HookManagerTest.class, "lannister"); + assertThat(resultSecond).isSameAs(NoopMethodHook.INSTANCE); + } + } +} diff --git a/inspectit-ocelot-core/src/test/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHookTest.java b/inspectit-ocelot-core/src/test/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHookTest.java index b5402e98d3..db396f4e0a 100644 --- a/inspectit-ocelot-core/src/test/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHookTest.java +++ b/inspectit-ocelot-core/src/test/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHookTest.java @@ -1,6 +1,5 @@ package rocks.inspectit.ocelot.core.instrumentation.hook; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -16,6 +15,7 @@ import java.util.Arrays; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -34,16 +34,26 @@ public class MethodHookTest { @Mock private ActionScopeFactory actionScopeFactory; - @BeforeEach - void setupContextManagerMock() { - when(contextManager.enterNewContext()).thenReturn(context); - } - @Nested class OnEnter { + @Test + void ensureRecursionGateReset() { + // we provoke a NPE + MethodHook hook = MethodHook.builder().actionScopeFactory(mock(ActionScopeFactory.class)).build(); + + assertThat(HookManager.RECURSION_GATE.get()).isFalse(); + + // execute hook + assertThatNullPointerException().isThrownBy(() -> hook.onEnter(null, null)); + + assertThat(HookManager.RECURSION_GATE.get()).isFalse(); + } + @Test void testExceptionHandling() { + when(contextManager.enterNewContext()).thenReturn(context); + IHookAction first = Mockito.mock(IHookAction.class); IHookAction second = Mockito.mock(IHookAction.class); IHookAction third = Mockito.mock(IHookAction.class); @@ -83,6 +93,8 @@ void testExceptionHandling() { @Test void testReactivationOfActionsOnCopy() { + when(contextManager.enterNewContext()).thenReturn(context); + IHookAction action = Mockito.mock(IHookAction.class); doThrow(Error.class).when(action).execute(any()); MethodHook hook = MethodHook.builder() @@ -122,8 +134,23 @@ void testReactivationOfActionsOnCopy() { @Nested class OnExit { + @Test + void ensureRecursionGateReset() { + // we provoke a NPE + MethodHook hook = MethodHook.builder().actionScopeFactory(mock(ActionScopeFactory.class)).build(); + + assertThat(HookManager.RECURSION_GATE.get()).isFalse(); + + // execute hook + assertThatNullPointerException().isThrownBy(() -> hook.onExit(null, null, null, null, null)); + + assertThat(HookManager.RECURSION_GATE.get()).isFalse(); + } + @Test void testExceptionHandling() { + when(contextManager.enterNewContext()).thenReturn(context); + IHookAction first = Mockito.mock(IHookAction.class); IHookAction second = Mockito.mock(IHookAction.class); IHookAction third = Mockito.mock(IHookAction.class); @@ -157,6 +184,8 @@ void testExceptionHandling() { @Test void testReactivationOfActionsOnCopy() { + when(contextManager.enterNewContext()).thenReturn(context); + IHookAction action = Mockito.mock(IHookAction.class); doThrow(Error.class).when(action).execute(any()); MethodHook hook = MethodHook.builder() @@ -190,7 +219,5 @@ void testReactivationOfActionsOnCopy() { verify(actionScopeFactory, times(2)).createScope(action); verifyNoMoreInteractions(actionScopeFactory, action); } - } - } From e09bcfc7da3c9a50fcb5aa9cee7b2a665d93ee4c Mon Sep 17 00:00:00 2001 From: Heiko Holz Date: Tue, 25 Jan 2022 14:26:10 +0100 Subject: [PATCH 3/5] Fixed typo in HookManager comment --- .../inspectit/ocelot/core/instrumentation/hook/HookManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java index 2bad3baada..f7ffe67572 100644 --- a/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java +++ b/inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/HookManager.java @@ -32,7 +32,7 @@ public class HookManager { /** * Thread local flag for marking the current thread that it is currently in the execution/scope of agent actions. - * This is used to prevent a endless action recursion in case an instrumented action is invoked within another + * This is used to prevent an endless action recursion in case an instrumented action is invoked within another * action. In that case, the instrumentation has to be suppressed. */ public static final ThreadLocal RECURSION_GATE = ThreadLocal.withInitial(() -> false); From 233ed67ab662d8c850ca7eac237b0f18863de8d0 Mon Sep 17 00:00:00 2001 From: Marius Oehler Date: Wed, 16 Feb 2022 16:28:49 +0100 Subject: [PATCH 4/5] Adding system test to verify that stackoverflow errors are prevented --- .../hook/RecursionInstrumentation.java | 34 +++++++++++++++++++ .../config/recursiveInstrumentation.yml | 24 +++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/RecursionInstrumentation.java create mode 100644 inspectit-ocelot-agent/src/system-test/resources/config/recursiveInstrumentation.yml diff --git a/inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/RecursionInstrumentation.java b/inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/RecursionInstrumentation.java new file mode 100644 index 0000000000..0c23bb9dd3 --- /dev/null +++ b/inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/RecursionInstrumentation.java @@ -0,0 +1,34 @@ +package rocks.inspectit.ocelot.instrumentation.hook; + +import org.junit.jupiter.api.Test; +import rocks.inspectit.ocelot.instrumentation.InstrumentationSysTestBase; +import rocks.inspectit.ocelot.utils.TestUtils; + +import java.util.concurrent.atomic.AtomicInteger; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RecursionInstrumentation extends InstrumentationSysTestBase { + + private static AtomicInteger invocationCount = new AtomicInteger(0); + + /** + * This method is instrumentation and will be called in the instrumentation itself + * which would result in endless loop and StackOverflowError. + */ + public static void helloWorld() { + System.out.println("Hello World!"); + invocationCount.incrementAndGet(); + } + + @Test + public void recursiveInstrumentation() { + TestUtils.waitForClassInstrumentations(RecursionInstrumentation.class); + + helloWorld(); + + // two calls - one of the application and one (only!) due to the instrumentation + assertThat(invocationCount.get()).isEqualTo(2); + } + +} diff --git a/inspectit-ocelot-agent/src/system-test/resources/config/recursiveInstrumentation.yml b/inspectit-ocelot-agent/src/system-test/resources/config/recursiveInstrumentation.yml new file mode 100644 index 0000000000..0d6217dc0b --- /dev/null +++ b/inspectit-ocelot-agent/src/system-test/resources/config/recursiveInstrumentation.yml @@ -0,0 +1,24 @@ +# Configuration used in rocks.inspectit.ocelot.instrumentation.hook.RecursionInstrumentation +inspectit: + instrumentation: + actions: + 'a_recursive_helloWorld': + is-void: true + value-body: | + // Call instrumented method to provoke infinity loop + rocks.inspectit.ocelot.instrumentation.hook.RecursionInstrumentation.helloWorld(); + + scopes: + 's_RecursionInstrumentation_helloWorld': + type: + name: 'rocks.inspectit.ocelot.instrumentation.hook.RecursionInstrumentation' + methods: + - name: 'helloWorld' + + rules: + 'r_recursive_test': + scopes: + 's_RecursionInstrumentation_helloWorld': true + entry: + 'c_invoke_hello': + action: 'a_recursive_helloWorld' \ No newline at end of file From 18d9229f6607e1fa75b113f01d6a7e765171db20 Mon Sep 17 00:00:00 2001 From: Heiko Holz Date: Thu, 17 Feb 2022 13:27:56 +0100 Subject: [PATCH 5/5] #377: Refactoring RecursionInstrumentation.java to RecursionInstrumentationTest.java (and updating recursiveInstrumentation.yml) --- ...strumentation.java => RecursionInstrumentationTest.java} | 6 +++--- .../resources/config/recursiveInstrumentation.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/{RecursionInstrumentation.java => RecursionInstrumentationTest.java} (83%) diff --git a/inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/RecursionInstrumentation.java b/inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/RecursionInstrumentationTest.java similarity index 83% rename from inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/RecursionInstrumentation.java rename to inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/RecursionInstrumentationTest.java index 0c23bb9dd3..d4624aa37d 100644 --- a/inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/RecursionInstrumentation.java +++ b/inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/hook/RecursionInstrumentationTest.java @@ -8,12 +8,12 @@ import static org.assertj.core.api.Assertions.assertThat; -public class RecursionInstrumentation extends InstrumentationSysTestBase { +public class RecursionInstrumentationTest extends InstrumentationSysTestBase { private static AtomicInteger invocationCount = new AtomicInteger(0); /** - * This method is instrumentation and will be called in the instrumentation itself + * This method is instrumented and will be called in the instrumentation itself * which would result in endless loop and StackOverflowError. */ public static void helloWorld() { @@ -23,7 +23,7 @@ public static void helloWorld() { @Test public void recursiveInstrumentation() { - TestUtils.waitForClassInstrumentations(RecursionInstrumentation.class); + TestUtils.waitForClassInstrumentations(RecursionInstrumentationTest.class); helloWorld(); diff --git a/inspectit-ocelot-agent/src/system-test/resources/config/recursiveInstrumentation.yml b/inspectit-ocelot-agent/src/system-test/resources/config/recursiveInstrumentation.yml index 0d6217dc0b..768110d59d 100644 --- a/inspectit-ocelot-agent/src/system-test/resources/config/recursiveInstrumentation.yml +++ b/inspectit-ocelot-agent/src/system-test/resources/config/recursiveInstrumentation.yml @@ -6,12 +6,12 @@ inspectit: is-void: true value-body: | // Call instrumented method to provoke infinity loop - rocks.inspectit.ocelot.instrumentation.hook.RecursionInstrumentation.helloWorld(); + rocks.inspectit.ocelot.instrumentation.hook.RecursionInstrumentationTest.helloWorld(); scopes: 's_RecursionInstrumentation_helloWorld': type: - name: 'rocks.inspectit.ocelot.instrumentation.hook.RecursionInstrumentation' + name: 'rocks.inspectit.ocelot.instrumentation.hook.RecursionInstrumentationTest' methods: - name: 'helloWorld'