Browse Source

SONAR-6260 Merge PeriodFinder and FeedPeriodsStep

tags/5.2-RC1
Julien Lancelot 9 years ago
parent
commit
64032ec6f5
18 changed files with 397 additions and 572 deletions
  1. 0
    3
      server/sonar-server/src/main/java/org/sonar/server/computation/container/ComputeEngineContainerImpl.java
  2. 8
    67
      server/sonar-server/src/main/java/org/sonar/server/computation/period/Period.java
  3. 0
    125
      server/sonar-server/src/main/java/org/sonar/server/computation/period/PeriodFinder.java
  4. 106
    23
      server/sonar-server/src/main/java/org/sonar/server/computation/step/FeedPeriodsStep.java
  5. 0
    243
      server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodFinderTest.java
  6. 1
    49
      server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodTest.java
  7. 1
    2
      server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodsHolderImplTest.java
  8. 220
    14
      server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java
  9. 0
    46
      server/sonar-server/src/test/resources/org/sonar/server/computation/period/PeriodFinderTest/previous_version_deleted.xml
  10. 7
    0
      server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/empty.xml
  11. 0
    0
      server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/find_by_date.xml
  12. 0
    0
      server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/find_by_days.xml
  13. 0
    0
      server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/find_by_previous_analysis.xml
  14. 0
    0
      server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/find_by_previous_version.xml
  15. 0
    0
      server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/find_by_version.xml
  16. 0
    0
      server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/no_previous_version.xml
  17. 39
    0
      server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/previous_version_deleted.xml
  18. 15
    0
      server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/unprocessed_snapshots.xml

+ 0
- 3
server/sonar-server/src/main/java/org/sonar/server/computation/container/ComputeEngineContainerImpl.java View File

@@ -50,7 +50,6 @@ import org.sonar.server.computation.issue.SourceLinesCache;
import org.sonar.server.computation.language.PlatformLanguageRepository;
import org.sonar.server.computation.measure.MeasureRepositoryImpl;
import org.sonar.server.computation.measure.MetricCache;
import org.sonar.server.computation.period.PeriodFinder;
import org.sonar.server.computation.period.PeriodsHolderImpl;
import org.sonar.server.computation.step.ComputationStep;
import org.sonar.server.computation.step.ComputationSteps;
@@ -121,8 +120,6 @@ public class ComputeEngineContainerImpl extends ComponentContainer implements Co

BatchReportDirectoryHolderImpl.class,

PeriodFinder.class,

// repositories
PlatformLanguageRepository.class,
MeasureRepositoryImpl.class,

+ 8
- 67
server/sonar-server/src/main/java/org/sonar/server/computation/period/Period.java View File

@@ -20,102 +20,43 @@

package org.sonar.server.computation.period;

import java.util.Calendar;
import java.util.Date;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.sonar.api.CoreProperties;
import org.sonar.api.utils.DateUtils;
import org.sonar.core.component.SnapshotDto;

public class Period {

private int index;
private String mode, modeParameter;
private SnapshotDto projectSnapshot;
/**
* Date resolved from the settings of the period
* - date : the given date
* - days : nearest analysis date found
* - previous analysis : date of the last analysis
* - previous version : date of the analysis of the previous version
* - version : date of the analysis of the given version
*/
private Long targetDate = null;
private long snapshotDate;

public Period(String mode, @Nullable Long targetDate, SnapshotDto projectSnapshot) {
this.mode = mode;
if (targetDate != null) {
this.targetDate = targetDate;
}
this.projectSnapshot = projectSnapshot;
}

public Period setIndex(int index) {
public Period(int index, String mode, @Nullable String modeParameter, long snapshotDate) {
this.index = index;
return this;
this.mode = mode;
this.modeParameter = modeParameter;
this.snapshotDate = snapshotDate;
}

public int getIndex() {
return index;
}

public SnapshotDto getProjectSnapshot() {
return projectSnapshot;
}

/**
* Date of the snapshot
*/
public Long getSnapshotDate() {
return projectSnapshot != null ? projectSnapshot.getCreatedAt() : null;
return snapshotDate;
}

public String getMode() {
return mode;
}

@CheckForNull
public String getModeParameter() {
return modeParameter;
}

public Period setModeParameter(String s) {
this.modeParameter = s;
return this;
}

public Long getTargetDate() {
return targetDate;
}

@Override
public String toString() {
Date snapshotDate = new Date(getSnapshotDate());
if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_VERSION)) {
String label = String.format("Compare to version %s", modeParameter);
if (targetDate != null) {
label += String.format(" (%s)", DateUtils.formatDate(snapshotDate));
}
return label;
}
if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_DAYS)) {
return String.format("Compare over %s days (%s, analysis of %s)", modeParameter, formatDate(),DateUtils.formatDate(snapshotDate));
}
if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS)) {
return String.format("Compare to previous analysis (%s)", DateUtils.formatDate(snapshotDate));
}
if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION)) {
return String.format("Compare to previous version (%s)", DateUtils.formatDate(snapshotDate));
}
if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_DATE)) {
return String.format("Compare to date %s (analysis of %s)", formatDate(), DateUtils.formatDate(snapshotDate));
}
return ReflectionToStringBuilder.toString(this);
}

private String formatDate() {
return DateUtils.formatDate(org.apache.commons.lang.time.DateUtils.truncate(new Date(targetDate), Calendar.SECOND));
}

}

+ 0
- 125
server/sonar-server/src/main/java/org/sonar/server/computation/period/PeriodFinder.java View File

@@ -1,125 +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.period;

import com.google.common.annotations.VisibleForTesting;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.annotation.CheckForNull;
import org.sonar.api.CoreProperties;
import org.sonar.api.utils.DateUtils;
import org.sonar.core.component.SnapshotDto;
import org.sonar.core.component.SnapshotQuery;
import org.sonar.core.persistence.DbSession;
import org.sonar.server.db.DbClient;

