11package edu .harvard .iq .dataverse .export ;
22
3+ import edu .harvard .iq .dataverse .DataFile ;
4+ import edu .harvard .iq .dataverse .Dataset ;
35import edu .harvard .iq .dataverse .DatasetVersion ;
46import edu .harvard .iq .dataverse .db .performance .JpaTestBootstrap ;
57import edu .harvard .iq .dataverse .util .testing .Tags ;
8+ import edu .harvard .iq .dataverse .util .testing .fixtures .DatasetFixtureBuilder ;
9+ import edu .harvard .iq .dataverse .util .testing .recipes .DatasetRecipe ;
10+ import edu .harvard .iq .dataverse .util .testing .recipes .DatasetTypeRecipe ;
11+ import edu .harvard .iq .dataverse .util .testing .recipes .FileRecipe ;
12+ import edu .harvard .iq .dataverse .util .testing .recipes .VersionRecipe ;
13+ import net .ttddyy .dsproxy .QueryCount ;
14+ import net .ttddyy .dsproxy .QueryCountHolder ;
615import org .junit .jupiter .api .AfterAll ;
716import org .junit .jupiter .api .BeforeAll ;
817import org .junit .jupiter .api .Tag ;
918import org .junit .jupiter .api .Test ;
1019import org .testcontainers .junit .jupiter .Testcontainers ;
1120import org .testcontainers .postgresql .PostgreSQLContainer ;
1221
22+ import java .time .Instant ;
23+ import java .time .temporal .ChronoUnit ;
24+
1325import static org .junit .jupiter .api .Assertions .assertNotNull ;
1426import static org .junit .jupiter .api .Assumptions .assumeTrue ;
1527
@@ -21,15 +33,37 @@ class HugeDatasetExportPerformanceIT {
2133 static PostgreSQLContainer postgres = new PostgreSQLContainer ("postgres:16" );
2234 static JpaTestBootstrap jpa ;
2335
36+ static Dataset regularFilesDataset ;
37+
2438 @ BeforeAll
2539 static void setUp () {
2640 postgres .start ();
2741 jpa = new JpaTestBootstrap (postgres );
2842 jpa .start ();
2943
30- // TODO: run schema migration / load fixture here
44+ DatasetRecipe regularFiles = DatasetRecipe .of (
45+ DatasetTypeRecipe .dataset (),
46+ VersionRecipe .of (
47+ FileRecipe .regular (1000 )
48+ )
49+ );
3150
51+ // Build the fixture
52+ var regularFixture = DatasetFixtureBuilder .builder ().recipe (regularFiles ).build ();
3253
54+ // Some entities need to be present in the database to appropriatly let the ORM create the mappings
55+ jpa .inTransactionVoid (em -> em .persist (regularFixture .datasetType ()));
56+
57+ // Persist the actual dataset
58+ regularFilesDataset = regularFixture .dataset ();
59+ jpa .inTransactionVoid (em -> {
60+ // DataFile has no cascade path from Dataset, so each file must be persisted explicitly before
61+ // the dataset graph is flushed.
62+ for (DataFile dataFile : regularFixture .dataFiles ()) {
63+ em .persist (dataFile );
64+ }
65+ em .persist (regularFilesDataset );
66+ });
3367 }
3468
3569 @ AfterAll
@@ -42,16 +76,30 @@ static void tearDown() {
4276
4377 @ Test
4478 void shouldExportLargeDataset () {
45- Long datasetVersionId = 123L ;
79+ Long datasetVersionId = regularFilesDataset .getId ();
80+
81+ QueryCountHolder .clear ();
82+ Instant start = Instant .now ();
4683
4784 String json = jpa .inTransaction (em -> {
4885 var datasetVersion = em .find (DatasetVersion .class , datasetVersionId );
4986 assumeTrue (datasetVersion != null , "No dataset version available in DB. Check fixtures!" );
5087
5188 InternalExportDataProvider provider = new InternalExportDataProvider (datasetVersion );
52- return provider .getDatasetFileDetails ().toString ();
89+ var details = provider .getDatasetFileDetails ();
90+ return details .toString ();
5391 });
5492
5593 assertNotNull (json );
94+
95+ Instant end = Instant .now ();
96+
97+ QueryCount count = QueryCountHolder .getGrandTotal ();
98+ System .out .println ("Elapsed ms: " + start .until (end , ChronoUnit .MILLIS ));
99+ System .out .println ("Total queries: " + count .getTotal ());
100+ System .out .println ("Select queries: " + count .getSelect ());
101+ System .out .println ("Insert queries: " + count .getInsert ());
102+ System .out .println ("Update queries: " + count .getUpdate ());
103+ System .out .println ("Delete queries: " + count .getDelete ());
56104 }
57105}
0 commit comments