summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-06-19 16:30:50 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-06-19 17:04:59 +0200
commit79ba8fae37f8ae49d17eeaea7654b79df491061c (patch)
tree4b86b54e88ba781ca1fa27a4a6a244e2eaa6be8e
parent58a25705df84a5a129e87bf914d3cacbd6b2607b (diff)
downloadsonarqube-79ba8fae37f8ae49d17eeaea7654b79df491061c.tar.gz
sonarqube-79ba8fae37f8ae49d17eeaea7654b79df491061c.zip
SONAR-5403 Migrations that convert technical debt from hours to minutes are too slow
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigration.java2
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java2
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java8
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java2
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java18
-rw-r--r--sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/db/migrations/v43/WorkDurationConvertorTest.java27
7 files changed, 52 insertions, 11 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigration.java
index 7739ea46910..6bb5b0f12e3 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigration.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigration.java
@@ -56,6 +56,8 @@ public class ConvertIssueDebtToMinutesMigration implements DatabaseMigration {
@Override
public void execute() {
+ workDurationConvertor.init();
+
new MassUpdater(db).execute(
new MassUpdater.InputLoader<Row>() {
@Override
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java
index 0bb8d3cb7cf..6f629ee260a 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigration.java
@@ -48,6 +48,8 @@ public class DevelopmentCostMeasuresMigration implements DatabaseMigration {
@Override
public void execute() {
+ workDurationConvertor.init();
+
new MassUpdater(db).execute(
new MassUpdater.InputLoader<Row>() {
@Override
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java
index ee2dff668a9..ad2b816aec1 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/IssueChangelogMigration.java
@@ -47,18 +47,20 @@ public class IssueChangelogMigration implements DatabaseMigration {
private final Database db;
public IssueChangelogMigration(Database database, PropertiesDao propertiesDao) {
- this(database, propertiesDao, System2.INSTANCE);
+ this(database, new WorkDurationConvertor(propertiesDao), System2.INSTANCE);
}
@VisibleForTesting
- IssueChangelogMigration(Database database, PropertiesDao propertiesDao, System2 system2) {
+ IssueChangelogMigration(Database database, WorkDurationConvertor convertor, System2 system2) {
this.db = database;
- this.workDurationConvertor = new WorkDurationConvertor(propertiesDao);
+ this.workDurationConvertor = convertor;
this.system2 = system2;
}
@Override
public void execute() {
+ workDurationConvertor.init();
+
new MassUpdater(db).execute(
new MassUpdater.InputLoader<Row>() {
@Override
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java
index 85fe5a192b1..9dd4ab82a4b 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigration.java
@@ -61,6 +61,8 @@ public class TechnicalDebtMeasuresMigration implements DatabaseMigration {
@Override
public void execute() {
+ workDurationConvertor.init();
+
new MassUpdater(db).execute(
new MassUpdater.InputLoader<Row>() {
@Override
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java
index b31ec9e2614..bcdab54e5cb 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/v43/WorkDurationConvertor.java
@@ -29,6 +29,8 @@ class WorkDurationConvertor {
static final String HOURS_IN_DAY_PROPERTY = "sonar.technicalDebt.hoursInDay";
+ private Integer hoursInDay;
+
private final PropertiesDao propertiesDao;
WorkDurationConvertor(PropertiesDao propertiesDao) {
@@ -36,7 +38,7 @@ class WorkDurationConvertor {
}
long createFromLong(long durationInLong) {
- int hoursInDay = hoursInDay();
+ checkHoursInDay();
long durationInMinutes = 0L;
@@ -62,17 +64,23 @@ class WorkDurationConvertor {
}
long createFromDays(double days) {
- return ((Double) (days * hoursInDay() * ONE_HOUR)).longValue();
+ checkHoursInDay();
+
+ return ((Double) (days * hoursInDay * ONE_HOUR)).longValue();
}
- private int hoursInDay() {
+ void init() {
PropertyDto propertyDto = propertiesDao.selectGlobalProperty(HOURS_IN_DAY_PROPERTY);
String value = propertyDto != null ? propertyDto.getValue() : "8";
- int hoursInDay = Integer.valueOf(value);
+ hoursInDay = Integer.valueOf(value);
if (hoursInDay < 0) {
throw new IllegalArgumentException(String.format("Bad value of %s: %d", HOURS_IN_DAY_PROPERTY, hoursInDay));
}
- return hoursInDay;
}
+ private void checkHoursInDay(){
+ if (hoursInDay == null) {
+ throw new IllegalStateException("init() has not been called");
+ }
+ }
}
diff --git a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java
index 9808acbc3ee..f55925542b6 100644
--- a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationTest.java
@@ -54,7 +54,9 @@ public class IssueChangelogMigrationTest {
when(system2.now()).thenReturn(DateUtils.parseDateTime("2014-02-19T19:10:03+0100").getTime());
when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("8"));
- migration = new IssueChangelogMigration(db.database(), propertiesDao, system2);
+ WorkDurationConvertor convertor = new WorkDurationConvertor(propertiesDao);
+ convertor.init();
+ migration = new IssueChangelogMigration(db.database(), convertor, system2);
}
@Test
diff --git a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/WorkDurationConvertorTest.java b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/WorkDurationConvertorTest.java
index eb64d80f1f9..843bfa0a344 100644
--- a/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/WorkDurationConvertorTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/WorkDurationConvertorTest.java
@@ -42,6 +42,7 @@ public class WorkDurationConvertorTest {
@Test
public void convert_from_long() throws Exception {
+ convertor.init();
when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue(Integer.toString(HOURS_IN_DAY)));
assertThat(convertor.createFromLong(1)).isEqualTo(ONE_MINUTE);
@@ -52,14 +53,16 @@ public class WorkDurationConvertorTest {
@Test
public void convert_from_long_use_default_value_for_hours_in_day_when_no_property() throws Exception {
+ convertor.init();
assertThat(convertor.createFromLong(1)).isEqualTo(ONE_MINUTE);
}
@Test
public void fail_convert_from_long_on_bad_hours_in_day_property() throws Exception {
+ when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("-2"));
+ WorkDurationConvertor workDurationConvertor = new WorkDurationConvertor(propertiesDao);
try {
- when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue("-2"));
- convertor.createFromLong(1);
+ workDurationConvertor.init();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class);
@@ -68,6 +71,7 @@ public class WorkDurationConvertorTest {
@Test
public void convert_from_days() throws Exception {
+ convertor.init();
when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue(Integer.toString(HOURS_IN_DAY)));
assertThat(convertor.createFromDays(1.0)).isEqualTo(ONE_DAY_IN_MINUTES);
@@ -77,4 +81,23 @@ public class WorkDurationConvertorTest {
assertThat(convertor.createFromDays(0.01)).isEqualTo(4L);
}
+ @Test
+ public void fail_it_init_has_not_been_called() throws Exception {
+ when(propertiesDao.selectGlobalProperty(WorkDurationConvertor.HOURS_IN_DAY_PROPERTY)).thenReturn(new PropertyDto().setValue(Integer.toString(HOURS_IN_DAY)));
+
+ try {
+ assertThat(convertor.createFromLong(1L));
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ }
+
+ try {
+ assertThat(convertor.createFromDays(1.0));
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ }
+ }
+
}