import static org.sonar.core.component.SnapshotQuery.SORT_FIELD.BY_DATE;
import static org.sonar.core.component.SnapshotQuery.SORT_ORDER.ASC;
import static org.sonar.core.component.SnapshotQuery.SORT_ORDER.DESC;

public class PeriodFinder {

private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(DateUtils.DATE_FORMAT);

private final DbClient dbClient;

public PeriodFinder(DbClient dbClient) {
this.dbClient = dbClient;
}

@CheckForNull
public Period findByDate(DbSession session, Long projectId, Date date) {
SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectId).setCreatedAfter(date.getTime()).setSort(BY_DATE, ASC));
if (snapshot == null) {
return null;
}
return new Period(CoreProperties.TIMEMACHINE_MODE_DATE, date.getTime(), snapshot).setModeParameter(DATE_FORMAT.format(date));
}

@CheckForNull
public Period findByDays(DbSession session, Long projectId, long analysisDate, int days) {
List<SnapshotDto> snapshots = dbClient.snapshotDao().selectSnapshotsByQuery(session, createCommonQuery(projectId).setCreatedBefore(analysisDate).setSort(BY_DATE, ASC));
long targetDate = DateUtils.addDays(new Date(analysisDate), -days).getTime();
SnapshotDto snapshot = findNearestSnapshotToTargetDate(snapshots, targetDate);
if (snapshot == null) {
return null;
}
return new Period(CoreProperties.TIMEMACHINE_MODE_DAYS, targetDate, snapshot).setModeParameter(String.valueOf(days));
}

@CheckForNull
public Period findByPreviousAnalysis(DbSession session, Long projectId, long analysisDate) {
SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectId).setCreatedBefore(analysisDate).setIsLast(true).setSort(BY_DATE, DESC));
if (snapshot == null) {
return null;
}
return new Period(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, snapshot.getCreatedAt(), snapshot).setModeParameter(DATE_FORMAT.format(snapshot.getCreatedAt()));
}

@CheckForNull
public Period findByPreviousVersion(DbSession session, Long projectId, String version) {
List<SnapshotDto> snapshotDtos = dbClient.snapshotDao().selectPreviousVersionSnapshots(session, projectId, version);
if (snapshotDtos.isEmpty()) {
return null;
}
SnapshotDto snapshotDto = snapshotDtos.get(0);
return new Period(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, snapshotDto.getCreatedAt(), snapshotDto).setModeParameter(snapshotDto.getVersion());
}

@CheckForNull
public Period findByVersion(DbSession session, Long projectId, String version) {
SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectId).setVersion(version).setSort(BY_DATE, DESC));
if (snapshot == null) {
return null;
}
return new Period(CoreProperties.TIMEMACHINE_MODE_VERSION, snapshot.getCreatedAt(), snapshot).setModeParameter(version);
}

@VisibleForTesting
@CheckForNull
static SnapshotDto findNearestSnapshotToTargetDate(List<SnapshotDto> snapshots, Long targetDate) {
long bestDistance = Long.MAX_VALUE;
SnapshotDto nearest = null;
for (SnapshotDto snapshot : snapshots) {
long distance = Math.abs(snapshot.getCreatedAt() - targetDate);
if (distance <= bestDistance) {
bestDistance = distance;
nearest = snapshot;
}
}
return nearest;
}

@CheckForNull
private SnapshotDto findFirstSnapshot(DbSession session, SnapshotQuery query) {
List<SnapshotDto> snapshots = dbClient.snapshotDao().selectSnapshotsByQuery(session, query);
if (snapshots.size() >= 1) {
return snapshots.get(0);
}
return null;
}

private static SnapshotQuery createCommonQuery(Long projectId) {
return new SnapshotQuery().setComponentId(projectId).setStatus(SnapshotDto.STATUS_PROCESSED);
}

}

+ 106
- 23
server/sonar-server/src/main/java/org/sonar/server/computation/step/FeedPeriodsStep.java View File

@@ -21,31 +21,35 @@
package org.sonar.server.computation.step;

import com.google.common.base.Strings;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.component.SnapshotDto;
import org.sonar.core.component.SnapshotQuery;
import org.sonar.core.persistence.DbSession;
import org.sonar.server.computation.batch.BatchReportReader;
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.TreeRootHolder;
import org.sonar.server.computation.period.Period;
import org.sonar.server.computation.period.PeriodFinder;
import org.sonar.server.computation.period.PeriodsHolderImpl;
import org.sonar.server.db.DbClient;

import static org.sonar.core.component.SnapshotQuery.SORT_FIELD.BY_DATE;
import static org.sonar.core.component.SnapshotQuery.SORT_ORDER.ASC;
import static org.sonar.core.component.SnapshotQuery.SORT_ORDER.DESC;

