From bd0ec5f4b739077d9422b81de47fd1222da6e94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E6=88=9F?= Date: Mon, 7 Dec 2020 23:26:18 +0800 Subject: [PATCH] reduce log reset frequency --- .../transformer/TestableClassTransformer.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java b/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java index 9b8f804..7a7eb1e 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java @@ -40,22 +40,24 @@ public class TestableClassTransformer implements ClassFileTransformer { // Ignore system class and reloaded class return null; } + byte[] bytes = null; try { if (shouldTransformAsSourceClass(className)) { // it's a source class with testable enabled LogUtil.diagnose("Handling source class %s", className); List injectMethods = getTestableMockMethods(ClassUtil.getTestClassName(className)); - return new SourceClassHandler(injectMethods).getBytes(classFileBuffer); + bytes = new SourceClassHandler(injectMethods).getBytes(classFileBuffer); + resetMockContext(); } else if (shouldTransformAsTestClass(className)) { // it's a test class with testable enabled LogUtil.diagnose("Handling test class %s", className); - return new TestClassHandler().getBytes(classFileBuffer); + bytes = new TestClassHandler().getBytes(classFileBuffer); + resetMockContext(); } - LogUtil.resetLogLevel(); } catch (IOException e) { - return null; + LogUtil.warn("Failed to transform class " + className); } - return null; + return bytes; } private boolean shouldTransformAsSourceClass(String className) { @@ -155,6 +157,10 @@ public class TestableClassTransformer implements ClassFileTransformer { } } + private void resetMockContext() { + LogUtil.resetLogLevel(); + } + /** * Split desc to "first parameter" and "desc of rest parameters" * @param desc method desc