-
Notifications
You must be signed in to change notification settings - Fork 188
/
SqlRepoTestUtil.java
94 lines (84 loc) · 3.24 KB
/
SqlRepoTestUtil.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* 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.
*/
package com.evolveum.midpoint.repo.sql.testing;
import org.testng.AssertJUnit;
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) {
String error = checkVersionProgress(prevVersion, nextVersion);
if (error != null) {
AssertJUnit.fail(error);
}
}
public static String checkVersionProgress(String prevVersion, String nextVersion) {
String error = checkVersionProgressInternal(prevVersion, nextVersion);
if (error == null) {
return null;
}
return "Invalid version progress from '" + prevVersion + "' to '" + nextVersion + "': " + error;
}
private static String checkVersionProgressInternal(String prevVersion, String nextVersion) {
if (nextVersion == null) {
return "null next version";
}
if (prevVersion == null) {
// anything is OK
return null;
}
if (prevVersion.equals(nextVersion)) {
return "version are same";
}
int prevInt;
try {
prevInt = Integer.parseInt(prevVersion);
} catch (NumberFormatException e) {
return "previous version is not numeric";
}
int nextInt;
try {
nextInt = Integer.parseInt(nextVersion);
} catch (NumberFormatException e) {
return "next version is not numeric";
}
if (nextInt <= prevInt) {
return "wrong numeric order";
}
return null;
}
/**
* Returns report callback adding query section to the performance test report.
* Note that the section is NOT added if the count of queries is 0.
*/
public static TestMonitor.ReportCallback reportCallbackQuerySummary(
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());
};
}
/**
* Returns report callback adding detailed query dump section to the performance test report.
* Note that the section is NOT added if the count of queries is 0.
* This section is more for visual comparison/interpretation than for graphing.
*/
public static TestMonitor.ReportCallback reportCallbackQueryList(
TestQueryListener testQueryListener) {
return testMonitor -> {
if (testQueryListener.hasNoEntries()) {
return;
}
TestReportSection section = testMonitor.addRawReportSection("query-list");
testQueryListener.getEntries().forEach(e -> section.addRow(e.query));
};
}
}