/**
* Populates the {@link org.sonar.server.computation.period.PeriodsHolder}
*
@@ -55,25 +59,22 @@ import org.sonar.server.db.DbClient;
* - If a snapshot is found, a new period is added to the repository
*/
public class FeedPeriodsStep implements ComputationStep {
private static final Logger LOG = LoggerFactory.getLogger(PeriodsHolderImpl.class);

private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(DateUtils.DATE_FORMAT);
private static final Logger LOG = Loggers.get(FeedPeriodsStep.class);

private static final int NUMBER_OF_PERIODS = 5;

private final DbClient dbClient;
private final Settings settings;
private final TreeRootHolder treeRootHolder;
private final PeriodFinder periodFinder;
private final BatchReportReader batchReportReader;
private final PeriodsHolderImpl periodsHolder;

public FeedPeriodsStep(DbClient dbClient, Settings settings, TreeRootHolder treeRootHolder, PeriodFinder periodFinder, BatchReportReader batchReportReader,
public FeedPeriodsStep(DbClient dbClient, Settings settings, TreeRootHolder treeRootHolder, BatchReportReader batchReportReader,
PeriodsHolderImpl periodsHolder) {
this.dbClient = dbClient;
this.settings = settings;
this.treeRootHolder = treeRootHolder;
this.periodFinder = periodFinder;
this.batchReportReader = batchReportReader;
this.periodsHolder = periodsHolder;
}
@@ -100,8 +101,7 @@ public class FeedPeriodsStep implements ComputationStep {
Period period = periodResolver.resolve(index);
// SONAR-4700 Add a past snapshot only if it exists
if (period != null) {
periods.add(period.setIndex(index));
LOG.debug(period.toString());
periods.add(period);
}
}
}
@@ -130,6 +130,9 @@ public class FeedPeriodsStep implements ComputationStep {
@CheckForNull
private Period resolve(int index) {
String propertyValue = getPropertyValue(qualifier, settings, index);
if (StringUtils.isBlank(propertyValue)) {
return null;
}
Period period = resolve(index, propertyValue);
if (period == null && StringUtils.isNotBlank(propertyValue)) {
LOG.debug("Property " + CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + " is not valid: " + propertyValue);
@@ -139,25 +142,21 @@ public class FeedPeriodsStep implements ComputationStep {

@CheckForNull
private Period resolve(int index, String property) {
if (StringUtils.isBlank(property)) {
return null;
}

Integer days = tryToResolveByDays(property);
if (days != null) {
return periodFinder.findByDays(session, projectId, analysisDate, days);
return findByDays(index, days);
}
Date date = tryToResolveByDate(property);
if (date != null) {
return periodFinder.findByDate(session, projectId, date);
return findByDate(index, date);
}
if (StringUtils.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, property)) {
return periodFinder.findByPreviousAnalysis(session, projectId, analysisDate);
return findByPreviousAnalysis(index);
}
if (StringUtils.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, property)) {
return periodFinder.findByPreviousVersion(session, projectId, currentVersion);
return findByPreviousVersion(index);
}
return periodFinder.findByVersion(session, projectId, property);
return findByVersion(index, property);
}

@CheckForNull
@@ -172,11 +171,95 @@ public class FeedPeriodsStep implements ComputationStep {
@CheckForNull
private Date tryToResolveByDate(String property) {
try {
return DATE_FORMAT.parse(property);
} catch (ParseException e) {
return DateUtils.parseDate(property);
} catch (Exception e) {
return null;
}
}

private Period findByDate(int index, Date date) {
SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectId).setCreatedAfter(date.getTime()).setSort(BY_DATE, ASC));
if (snapshot == null) {
return null;
}
LOG.debug(String.format("Compare to date %s (analysis of %s)", formatDate(date.getTime()), formatDate(snapshot.getCreatedAt())));
return new Period(index, CoreProperties.TIMEMACHINE_MODE_DATE, DateUtils.formatDate(date), snapshot.getCreatedAt());
}

@CheckForNull
private Period findByDays(int index, int days) {
List<SnapshotDto> snapshots = dbClient.snapshotDao().selectSnapshotsByQuery(session, createCommonQuery(projectId).setCreatedBefore(analysisDate).setSort(BY_DATE, ASC));
long targetDate = DateUtils.addDays(new Date(analysisDate), -days).getTime();
SnapshotDto snapshot = findNearestSnapshotToTargetDate(snapshots, targetDate);
if (snapshot == null) {
return null;
}
LOG.debug(String.format("Compare over %s days (%s, analysis of %s)", String.valueOf(days), formatDate(targetDate), formatDate(snapshot.getCreatedAt())));
return new Period(index, CoreProperties.TIMEMACHINE_MODE_DAYS, String.valueOf(days), snapshot.getCreatedAt());
}

@CheckForNull
private Period findByPreviousAnalysis(int index) {
SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectId).setCreatedBefore(analysisDate).setIsLast(true).setSort(BY_DATE, DESC));
if (snapshot == null) {
return null;
}
LOG.debug(String.format("Compare to previous analysis (%s)", formatDate(snapshot.getCreatedAt())));
return new Period(index, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, formatDate(snapshot.getCreatedAt()), snapshot.getCreatedAt());
}

@CheckForNull
private Period findByPreviousVersion(int index) {
List<SnapshotDto> snapshotDtos = dbClient.snapshotDao().selectPreviousVersionSnapshots(session, projectId, currentVersion);
if (snapshotDtos.isEmpty()) {
return null;
}
SnapshotDto snapshotDto = snapshotDtos.get(0);
LOG.debug(String.format("Compare to previous version (%s)", formatDate(snapshotDto.getCreatedAt())));
return new Period(index, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, snapshotDto.getVersion(), snapshotDto.getCreatedAt());
}

@CheckForNull
private Period findByVersion(int index, String version) {
SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectId).setVersion(version).setSort(BY_DATE, DESC));
if (snapshot == null) {
return null;
}
LOG.debug(String.format("Compare to version (%s) (%s)", version, formatDate(snapshot.getCreatedAt())));
return new Period(index, CoreProperties.TIMEMACHINE_MODE_VERSION, version, snapshot.getCreatedAt());
}

@CheckForNull
private SnapshotDto findFirstSnapshot(DbSession session, SnapshotQuery query) {
List<SnapshotDto> snapshots = dbClient.snapshotDao().selectSnapshotsByQuery(session, query);
if (!snapshots.isEmpty()) {
return snapshots.get(0);
}
return null;
}

}

@CheckForNull
private static SnapshotDto findNearestSnapshotToTargetDate(List<SnapshotDto> snapshots, Long targetDate) {
long bestDistance = Long.MAX_VALUE;
SnapshotDto nearest = null;
for (SnapshotDto snapshot : snapshots) {
long distance = Math.abs(snapshot.getCreatedAt() - targetDate);
if (distance <= bestDistance) {
bestDistance = distance;
nearest = snapshot;
}
}
return nearest;
}

