aboutsummaryrefslogtreecommitdiffstats
path: root/ut-monitoring
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2021-11-17 22:54:06 +0100
committersonartech <sonartech@sonarsource.com>2021-11-19 20:03:27 +0000
commita3d88ea27c35921647d7602755828ca73e15e865 (patch)
tree5626c38afab1ea00ab9897da431476c17b478bbe /ut-monitoring
parent92f482f2aa43e4aa36e0fda377d13b9dc3282ff9 (diff)
downloadsonarqube-a3d88ea27c35921647d7602755828ca73e15e865.tar.gz
sonarqube-a3d88ea27c35921647d7602755828ca73e15e865.zip
SONAR-15631 - Refactor UTs to stop using ExpectedException
Diffstat (limited to 'ut-monitoring')
-rw-r--r--ut-monitoring/src/main/java/org/sonarqube/ut/aspects/AspectAssistant.java27
1 files changed, 15 insertions, 12 deletions
diff --git a/ut-monitoring/src/main/java/org/sonarqube/ut/aspects/AspectAssistant.java b/ut-monitoring/src/main/java/org/sonarqube/ut/aspects/AspectAssistant.java
index 26007ee0599..6fbc91b4e44 100644
--- a/ut-monitoring/src/main/java/org/sonarqube/ut/aspects/AspectAssistant.java
+++ b/ut-monitoring/src/main/java/org/sonarqube/ut/aspects/AspectAssistant.java
@@ -42,7 +42,6 @@ public class AspectAssistant {
private static final Path PATH = Paths.get("/tmp/ut-backend-monitoring.log");
private static final Gson GSON = new Gson();
-
static {
try {
if (!Files.exists(PATH, LinkOption.NOFOLLOW_LINKS)) {
@@ -62,25 +61,29 @@ public class AspectAssistant {
}
public static Object measure(ProceedingJoinPoint jp, Consumer<Measure> populator) throws Throwable {
- try {
long start = System.currentTimeMillis();
- Object proceed = jp.proceed();
+ try {
+ Object proceed = jp.proceed();
+ getMeasure(populator, start);
+ return proceed;
+ } catch (Throwable t) {
+ getMeasure(populator, start);
+ throw t;
+ }
+ }
+
+ private static void getMeasure(Consumer<Measure> populator, long start) {
long executionTime = System.currentTimeMillis() - start;
if (executionTime > 0) {
Measure measure = new Measure()
- .setDuration(executionTime)
- .setCommit(COMMIT_HASH)
- .setBuild(BUILD_NUMBER)
- .setTimestamp(LocalDateTime.now(ZoneId.of("UTC")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
+ .setDuration(executionTime)
+ .setCommit(COMMIT_HASH)
+ .setBuild(BUILD_NUMBER)
+ .setTimestamp(LocalDateTime.now(ZoneId.of("UTC")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
populator.accept(measure);
AspectAssistant.persistMeasure(measure);
}
- return proceed; }
- catch (Throwable t) {
- System.out.println(t.getMessage());
- return null;
- }
}
}