@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);
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()
*/
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();
- }
}
+++ /dev/null
-/*
- * 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");
- }
-}