private static SnapshotQuery createCommonQuery(Long projectId) {
return new SnapshotQuery().setComponentId(projectId).setStatus(SnapshotDto.STATUS_PROCESSED);
}

private static String formatDate(long date) {
return DateUtils.formatDate(org.apache.commons.lang.time.DateUtils.truncate(new Date(date), Calendar.SECOND));
}

private static String getPropertyValue(@Nullable String qualifier, Settings settings, int index) {

+ 0
- 243
server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodFinderTest.java View File

@@ -1,243 +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.period;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.time.DateUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sonar.api.CoreProperties;
import org.sonar.core.component.SnapshotDto;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.component.db.SnapshotDao;
import org.sonar.server.db.DbClient;
import org.sonar.test.DbTests;

import static org.assertj.core.api.Assertions.assertThat;

@Category(DbTests.class)
public class PeriodFinderTest {

private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

@ClassRule
public static final DbTester dbTester = new DbTester();

DbClient dbClient;

DbSession dbSession;

PeriodFinder periodFinder;

@Before
public void setUp() throws Exception {
dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new SnapshotDao());
dbSession = dbClient.openSession(false);
periodFinder = new PeriodFinder(dbClient);
}

@After
public void tearDown() throws Exception {
dbSession.close();
}

@Test
public void find_by_date() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_date.xml");
String textDate = "2008-11-22";
Date date = DATE_FORMAT.parse(textDate);

Period result = periodFinder.findByDate(dbSession, 1L, date);

// Return analysis from given date 2008-11-22
assertThat(result.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
assertThat(result.getModeParameter()).isEqualTo(textDate);
assertThat(result.getSnapshotDate()).isEqualTo(1227358680000L);
assertThat(result.getTargetDate()).isEqualTo(date.getTime());
assertThat(result.getProjectSnapshot().getId()).isEqualTo(1006L);
}

@Test
public void find_by_date_search_for_nearest_later_analysis() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_date.xml");
String date = "2008-11-24";

Period result = periodFinder.findByDate(dbSession, 1L, DATE_FORMAT.parse(date));

// No analysis have been done at this date, it should return the one from the date after (2008-11-25)
assertThat(result.getSnapshotDate()).isEqualTo(1227617880000L);
assertThat(result.getProjectSnapshot().getId()).isEqualTo(1009L);
}

@Test
public void not_find_by_date() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_date.xml");
String date = "2008-11-22";

// No analysis for this project
assertThat(periodFinder.findByDate(dbSession, 123L, DATE_FORMAT.parse(date))).isNull();
}

@Test
public void find_by_days() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_days.xml");

Period result = periodFinder.findByDays(dbSession, 1L, DATE_FORMAT.parse("2008-11-16").getTime(), 50);

// Return analysis from the 2008-11-01
assertThat(result.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DAYS);
assertThat(result.getModeParameter()).isEqualTo("50");
assertThat(result.getSnapshotDate()).isEqualTo(1225544280000L);
assertThat(result.getTargetDate()).isBetween(DATE_FORMAT.parse("2008-09-26").getTime(), DATE_FORMAT.parse("2008-09-27").getTime());
assertThat(result.getProjectSnapshot().getId()).isEqualTo(1000L);
}

@Test
public void ignore_unprocessed_snapshots() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_days.xml");

Period result = periodFinder.findByDays(dbSession, 1L, DATE_FORMAT.parse("2008-11-16").getTime(), 7);

// Return analysis from the 2008-11-13, the matching one from 2008-11-12 should be ignored
assertThat(result.getProjectSnapshot().getId()).isEqualTo(1006L);
}

@Test
public void not_find_by_days() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_days.xml");

// No analysis for this project
assertThat(periodFinder.findByDays(dbSession, 123L, DATE_FORMAT.parse("2008-11-16").getTime(), 7)).isNull();
}

@Test
public void locate_nearest_snapshot_before() throws ParseException {
Date current = DATE_FORMAT.parse("2010-10-20");
// distance: 15 => target is 2010-10-05

List<SnapshotDto> snapshots = Arrays.asList(
new SnapshotDto().setId(1L).setCreatedAt(DATE_FORMAT.parse("2010-09-30").getTime()),
new SnapshotDto().setId(2L).setCreatedAt(DATE_FORMAT.parse("2010-10-03").getTime()), // -2 days
new SnapshotDto().setId(3L).setCreatedAt(DATE_FORMAT.parse("2010-10-08").getTime()), // +3 days
new SnapshotDto().setId(4L).setCreatedAt(DATE_FORMAT.parse("2010-10-12").getTime()) // +7 days
);
assertThat(PeriodFinder.findNearestSnapshotToTargetDate(snapshots, DateUtils.addDays(current, -15).getTime()).getId()).isEqualTo(2);
}

@Test
public void locate_nearest_snapshot_after() throws ParseException {
Date current = DATE_FORMAT.parse("2010-10-20");
// distance: 15 => target is 2010-10-05

List<SnapshotDto> snapshots = Arrays.asList(
new SnapshotDto().setId(1L).setCreatedAt(DATE_FORMAT.parse("2010-09-30").getTime()),
new SnapshotDto().setId(2L).setCreatedAt(DATE_FORMAT.parse("2010-10-01").getTime()), // -4 days
new SnapshotDto().setId(3L).setCreatedAt(DATE_FORMAT.parse("2010-10-08").getTime()), // +3 days
new SnapshotDto().setId(4L).setCreatedAt(DATE_FORMAT.parse("2010-10-12").getTime()) // +7 days
);
assertThat(PeriodFinder.findNearestSnapshotToTargetDate(snapshots, DateUtils.addDays(current, -15).getTime()).getId()).isEqualTo(3);
}

