diff options
author | Klaudio Sinani <klaudio.sinani@sonarsource.com> | 2021-11-17 22:54:06 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-11-19 20:03:27 +0000 |
commit | a3d88ea27c35921647d7602755828ca73e15e865 (patch) | |
tree | 5626c38afab1ea00ab9897da431476c17b478bbe /ut-monitoring | |
parent | 92f482f2aa43e4aa36e0fda377d13b9dc3282ff9 (diff) | |
download | sonarqube-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.java | 27 |
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; - } } } |