diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2014-10-08 16:49:33 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2014-10-08 17:41:54 +0200 |
commit | 147f8281bec1af2d3e3594e69b9816af61d88fe0 (patch) | |
tree | dd26cd4ba9b2f9b7d5538785e6b112239818eaa9 | |
parent | fac42bff8871befc994f1efd5cb8e6c803f44283 (diff) | |
download | sonarqube-147f8281bec1af2d3e3594e69b9816af61d88fe0.tar.gz sonarqube-147f8281bec1af2d3e3594e69b9816af61d88fe0.zip |
SONAR-5626: Refactor and test task/thread management. Analyze report
16 files changed, 271 insertions, 55 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/UploadReportAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/UploadReportAction.java index d68a28ff31a..e600326edb6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/batch/UploadReportAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/UploadReportAction.java @@ -24,6 +24,8 @@ import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.RequestHandler; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; +import org.sonar.server.computation.AnalysisReportTask; +import org.sonar.server.computation.AnalysisReportTaskLauncher; import org.sonar.server.computation.ComputationService; public class UploadReportAction implements RequestHandler { @@ -33,9 +35,11 @@ public class UploadReportAction implements RequestHandler { static final String PARAM_PROJECT = "project"; private final ComputationService computationService; + private final AnalysisReportTaskLauncher analysisTaskLauncher; - public UploadReportAction(ComputationService computationService) { + public UploadReportAction(ComputationService computationService, AnalysisReportTaskLauncher analysisTaskLauncher) { this.computationService = computationService; + this.analysisTaskLauncher = analysisTaskLauncher; } void define(WebService.NewController controller) { @@ -57,7 +61,11 @@ public class UploadReportAction implements RequestHandler { public void handle(Request request, Response response) throws Exception { String projectKey = request.mandatoryParam(PARAM_PROJECT); - computationService.create(projectKey); - } + computationService.addAnalysisReport(projectKey); + + // TODO remove synchronization as soon as it won't break ITs ! + (new AnalysisReportTask(computationService)).run(); + analysisTaskLauncher.startAnalysisTaskNow(); + } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportTask.java b/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportTask.java index 24eb04f9d39..64349a575bd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportTask.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportTask.java @@ -22,37 +22,19 @@ package org.sonar.server.computation; import org.sonar.core.computation.db.AnalysisReportDto; -import java.util.concurrent.TimeUnit; - -public class AnalysisReportTask extends Thread { - private static final String TASK_NAME = "AnalysisReportTask"; - private static final int SLEEP_DURATION_IN_SECONDS = 10; +public class AnalysisReportTask implements Runnable { private final ComputationService service; - // TODO to improve – the computationService singleton should be retrieved directly in the pico container public AnalysisReportTask(ComputationService service) { - super(TASK_NAME); this.service = service; } @Override public void run() { - while (!this.isInterrupted()) { - AnalysisReportDto report = service.findAndBookNextAvailableAnalysisReport(); - if (report == null) { - sleepBeforeNextAttempt(); - } else { - service.analyzeReport(report); - } - } - } - - private void sleepBeforeNextAttempt() { - try { - TimeUnit.SECONDS.sleep(SLEEP_DURATION_IN_SECONDS); - } catch (InterruptedException e) { - // thread interrupted while sleeping, no action needed + AnalysisReportDto report = service.findAndBookNextAvailableAnalysisReport(); + if (report != null) { + service.analyzeReport(report); } } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportTaskLauncher.java b/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportTaskLauncher.java index 06f07eda815..3283b159b52 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportTaskLauncher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportTaskLauncher.java @@ -20,28 +20,58 @@ package org.sonar.server.computation; +import com.google.common.annotations.VisibleForTesting; import org.picocontainer.Startable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sonar.api.ServerComponent; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + public class AnalysisReportTaskLauncher implements Startable, ServerComponent { + private final Logger LOG = LoggerFactory.getLogger(AnalysisReportTaskLauncher.class); private final ComputationService service; + private final ScheduledExecutorService executorService; - private AnalysisReportTask task; + private final long delayBetweenTasks; + private final long delayForFirstStart; + private final TimeUnit timeUnit; public AnalysisReportTaskLauncher(ComputationService service) { this.service = service; + this.executorService = Executors.newSingleThreadScheduledExecutor(); + + this.delayBetweenTasks = 10; + this.delayForFirstStart = 0; + this.timeUnit = TimeUnit.SECONDS; + } + + @VisibleForTesting + AnalysisReportTaskLauncher(ComputationService service, long delayForFirstStart, long delayBetweenTasks, TimeUnit timeUnit) { + this.executorService = Executors.newSingleThreadScheduledExecutor(); + + this.delayBetweenTasks = delayBetweenTasks; + this.delayForFirstStart = delayForFirstStart; + this.timeUnit = timeUnit; + this.service = service; } @Override public void start() { - task = new AnalysisReportTask(service); - task.start(); + executorService.scheduleAtFixedRate(new AnalysisReportTask(service), delayForFirstStart, delayBetweenTasks, timeUnit); + LOG.info("AnalysisReportTaskLauncher started"); } @Override public void stop() { - task.interrupt(); + executorService.shutdown(); + LOG.info("AnalysisReportTaskLauncher stopped"); } + public void startAnalysisTaskNow() { + executorService.execute(new AnalysisReportTask(service)); + } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java index b4a800e6d9d..3ab613cdf6c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java @@ -60,7 +60,7 @@ public class ComputationService implements ServerComponent { this.permissionService = permissionService; } - public void create(String projectKey) { + public void addAnalysisReport(String projectKey) { UserSession.get().checkGlobalPermission(GlobalPermissions.SCAN_EXECUTION); AnalysisReportDto report = newPendingAnalysisReport(projectKey); @@ -68,17 +68,18 @@ public class ComputationService implements ServerComponent { DbSession session = dbClient.openSession(false); try { checkThatProjectExistsInDatabase(projectKey, session); - dao.insert(session, report); - session.commit(); - - analyzeReport(report); - + insertReportInDatabase(report, session); } finally { LOG.debug(String.format("Analysis for project '%s' inserted in the queue", projectKey)); MyBatis.closeQuietly(session); } } + private void insertReportInDatabase(AnalysisReportDto report, DbSession session) { + dao.insert(session, report); + session.commit(); + } + private void checkThatProjectExistsInDatabase(String projectKey, DbSession session) { dbClient.componentDao().getAuthorizedComponentByKey(projectKey, session); } @@ -111,10 +112,6 @@ public class ComputationService implements ServerComponent { AnalysisReportDto report = dao.tryToBookReportAnalysis(session, nextAvailableReport); session.commit(); - if (report != null) { // TODO TBE remove asap ! - analyzeReport(report); - } - return report; } finally { MyBatis.closeQuietly(session); @@ -132,9 +129,16 @@ public class ComputationService implements ServerComponent { } catch (Exception exception) { LOG.debug(String.format("Error during analysis '%s' of project '%s'", report.getId(), projectKey), exception); } finally { + deleteReportFromQueue(session, report); MyBatis.closeQuietly(session); - LOG.debug(String.format("Analysis '%s' of project '%s' finished.", report.getId(), projectKey)); } + + LOG.debug(String.format("Analysis '%s' of project '%s' successfully finished.", report.getId(), projectKey)); + } + + private void deleteReportFromQueue(DbSession session, AnalysisReportDto report) { + dao.delete(session, report); + session.commit(); } private void indexProjectIssues(DbSession session, String projectKey) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java b/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java index 3a82846e751..200c36f7596 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java @@ -29,6 +29,7 @@ import org.sonar.core.persistence.DbSession; import org.sonar.server.db.BaseDao; import javax.annotation.CheckForNull; + import java.util.Date; import java.util.List; import java.util.Map; @@ -123,4 +124,9 @@ public class AnalysisReportDao extends BaseDao<AnalysisReportMapper, AnalysisRep protected Map<String, Object> getSynchronizationParams(Date date, Map<String, String> params) { throw new UnsupportedOperationException(); } + + @Override + protected void doDeleteByKey(DbSession session, String id) { + mapper(session).delete(Long.valueOf(id)); + } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java index e0c9d3680da..2a917a3c4ad 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java @@ -86,6 +86,7 @@ import org.sonar.server.component.db.ComponentDao; import org.sonar.server.component.db.SnapshotDao; import org.sonar.server.component.ws.*; import org.sonar.server.computation.AnalysisReportTaskCleaner; +import org.sonar.server.computation.AnalysisReportTaskLauncher; import org.sonar.server.computation.ComputationService; import org.sonar.server.computation.db.AnalysisReportDao; import org.sonar.server.config.ws.PropertiesWs; @@ -588,6 +589,7 @@ class ServerComponents { // Compute engine pico.addSingleton(ComputationService.class); + pico.addSingleton(AnalysisReportTaskLauncher.class); for (Object components : level4AddedComponents) { pico.addSingleton(components); diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java index 7bc6cde5e52..709b1f762ca 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java @@ -30,6 +30,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.sonar.api.resources.Languages; import org.sonar.core.properties.PropertiesDao; +import org.sonar.server.computation.AnalysisReportTaskLauncher; import org.sonar.server.computation.ComputationService; import org.sonar.server.db.DbClient; import org.sonar.server.qualityprofile.QProfileFactory; @@ -61,10 +62,10 @@ public class BatchWsTest { @Before public void before() throws IOException { tester = new WsTester(new BatchWs(batchIndex, - new GlobalReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class)), - new ProjectReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class), mock(QProfileFactory.class), mock(QProfileLoader.class), mock(RuleService.class), - mock(Languages.class)), - new UploadReportAction(mock(ComputationService.class)))); + new GlobalReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class)), + new ProjectReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class), mock(QProfileFactory.class), mock(QProfileLoader.class), mock(RuleService.class), + mock(Languages.class)), + new UploadReportAction(mock(ComputationService.class), mock(AnalysisReportTaskLauncher.class)))); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/UploadReportActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/UploadReportActionTest.java index 1680f3127b7..c306119bcfe 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/UploadReportActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/UploadReportActionTest.java @@ -24,6 +24,7 @@ import org.junit.Before; import org.junit.Test; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; +import org.sonar.server.computation.AnalysisReportTaskLauncher; import org.sonar.server.computation.ComputationService; import static org.mockito.Matchers.anyString; @@ -35,12 +36,14 @@ public class UploadReportActionTest { private UploadReportAction sut; private ComputationService computationService; + private AnalysisReportTaskLauncher analysisTaskLauncher; @Before public void before() { computationService = mock(ComputationService.class); + analysisTaskLauncher = mock(AnalysisReportTaskLauncher.class); - sut = new UploadReportAction(computationService); + sut = new UploadReportAction(computationService, analysisTaskLauncher); } @Test @@ -51,7 +54,8 @@ public class UploadReportActionTest { sut.handle(request, response); - verify(computationService).create(DEFAULT_PROJECT_KEY); + verify(computationService).addAnalysisReport(DEFAULT_PROJECT_KEY); + verify(analysisTaskLauncher).startAnalysisTaskNow(); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/AnalysisReportTaskLauncherTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/AnalysisReportTaskLauncherTest.java new file mode 100644 index 00000000000..afb9ec162b6 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/AnalysisReportTaskLauncherTest.java @@ -0,0 +1,81 @@ +/* + * 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 org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Timeout; + +import java.util.concurrent.TimeUnit; + +import static org.mockito.Mockito.*; + +public class AnalysisReportTaskLauncherTest { + + @Rule + public Timeout timeout = new Timeout(5000); + private AnalysisReportTaskLauncher sut; + private ComputationService service; + + @Before + public void before() { + this.service = mock(ComputationService.class); + } + + @After + public void after() { + sut.stop(); + } + + @Test + public void call_findAndBook_when_launching_a_recurrent_task() { + sut = new AnalysisReportTaskLauncher(service, 0, 1, TimeUnit.MILLISECONDS); + + sut.start(); + + sleep(); + + verify(service, atLeastOnce()).findAndBookNextAvailableAnalysisReport(); + } + + @Test + public void call_findAndBook_when_executing_task_immediatly() { + sut = new AnalysisReportTaskLauncher(service, 1, 1, TimeUnit.HOURS); + sut.start(); + + sut.startAnalysisTaskNow(); + + sleep(); + + verify(service, atLeastOnce()).findAndBookNextAvailableAnalysisReport(); + } + + private void sleep() { + try { + TimeUnit.MILLISECONDS.sleep(5L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/AnalysisReportTaskTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/AnalysisReportTaskTest.java new file mode 100644 index 00000000000..f2205502c2e --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/AnalysisReportTaskTest.java @@ -0,0 +1,59 @@ +/* + * 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 org.junit.Before; +import org.junit.Test; +import org.sonar.core.computation.db.AnalysisReportDto; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.*; + +public class AnalysisReportTaskTest { + + private AnalysisReportTask sut; + private ComputationService service; + + @Before + public void before() { + this.service = mock(ComputationService.class); + this.sut = new AnalysisReportTask(service); + } + + @Test + public void call_findAndBook_and_no_call_to_analyze_if_no_report_found() { + sut.run(); + + verify(service).findAndBookNextAvailableAnalysisReport(); + verify(service, times(0)).analyzeReport(any(AnalysisReportDto.class)); + } + + @Test + public void call_findAndBook_and_then_analyze_if_there_is_a_report() { + when(service.findAndBookNextAvailableAnalysisReport()).thenReturn(AnalysisReportDto.newForTests(1L)); + + sut.run(); + + verify(service).findAndBookNextAvailableAnalysisReport(); + verify(service).analyzeReport(any(AnalysisReportDto.class)); + } + +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceMediumTest.java index 662bbbf5d84..42c987d437e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceMediumTest.java @@ -101,7 +101,7 @@ public class ComputationServiceMediumTest { @Test public void create_analysis_report_and_retrieve_it() { insertPermissionsForProject(DEFAULT_PROJECT_KEY); - sut.create(DEFAULT_PROJECT_KEY); + sut.addAnalysisReport(DEFAULT_PROJECT_KEY); List<AnalysisReportDto> reports = sut.findByProjectKey(DEFAULT_PROJECT_KEY); AnalysisReportDto report = reports.get(0); @@ -116,9 +116,9 @@ public class ComputationServiceMediumTest { insertPermissionsForProject("2"); insertPermissionsForProject("3"); - sut.create(DEFAULT_PROJECT_KEY); - sut.create("2"); - sut.create("3"); + sut.addAnalysisReport(DEFAULT_PROJECT_KEY); + sut.addAnalysisReport("2"); + sut.addAnalysisReport("3"); AnalysisReportDto firstBookedReport = sut.findAndBookNextAvailableAnalysisReport(); AnalysisReportDto secondBookedReport = sut.findAndBookNextAvailableAnalysisReport(); @@ -130,6 +130,19 @@ public class ComputationServiceMediumTest { assertThat(thirdBookedReport.getProjectKey()).isEqualTo("3"); } + @Test + public void analyze_report() { + insertPermissionsForProject(DEFAULT_PROJECT_KEY); + sut.addAnalysisReport(DEFAULT_PROJECT_KEY); + + AnalysisReportDto report = sut.findAndBookNextAvailableAnalysisReport(); + + sut.analyzeReport(report); + + assertThat(sut.findByProjectKey(DEFAULT_PROJECT_KEY)).isEmpty(); + + } + private ComponentDto insertPermissionsForProject(String projectKey) { ComponentDto project = new ComponentDto().setKey(projectKey); db.componentDao().insert(session, project); @@ -158,7 +171,7 @@ public class ComputationServiceMediumTest { MockUserSession.set().setLogin("gandalf").addProjectPermissions(UserRole.USER, project.key()); - sut.create(project.getKey()); + sut.addAnalysisReport(project.getKey()); } @Test @@ -181,7 +194,7 @@ public class ComputationServiceMediumTest { clearIssueIndexToSimulateBatchInsertWithoutIndexing(); - sut.create(DEFAULT_PROJECT_KEY); + sut.addAnalysisReport(DEFAULT_PROJECT_KEY); List<AnalysisReportDto> reports = sut.findByProjectKey(DEFAULT_PROJECT_KEY); sut.analyzeReport(reports.get(0)); @@ -194,7 +207,7 @@ public class ComputationServiceMediumTest { public void add_project_issue_permission_in_index() throws Exception { ComponentDto project = insertPermissionsForProject(DEFAULT_PROJECT_KEY); - sut.create(DEFAULT_PROJECT_KEY); + sut.addAnalysisReport(DEFAULT_PROJECT_KEY); List<AnalysisReportDto> reports = sut.findByProjectKey(DEFAULT_PROJECT_KEY); sut.analyzeReport(reports.get(0)); @@ -230,7 +243,7 @@ public class ComputationServiceMediumTest { clearIssueIndexToSimulateBatchInsertWithoutIndexing(); - sut.create(DEFAULT_PROJECT_KEY); + sut.addAnalysisReport(DEFAULT_PROJECT_KEY); List<AnalysisReportDto> reports = sut.findByProjectKey(DEFAULT_PROJECT_KEY); sut.analyzeReport(reports.get(0)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java index 8ce075d6387..bca5e5be1b1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java @@ -223,6 +223,16 @@ public class AnalysisReportDaoTest { assertThat(reportBooked.getId()).isEqualTo(1L); } + @Test + public void delete_one_analysis_report() { + db.prepareDbUnit(getClass(), "one_analysis_report.xml"); + + dao.delete(session, AnalysisReportDto.newForTests(1L)); + session.commit(); + + db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports"); + } + @Test(expected = UnsupportedOperationException.class) public void doGetNullableByKey_is_not_implemented_yet() { dao.doGetNullableByKey(session, "ANY_STRING"); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml new file mode 100644 index 00000000000..f79f571b90e --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml @@ -0,0 +1,10 @@ +<dataset> + <analysis_reports + id="1" + project_key="123456789-987654321" + report_data="data-project" + report_status="WORKING" + created_at="2014-09-24" + updated_at="2014-09-25" + /> +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java index 03493275fda..dd50da26adb 100644 --- a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java +++ b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java @@ -72,7 +72,7 @@ public class AnalysisReportDto extends Dto<String> { @Override public String getKey() { - return getProjectKey(); + return String.valueOf(getId()); } public Long getId() { diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java index c3f061c071c..460cea7d5c7 100644 --- a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java @@ -47,4 +47,6 @@ public interface AnalysisReportMapper { @Param("busyStatus") AnalysisReportDto.Status busyStatus); AnalysisReportDto selectById(Long id); + + void delete(Long id); } diff --git a/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml index dbc90b8381b..c5b1e69c81a 100644 --- a/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml @@ -39,6 +39,10 @@ truncate table analysis_reports </delete> + <delete id="delete"> + delete analysis_reports where id=#{id} + </delete> + <select id="selectById" resultType="AnalysisReport"> select <include refid="reportColumns"/> |