@Test
public void find_by_previous_analysis() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_previous_analysis.xml");

Period result = periodFinder.findByPreviousAnalysis(dbSession, 1L, DATE_FORMAT.parse("2008-11-27").getTime());

// Return analysis from given date 2008-11-22
assertThat(result.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
assertThat(result.getModeParameter()).isEqualTo(DATE_FORMAT.format(new Date(1227617880000L)));
assertThat(result.getSnapshotDate()).isEqualTo(1227617880000L);
assertThat(result.getTargetDate()).isEqualTo(1227617880000L);
assertThat(result.getProjectSnapshot().getId()).isEqualTo(1009L);
}

@Test
public void not_find_by_previous_analysis() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_previous_analysis.xml");

// No analysis for this project
assertThat(periodFinder.findByPreviousAnalysis(dbSession, 2L, DATE_FORMAT.parse("2008-11-27").getTime())).isNull();
}

@Test
public void find_by_previous_version() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_previous_version.xml");

Period result = periodFinder.findByPreviousVersion(dbSession, 1L, "1.2-SNAPSHOT");

// Return analysis from given date 2008-11-22
assertThat(result.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
assertThat(result.getModeParameter()).isEqualTo("1.1");
assertThat(result.getSnapshotDate()).isEqualTo(1225803480000L);
assertThat(result.getTargetDate()).isEqualTo(1225803480000L);
assertThat(result.getProjectSnapshot().getId()).isEqualTo(1001L);
}

@Test
public void find_by_previous_version_when_previous_version_deleted() throws Exception {
dbTester.prepareDbUnit(getClass(), "previous_version_deleted.xml");

Period result = periodFinder.findByPreviousVersion(dbSession, 1L, "1.2-SNAPSHOT");

// Return analysis from given date 2008-11-22
assertThat(result.getModeParameter()).isEqualTo("1.0");
assertThat(result.getSnapshotDate()).isEqualTo(1225630680000L);
assertThat(result.getTargetDate()).isEqualTo(1225630680000L);
assertThat(result.getProjectSnapshot().getId()).isEqualTo(1000L);
}

@Test
public void not_find_previous_version() throws Exception {
dbTester.prepareDbUnit(getClass(), "no_previous_version.xml");

assertThat(periodFinder.findByPreviousVersion(dbSession, 1L, "1.2-SNAPSHOT")).isNull();
}

@Test
public void find_by_version() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_version.xml");

Period result = periodFinder.findByVersion(dbSession, 1L, "1.1");

assertThat(result.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION);
assertThat(result.getModeParameter()).isEqualTo("1.1");
assertThat(result.getSnapshotDate()).isEqualTo(1225803480000L);
assertThat(result.getTargetDate()).isEqualTo(1225803480000L);
assertThat(result.getProjectSnapshot().getId()).isEqualTo(1009L);
}

@Test
public void not_find_by_version() throws Exception {
dbTester.prepareDbUnit(getClass(), "find_by_version.xml");

assertThat(periodFinder.findByVersion(dbSession, 1L, "1.0")).isNull();
}

}

+ 1
- 49
server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodTest.java View File

@@ -22,7 +22,6 @@ package org.sonar.server.computation.period;

import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.core.component.SnapshotDto;

import static org.assertj.core.api.Assertions.assertThat;

@@ -31,59 +30,12 @@ public class PeriodTest {
@Test
public void test_some_setters_and_getters() {
Long date = System.currentTimeMillis();
SnapshotDto snapshotDto = new SnapshotDto().setCreatedAt(date);
Period period = new Period(CoreProperties.TIMEMACHINE_MODE_VERSION, 1000L, snapshotDto)
.setModeParameter("2.3")
.setIndex(1);
Period period = new Period(1, CoreProperties.TIMEMACHINE_MODE_VERSION, "2.3", date);

assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION);
assertThat(period.getModeParameter()).isEqualTo("2.3");
assertThat(period.getIndex()).isEqualTo(1);
assertThat(period.getProjectSnapshot()).isEqualTo(snapshotDto);
assertThat(period.getSnapshotDate()).isEqualTo(date);
assertThat(period.getTargetDate()).isEqualTo(1000L);
}

@Test
public void to_string_for_version() {
Period period = new Period(CoreProperties.TIMEMACHINE_MODE_VERSION, 1000L, new SnapshotDto().setCreatedAt(System.currentTimeMillis())).setModeParameter("2.3");
assertThat(period.toString()).startsWith("Compare to version 2.3");
}

@Test
public void to_string_for_version_without_date() {
Period period = new Period(CoreProperties.TIMEMACHINE_MODE_VERSION, null, new SnapshotDto().setCreatedAt(System.currentTimeMillis())).setModeParameter("2.3");
assertThat(period.toString()).isEqualTo("Compare to version 2.3");
}

@Test
public void to_string_for_number_of_days() {
Period period = new Period(CoreProperties.TIMEMACHINE_MODE_DAYS, 1000L, new SnapshotDto().setCreatedAt(System.currentTimeMillis())).setModeParameter("30");
assertThat(period.toString()).startsWith("Compare over 30 days (");
}

@Test
public void to_string_for_number_of_days_with_snapshot() {
Period period = new Period(CoreProperties.TIMEMACHINE_MODE_DAYS, 1000L, new SnapshotDto().setCreatedAt(System.currentTimeMillis())).setModeParameter("30");
assertThat(period.toString()).startsWith("Compare over 30 days (");
}

@Test
public void to_string_for_date() {
Period period = new Period(CoreProperties.TIMEMACHINE_MODE_DATE, 1000L, new SnapshotDto().setCreatedAt(System.currentTimeMillis()));
assertThat(period.toString()).startsWith("Compare to date ");
}

