diff --git a/infra/schema/src/test/java/com/evolveum/midpoint/schema/performance/AbstractSchemaPerformanceTest.java b/infra/schema/src/test/java/com/evolveum/midpoint/schema/performance/AbstractSchemaPerformanceTest.java index d72640979f9..3b79dc30711 100644 --- a/infra/schema/src/test/java/com/evolveum/midpoint/schema/performance/AbstractSchemaPerformanceTest.java +++ b/infra/schema/src/test/java/com/evolveum/midpoint/schema/performance/AbstractSchemaPerformanceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2018 Evolveum and contributors + * Copyright (C) 2010-2021 Evolveum and contributors * * This work is dual-licensed under the Apache License 2.0 * and European Union Public License. See LICENSE file for details. @@ -10,18 +10,17 @@ import java.io.File; import java.io.IOException; -import com.evolveum.midpoint.prism.impl.match.MatchingRuleRegistryFactory; -import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import org.javasimon.Split; import org.javasimon.Stopwatch; import org.jetbrains.annotations.NotNull; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeSuite; import org.xml.sax.SAXException; import com.evolveum.midpoint.prism.PrismObject; +import com.evolveum.midpoint.prism.impl.match.MatchingRuleRegistryFactory; +import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import com.evolveum.midpoint.prism.util.PrismTestUtil; import com.evolveum.midpoint.schema.MidPointPrismContextFactory; import com.evolveum.midpoint.schema.constants.MidPointConstants; @@ -34,7 +33,7 @@ import com.evolveum.midpoint.util.exception.SchemaException; import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType; -public abstract class AbstractSchemaPerformanceTest extends AbstractUnitTest implements PerformanceTestClassMixin { +public abstract class AbstractSchemaPerformanceTest extends AbstractUnitTest implements PerformanceTestClassMixin { protected static final String LABEL = "new-mapxnode"; @@ -102,10 +101,4 @@ protected double measureSingle(String label, CheckedProducer producer, long e public PrismObject getJack() throws SchemaException, IOException { return getPrismContext().parserFor(USER_JACK_FILE).parse(); } - - @AfterClass - @Override - public void dumpReport() { - PerformanceTestClassMixin.super.dumpReport(); - } } diff --git a/infra/test-util/src/main/java/com/evolveum/midpoint/test/util/AbstractSpringTest.java b/infra/test-util/src/main/java/com/evolveum/midpoint/test/util/AbstractSpringTest.java index 71a29dfc8a1..810ead8a432 100644 --- a/infra/test-util/src/main/java/com/evolveum/midpoint/test/util/AbstractSpringTest.java +++ b/infra/test-util/src/main/java/com/evolveum/midpoint/test/util/AbstractSpringTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2020 Evolveum and contributors + * Copyright (C) 2010-2021 Evolveum and contributors * * This work is dual-licensed under the Apache License 2.0 * and European Union Public License. See LICENSE file for details. @@ -17,10 +17,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; -import com.evolveum.midpoint.tools.testng.MidpointTestContext; -import com.evolveum.midpoint.tools.testng.MidpointTestMixin; -import com.evolveum.midpoint.tools.testng.SimpleMidpointTestContext; -import com.evolveum.midpoint.tools.testng.TestMonitor; +import com.evolveum.midpoint.tools.testng.*; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; @@ -65,6 +62,14 @@ public void displayTestClassFooter() { displayTestFooter("Finishing with TEST CLASS: " + getClass().getName()); } + // see the comment in PerformanceTestClassMixin for explanation + @AfterClass + public void dumpReport() { + if (this instanceof PerformanceTestClassMixin) { + ((PerformanceTestClassMixin) this).dumpReport(getClass().getSimpleName()); + } + } + @BeforeMethod public void startTestContext(ITestResult testResult) throws Exception { SimpleMidpointTestContext context = SimpleMidpointTestContext.create(testResult); @@ -91,18 +96,18 @@ public MidpointTestContext getTestContext() { /** * This method null all fields which are not static, final or primitive type. - *

+ * * All this is just to make GC work during DirtiesContext after every test class, * because test class instances are not GCed immediately. * If they hold autowired fields like sessionFactory (for example * through SqlRepositoryService impl), their memory footprint is getting big. * This can manifest as failed test initialization because of OOM in modules like model-intest. * Strangely, this will not fail the Jenkins build (but makes it much slower). - *

+ * * Note that this does not work for components injected through constructor into * final fields - if we need this cleanup, make the field non-final. */ - @AfterClass(alwaysRun = true) + @AfterClass(alwaysRun = true, dependsOnMethods = "dumpReport") protected void clearClassFields() throws Exception { logger.trace("Clearing all fields for test class {}", getClass().getName()); clearClassFields(this, getClass()); @@ -114,9 +119,7 @@ private void clearClassFields(Object object, Class forClass) throws Exception } for (Field field : forClass.getDeclaredFields()) { - // we need to skip testMonitor to have it non-null in PerformanceTestMixin#dumpReport - if (field.getName().equals("testMonitor") - || Modifier.isFinal(field.getModifiers()) + if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers()) || field.getType().isPrimitive()) { continue; diff --git a/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/AbstractUnitTest.java b/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/AbstractUnitTest.java index 25ead7f0b59..1c2188e8c37 100644 --- a/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/AbstractUnitTest.java +++ b/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/AbstractUnitTest.java @@ -51,6 +51,14 @@ public void displayTestClassFooter() { displayTestFooter("Finishing with TEST CLASS: " + getClass().getName()); } + // see the comment in PerformanceTestClassMixin for explanation + @AfterClass + public void dumpReport() { + if (this instanceof PerformanceTestClassMixin) { + ((PerformanceTestClassMixin) this).dumpReport(getClass().getSimpleName()); + } + } + @BeforeMethod public void startTestContext(ITestResult testResult) { SimpleMidpointTestContext context = SimpleMidpointTestContext.create(testResult); diff --git a/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/PerformanceTestClassMixin.java b/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/PerformanceTestClassMixin.java index 34aef7074f0..454b8b0c1d8 100644 --- a/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/PerformanceTestClassMixin.java +++ b/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/PerformanceTestClassMixin.java @@ -1,12 +1,11 @@ /* - * Copyright (C) 2010-2020 Evolveum and contributors + * Copyright (C) 2010-2021 Evolveum and contributors * * This work is dual-licensed under the Apache License 2.0 * and European Union Public License. See LICENSE file for details. */ package com.evolveum.midpoint.tools.testng; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; /** @@ -22,8 +21,10 @@ default void initTestMonitor() { createTestMonitor(); } - @AfterClass - default void dumpReport() { - dumpReport(getClass().getSimpleName()); - } + /* + * @AfterClass dumpReport() implemented in AbstractUnitTest and AbstractSpringTest. + * After-class method is implemented in both concrete classes with `instanceof` check, + * because if implemented here the method is called too late. + * This is not a problem for before-class method, so it stays here. + */ }