Skip to content

Commit

Permalink
perf testing: aligned with functionality from master
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed May 4, 2021
1 parent 60da00c commit 99cae57
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 65 deletions.
Expand Up @@ -8,6 +8,7 @@

import com.evolveum.midpoint.gui.api.component.MainObjectListPanel;

import com.evolveum.midpoint.tools.testng.PerformanceTestMethodMixin;
import com.evolveum.midpoint.web.page.admin.configuration.PageSystemConfiguration;

import com.evolveum.midpoint.web.page.admin.server.PageTasks;
Expand All @@ -29,7 +30,6 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.statistics.OperationsPerformanceInformationUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.tools.testng.PerformanceTestMixin;
import com.evolveum.midpoint.util.statistics.OperationsPerformanceMonitor;
import com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest;
import com.evolveum.midpoint.web.page.admin.home.PageDashboardInfo;
Expand All @@ -47,7 +47,7 @@
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@ActiveProfiles("test")
@SpringBootTest(classes = TestMidPointSpringApplication.class)
public class MidScaleGuiTest extends AbstractInitializedGuiIntegrationTest implements PerformanceTestMixin {
public class MidScaleGuiTest extends AbstractInitializedGuiIntegrationTest implements PerformanceTestMethodMixin {

private static final String TEST_DIR = "./src/test/resources/midScale";

Expand Down
Expand Up @@ -11,27 +11,30 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.jetbrains.annotations.NotNull;
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;
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.tools.testng.AbstractUnitTest;
import com.evolveum.midpoint.tools.testng.PerformanceTestClassMixin;
import com.evolveum.midpoint.util.CheckedProducer;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

public class AbstractSchemaPerformanceTest extends AbstractUnitTest {
public class AbstractSchemaPerformanceTest extends AbstractUnitTest implements PerformanceTestClassMixin {

protected static final String LABEL = "new-mapxnode";

Expand All @@ -40,7 +43,7 @@ public class AbstractSchemaPerformanceTest extends AbstractUnitTest {

public static final File RESULTS_FILE = new File("target/results.csv");

public static final int DEFAULT_EXECUTION = 3000;
public static final int DEFAULT_EXECUTION = 3;
public static final int DEFAULT_REPEATS = 5;
protected static final String NS_FOO = "http://www.example.com/foo";

Expand All @@ -54,6 +57,12 @@ public void setup() throws SchemaException, SAXException, IOException {
assert !InternalsConfig.isConsistencyChecks();
}

@BeforeClass
@Override
public void initTestMonitor() {
PerformanceTestClassMixin.super.initTestMonitor();
}

protected void measure(String label, CheckedProducer<?> producer) throws CommonException, IOException {
measure(label, producer, DEFAULT_EXECUTION, DEFAULT_REPEATS);
}
Expand Down
Expand Up @@ -6,7 +6,6 @@
*/
package com.evolveum.midpoint.test.util;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

Expand Down Expand Up @@ -37,11 +36,18 @@ public abstract class AbstractSpringTest extends AbstractTestNGSpringContextTest

private TestMonitor testMonitor;

// called only by tests that need it
public void initializeTestMonitor() {
/** Called only by tests that need it, implements performance mixin interface. */
public TestMonitor createTestMonitor() {
testMonitor = new TestMonitor();
return testMonitor;
}

/** Called only by tests that need it, implements performance mixin interface. */
public void destroyTestMonitor() {
testMonitor = null;
}

/** Called only by tests that need it, implements performance mixin interface. */
public TestMonitor testMonitor() {
return testMonitor;
}
Expand Down Expand Up @@ -90,14 +96,14 @@ 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.
*/
Expand Down
Expand Up @@ -21,7 +21,7 @@

import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.tools.testng.PerformanceTestMixin;
import com.evolveum.midpoint.tools.testng.PerformanceTestClassMixin;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand All @@ -38,7 +38,7 @@
@ContextConfiguration(locations = { "../../../../../ctx-test.xml" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class MidScaleRepoTest extends BaseSQLRepoTest
implements PerformanceTestMixin {
implements PerformanceTestClassMixin {

public static final int RESOURCE_COUNT = 10;
public static final int BASE_USER_COUNT = 1000;
Expand Down
Expand Up @@ -44,7 +44,7 @@
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.testing.story.AbstractStoryTest;
import com.evolveum.midpoint.tools.testng.PerformanceTestMixin;
import com.evolveum.midpoint.tools.testng.PerformanceTestClassMixin;
import com.evolveum.midpoint.tools.testng.TestReportSection;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand All @@ -59,7 +59,7 @@
@SuppressWarnings("BusyWait")
@ContextConfiguration(locations = { "classpath:ctx-story-test-main.xml" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class TestSystemPerformance extends AbstractStoryTest implements PerformanceTestMixin {
public class TestSystemPerformance extends AbstractStoryTest implements PerformanceTestClassMixin {

public static final File TEST_DIR = new File(MidPointTestConstants.TEST_RESOURCES_DIR, "system-perf");
static final File TARGET_DIR = new File(TARGET_DIR_PATH);
Expand Down
Expand Up @@ -25,11 +25,18 @@ public abstract class AbstractUnitTest implements MidpointTestMixin {

private TestMonitor testMonitor;

// called only by tests that need it
public void initializeTestMonitor() {
/** Called only by tests that need it, implements performance mixin interface. */
public TestMonitor createTestMonitor() {
testMonitor = new TestMonitor();
return testMonitor;
}

/** Called only by tests that need it, implements performance mixin interface. */
public void destroyTestMonitor() {
testMonitor = null;
}

/** Called only by tests that need it, implements performance mixin interface. */
public TestMonitor testMonitor() {
return testMonitor;
}
Expand Down
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2010-2020 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 com.google.common.base.Joiner;
import org.javasimon.Stopwatch;

/**
* Common mixin supporting work with {@link TestMonitor}, use one of the sub-interfaces based
* on the required scope measured by the test monitor (class or method).
* Test class (perhaps abstract superclass) must implement create/destroy/"get" methods,
* the rest should be taken care of by the lifecycle methods in sub-interfaces.
*/
public interface PerformanceTestCommonMixin extends MidpointTestMixin {

Joiner MONITOR_JOINER = Joiner.on(".");

/** Used for reporting at the end of the scope, but also for adding monitors by the test code. */
TestMonitor testMonitor();

/** Called after method or class, see sub-interfaces. */
TestMonitor createTestMonitor();

/** Implement, don't call, used by {@link #dumpReport}. */
void destroyTestMonitor();

/**
* Dumps the report and <b>"destroys" the test monitor</b> to allow its garbage collection.
* Otherwise if many test objects are part of the test runtime it can take a lot of memory.
* Called after method or class, see sub-interfaces.
*
* @param reportedTestName reported test name can be a class name or class+method name
* combination depending on the test monitor scope
*/
default void dumpReport(String reportedTestName) {
TestMonitor testMonitor = testMonitor();
testMonitor.dumpReport(reportedTestName);
destroyTestMonitor();
}

default Stopwatch stopwatch(String name, String description) {
return testMonitor().stopwatch(name, description);
}

/**
* Returns final name from name parts, joined with predefined character (yes, it's a dot).
*/
default String monitorName(String... nameParts) {
return MONITOR_JOINER.join(nameParts);
}
}
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2010-2020 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 java.lang.reflect.Method;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

/**
* Mixin supporting work with {@link TestMonitor} at the method-scope level
* (one test report for each test method).
* Details of setting of {@link TestMonitor} is up to the class, methods from
* {@link PerformanceTestCommonMixin} must be implemented.
*/
public interface PerformanceTestMethodMixin extends PerformanceTestCommonMixin {

@BeforeMethod
default void initTestMonitor() {
createTestMonitor();
}

@AfterMethod
default void dumpReport(Method method) {
dumpReport(getClass().getSimpleName() + "#" + method.getName());
}
}

This file was deleted.

0 comments on commit 99cae57

Please sign in to comment.