@Test
public void to_string_for_date_with_snapshot() {
Period period = new Period(CoreProperties.TIMEMACHINE_MODE_DATE, 1000L, new SnapshotDto().setCreatedAt(System.currentTimeMillis()));
assertThat(period.toString()).startsWith("Compare to date ");
}

@Test
public void to_string_for_previous_analysis() {
Period period = new Period(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, 1000L, new SnapshotDto().setCreatedAt(System.currentTimeMillis()));
assertThat(period.toString()).startsWith("Compare to previous analysis ");
}

}

+ 1
- 2
server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodsHolderImplTest.java View File

@@ -25,7 +25,6 @@ import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.core.component.SnapshotDto;

import static org.assertj.core.api.Assertions.assertThat;

@@ -37,7 +36,7 @@ public class PeriodsHolderImplTest {
@Test
public void get_periods() throws Exception {
List<Period> periods = new ArrayList<>();
periods.add(new Period("mode", null, new SnapshotDto()));
periods.add(new Period(1, "mode", null, 1000L));

PeriodsHolderImpl periodsHolder = new PeriodsHolderImpl();
periodsHolder.setPeriods(periods);

+ 220
- 14
server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java View File

@@ -23,7 +23,6 @@ package org.sonar.server.computation.step;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.junit.After;
import org.junit.Before;
@@ -33,6 +32,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.core.persistence.DbSession;
@@ -44,7 +44,6 @@ import org.sonar.server.computation.batch.TreeRootHolderRule;
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.DumbComponent;
import org.sonar.server.computation.period.Period;
import org.sonar.server.computation.period.PeriodFinder;
import org.sonar.server.computation.period.PeriodsHolderImpl;
import org.sonar.server.db.DbClient;
import org.sonar.test.DbTests;
@@ -67,6 +66,9 @@ public class FeedPeriodsStepTest extends BaseStepTest {
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();

@Rule
public LogTester logTester = new LogTester();

PeriodsHolderImpl periodsHolder = new PeriodsHolderImpl();

DbClient dbClient;
@@ -101,7 +103,7 @@ public class FeedPeriodsStepTest extends BaseStepTest {
Component project = new DumbComponent(Component.Type.PROJECT, 1, "ABCD", PROJECT_KEY);
treeRootHolder.setRoot(project);

sut = new FeedPeriodsStep(dbClient, settings, treeRootHolder, new PeriodFinder(dbClient), reportReader, periodsHolder);
sut = new FeedPeriodsStep(dbClient, settings, treeRootHolder, reportReader, periodsHolder);
}

@After
@@ -118,23 +120,20 @@ public class FeedPeriodsStepTest extends BaseStepTest {
}

@Test
public void get_one_period() throws Exception {
public void feed_one_period() throws Exception {
dbTester.prepareDbUnit(getClass(), "shared.xml");

String textDate = "2008-11-22";
Date date = DATE_FORMAT.parse(textDate);
settings.setProperty("sonar.timemachine.period1", textDate);

sut.execute();
List<Period> periods = periodsHolder.getPeriods();
assertThat(periods).hasSize(1);

Period period = periods.get(0);
Period period = periods.get(0);
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
assertThat(period.getModeParameter()).isEqualTo(textDate);
assertThat(period.getSnapshotDate()).isEqualTo(1227358680000L);
assertThat(period.getTargetDate()).isEqualTo(date.getTime());
assertThat(period.getProjectSnapshot().getId()).isEqualTo(1003L);
}

@Test
@@ -158,7 +157,214 @@ public class FeedPeriodsStepTest extends BaseStepTest {
}

@Test
public void get_five_different_periods() throws Exception {
public void ignore_unprocessed_snapshots() throws Exception {
dbTester.prepareDbUnit(getClass(), "unprocessed_snapshots.xml");

settings.setProperty("sonar.timemachine.period1", "100");

sut.execute();
assertThat(periodsHolder.getPeriods()).isEmpty();
}

@Test
public void feed_period_by_date() throws Exception {
dbTester.prepareDbUnit(getClass(), "shared.xml");

String textDate = "2008-11-22";
settings.setProperty("sonar.timemachine.period1", textDate);

sut.execute();
List<Period> periods = periodsHolder.getPeriods();
assertThat(periods).hasSize(1);

Period period = periods.get(0);
// Return analysis from given date 2008-11-22
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
assertThat(period.getModeParameter()).isEqualTo(textDate);
assertThat(period.getSnapshotDate()).isEqualTo(1227358680000L);

assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs().get(0)).startsWith("Compare to date 2008-11-22 (analysis of ");
}

@Test
public void search_by_date_return_nearest_later_analysis() throws Exception {
dbTester.prepareDbUnit(getClass(), "shared.xml");
String date = "2008-11-24";

settings.setProperty("sonar.timemachine.period1", date);

sut.execute();
List<Period> periods = periodsHolder.getPeriods();
assertThat(periods).hasSize(1);

// Analysis form 2008-11-29
Period period = periods.get(0);
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
assertThat(period.getModeParameter()).isEqualTo(date);
assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L);
}

@Test
public void no_period_by_date() throws Exception {
dbTester.prepareDbUnit(getClass(), "shared.xml");

// No analysis at and after this date
settings.setProperty("sonar.timemachine.period1", "2008-11-30");

sut.execute();
assertThat(periodsHolder.getPeriods()).isEmpty();
}

@Test
public void feed_period_by_days() throws Exception {
dbTester.prepareDbUnit(getClass(), "shared.xml");

settings.setProperty("sonar.timemachine.period1", "10");

sut.execute();
List<Period> periods = periodsHolder.getPeriods();
assertThat(periods).hasSize(1);

// return analysis from 2008-11-20
Period period = periods.get(0);
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DAYS);
assertThat(period.getModeParameter()).isEqualTo("10");
assertThat(period.getSnapshotDate()).isEqualTo(1227157200000L);

assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs().get(0)).startsWith("Compare over 10 days (2008-11-20, analysis of ");
}

@Test
public void no_period_by_days() throws Exception {
dbTester.prepareDbUnit(getClass(), "empty.xml");

settings.setProperty("sonar.timemachine.period1", "0");

sut.execute();
assertThat(periodsHolder.getPeriods()).isEmpty();
}

@Test
public void feed_period_by_previous_analysis() throws Exception {
dbTester.prepareDbUnit(getClass(), "shared.xml");

settings.setProperty("sonar.timemachine.period1", "previous_analysis");

sut.execute();
List<Period> periods = periodsHolder.getPeriods();
assertThat(periods).hasSize(1);

// return analysis from 2008-11-29
Period period = periods.get(0);
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
assertThat(period.getModeParameter()).isNotNull();
assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L);

assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs().get(0)).startsWith("Compare to previous analysis (");
}

