aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-10-02 23:07:53 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-10-03 12:27:37 +0200
commit07bb41d3a8489b5c8ff9a6c406030ef962c202ca (patch)
treef36728746303d0bfefa1888f7a37a5a9bbfab58b /server
parentc193d4deb5b7a1987e5e9531ff2c20d83e7c970b (diff)
downloadsonarqube-07bb41d3a8489b5c8ff9a6c406030ef962c202ca.tar.gz
sonarqube-07bb41d3a8489b5c8ff9a6c406030ef962c202ca.zip
Replace the CE class TypedException by an interface
so that a class inheriting MessageException can provide a type of error.
Diffstat (limited to 'server')
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java16
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/step/TypedException.java30
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/step/TypedExceptionTest.java54
3 files changed, 24 insertions, 76 deletions
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java
index 3626afc8a63..eb34e2cee5c 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java
@@ -242,7 +242,7 @@ public class InternalCeQueueImplTest {
@Test
public void remove_saves_error_when_TypedMessageException_is_provided() {
- Throwable error = new TypedException("aType", "aMessage");
+ Throwable error = new TypedExceptionImpl("aType", "aMessage");
CeTask task = submit(CeTaskTypes.REPORT, "PROJECT_1");
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1);
@@ -254,6 +254,20 @@ public class InternalCeQueueImplTest {
assertThat(activityDto.getErrorStacktrace()).isEqualToIgnoringWhitespace(stacktraceToString(error));
}
+ private static class TypedExceptionImpl extends RuntimeException implements TypedException {
+ private final String type;
+
+ private TypedExceptionImpl(String type, String message) {
+ super(message);
+ this.type = type;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+ }
+
@Test
public void remove_copies_executionCount_and_workerUuid() {
dbTester.getDbClient().ceQueueDao().insert(session, new CeQueueDto()
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/step/TypedException.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/step/TypedException.java
index fb1197a43d4..c2e7172427c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/step/TypedException.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/step/TypedException.java
@@ -19,27 +19,15 @@
*/
package org.sonar.server.computation.task.step;
-import static java.util.Objects.requireNonNull;
-
-public class TypedException extends RuntimeException {
-
- private final String type;
-
- public TypedException(String type, String message) {
- super(message);
- this.type = requireNonNull(type, "Type must not be null");
- }
+/**
+ * This interface is implemented by the exceptions
+ * that provide a type of error when failing
+ * a Compute Engine task.
+ * The error type is persisted and available in
+ * the tasks returned by the web services api/ce.
+ */
+public interface TypedException {
- public String getType() {
- return type;
- }
+ String getType();
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("[");
- sb.append("type='").append(type).append("',");
- sb.append("message='").append(getMessage()).append("'");
- sb.append(']');
- return sb.toString();
- }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/step/TypedExceptionTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/step/TypedExceptionTest.java
deleted file mode 100644
index 80dfe6cbadb..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/step/TypedExceptionTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.computation.task.step;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TypedExceptionTest {
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @Test
- public void should_create_exception() {
- TypedException exception = new TypedException("aType", "the message");
- assertThat(exception.getMessage()).isEqualTo("the message");
- assertThat(exception.getType()).isEqualTo("aType");
- }
-
- @Test
- public void test_toString() {
- TypedException exception = new TypedException("aType", "the message");
-
- assertThat(exception.toString()).isEqualTo("[type='aType',message='the message']");
- }
-
- @Test
- public void throw_NPE_if_type_is_null() {
- expectedException.expect(NullPointerException.class);
- expectedException.expectMessage("Type must not be null");
-
- new TypedException(null, "the message");
- }
-}