aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-09-04 12:24:25 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-09-04 12:25:48 +0200
commit609bb9ad43bf3c19da6dff5b66f39ded9d6b2265 (patch)
treec7b2c9a15900f72b420de2159f5b65065aa1a90c /sonar-batch
parent9920ceb7d337e93223a30333236f42a446a2e1f0 (diff)
downloadsonarqube-609bb9ad43bf3c19da6dff5b66f39ded9d6b2265.tar.gz
sonarqube-609bb9ad43bf3c19da6dff5b66f39ded9d6b2265.zip
SONAR-4602 Evict dryRun cache when a new snapshot is available
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java19
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java9
2 files changed, 23 insertions, 5 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
index f25f92de517..3bd4a77946a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
@@ -31,6 +31,9 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Scopes;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.batch.index.ResourcePersister;
+import org.sonar.core.dryrun.DryRunCache;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
import javax.persistence.Query;
@@ -45,19 +48,31 @@ public class UpdateStatusJob implements BatchComponent {
private ResourcePersister resourcePersister;
private Settings settings;
private Project project;
+ private PropertiesDao propertiesDao;
- public UpdateStatusJob(Settings settings, ServerClient server, DatabaseSession session, ResourcePersister resourcePersister, Project project, Snapshot snapshot) {
+ public UpdateStatusJob(Settings settings, ServerClient server, DatabaseSession session,
+ ResourcePersister resourcePersister, Project project, Snapshot snapshot, PropertiesDao propertiesDao) {
this.session = session;
this.server = server;
this.resourcePersister = resourcePersister;
this.project = project;
this.snapshot = snapshot;
this.settings = settings;
+ this.propertiesDao = propertiesDao;
}
public void execute() {
disablePreviousSnapshot();
enableCurrentSnapshot();
+ updateDryRunLastModificationTimestamp();
+ }
+
+ private void updateDryRunLastModificationTimestamp() {
+ propertiesDao.setProperty(
+ new PropertyDto()
+ .setKey(DryRunCache.SONAR_DRY_RUN_CACHE_LAST_UPDATE_KEY)
+ .setResourceId(Long.valueOf(project.getId()))
+ .setValue(String.valueOf(System.nanoTime())));
}
private void disablePreviousSnapshot() {
@@ -115,7 +130,7 @@ public class UpdateStatusJob implements BatchComponent {
query.setParameter("last", last);
query.setParameter("rootId", snapshot.getId());
query.setParameter("path", snapshot.getPath() + snapshot.getId() + ".%");
- query.setParameter("pathRootId", snapshot.getRootId()==null ? snapshot.getId() : snapshot.getRootId());
+ query.setParameter("pathRootId", snapshot.getRootId() == null ? snapshot.getId() : snapshot.getRootId());
query.executeUpdate();
session.commit();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
index b38e777583e..6b4040d15b5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
@@ -32,6 +32,7 @@ import org.sonar.batch.index.DefaultResourcePersister;
import org.sonar.batch.index.ResourceCache;
import org.sonar.batch.index.ResourcePersister;
import org.sonar.batch.index.SnapshotCache;
+import org.sonar.core.properties.PropertiesDao;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import javax.persistence.Query;
@@ -60,9 +61,11 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
setupData("sharedFixture", fixture);
DatabaseSession session = getSession();
+ Project project = new Project("foo");
+ project.setId(1);
UpdateStatusJob job = new UpdateStatusJob(new Settings().appendProperty(CoreProperties.SERVER_BASE_URL, "http://myserver/"), mock(ServerClient.class), session,
new DefaultResourcePersister(session, mock(ResourcePermissions.class), mock(SnapshotCache.class), mock(ResourceCache.class)),
- mock(Project.class), loadSnapshot(snapshotId));
+ project, loadSnapshot(snapshotId), mock(PropertiesDao.class));
job.execute();
checkTables(fixture, "snapshots");
@@ -80,7 +83,7 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
settings.setProperty(CoreProperties.SERVER_BASE_URL, "http://myserver/");
Project project = new Project("struts");
UpdateStatusJob job = new UpdateStatusJob(settings, mock(ServerClient.class), mock(DatabaseSession.class),
- mock(ResourcePersister.class), project, mock(Snapshot.class));
+ mock(ResourcePersister.class), project, mock(Snapshot.class), mock(PropertiesDao.class));
Logger logger = mock(Logger.class);
job.logSuccess(logger);
@@ -94,7 +97,7 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
settings.setProperty("sonar.dryRun", true);
Project project = new Project("struts");
UpdateStatusJob job = new UpdateStatusJob(settings, mock(ServerClient.class), mock(DatabaseSession.class),
- mock(ResourcePersister.class), project, mock(Snapshot.class));
+ mock(ResourcePersister.class), project, mock(Snapshot.class), mock(PropertiesDao.class));
Logger logger = mock(Logger.class);
job.logSuccess(logger);