@Test
public void no_period_by_previous_analysis() throws Exception {
dbTester.prepareDbUnit(getClass(), "empty.xml");

settings.setProperty("sonar.timemachine.period1", "previous_analysis");

sut.execute();
assertThat(periodsHolder.getPeriods()).isEmpty();
}

@Test
public void feed_period_by_previous_version() throws Exception {
dbTester.prepareDbUnit(getClass(), "shared.xml");

settings.setProperty("sonar.timemachine.period1", "previous_version");

sut.execute();
List<Period> periods = periodsHolder.getPeriods();
assertThat(periods).hasSize(1);

// Analysis form 2008-11-12
Period period = periods.get(0);
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
assertThat(period.getModeParameter()).isEqualTo("1.0");
assertThat(period.getSnapshotDate()).isEqualTo(1226494680000L);

assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs().get(0)).startsWith("Compare to previous version (");
}

@Test
public void feed_period_by_previous_version_wit_previous_version_deleted() throws Exception {
dbTester.prepareDbUnit(getClass(), "previous_version_deleted.xml");

settings.setProperty("sonar.timemachine.period1", "previous_version");

sut.execute();
List<Period> periods = periodsHolder.getPeriods();
assertThat(periods).hasSize(1);

// Analysis form 2008-11-11
Period period = periods.get(0);
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
assertThat(period.getModeParameter()).isEqualTo("0.9");
assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);
}

@Test
public void no_period_by_previous_version() throws Exception {
dbTester.prepareDbUnit(getClass(), "empty.xml");

settings.setProperty("sonar.timemachine.period1", "previous_version");

sut.execute();
assertThat(periodsHolder.getPeriods()).isEmpty();
}

@Test
public void no_period_by_previous_version_when_no_event_version() throws Exception {
dbTester.prepareDbUnit(getClass(), "no_previous_version.xml");

settings.setProperty("sonar.timemachine.period1", "previous_version");

sut.execute();
assertThat(periodsHolder.getPeriods()).isEmpty();
}

@Test
public void feed_period_by_version() throws Exception {
dbTester.prepareDbUnit(getClass(), "shared.xml");

settings.setProperty("sonar.timemachine.period1", "0.9");

sut.execute();
List<Period> periods = periodsHolder.getPeriods();
assertThat(periods).hasSize(1);

// Analysis form 2008-11-11
Period period = periods.get(0);
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION);
assertThat(period.getModeParameter()).isEqualTo("0.9");
assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);

assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs().get(0)).startsWith("Compare to version (0.9) (");
}

@Test
public void no_period_by_version() throws Exception {
dbTester.prepareDbUnit(getClass(), "empty.xml");

settings.setProperty("sonar.timemachine.period1", "0.8");

sut.execute();
assertThat(periodsHolder.getPeriods()).isEmpty();
}

