Skip to content

Commit 0a1817f

Browse files
authored
Merge pull request #12365 from IQSS/11405-optimize-huge-exports
Performance Testing Infrastructure Bits
2 parents f9f4afb + 36c9e93 commit 0a1817f

29 files changed

Lines changed: 2494 additions & 2 deletions

doc/sphinx-guides/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Sphinx==7.4.0
44
sphinx-icon==0.1.2
55

66
# Markdown support
7-
myst-parser==2.0.0
7+
myst-parser==4.0.0
88

99
# tabs
1010
sphinx-tabs==3.4.5
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package edu.harvard.iq.dataverse.somepackage;
2+
3+
import edu.harvard.iq.dataverse.util.testing.performance.JpaEntityManagerService;
4+
import edu.harvard.iq.dataverse.util.testing.performance.JpaPerformanceTest;
5+
import net.ttddyy.dsproxy.QueryCount;
6+
import net.ttddyy.dsproxy.QueryCountHolder;
7+
import org.junit.jupiter.api.BeforeAll;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.time.Instant;
11+
import java.time.temporal.ChronoUnit;
12+
import jakarta.persistence.EntityManager;
13+
14+
import static org.junit.jupiter.api.Assertions.assertNotNull;
15+
16+
// Single annotation for automatic setup of
17+
// 1) basic tags for JUnit groups,
18+
// 2) shared PostgreSQL server via Testcontainers, and
19+
// 3) creation and injection of JPA entity manager service.
20+
@JpaPerformanceTest
21+
class SamplePerformanceIT {
22+
23+
static JpaEntityManagerService jpa;
24+
25+
@BeforeAll
26+
static void setUp() {
27+
// A manual start is necessary to allow you to selectively enable service features as necessary
28+
jpa.start();
29+
30+
// inTransactionVoid: Use this when you only need to execute database operations
31+
// (e.g., persisting test fixtures) without returning a value.
32+
jpa.inTransactionVoid(em -> {
33+
// EntityManager em is provided here.
34+
// em.persist(myEntity);
35+
});
36+
}
37+
38+
@Test
39+
void shouldMeasureOperationPerformance() {
40+
// Clear any previous query statistics
41+
QueryCountHolder.clear();
42+
Instant start = Instant.now();
43+
44+
// inTransaction: Use this when your operation returns a result that needs
45+
// to be asserted or measured.
46+
Object result = jpa.inTransaction(em -> {
47+
// Execute your performance-critical operation using the EntityManager.
48+
// return result;
49+
return null; // Placeholder
50+
});
51+
52+
Instant end = Instant.now();
53+
assertNotNull(result);
54+
55+
// Retrieve and log ORM statistics
56+
QueryCount count = QueryCountHolder.getGrandTotal();
57+
System.out.println("Elapsed ms: " + start.until(end, ChronoUnit.MILLIS));
58+
System.out.println("Total queries: " + count.getTotal());
59+
System.out.println("Select queries: " + count.getSelect());
60+
System.out.println("Insert queries: " + count.getInsert());
61+
System.out.println("Update queries: " + count.getUpdate());
62+
System.out.println("Delete queries: " + count.getDelete());
63+
}
64+
}

doc/sphinx-guides/source/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
templates_path = ['_templates']
5555

5656
# The suffix of source filenames.
57-
source_suffix = '.rst'
57+
source_suffix = {
58+
".rst": "restructuredtext",
59+
".md": "markdown",
60+
}
5861

5962
# The encoding of source files.
6063
#source_encoding = 'utf-8-sig'

doc/sphinx-guides/source/developers/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ Developer Guide
4646
fontcustom
4747
classic-dev-env
4848
search-services
49+
testing/fixtures.md
50+
testing/performance.md
4951

0 commit comments

Comments
 (0)