Skip to content

Commit

Permalink
perf-test-support: added missing features/hooks+queries from master
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed May 14, 2021
1 parent 1942c35 commit a63e02d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 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 @@ -9,10 +9,9 @@

import org.testng.AssertJUnit;

/**
* @author semancik
*
*/
import com.evolveum.midpoint.tools.testng.TestMonitor;
import com.evolveum.midpoint.tools.testng.TestReportSection;

public class SqlRepoTestUtil {

public static void assertVersionProgress(String prevVersion, String nextVersion) {
Expand All @@ -27,7 +26,7 @@ public static String checkVersionProgress(String prevVersion, String nextVersion
if (error == null) {
return null;
}
return "Invalid version progress from '"+prevVersion+"' to '"+nextVersion+"': "+error;
return "Invalid version progress from '" + prevVersion + "' to '" + nextVersion + "': " + error;
}

private static String checkVersionProgressInternal(String prevVersion, String nextVersion) {
Expand Down Expand Up @@ -59,4 +58,20 @@ private static String checkVersionProgressInternal(String prevVersion, String ne
return null;
}

/**
* Returns report callback effectively wrapping around "this" at the moment the callback is created.
* Note that the section is NOT added if the count of queries is 0.
*/
public static TestMonitor.ReportCallback createReportCallback(TestQueryListener testQueryListener) {
return testMonitor -> {
if (testQueryListener.hasNoEntries()) {
return;
}

TestReportSection section = testMonitor.addReportSection("query")
.withColumns("metric", "count");
section.addRow("query-count", testQueryListener.getQueryCount());
section.addRow("execution-count", testQueryListener.getExecutionCount());
};
}
}
@@ -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 @@ -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 @@ -58,6 +56,7 @@
import com.evolveum.midpoint.repo.sql.helpers.JdbcSession;
import com.evolveum.midpoint.repo.sql.pure.FlexibleRelationalPathBase;
import com.evolveum.midpoint.repo.sql.pure.mapping.QueryModelMapping;
import com.evolveum.midpoint.repo.sql.testing.SqlRepoTestUtil;
import com.evolveum.midpoint.repo.sql.testing.TestQueryListener;
import com.evolveum.midpoint.repo.sql.util.HibernateToSqlTranslator;
import com.evolveum.midpoint.repo.sql.util.RUtil;
Expand All @@ -69,10 +68,12 @@
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.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,14 @@ public void afterMethod(Method method) {
}
}

@AfterClass
public void reportPerfData() {
if (testMonitor() != null) {
TestReportUtil.reportPerfData(testMonitor());
}
/** Called only by performance tests. */
@Override
public TestMonitor createTestMonitor() {
OperationsPerformanceMonitor.INSTANCE.clearGlobalPerformanceInformation();
queryListener.clear();
return super.createTestMonitor()
.addReportCallback(TestReportUtil::reportPerfData)
.addReportCallback(SqlRepoTestUtil.createReportCallback(queryListener));
}

protected boolean isUsingH2() {
Expand Down
5 changes: 5 additions & 0 deletions repo/repo-test-util/pom.xml
Expand Up @@ -85,6 +85,11 @@
<artifactId>util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>repo-sql-impl-test</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
Expand Down
@@ -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 Down Expand Up @@ -49,7 +49,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 @@ -83,6 +82,8 @@
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.repo.api.RepoAddOptions;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.sql.testing.SqlRepoTestUtil;
import com.evolveum.midpoint.repo.sql.testing.TestQueryListener;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.constants.ConnectorTestOperation;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
Expand Down Expand Up @@ -111,8 +112,10 @@
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.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 @@ -171,6 +174,7 @@ public abstract class AbstractIntegrationTest extends AbstractSpringTest
@Autowired protected SchemaHelper schemaHelper;
@Autowired protected MatchingRuleRegistry matchingRuleRegistry;
@Autowired protected LocalizationService localizationService;
@Autowired protected TestQueryListener queryListener;

@Autowired(required = false)
@Qualifier("repoSimpleObjectResolver")
Expand Down Expand Up @@ -303,11 +307,15 @@ public void finishTestContext(ITestResult testResult) {
}
}

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

return super.createTestMonitor()
.addReportCallback(TestReportUtil::reportPerfData)
.addReportCallback(SqlRepoTestUtil.createReportCallback(queryListener));
}

protected TracingProfileType getTestMethodTracingProfile() {
Expand Down

0 comments on commit a63e02d

Please sign in to comment.