-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerformanceTests.java
67 lines (53 loc) · 1.94 KB
/
PerformanceTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package io.github.rieske.dbtest;
import io.github.rieske.dbtest.extension.DatabaseTestExtension;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.RepeatedTest;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
public abstract class PerformanceTests {
private final DatabaseTestExtension slowExtension;
private final DatabaseTestExtension fastExtension;
public PerformanceTests(DatabaseTestExtension slowExtension, DatabaseTestExtension fastExtension) {
this.slowExtension = slowExtension;
this.fastExtension = fastExtension;
}
@Nested
class SlowTests extends TestTemplate {
SlowTests() {
super(slowExtension);
}
}
@Nested
class FastTests extends TestTemplate {
FastTests() {
super(fastExtension);
}
}
abstract static class TestTemplate extends DatabaseTest {
private static final int REPETITIONS = 100;
TestTemplate(DatabaseTestExtension database) {
super(database);
}
@RepeatedTest(REPETITIONS)
void doNothing() {
}
@RepeatedTest(REPETITIONS)
void initDatabaseOnly() {
database.getDataSource();
}
@RepeatedTest(REPETITIONS)
void interactWithDatabase() {
UUID id = UUID.randomUUID();
String foo = UUID.randomUUID().toString();
executeUpdateSql("INSERT INTO some_table(id, foo) VALUES('" + id + "', '" + foo + "')");
int recordCount = getRecordCount();
assertThat(recordCount).isGreaterThanOrEqualTo(1);
executeQuerySql("SELECT * FROM some_table WHERE id='" + id + "'", rs -> {
assertThat(rs.next()).isTrue();
assertThat(UUID.fromString(rs.getString(1))).isEqualTo(id);
assertThat(rs.getString(2)).isEqualTo(foo);
return null;
});
}
}
}