Skip to content

Commit

Permalink
mid-scale perf-test support: added method-scope test
Browse files Browse the repository at this point in the history
To dump report after each test, implement PerformanceTestMethodMixin
instead of PerformanceTestClassMixin. Check AbstractIntegrationTest
to see how support methods should be implemented.
  • Loading branch information
virgo47 committed Dec 10, 2020
1 parent 0ed624f commit f4c4374
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 92 deletions.
Expand Up @@ -6,6 +6,8 @@
*/
package com.evolveum.midpoint.gui;

import java.io.File;

import org.javasimon.Split;
import org.javasimon.Stopwatch;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -23,7 +25,7 @@
import com.evolveum.midpoint.schema.statistics.AbstractStatisticsPrinter;
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.tools.testng.PerformanceTestMethodMixin;
import com.evolveum.midpoint.util.statistics.OperationsPerformanceMonitor;
import com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest;
import com.evolveum.midpoint.web.page.admin.home.PageDashboardInfo;
Expand All @@ -34,14 +36,15 @@
import com.evolveum.midpoint.web.page.self.PageSelfCredentials;
import com.evolveum.midpoint.web.page.self.PageSelfDashboard;
import com.evolveum.midpoint.web.page.self.PageUserSelfProfile;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import java.io.File;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AdminGuiConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationsPerformanceInformationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType;

@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 @@ -70,7 +73,6 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
ItemPath.create(SystemConfigurationType.F_ADMIN_GUI_CONFIGURATION, AdminGuiConfigurationType.F_ENABLE_EXPERIMENTAL_FEATURES),
initTask, initResult, true);


}

@BeforeMethod
Expand Down Expand Up @@ -102,16 +104,14 @@ public void test040PageRequestRole() {
runTestFor(PageAssignmentShoppingCart.class, "requestRole", "Request a role");
}


@Test
public void test110PageDashboard() {
displayTestTitle(getTestName());
runTestFor(PageDashboardInfo.class, "dashboard", "Info Dashboard");
}

