Skip to content

Commit

Permalink
perf testing: fixed @afterclass dumpReport timing
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed May 4, 2021
1 parent e54f48c commit 33c4bd8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
@@ -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.
Expand All @@ -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;
Expand All @@ -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";

Expand Down Expand Up @@ -102,10 +101,4 @@ protected double measureSingle(String label, CheckedProducer<?> producer, long e
public PrismObject<UserType> getJack() throws SchemaException, IOException {
return getPrismContext().parserFor(USER_JACK_FILE).parse();
}

@AfterClass
@Override
public void dumpReport() {
PerformanceTestClassMixin.super.dumpReport();
}
}
@@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -91,18 +96,18 @@ public MidpointTestContext getTestContext() {

/**
* This method null all fields which are not static, final or primitive type.
* <p>
*
* 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).
* <p>
*
* 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());
Expand All @@ -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;
Expand Down
Expand Up @@ -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);
Expand Down
@@ -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;

/**
Expand All @@ -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.
*/
}

0 comments on commit 33c4bd8

Please sign in to comment.