]> source.dussan.org Git - sonarqube.git/commitdiff
Compute Engine - give context when failing to retrieve a snapshot
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 28 Oct 2014 15:11:44 +0000 (16:11 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 28 Oct 2014 15:24:57 +0000 (16:24 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/SwitchSnapshotStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/SwitchSnapshotStepTest.java
server/sonar-server/src/test/resources/org/sonar/server/computation/SwitchSnapshotStepTest/empty.xml [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java

index a1f3dbf79938d258f434ea67a0c1bc2a16de1d18..a078a77ee0b9b44e5221468288df8c4caa3b4367 100644 (file)
@@ -47,7 +47,13 @@ public class SwitchSnapshotStep implements ComputationStep {
   }
 
   private void disablePreviousSnapshot(DbSession session, AnalysisReportDto report) {
-    SnapshotDto referenceSnapshot = dao.getByKey(session, report.getSnapshotId());
+    SnapshotDto referenceSnapshot;
+
+    try {
+      referenceSnapshot = dao.getByKey(session, report.getSnapshotId());
+    } catch (Exception exception) {
+      throw new IllegalStateException(String.format("Unexpected error while trying to retrieve snapshot of analysis %s", report), exception);
+    }
 
     List<SnapshotDto> snapshots = dao.findSnapshotAndChildrenOfProjectScope(session, referenceSnapshot);
     for (SnapshotDto snapshot : snapshots) {
index e1f74f4cb19874274ac05265391fbc155e41d489..c07035e79751d88c74483701e4266e72329fff26 100644 (file)
@@ -65,4 +65,11 @@ public class SwitchSnapshotStepTest {
 
     db.assertDbUnit(getClass(), "snapshots-result.xml", "snapshots");
   }
+
+  @Test(expected = IllegalStateException.class)
+  public void throw_IllegalStateException_when_not_finding_snapshot() {
+    db.prepareDbUnit(getClass(), "empty.xml");
+
+    sut.execute(session, AnalysisReportDto.newForTests(1L).setSnapshotId(1L));
+  }
 }
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/SwitchSnapshotStepTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/SwitchSnapshotStepTest/empty.xml
new file mode 100644 (file)
index 0000000..871dedc
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+
+</dataset>
index 1491a1ae19c6e08d1fd8c3b25c2888565ff9a5f4..dd54bb2cb47d3ef8647ea422e3f642d60dd75035 100644 (file)
@@ -106,6 +106,7 @@ public class AnalysisReportDto extends Dto<String> {
     return Objects.toStringHelper(this)
       .add("id", getId())
       .add("projectKey", getProjectKey())
+      .add("snapshotId", getSnapshotId())
       .add("status", getStatus())
       .add("createdAt", getCreatedAt())
       .add("startedAt", getStartedAt())