@Test
public void feed_five_different_periods() throws Exception {
dbTester.prepareDbUnit(getClass(), "shared.xml");

settings.setProperty("sonar.timemachine.period1", "2008-11-22"); // Analysis from 2008-11-22 should be returned
@@ -181,23 +387,23 @@ public class FeedPeriodsStepTest extends BaseStepTest {

assertThat(periods.get(0).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
assertThat(periods.get(0).getIndex()).isEqualTo(1);
assertThat(periods.get(0).getProjectSnapshot().getId()).isEqualTo(1003L);
assertThat(periods.get(0).getSnapshotDate()).isEqualTo(1227358680000L);

assertThat(periods.get(1).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DAYS);
assertThat(periods.get(1).getIndex()).isEqualTo(2);
assertThat(periods.get(1).getProjectSnapshot().getId()).isEqualTo(1002L);
assertThat(periods.get(1).getSnapshotDate()).isEqualTo(1227157200000L);

assertThat(periods.get(2).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
assertThat(periods.get(2).getIndex()).isEqualTo(3);
assertThat(periods.get(2).getProjectSnapshot().getId()).isEqualTo(1004L);
assertThat(periods.get(2).getSnapshotDate()).isEqualTo(1227934800000L);

assertThat(periods.get(3).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
assertThat(periods.get(3).getIndex()).isEqualTo(4);
assertThat(periods.get(3).getProjectSnapshot().getId()).isEqualTo(1001L);
assertThat(periods.get(3).getSnapshotDate()).isEqualTo(1226494680000L);

assertThat(periods.get(4).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION);
assertThat(periods.get(4).getIndex()).isEqualTo(5);
assertThat(periods.get(4).getProjectSnapshot().getId()).isEqualTo(1000L);
assertThat(periods.get(4).getSnapshotDate()).isEqualTo(1226379600000L);
}

@Test

+ 0
- 46
server/sonar-server/src/test/resources/org/sonar/server/computation/period/PeriodFinderTest/previous_version_deleted.xml View File

@@ -1,46 +0,0 @@
<dataset>

<projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
root_id="[null]" uuid="ABCD"
description="[null]"
enabled="true" language="java" copy_resource_id="[null]" person_id="[null]"/>


<!-- version 1.0 -->
<snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
period5_param="[null]" period5_date="[null]"
project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
scope="PRJ" qualifier="TRK" created_at="1225630680000" build_date="1225630680000" version="1.0" path=""
status="P" islast="false" depth="0"/>

<!-- version 1.1 -->
<snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
period5_param="[null]" period5_date="[null]"
project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
scope="PRJ" qualifier="TRK" created_at="1225803480000" build_date="1225803480000" version="1.1" path=""
status="P" islast="false" depth="0"/>

<!-- version 1.2-SNAPSHOT -->
<snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
period5_param="[null]" period5_date="[null]"
project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
scope="PRJ" qualifier="TRK" created_at="1225976280000" build_date="1225976280000" version="1.2-SNAPSHOT" path=""
status="P" islast="false" depth="0"/>

<events id="1" name="1.0" component_uuid="ABCD" snapshot_id="1000" category="Version" event_date="1225630680000" created_at="1225630680000" description=""
event_data="[null]"/>
<events id="2" name="Foo" component_uuid="ABCD" snapshot_id="1000" category="Other" event_date="1225717080000" created_at="1225717080000" description=""
event_data="[null]"/>
<!-- The "1.1" version was deleted from the history : -->
<!-- events id="3" name="1.1" component_uuid="ABCD" snapshot_id="1001" category="Version" event_date="2008-11-04 13:58:00.00" created_at="2008-11-04 13:58:00.00" description=""/-->
<events id="4" name="Bar" component_uuid="ABCD" snapshot_id="1001" category="Other" event_date="1225889880000" created_at="1225889880000" description=""
event_data="[null]"/>
<events id="5" name="Uhh" component_uuid="ABCD" snapshot_id="1002" category="Other" event_date="1226062680000" created_at="1226062680000" description=""
event_data="[null]"/>
<events id="6" name="1.2-SNAPSHOT" component_uuid="ABCD" snapshot_id="1003" category="Version" event_date="1226235480000" created_at="1226235480000" description=""
event_data="[null]"/>

</dataset>

+ 7
- 0
server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/empty.xml View File

@@ -0,0 +1,7 @@
<dataset>

<projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="PROJECT_KEY" name="project" long_name="[null]" description="[null]"
uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
enabled="true" language="java" copy_resource_id="[null]" person_id="[null]"/>

</dataset>

server/sonar-server/src/test/resources/org/sonar/server/computation/period/PeriodFinderTest/find_by_date.xml → server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/find_by_date.xml View File


server/sonar-server/src/test/resources/org/sonar/server/computation/period/PeriodFinderTest/find_by_days.xml → server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/find_by_days.xml View File


server/sonar-server/src/test/resources/org/sonar/server/computation/period/PeriodFinderTest/find_by_previous_analysis.xml → server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/find_by_previous_analysis.xml View File


server/sonar-server/src/test/resources/org/sonar/server/computation/period/PeriodFinderTest/find_by_previous_version.xml → server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/find_by_previous_version.xml View File


server/sonar-server/src/test/resources/org/sonar/server/computation/period/PeriodFinderTest/find_by_version.xml → server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/find_by_version.xml View File


server/sonar-server/src/test/resources/org/sonar/server/computation/period/PeriodFinderTest/no_previous_version.xml → server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/no_previous_version.xml View File


+ 39
- 0
server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/previous_version_deleted.xml View File

@@ -0,0 +1,39 @@
<dataset>

<projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="PROJECT_KEY" name="project" long_name="[null]" description="[null]"
uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
enabled="true" language="java" copy_resource_id="[null]" person_id="[null]"/>

<!-- 2008-11-11 -->
<!-- Version 0.9 -->
<snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
period5_param="[null]" period5_date="[null]"
project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path=""
status="P" islast="false" depth="0"/>

<!-- 2008-11-12 -->
<!-- Version 1.0 -->
<snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
scope="PRJ" qualifier="TRK" created_at="1226494680000" build_date="1226494680000" version="1.0" path=""
status="P" islast="false" depth="0"/>

<!-- 2008-11-20 -->
<!-- version 1.1 -->
<snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
period5_param="[null]" period5_date="[null]"
project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
scope="PRJ" qualifier="TRK" created_at="1227157200000" build_date="1227157200000" version="1.1" path=""
status="P" islast="false" depth="0"/>


<events id="1" name="0.9" component_uuid="ABCD" snapshot_id="1000" category="Version" event_date="1226379600000" created_at="1226379600000" description="" event_data="[null]"/>
<!-- The "1.0" version was deleted from the history : -->
<!--<events id="2" name="1.0" component_uuid="ABCD" snapshot_id="1001" category="Version" event_date="1226494680000" created_at="1226494680000" description="" event_data="[null]"/>-->
<events id="3" name="1.1" component_uuid="ABCD" snapshot_id="1004" category="Version" event_date="1227934800000" created_at="1227934800000" description="" event_data="[null]"/>

</dataset>

+ 15
- 0
server/sonar-server/src/test/resources/org/sonar/server/computation/step/FeedPeriodsStepTest/unprocessed_snapshots.xml View File

@@ -0,0 +1,15 @@
<dataset>

<projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="PROJECT_KEY" name="project" long_name="[null]" description="[null]"
uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
enabled="true" language="java" copy_resource_id="[null]" person_id="[null]"/>

<!-- Unprocessed snapshot -->
<snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
period5_param="[null]" period5_date="[null]"
project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path=""
status="U" islast="false" depth="0"/>

</dataset>

Loading…
Cancel
Save