private void runTestFor(Class pageToRender, String stopwathName, String stopwatchDescription) {
OperationsPerformanceMonitor.INSTANCE.clearGlobalPerformanceInformation();
Stopwatch stopwatch = stopwatch(stopwathName, stopwatchDescription);
private void runTestFor(Class pageToRender, String stopwatchName, String stopwatchDescription) {
Stopwatch stopwatch = stopwatch(stopwatchName, stopwatchDescription);
for (int i = 0; i < 1; i++) {
try (Split ignored = stopwatch.start()) {
queryListener.start();
Expand All @@ -130,7 +130,6 @@ private void runTestFor(Class pageToRender, String stopwathName, String stopwatc
new AbstractStatisticsPrinter.Options(AbstractStatisticsPrinter.Format.TEXT, AbstractStatisticsPrinter.SortBy.TIME), null, null));
}


@Test
public void test210listUsers() {
logger.info(getTestName());
Expand All @@ -153,7 +152,6 @@ public void test310orgTree() throws Exception {
@Test(enabled = false) // doesn't work because of getPageBase usages
public void test200sidebarMenu() {
logger.info(getTestName());
OperationsPerformanceMonitor.INSTANCE.clearGlobalPerformanceInformation();
Stopwatch stopwatch = stopwatch("sidebar", "sidebar perf");
try (Split ignored = stopwatch.start()) {
queryListener.start();
Expand Down
Expand Up @@ -27,10 +27,10 @@
import com.evolveum.midpoint.prism.PrismParser;
import com.evolveum.midpoint.prism.PrismSerializer;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.tools.testng.PerformanceTestMixin;
import com.evolveum.midpoint.tools.testng.PerformanceTestClassMixin;
import com.evolveum.midpoint.util.exception.SchemaException;

public class PerfTestCodecObject extends AbstractSchemaTest implements PerformanceTestMixin {
public class PerfTestCodecObject extends AbstractSchemaTest implements PerformanceTestClassMixin {

static final List<String> FORMAT = ImmutableList.of("xml", "json", "yaml");
static final List<String> NS = ImmutableList.of("no-ns", "ns");
Expand Down
Expand Up @@ -27,14 +27,14 @@
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.PerformanceTestMixin;
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 implements PerformanceTestMixin {
public class AbstractSchemaPerformanceTest extends AbstractUnitTest implements PerformanceTestClassMixin {

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

Expand Down Expand Up @@ -62,7 +62,7 @@ public void setup() throws SchemaException, SAXException, IOException {
@BeforeClass
@Override
public void initTestMonitor() {
PerformanceTestMixin.super.initTestMonitor();
PerformanceTestClassMixin.super.initTestMonitor();
}

protected void measure(String label, String note, CheckedProducer<?> producer) throws CommonException, IOException {
Expand Down Expand Up @@ -106,6 +106,6 @@ public PrismObject<UserType> getJack() throws SchemaException, IOException {
@AfterClass
@Override
public void dumpReport() {
PerformanceTestMixin.super.dumpReport();
PerformanceTestClassMixin.super.dumpReport();
}
}
Expand Up @@ -12,14 +12,14 @@
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
import com.evolveum.midpoint.prism.xnode.RootXNode;
import com.evolveum.midpoint.tools.testng.PerformanceTestMixin;
import com.evolveum.midpoint.tools.testng.PerformanceTestClassMixin;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.testng.annotations.Test;

import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext;

public class TestBasicPerformance extends AbstractSchemaPerformanceTest implements PerformanceTestMixin {
public class TestBasicPerformance extends AbstractSchemaPerformanceTest implements PerformanceTestClassMixin {

@Test
public void test010Dummy() throws Exception {
Expand Down
Expand Up @@ -39,11 +39,17 @@ 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 void createTestMonitor() {
testMonitor = new TestMonitor();
}

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

/** Called only by tests that need it, implements performance mixin interface. */
public TestMonitor testMonitor() {
return testMonitor;
}
Expand Down
Expand Up @@ -17,7 +17,11 @@

public class TestReportUtil {

public static void reportPerfData(TestMonitor testMonitor) {
/**
* Adds global performance information as a report section to the {@link TestMonitor}.
* Does not clear the data, do not forget to call clearing in the right life-cycle method.
*/
public static void reportGlobalPerfData(TestMonitor testMonitor) {
OperationsPerformanceInformationType performanceInformation =
OperationsPerformanceInformationUtil.toOperationsPerformanceInformationType(
OperationsPerformanceMonitor.INSTANCE.getGlobalPerformanceInformation());
Expand Down
Expand Up @@ -14,7 +14,6 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
Expand All @@ -32,7 +31,6 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeSuite;
import org.xml.sax.SAXException;
Expand All @@ -56,11 +54,11 @@
import com.evolveum.midpoint.repo.sql.data.common.embedded.REmbeddedReference;
import com.evolveum.midpoint.repo.sql.helpers.BaseHelper;
import com.evolveum.midpoint.repo.sql.helpers.JdbcSession;
import com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase;
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping;
import com.evolveum.midpoint.repo.sql.testing.TestQueryListener;
import com.evolveum.midpoint.repo.sql.util.HibernateToSqlTranslator;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping;
import com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
Expand All @@ -69,10 +67,13 @@
import com.evolveum.midpoint.test.util.InfraTestMixin;
import com.evolveum.midpoint.test.util.TestReportUtil;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.tools.testng.PerformanceTestCommonMixin;
import com.evolveum.midpoint.tools.testng.TestMonitor;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.statistics.OperationsPerformanceMonitor;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
Expand Down Expand Up @@ -150,7 +151,7 @@ public void initializeTestClass() throws Exception {
}

@AfterMethod
public void afterMethod(Method method) {
public void afterMethod() {
try {
Session session = factory.getCurrentSession();
if (session != null) {
Expand All @@ -163,11 +164,20 @@ public void afterMethod(Method method) {
}
}

@AfterClass
public void reportPerfData() {
if (testMonitor() != null) {
TestReportUtil.reportPerfData(testMonitor());
}
/** Called only by performance tests. */
@Override
public void createTestMonitor() {
super.createTestMonitor();
OperationsPerformanceMonitor.INSTANCE.clearGlobalPerformanceInformation();
}

/**
* Called only by performance tests, overrides {@link PerformanceTestCommonMixin#beforeDumpReport}.
* Data reported here should be reset in {@link #createTestMonitor()} so they don't accumulate
* in case of method-scoped monitor reports.
*/
public void beforeDumpReport(TestMonitor testMonitor) {
TestReportUtil.reportGlobalPerfData(testMonitor);
}

protected boolean isUsingH2() {
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 @@ -50,7 +50,6 @@
import org.testng.Assert;
import org.testng.AssertJUnit;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
Expand Down Expand Up @@ -112,8 +111,11 @@
import com.evolveum.midpoint.test.util.*;
import com.evolveum.midpoint.tools.testng.CurrentTestResultHolder;
import com.evolveum.midpoint.tools.testng.MidpointTestContext;
import com.evolveum.midpoint.tools.testng.PerformanceTestCommonMixin;
import com.evolveum.midpoint.tools.testng.TestMonitor;
import com.evolveum.midpoint.util.*;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.statistics.OperationsPerformanceMonitor;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
Expand Down Expand Up @@ -304,11 +306,20 @@ public void finishTestContext(ITestResult testResult) {
}
}

@AfterClass
public void reportPerfData() {
if (testMonitor() != null) {
TestReportUtil.reportPerfData(testMonitor());
}
/** Called only by performance tests. */
@Override
public void createTestMonitor() {
super.createTestMonitor();
OperationsPerformanceMonitor.INSTANCE.clearGlobalPerformanceInformation();
}

/**
* Called only by performance tests, overrides {@link PerformanceTestCommonMixin#beforeDumpReport}.
* Data reported here should be reset in {@link #createTestMonitor()} so they don't accumulate
* in case of method-scoped monitor reports.
*/
public void beforeDumpReport(TestMonitor testMonitor) {
TestReportUtil.reportGlobalPerfData(testMonitor);
}

protected TracingProfileType getTestMethodTracingProfile() {
Expand Down
Expand Up @@ -25,11 +25,17 @@ 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 void createTestMonitor() {
testMonitor = new TestMonitor();
}

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

/** Called only by tests that need it, implements performance mixin interface. */
public TestMonitor testMonitor() {
return testMonitor;
}
Expand Down
@@ -0,0 +1,29 @@
/*
* 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 org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

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

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

@AfterClass
default void dumpReport() {
dumpReport(getClass().getSimpleName());
}
}

0 comments on commit f4c4374

Please sign in to comment.