]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6834 refactor CeQueue.submit()
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 21 Sep 2015 17:10:15 +0000 (19:10 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 21 Sep 2015 17:10:15 +0000 (19:10 +0200)
14 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/CeQueue.java
server/sonar-server/src/main/java/org/sonar/server/computation/CeQueueImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/CeTask.java
server/sonar-server/src/main/java/org/sonar/server/computation/CeTaskSubmit.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/CeWorkerImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/ReportFiles.java
server/sonar-server/src/main/java/org/sonar/server/computation/ReportSubmitter.java
server/sonar-server/src/main/java/org/sonar/server/computation/TaskSubmission.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/CeQueueImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/CeWorkerImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/CleanReportQueueListenerTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/ReportSubmitterTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/TestTaskSubmission.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeSubmitWsActionTest.java

index fd8864b0fe38217c338cc0b334fbd110283e7b85..7669bda21245a6c957b7fe0c71cca75c2a328b84 100644 (file)
@@ -31,18 +31,18 @@ import org.sonar.db.ce.CeActivityDto;
  */
 public interface CeQueue {
   /**
-   * Build an instance of {@link TaskSubmission} required for {@link #submit(TaskSubmission)}. It allows
+   * Build an instance of {@link CeTaskSubmit} required for {@link #submit(CeTaskSubmit)}. It allows
    * to enforce that task ids are generated by the queue. It's used also for having access
    * to the id before submitting the task to the queue.
    */
-  TaskSubmission prepareSubmit();
+  CeTaskSubmit.Builder prepareSubmit();
 
   /**
    * Submits a task to the queue. The task is processed asynchronously.
    * If submits are paused (see {@link #isSubmitPaused()}, then an
    * unchecked exception is thrown.
    */
-  CeTask submit(TaskSubmission submission);
+  CeTask submit(CeTaskSubmit submission);
 
   /**
    * Peek the oldest task in status {@link org.sonar.db.ce.CeQueueDto.Status#PENDING}.
index dd4c8495503a74bd4d2e3c91fcad67ca5fac2c00..67cd61d6bd830824c03beaa6b2ba607a72b70e95 100644 (file)
@@ -20,9 +20,7 @@
 package org.sonar.server.computation;
 
 import com.google.common.base.Optional;
-import com.google.common.base.Strings;
 import java.util.concurrent.atomic.AtomicBoolean;
-import javax.annotation.Nullable;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactory;
@@ -30,9 +28,9 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeQueueDto;
+import org.sonar.db.component.ComponentDto;
 import org.sonar.server.computation.monitoring.CEQueueStatus;
 
-import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 import static java.lang.String.format;
 
@@ -59,41 +57,34 @@ public class CeQueueImpl implements CeQueue {
   }
 
   @Override
-  public TaskSubmission prepareSubmit() {
-    return new TaskSubmissionImpl(uuidFactory.create());
+  public CeTaskSubmit.Builder prepareSubmit() {
+    return new CeTaskSubmit.Builder(uuidFactory.create());
   }
 
   @Override
-  public CeTask submit(TaskSubmission submission) {
-    checkArgument(!Strings.isNullOrEmpty(submission.getUuid()));
-    checkArgument(!Strings.isNullOrEmpty(submission.getType()));
-    checkArgument(submission instanceof TaskSubmissionImpl);
+  public CeTask submit(CeTaskSubmit submission) {
     checkState(!submitPaused.get(), "Compute Engine does not currently accept new tasks");
 
-    CeTask task = new CeTask(submission);
     DbSession dbSession = dbClient.openSession(false);
     try {
-      CeQueueDto dto = createQueueDtoForSubmit(task);
+      CeQueueDto dto = new CeQueueDto();
+      dto.setUuid(submission.getUuid());
+      dto.setTaskType(submission.getType());
+      dto.setComponentUuid(submission.getComponentUuid());
+      dto.setStatus(CeQueueDto.Status.PENDING);
+      dto.setSubmitterLogin(submission.getSubmitterLogin());
+      dto.setStartedAt(null);
       dbClient.ceQueueDao().insert(dbSession, dto);
+      CeTask task = loadTask(dbSession, dto);
       dbSession.commit();
       queueStatus.addReceived();
       return task;
+
     } finally {
       dbClient.closeSession(dbSession);
     }
   }
 
-  private CeQueueDto createQueueDtoForSubmit(CeTask task) {
-    CeQueueDto dto = new CeQueueDto();
-    dto.setUuid(task.getUuid());
-    dto.setTaskType(task.getType());
-    dto.setComponentUuid(task.getComponentUuid());
-    dto.setStatus(CeQueueDto.Status.PENDING);
-    dto.setSubmitterLogin(task.getSubmitterLogin());
-    dto.setStartedAt(null);
-    return dto;
-  }
-
   @Override
   public Optional<CeTask> peek() {
     if (peekPaused.get()) {
@@ -104,8 +95,8 @@ public class CeQueueImpl implements CeQueue {
       Optional<CeQueueDto> dto = dbClient.ceQueueDao().peek(dbSession);
       CeTask task = null;
       if (dto.isPresent()) {
+        task = loadTask(dbSession, dto.get());
         queueStatus.addInProgress();
-        task = new CeTask(dto.get());
       }
       return Optional.fromNullable(task);
 
@@ -114,6 +105,23 @@ public class CeQueueImpl implements CeQueue {
     }
   }
 
+  private CeTask loadTask(DbSession dbSession, CeQueueDto dto) {
+    CeTask.Builder builder = new CeTask.Builder();
+    builder.setUuid(dto.getUuid());
+    builder.setType(dto.getTaskType());
+    builder.setSubmitterLogin(dto.getSubmitterLogin());
+    String componentUuid = dto.getComponentUuid();
+    if (componentUuid != null) {
+      builder.setComponentUuid(componentUuid);
+      Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
+      if (component.isPresent()) {
+        builder.setComponentKey(component.get().getKey());
+        builder.setComponentName(component.get().name());
+      }
+    }
+    return builder.build();
+  }
+
   @Override
   public boolean cancel(String taskUuid) {
     DbSession dbSession = dbClient.openSession(false);
@@ -131,9 +139,10 @@ public class CeQueueImpl implements CeQueue {
   }
 
   void cancel(DbSession dbSession, CeQueueDto q) {
+    CeTask task = loadTask(dbSession, q);
     CeActivityDto activityDto = new CeActivityDto(q);
     activityDto.setStatus(CeActivityDto.Status.CANCELED);
-    remove(dbSession, new CeTask(q), q, activityDto);
+    remove(dbSession, task, q, activityDto);
   }
 
   @Override
@@ -233,53 +242,4 @@ public class CeQueueImpl implements CeQueue {
   public boolean isPeekPaused() {
     return peekPaused.get();
   }
-
-  private static class TaskSubmissionImpl implements TaskSubmission {
-    private final String uuid;
-    private String type;
-    private String componentUuid;
-    private String submitterLogin;
-
-    private TaskSubmissionImpl(String uuid) {
-      this.uuid = uuid;
-    }
-
-    @Override
-    public String getUuid() {
-      return uuid;
-    }
-
-    @Override
-    public String getType() {
-      return type;
-    }
-
-    @Override
-    public TaskSubmission setType(@Nullable String s) {
-      this.type = s;
-      return this;
-    }
-
-    @Override
-    public String getComponentUuid() {
-      return componentUuid;
-    }
-
-    @Override
-    public TaskSubmission setComponentUuid(@Nullable String s) {
-      this.componentUuid = s;
-      return this;
-    }
-
-    @Override
-    public String getSubmitterLogin() {
-      return submitterLogin;
-    }
-
-    @Override
-    public TaskSubmission setSubmitterLogin(@Nullable String s) {
-      this.submitterLogin = s;
-      return this;
-    }
-  }
 }
index 172f5ba6c5a1610bc00b82e723d4ddda4b14b6b0..62ef351b83aa0142acfe9167abe74f6046b29e7a 100644 (file)
@@ -23,8 +23,8 @@ import com.google.common.base.Objects;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
-import org.sonar.db.ce.CeQueueDto;
 
+import static com.google.common.base.Strings.emptyToNull;
 import static java.util.Objects.requireNonNull;
 
 @Immutable
@@ -33,21 +33,17 @@ public class CeTask {
   private final String type;
   private final String uuid;
   private final String componentUuid;
+  private final String componentKey;
+  private final String componentName;
   private final String submitterLogin;
 
-  public CeTask(String uuid, String type, @Nullable String componentUuid, @Nullable String submitterLogin) {
-    this.uuid = requireNonNull(uuid);
-    this.type = requireNonNull(type);
-    this.componentUuid = componentUuid;
-    this.submitterLogin = submitterLogin;
-  }
-
-  CeTask(TaskSubmission submit) {
-    this(submit.getUuid(), submit.getType(), submit.getComponentUuid(), submit.getSubmitterLogin());
-  }
-
-  CeTask(CeQueueDto dto) {
-    this(dto.getUuid(), dto.getTaskType(), dto.getComponentUuid(), dto.getSubmitterLogin());
+  private CeTask(Builder builder) {
+    this.uuid = requireNonNull(emptyToNull(builder.uuid));
+    this.type = requireNonNull(emptyToNull(builder.type));
+    this.componentUuid = emptyToNull(builder.componentUuid);
+    this.componentKey = emptyToNull(builder.componentKey);
+    this.componentName = emptyToNull(builder.componentName);
+    this.submitterLogin = emptyToNull(builder.submitterLogin);
   }
 
   public String getUuid() {
@@ -63,6 +59,16 @@ public class CeTask {
     return componentUuid;
   }
 
+  @CheckForNull
+  public String getComponentKey() {
+    return componentKey;
+  }
+
+  @CheckForNull
+  public String getComponentName() {
+    return componentName;
+  }
+
   @CheckForNull
   public String getSubmitterLogin() {
     return submitterLogin;
@@ -94,4 +100,47 @@ public class CeTask {
   public int hashCode() {
     return uuid.hashCode();
   }
+
+  public static final class Builder {
+    private String uuid;
+    private String type;
+    private String componentUuid;
+    private String componentKey;
+    private String componentName;
+    private String submitterLogin;
+
+    public Builder setUuid(String uuid) {
+      this.uuid = uuid;
+      return this;
+    }
+
+    public Builder setType(String type) {
+      this.type = type;
+      return this;
+    }
+
+    public Builder setComponentUuid(String componentUuid) {
+      this.componentUuid = componentUuid;
+      return this;
+    }
+
+    public Builder setComponentKey(@Nullable String s) {
+      this.componentKey = s;
+      return this;
+    }
+
+    public Builder setComponentName(@Nullable String s) {
+      this.componentName = s;
+      return this;
+    }
+
+    public Builder setSubmitterLogin(@Nullable String s) {
+      this.submitterLogin = s;
+      return this;
+    }
+
+    public CeTask build() {
+      return new CeTask(this);
+    }
+  }
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/CeTaskSubmit.java b/server/sonar-server/src/main/java/org/sonar/server/computation/CeTaskSubmit.java
new file mode 100644 (file)
index 0000000..d7d21f4
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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;
+
+import java.util.Objects;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.Immutable;
+
+import static com.google.common.base.Strings.emptyToNull;
+
+@Immutable
+public final class CeTaskSubmit {
+
+  private final String uuid;
+  private final String type;
+  private final String componentUuid;
+  private final String submitterLogin;
+
+  private CeTaskSubmit(Builder builder) {
+    this.uuid = Objects.requireNonNull(emptyToNull(builder.uuid));
+    this.type = Objects.requireNonNull(emptyToNull(builder.type));
+    this.componentUuid = emptyToNull(builder.componentUuid);
+    this.submitterLogin = emptyToNull(builder.submitterLogin);
+  }
+
+  public String getType() {
+    return type;
+  }
+
+  public String getUuid() {
+    return uuid;
+  }
+
+  @CheckForNull
+  public String getComponentUuid() {
+    return componentUuid;
+  }
+
+  @CheckForNull
+  public String getSubmitterLogin() {
+    return submitterLogin;
+  }
+
+  public static final class Builder {
+    private final String uuid;
+    private String type;
+    private String componentUuid;
+    private String submitterLogin;
+
+    Builder(String uuid) {
+      this.uuid = uuid;
+    }
+
+    public String getUuid() {
+      return uuid;
+    }
+
+    public Builder setType(String s) {
+      this.type = s;
+      return this;
+    }
+
+    public Builder setComponentUuid(@Nullable String s) {
+      this.componentUuid = s;
+      return this;
+    }
+
+    public Builder setSubmitterLogin(@Nullable String s) {
+      this.submitterLogin = s;
+      return this;
+    }
+
+    public CeTaskSubmit build() {
+      return new CeTaskSubmit(this);
+    }
+  }
+}
index 3e2f8d29be19203231e42e64610fd9265380de07..c46d0a1f470e6116565fa3fe92c8e8e92596905b 100644 (file)
@@ -26,6 +26,8 @@ import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.util.logs.Profiler;
 import org.sonar.db.ce.CeActivityDto;
 
+import static java.lang.String.format;
+
 public class CeWorkerImpl implements CeWorker {
 
   private static final Logger LOG = Loggers.get(CeWorkerImpl.class);
@@ -40,7 +42,6 @@ public class CeWorkerImpl implements CeWorker {
 
   @Override
   public void run() {
-    Profiler profiler = Profiler.create(LOG).start();
     CeTask task;
     try {
       Optional<CeTask> taskOpt = queue.peek();
@@ -53,14 +54,17 @@ public class CeWorkerImpl implements CeWorker {
       return;
     }
 
+    // TODO delegate the message to the related task processor, according to task type
+    Profiler profiler = Profiler.create(LOG).startInfo(format("Analysis of project %s (report %s)", task.getComponentKey(), task.getUuid()));
     try {
       reportTaskProcessor.process(task);
       queue.remove(task, CeActivityDto.Status.SUCCESS);
     } catch (Throwable e) {
-      LOG.error(String.format("Failed to process task %s", task.getUuid()), e);
+      LOG.error(format("Failed to process task %s", task.getUuid()), e);
       queue.remove(task, CeActivityDto.Status.FAILED);
     } finally {
-      profiler.stopInfo(String.format("Total thread execution of project %s (report %s)", task.getComponentUuid(), task.getUuid()));
+
+      profiler.stopInfo();
     }
   }
 }
index a93fa71b4e53c5719f5080eab0d8c88805909d67..43067b71fee55982e2bc17f5549dcd9876d30acb 100644 (file)
@@ -45,8 +45,8 @@ public class ReportFiles {
     this.settings = settings;
   }
 
-  public void save(TaskSubmission taskSubmit, InputStream reportInput) {
-    File file = fileForUuid(taskSubmit.getUuid());
+  public void save(String taskUuid, InputStream reportInput) {
+    File file = fileForUuid(taskUuid);
     try {
       FileUtils.copyInputStreamToFile(reportInput, file);
     } catch (Exception e) {
index 4ec0abf3be146ac9a48231de5b7ef38069679ebb..bae1073871c053c71b1a297536f32076b1889587 100644 (file)
@@ -58,17 +58,17 @@ public class ReportSubmitter {
       NewComponent newProject = new NewComponent(projectKey, StringUtils.defaultIfBlank(projectName, projectKey));
       newProject.setBranch(projectBranch);
       newProject.setQualifier(Qualifiers.PROJECT);
-      // no need to verify the permission "provisionning" as it's already handled by componentService
+      // no need to verify the permission "provisioning" as it's already handled by componentService
       project = componentService.create(newProject);
     }
 
     // the report file must be saved before submitting the task
-    TaskSubmission submit = queue.prepareSubmit();
-    reportFiles.save(submit, reportInput);
+    CeTaskSubmit.Builder submit = queue.prepareSubmit();
+    reportFiles.save(submit.getUuid(), reportInput);
 
     submit.setType(CeTaskTypes.REPORT);
     submit.setComponentUuid(project.uuid());
     submit.setSubmitterLogin(userSession.getLogin());
-    return queue.submit(submit);
+    return queue.submit(submit.build());
   }
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/TaskSubmission.java b/server/sonar-server/src/main/java/org/sonar/server/computation/TaskSubmission.java
deleted file mode 100644 (file)
index 801bba9..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-public interface TaskSubmission {
-
-  String getUuid();
-
-  String getType();
-
-  TaskSubmission setType(String s);
-
-  @CheckForNull
-  String getComponentUuid();
-
-  TaskSubmission setComponentUuid(@Nullable String s);
-
-  @CheckForNull
-  String getSubmitterLogin();
-
-  TaskSubmission setSubmitterLogin(@Nullable String s);
-
-}
index a7b378a849bfb07556ed304ba68651d936598002..212cc4d044a9463ebc5545488f5313c33cc32ebb 100644 (file)
@@ -60,12 +60,12 @@ public class CeQueueImplTest {
 
   @Test
   public void test_submit() {
-    TaskSubmission submission = underTest.prepareSubmit();
+    CeTaskSubmit.Builder submission = underTest.prepareSubmit();
     submission.setComponentUuid("PROJECT_1");
     submission.setType(CeTaskTypes.REPORT);
     submission.setSubmitterLogin("rob");
 
-    CeTask task = underTest.submit(submission);
+    CeTask task = underTest.submit(submission.build());
     assertThat(task.getUuid()).isEqualTo(submission.getUuid());
     assertThat(task.getComponentUuid()).isEqualTo("PROJECT_1");
     assertThat(task.getSubmitterLogin()).isEqualTo("rob");
@@ -211,9 +211,9 @@ public class CeQueueImplTest {
   }
 
   private CeTask submit(String reportType, String componentUuid) {
-    TaskSubmission submission = underTest.prepareSubmit();
+    CeTaskSubmit.Builder submission = underTest.prepareSubmit();
     submission.setType(reportType);
     submission.setComponentUuid(componentUuid);
-    return underTest.submit(submission);
+    return underTest.submit(submission.build());
   }
 }
index cc33b0d81e8ae42eb814f5963c369e6a30d11748..5b484e02837580e3787fedb0b5ea9c4daa853e94 100644 (file)
@@ -47,7 +47,7 @@ public class CeWorkerImplTest {
 
   @Test
   public void peek_and_process_task() throws Exception {
-    CeTask task = new CeTask("TASK_1", CeTaskTypes.REPORT, "PROJECT_1", null);
+    CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin(null).build();
     when(queue.peek()).thenReturn(Optional.of(task));
 
     underTest.run();
@@ -58,7 +58,7 @@ public class CeWorkerImplTest {
 
   @Test
   public void fail_to_process_task() throws Exception {
-    CeTask task = new CeTask("TASK_1", CeTaskTypes.REPORT, "PROJECT_1", null);
+    CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin(null).build();
     when(queue.peek()).thenReturn(Optional.of(task));
     doThrow(new IllegalStateException()).when(taskProcessor).process(task);
 
index 0d6a631ba63ac139d1d49d86748fd14426aa533e..f87f16e60ba96398ada3507cf821ec07e2fbee8e 100644 (file)
@@ -33,7 +33,7 @@ public class CleanReportQueueListenerTest {
 
   @Test
   public void remove_report_file_if_success() {
-    CeTask task = new CeTask("TASK_1", CeTaskTypes.REPORT, "PROJECT_1", null);
+    CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin(null).build();
 
     underTest.onRemoved(task, CeActivityDto.Status.SUCCESS);
     verify(reportFiles).deleteIfExists("TASK_1");
@@ -41,7 +41,7 @@ public class CleanReportQueueListenerTest {
 
   @Test
   public void remove_report_file_if_failure() {
-    CeTask task = new CeTask("TASK_1", CeTaskTypes.REPORT, "PROJECT_1", null);
+    CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin(null).build();
 
     underTest.onRemoved(task, CeActivityDto.Status.FAILED);
     verify(reportFiles).deleteIfExists("TASK_1");
index 88b88f086b34863decab0fe8357acb8bcbba898d..4151a532fb148d344baede34311cd95900d6fa42 100644 (file)
@@ -49,15 +49,15 @@ public class ReportSubmitterTest {
 
   @Test
   public void submit_a_report_on_existing_project() {
-    when(queue.prepareSubmit()).thenReturn(new TestTaskSubmission("TASK_1"));
+    when(queue.prepareSubmit()).thenReturn(new CeTaskSubmit.Builder("TASK_1"));
     userSession.setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
     when(componentService.getNullableByKey("MY_PROJECT")).thenReturn(new ComponentDto().setUuid("P1"));
 
     underTest.submit("MY_PROJECT", null, "My Project", IOUtils.toInputStream("{binary}"));
 
-    verify(queue).submit(argThat(new TypeSafeMatcher<TaskSubmission>() {
+    verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {
       @Override
-      protected boolean matchesSafely(TaskSubmission submit) {
+      protected boolean matchesSafely(CeTaskSubmit submit) {
         return submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponentUuid().equals("P1") &&
           submit.getUuid().equals("TASK_1");
       }
@@ -71,16 +71,16 @@ public class ReportSubmitterTest {
 
   @Test
   public void provision_project_if_does_not_exist() throws Exception {
-    when(queue.prepareSubmit()).thenReturn(new TestTaskSubmission("TASK_1"));
+    when(queue.prepareSubmit()).thenReturn(new CeTaskSubmit.Builder("TASK_1"));
     userSession.setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION, GlobalPermissions.PROVISIONING);
     when(componentService.getNullableByKey("MY_PROJECT")).thenReturn(null);
     when(componentService.create(any(NewComponent.class))).thenReturn(new ComponentDto().setUuid("P1"));
 
     underTest.submit("MY_PROJECT", null, "My Project", IOUtils.toInputStream("{binary}"));
 
-    verify(queue).submit(argThat(new TypeSafeMatcher<TaskSubmission>() {
+    verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {
       @Override
-      protected boolean matchesSafely(TaskSubmission submit) {
+      protected boolean matchesSafely(CeTaskSubmit submit) {
         return submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponentUuid().equals("P1") &&
           submit.getUuid().equals("TASK_1");
       }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/TestTaskSubmission.java b/server/sonar-server/src/test/java/org/sonar/server/computation/TestTaskSubmission.java
deleted file mode 100644 (file)
index e4fe390..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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;
-
-import javax.annotation.Nullable;
-
-public class TestTaskSubmission implements TaskSubmission {
-  private final String uuid;
-  private String type;
-  private String componentUuid;
-  private String submitterLogin;
-
-  public TestTaskSubmission(String uuid) {
-    this.uuid = uuid;
-  }
-
-  @Override
-  public String getUuid() {
-    return uuid;
-  }
-
-  @Override
-  public String getType() {
-    return type;
-  }
-
-  @Override
-  public TaskSubmission setType(String s) {
-    this.type = s;
-    return this;
-  }
-
-  @Override
-  public String getComponentUuid() {
-    return componentUuid;
-  }
-
-  @Override
-  public TaskSubmission setComponentUuid(@Nullable String s) {
-    this.componentUuid = s;
-    return this;
-  }
-
-  @Override
-  public String getSubmitterLogin() {
-    return submitterLogin;
-  }
-
-  @Override
-  public TaskSubmission setSubmitterLogin(@Nullable String s) {
-    this.submitterLogin = s;
-    return this;
-  }
-}
index 01ead11b507d13cd5e699bb2403b4a8880dfa1d0..cfbb12b57ff56d4249ac7e98c2ca2c9141631db4 100644 (file)
@@ -47,7 +47,7 @@ public class CeSubmitWsActionTest {
 
   @Test
   public void submit_task_to_the_queue_and_ask_for_immediate_processing() {
-    CeTask task = new CeTask("TASK_1", CeTaskTypes.REPORT, "PROJECT_1", "robert");
+    CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin("robert").build();
     when(reportSubmitter.submit(eq("my_project"), Matchers.isNull(String.class), eq("My Project"), any(InputStream.class))).thenReturn(task);
 
     TestResponse wsResponse = tester.newRequest()
@@ -67,7 +67,7 @@ public class CeSubmitWsActionTest {
 
   @Test
   public void test_example_json_response() {
-    CeTask task = new CeTask("TASK_1", CeTaskTypes.REPORT, "PROJECT_1", "robert");
+    CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin("robert").build();
     when(reportSubmitter.submit(eq("my_project"), Matchers.isNull(String.class), eq("My Project"), any(InputStream.class))).thenReturn(task);
 
     TestResponse wsResponse = tester.newRequest()
@@ -86,7 +86,7 @@ public class CeSubmitWsActionTest {
    */
   @Test
   public void project_name_is_optional() {
-    CeTask task = new CeTask("TASK_1", CeTaskTypes.REPORT, "PROJECT_1", "robert");
+    CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin("robert").build();
     when(reportSubmitter.submit(eq("my_project"), Matchers.isNull(String.class), eq("my_project"), any(InputStream.class))).thenReturn(task);
 
     tester.newRequest()