use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.
the class BuildFinderTest method testSinceUntil.
@Test
public void testSinceUntil() {
final MockTimeService time = new MockTimeService(Dates.now().getTime());
myServer.setTimeService(time);
final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
final SFinishedBuild build10 = build().in(buildConf1).finish();
time.jumpTo(10);
final Date afterBuild10 = time.getNow();
time.jumpTo(10);
final SFinishedBuild build20 = build().in(buildConf2).failed().finish();
time.jumpTo(10);
final SFinishedBuild build25Deleted = build().in(buildConf2).failed().finish();
final long build25DeletedId = build25Deleted.getBuildId();
myFixture.getSingletonService(BuildHistory.class).removeEntry(build25Deleted);
final SFinishedBuild build30 = build().in(buildConf2).failedToStart().finish();
time.jumpTo(10);
final Date afterBuild30 = time.getNow();
time.jumpTo(10);
final SFinishedBuild build40 = build().in(buildConf1).finish();
time.jumpTo(10);
final SFinishedBuild build50Deleted = build().in(buildConf2).failed().finish();
final long build50DeletedId = build50Deleted.getBuildId();
myFixture.getSingletonService(BuildHistory.class).removeEntry(build50Deleted);
final SFinishedBuild build60 = build().in(buildConf2).finish();
time.jumpTo(10);
final Date afterBuild60 = time.getNow();
final SFinishedBuild build70 = build().in(buildConf1).finish();
time.jumpTo(10);
final SRunningBuild build80 = build().in(buildConf1).run();
time.jumpTo(10);
final SQueuedBuild build90 = build().in(buildConf1).addToQueue();
checkBuilds("sinceBuild:(id:" + build10.getBuildId() + ")", build70, build60, build40, build30, build20);
// checkBuilds("sinceBuild:(id:" + build10.getBuildId() + "),state:any", build90, build80, build70, build60, build40, build30, build20);
// checkBuilds("sinceBuild:(id:" + build25DeletedId + ")", build70, build60, build40,build30);
checkBuilds("untilBuild:(id:" + build60.getBuildId() + ")", build60, build40, build30, build20, build10);
if (build20.getStartDate().getTime() % 1000 == 0) {
// there is a bug/strange behavior in the obsolete builds finder, just make the test not fail:
// documenting current behavior
checkBuilds("sinceDate:" + fDate(build20.getStartDate()), build70, build60, build40, build30);
// documenting current behavior
checkBuilds("sinceDate:" + fDate(build20.getStartDate()) + ")", build70, build60, build40, build30);
checkBuilds("untilDate:" + fDate(build60.getStartDate()) + ")", build60, build40, build30, build20, build10);
} else {
// documenting current behavior
checkBuilds("sinceDate:" + fDate(build20.getStartDate()), build70, build60, build40, build30, build20);
// documenting current behavior
checkBuilds("sinceDate:" + fDate(build20.getStartDate()) + ")", build70, build60, build40, build30, build20);
checkBuilds("untilDate:" + fDate(build60.getStartDate()) + ")", build40, build30, build20, build10);
}
checkBuilds("sinceDate:" + fDate(afterBuild30) + ")", build70, build60, build40);
checkBuilds("untilDate:" + fDate(afterBuild30) + ")", build30, build20, build10);
// checkBuilds("sinceBuild:(id:" + build10.getBuildId() + "),sinceDate:" + fDate(build10.getStartDate()), build70, build60, build40, build30, build20);
// checkBuilds("sinceBuild:(id:" + build10.getBuildId() + "),sinceDate:" + fDate(afterBuild30), build70, build60, build40);
// checkBuilds("untilBuild:(id:" + build60.getBuildId() + "),untilDate:" + fDate(build60.getStartDate()), build60, build40, build30, build20, build10);
// checkBuilds("untilBuild:(id:" + build60.getBuildId() + "),untilDate:" + fDate(afterBuild30), build10, build20, build30);
checkBuilds("sinceBuild:(id:" + build20.getBuildId() + "),untilBuild:" + build60.getBuildId(), build60, build40, build30);
checkBuilds("sinceBuild:(id:" + build20.getBuildId() + "),untilDate:" + fDate(afterBuild30), build30);
checkBuilds("sinceDate:(" + fDate(afterBuild10) + "),untilDate:" + fDate(afterBuild30), build30, build20);
}
use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.
the class BuildPromotionFinderTest method testStopProcessing.
@Test(dataProvider = "allBooleans")
public void testStopProcessing(boolean timeAsSecondBoundary) {
final MockTimeService time = new MockTimeService(Dates.now().getTime());
myServer.setTimeService(time);
if (timeAsSecondBoundary) {
time.jumpTo(1000L - time.now() % 1000);
} else if (time.now() % 1000 == 0) {
time.jumpTo(10L);
}
final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
final SFinishedBuild finishedBuild03 = build().in(buildConf1).finish();
time.jumpTo(10);
final SFinishedBuild finishedBuild05 = build().in(buildConf1).finish();
time.jumpTo(10);
final SQueuedBuild queuedBuild10 = build().in(buildConf1).addToQueue();
time.jumpTo(10);
final SQueuedBuild queuedBuild20 = build().in(buildConf1).parameter("a", "x").addToQueue();
time.jumpTo(10);
myFixture.getBuildQueue().moveTop(queuedBuild20.getItemId());
final RunningBuildEx runningBuild20 = BuildBuilder.run(queuedBuild20, myFixture);
time.jumpTo(10);
final SQueuedBuild queuedBuild30 = build().in(buildConf1).parameter("a", "y").addToQueue();
time.jumpTo(10);
myFixture.getBuildQueue().moveTop(queuedBuild10.getItemId());
// adding one more agent to allow parallel builds
final MockBuildAgent agent2 = myFixture.createEnabledAgent("Ant");
final RunningBuildEx runningBuild10 = BuildBuilder.run(queuedBuild10, myFixture);
time.jumpTo(10);
final SFinishedBuild finishedBuild10 = myFixture.finishBuild(runningBuild10, false);
time.jumpTo(10);
final RunningBuildEx runningBuild30 = BuildBuilder.run(queuedBuild30, myFixture);
agent2.setEnabled(false, null, "");
time.jumpTo(10);
final SFinishedBuild finishedBuild30 = myFixture.finishBuild(runningBuild30, false);
time.jumpTo(10);
final SFinishedBuild finishedBuild20 = myFixture.finishBuild(runningBuild20, false);
time.jumpTo(10);
final SQueuedBuild queuedBuild40 = build().in(buildConf1).parameter("a", "z").addToQueue();
time.jumpTo(10);
final SQueuedBuild queuedBuild50 = build().in(buildConf1).parameter("a", "z1").addToQueue();
time.jumpTo(10);
myFixture.getBuildQueue().moveTop(queuedBuild50.getItemId());
final RunningBuildEx runningBuild50 = BuildBuilder.run(queuedBuild50, myFixture);
time.jumpTo(10);
checkBuilds("state:any", 7, getBuildPromotions(queuedBuild40, runningBuild50, finishedBuild30, finishedBuild10, finishedBuild20, finishedBuild05, finishedBuild03));
checkBuilds("startDate:(build:(id:" + finishedBuild10.getBuildId() + "),condition:after),state:any", 5, getBuildPromotions(runningBuild50, finishedBuild30));
checkBuilds("startDate:(build:(id:" + finishedBuild20.getBuildId() + "),condition:after),state:any", 6, getBuildPromotions(runningBuild50, finishedBuild30, finishedBuild10));
checkBuilds("startDate:(build:(id:" + finishedBuild30.getBuildId() + "),condition:after),state:any", 4, getBuildPromotions(runningBuild50));
checkBuilds("startDate:(build:(id:" + finishedBuild30.getBuildId() + "),condition:after)", 2, new BuildPromotion[] {});
checkBuilds("startDate:(build:(id:" + finishedBuild30.getBuildId() + "),condition:after),state:finished", 2, new BuildPromotion[] {});
checkBuilds("startDate:(build:(id:" + finishedBuild30.getBuildId() + "),condition:after),state:queued", 1, new BuildPromotion[] {});
checkBuilds("startDate:(build:(id:" + finishedBuild10.getBuildId() + "),condition:after)", 3, getBuildPromotions(finishedBuild30));
checkBuilds("startDate:(build:(id:" + finishedBuild20.getBuildId() + "),condition:after)", 4, getBuildPromotions(finishedBuild30, finishedBuild10));
if (finishedBuild10.getStartDate().getTime() % 1000 == 0) {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild10.getStartDate()) + ",condition:after),state:any", 5, getBuildPromotions(runningBuild50, finishedBuild30));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild10.getStartDate()) + ",condition:after,includeInitial:true),state:any", 5, getBuildPromotions(runningBuild50, finishedBuild30, finishedBuild10));
} else {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild10.getStartDate()) + ",condition:after),state:any", 5, getBuildPromotions(runningBuild50, finishedBuild30, finishedBuild10));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild10.getStartDate()) + ",condition:after,includeInitial:true),state:any", 5, getBuildPromotions(runningBuild50, finishedBuild30, finishedBuild10));
}
checkBuilds("startDate:(date:" + getTimeWithMs(finishedBuild10.getStartDate()) + ",condition:after),state:any", 5, getBuildPromotions(runningBuild50, finishedBuild30));
checkBuilds("startDate:(date:" + getTimeWithMs(new Date(finishedBuild10.getStartDate().getTime() - 1)) + ",condition:after),state:any", 5, getBuildPromotions(runningBuild50, finishedBuild30, finishedBuild10));
checkBuilds("startDate:(date:" + getTimeWithMs(new Date(finishedBuild10.getStartDate().getTime() + 1)) + ",condition:after),state:any", 5, getBuildPromotions(runningBuild50, finishedBuild30));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild10.getStartDate()) + ",condition:before),state:any", 7, getBuildPromotions(finishedBuild20, finishedBuild05, finishedBuild03));
if (finishedBuild20.getStartDate().getTime() % 1000 == 0) {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild20.getStartDate()) + ",condition:after),state:any", 6, getBuildPromotions(runningBuild50, finishedBuild30, finishedBuild10));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild20.getStartDate()) + ",condition:after,includeInitial:true),state:any", 6, getBuildPromotions(runningBuild50, finishedBuild30, finishedBuild10, finishedBuild20));
} else {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild20.getStartDate()) + ",condition:after),state:any", 6, getBuildPromotions(runningBuild50, finishedBuild30, finishedBuild10, finishedBuild20));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild20.getStartDate()) + ",condition:after,includeInitial:true),state:any", 6, getBuildPromotions(runningBuild50, finishedBuild30, finishedBuild10, finishedBuild20));
}
checkBuilds("startDate:(date:" + getTimeWithMs(new Date(finishedBuild20.getStartDate().getTime())) + ",condition:after),state:any", 6, getBuildPromotions(runningBuild50, finishedBuild30, finishedBuild10));
if (finishedBuild30.getStartDate().getTime() % 1000 == 0) {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild30.getStartDate()) + ",condition:after),state:any", 4, getBuildPromotions(runningBuild50));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild30.getStartDate()) + ",condition:after,includeInitial:true),state:any", 4, getBuildPromotions(runningBuild50, finishedBuild30));
} else {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild30.getStartDate()) + ",condition:after),state:any", 4, getBuildPromotions(runningBuild50, finishedBuild30));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild30.getStartDate()) + ",condition:after,includeInitial:true),state:any", 4, getBuildPromotions(runningBuild50, finishedBuild30));
}
checkBuilds("startDate:(date:" + getTimeWithMs(finishedBuild30.getStartDate()) + ",condition:after),state:any", 4, getBuildPromotions(runningBuild50));
if (finishedBuild30.getStartDate().getTime() % 1000 == 0) {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild30.getStartDate()) + ",condition:after)", 2, getBuildPromotions());
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild30.getStartDate()) + ",condition:after,includeInitial:true)", 2, getBuildPromotions(finishedBuild30));
} else {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild30.getStartDate()) + ",condition:after)", 2, getBuildPromotions(finishedBuild30));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild30.getStartDate()) + ",condition:after,includeInitial:true)", 2, getBuildPromotions(finishedBuild30));
}
checkBuilds("startDate:(date:" + getTimeWithMs(finishedBuild30.getStartDate()) + ",condition:after)", 2, new BuildPromotion[] {});
if (finishedBuild10.getStartDate().getTime() % 1000 == 0) {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild10.getStartDate()) + ",condition:after)", 3, getBuildPromotions(finishedBuild30));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild10.getStartDate()) + ",condition:after,includeInitial:true)", 3, getBuildPromotions(finishedBuild30, finishedBuild10));
} else {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild10.getStartDate()) + ",condition:after)", 3, getBuildPromotions(finishedBuild30, finishedBuild10));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild10.getStartDate()) + ",condition:after,includeInitial:true)", 3, getBuildPromotions(finishedBuild30, finishedBuild10));
}
checkBuilds("startDate:(date:" + getTimeWithMs(finishedBuild10.getStartDate()) + ",condition:after)", 3, getBuildPromotions(finishedBuild30));
if (finishedBuild20.getStartDate().getTime() % 1000 == 0) {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild20.getStartDate()) + ",condition:after)", 4, getBuildPromotions(finishedBuild30, finishedBuild10));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild20.getStartDate()) + ",condition:after,includeInitial:true)", 4, getBuildPromotions(finishedBuild30, finishedBuild10, finishedBuild20));
} else {
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild20.getStartDate()) + ",condition:after)", 4, getBuildPromotions(finishedBuild30, finishedBuild10, finishedBuild20));
checkBuilds("startDate:(date:" + Util.formatTime(finishedBuild20.getStartDate()) + ",condition:after,includeInitial:true)", 4, getBuildPromotions(finishedBuild30, finishedBuild10, finishedBuild20));
}
checkBuilds("startDate:(date:" + getTimeWithMs(finishedBuild20.getStartDate()) + ",condition:after)", 4, getBuildPromotions(finishedBuild30, finishedBuild10));
checkBuilds("startDate:(build:(id:" + finishedBuild20.getBuildId() + "),condition:after),startDate:(build:(id:" + finishedBuild30.getBuildId() + "),condition:before),state:any", 6, getBuildPromotions(finishedBuild10));
checkBuilds("startDate:(build:(id:" + finishedBuild05.getBuildId() + "),condition:after),finishDate:(build:(id:" + finishedBuild30.getBuildId() + "),condition:before),state:any", 7, getBuildPromotions(finishedBuild10));
}
use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.
the class BuildPromotionFinderTest method testSinceUntil.
@Test
public void testSinceUntil() {
final MockTimeService time = new MockTimeService(Dates.now().getTime());
myServer.setTimeService(time);
final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
final SFinishedBuild build10 = build().in(buildConf1).finish();
time.jumpTo(10);
final Date afterBuild10 = time.getNow();
time.jumpTo(10);
final SFinishedBuild build20 = build().in(buildConf2).failed().finish();
time.jumpTo(10);
final SFinishedBuild build25Deleted = build().in(buildConf2).failed().finish();
final long build25DeletedId = build25Deleted.getBuildId();
myFixture.getSingletonService(BuildHistory.class).removeEntry(build25Deleted);
final SFinishedBuild build30 = build().in(buildConf2).failedToStart().finish();
time.jumpTo(10);
final Date afterBuild30 = time.getNow();
time.jumpTo(10);
final SFinishedBuild build40 = build().in(buildConf1).finish();
time.jumpTo(10);
final SFinishedBuild build50Deleted = build().in(buildConf2).failed().finish();
final long build50DeletedId = build50Deleted.getBuildId();
myFixture.getSingletonService(BuildHistory.class).removeEntry(build50Deleted);
final SFinishedBuild build60 = build().in(buildConf2).finish();
time.jumpTo(10);
final Date afterBuild60 = time.getNow();
final SFinishedBuild build70 = build().in(buildConf1).finish();
time.jumpTo(10);
final SRunningBuild build80 = build().in(buildConf1).run();
time.jumpTo(10);
final SQueuedBuild build90 = build().in(buildConf1).addToQueue();
checkBuilds("defaultFilter:false", 8, getBuildPromotions(build90, build80, build70, build60, build40, build30, build20, build10));
checkBuilds("state:any", 7, getBuildPromotions(build90, build80, build70, build60, build40, build20, build10));
checkBuilds("defaultFilter:false,buildType:(id:" + buildConf1.getExternalId() + ")", 5, getBuildPromotions(build90, build80, build70, build40, build10));
checkBuilds("sinceBuild:(id:" + build10.getBuildId() + "),state:any", 7, getBuildPromotions(build90, build80, build70, build60, build40, build20));
checkBuilds("sinceBuild:(id:" + build10.getBuildId() + "),state:any,failedToStart:any", 8, getBuildPromotions(build90, build80, build70, build60, build40, build30, build20));
checkBuilds("sinceBuild:(id:" + build30.getBuildId() + "),state:any", 6, getBuildPromotions(build90, build80, build70, build60, build40));
checkBuilds("sinceBuild:(id:" + build30.getBuildId() + "),state:any,failedToStart:any", 6, getBuildPromotions(build90, build80, build70, build60, build40));
checkBuilds("sinceBuild:(id:" + build60.getBuildId() + "),state:any", 4, getBuildPromotions(build90, build80, build70));
if (build60.getStartDate().getTime() % 1000 == 0) {
// documenting current behavior for the legacy "sinceDate": it is not quite consistent when the time has 0 ms
checkBuilds("sinceDate:(" + Util.formatTime(build60.getStartDate()) + "),state:any", 5, getBuildPromotions(build80, build70));
checkBuilds("sinceBuild:(id:" + build30.getBuildId() + "),sinceDate:(" + Util.formatTime(build60.getStartDate()) + "),state:any", 5, getBuildPromotions(build80, build70));
} else {
checkBuilds("sinceDate:(" + Util.formatTime(build60.getStartDate()) + "),state:any", 5, getBuildPromotions(build80, build70, build60));
checkBuilds("sinceBuild:(id:" + build30.getBuildId() + "),sinceDate:(" + Util.formatTime(build60.getStartDate()) + "),state:any", 5, getBuildPromotions(build80, build70, build60));
}
checkExceptionOnBuildsSearch(BadRequestException.class, "sinceBuild:(xxx)");
checkExceptionOnBuildsSearch(BadRequestException.class, "sinceBuild:(buildType:(" + buildConf1.getId() + "),status:FAILURE)");
// documenting current behavior: extra ")" does not produce an error
checkBuilds("sinceBuild:(id:" + build25DeletedId + "),state:finished,defaultFilter:false", getBuildPromotions(build70, build60, build40, build30));
checkBuilds("untilBuild:(id:" + build60.getBuildId() + "),state:finished,defaultFilter:false", getBuildPromotions(build60, build40, build30, build20, build10));
checkBuilds("untilBuild:(id:" + build50DeletedId + "),state:any,defaultFilter:false", getBuildPromotions(build40, build30, build20, build10));
if (build20.getStartDate().getTime() % 1000 == 0) {
// documenting current behavior for the legacy "sinceDate": it is not quite consistent when the time has 0 ms
checkBuilds("sinceDate:" + Util.formatTime(build20.getStartDate()) + ",state:finished,defaultFilter:false", getBuildPromotions(build70, build60, build40, build30));
checkBuilds("sinceDate:" + Util.formatTime(build20.getStartDate()) + "),state:finished,defaultFilter:false", getBuildPromotions(build70, build60, build40, build30));
} else {
checkBuilds("sinceDate:" + Util.formatTime(build20.getStartDate()) + ",state:finished,defaultFilter:false", getBuildPromotions(build70, build60, build40, build30, build20));
checkBuilds("sinceDate:" + Util.formatTime(build20.getStartDate()) + "),state:finished,defaultFilter:false", getBuildPromotions(build70, build60, build40, build30, build20));
}
checkBuilds("sinceDate:" + Util.formatTime(afterBuild30) + "),state:finished,defaultFilter:false", getBuildPromotions(build70, build60, build40));
if (build60.getStartDate().getTime() % 1000 == 0) {
// documenting current behavior for the legacy "sinceDate": it is not quite consistent when the time has 0 ms
checkBuilds("untilDate:" + Util.formatTime(build60.getStartDate()) + "),state:finished,defaultFilter:false", getBuildPromotions(build60, build40, build30, build20, build10));
} else {
checkBuilds("untilDate:" + Util.formatTime(build60.getStartDate()) + "),state:finished,defaultFilter:false", getBuildPromotions(build40, build30, build20, build10));
}
checkBuilds("untilDate:" + Util.formatTime(afterBuild30) + "),state:finished,defaultFilter:false", getBuildPromotions(build30, build20, build10));
checkBuilds("sinceBuild:(id:" + build10.getBuildId() + "),sinceDate:" + Util.formatTime(build10.getStartDate()) + ",state:finished,defaultFilter:false", getBuildPromotions(build70, build60, build40, build30, build20));
checkBuilds("sinceBuild:(id:" + build10.getBuildId() + "),sinceDate:" + Util.formatTime(afterBuild30) + ",state:finished,defaultFilter:false", getBuildPromotions(build70, build60, build40));
if (build60.getStartDate().getTime() % 1000 == 0) {
// documenting current behavior for the legacy "sinceDate": it is not quite consistent when the time has 0 ms
checkBuilds("untilBuild:(id:" + build60.getBuildId() + "),untilDate:" + Util.formatTime(build60.getStartDate()) + ",state:finished,defaultFilter:false", getBuildPromotions(build60, build40, build30, build20, build10));
} else {
checkBuilds("untilBuild:(id:" + build60.getBuildId() + "),untilDate:" + Util.formatTime(build60.getStartDate()) + ",state:finished,defaultFilter:false", getBuildPromotions(build40, build30, build20, build10));
}
checkBuilds("untilBuild:(id:" + build60.getBuildId() + "),untilDate:" + Util.formatTime(afterBuild30) + ",state:finished,defaultFilter:false", getBuildPromotions(build30, build20, build10));
checkBuilds("sinceBuild:(id:" + build20.getBuildId() + "),untilBuild:" + build60.getBuildId() + ",state:finished,defaultFilter:false", getBuildPromotions(build60, build40, build30));
checkBuilds("sinceBuild:(id:" + build20.getBuildId() + "),untilDate:" + Util.formatTime(afterBuild30) + ",state:finished,defaultFilter:false", getBuildPromotions(build30));
checkBuilds("sinceDate:(" + Util.formatTime(afterBuild10) + "),untilDate:" + Util.formatTime(afterBuild30) + ",state:finished,defaultFilter:false", getBuildPromotions(build30, build20));
}
use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.
the class BuildPromotionFinderTest method testTimesNoTimeZone.
@Test
public void testTimesNoTimeZone() {
// using year 2001 as with 2016 there are not actual tz issues (e.g. MSK with JDK 1.8_05)
final MockTimeService time = new MockTimeService(new DateTime(2001, 2, 16, 16, 47, 43, 0).getMillis());
myServer.setTimeService(time);
// recreate finders to let time service sink in
initFinders();
final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
final SFinishedBuild build10 = build().in(buildConf1).finish();
time.jumpTo(120);
final SFinishedBuild build15 = build().in(buildConf1).finish();
time.jumpTo(120);
final SFinishedBuild build20 = build().in(buildConf1).finish();
checkBuilds("finishDate:(date:2001-02-16T16:47:44)", getBuildPromotions(build20, build15));
checkBuilds("finishDate:(date:20010216T164744.0)", getBuildPromotions(build20, build15));
}
use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.
the class BuildPromotionFinderTest method testTimes.
@Test(dataProvider = "allBooleans")
public void testTimes(boolean timeAsSecondBoundary) {
final MockTimeService time = new MockTimeService(Dates.now().getTime());
myServer.setTimeService(time);
// recreate finders to let time service sink in
initFinders();
if (timeAsSecondBoundary) {
time.jumpTo(1000L - time.now() % 1000);
} else if (time.now() % 1000 == 0) {
time.jumpTo(10L);
}
final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
final SQueuedBuild queuedBuild10 = build().in(buildConf1).addToQueue();
final SQueuedBuild queuedBuild20 = build().in(buildConf2).addToQueue();
time.jumpTo(10);
final SFinishedBuild build10 = myFixture.finishBuild(BuildBuilder.run(queuedBuild10, myFixture), false);
time.jumpTo(10);
final Date afterBuild10 = time.getNow();
time.jumpTo(10);
// ensuring next jump will be within the same second
time.jumpTo(1000L - time.now() % 1000 + 100);
final SFinishedBuild build20 = myFixture.finishBuild(BuildBuilder.run(queuedBuild20, myFixture), false);
time.jumpTo(100L);
final SFinishedBuild build23 = build().in(buildConf2).finish();
time.jumpTo(10);
final SFinishedBuild build25Deleted = build().in(buildConf2).failed().finish();
final long build25DeletedId = build25Deleted.getBuildId();
myFixture.getSingletonService(BuildHistory.class).removeEntry(build25Deleted);
final BuildBuilder queuedBuild30 = build().in(buildConf2);
time.jumpTo(10);
final SFinishedBuild build30 = queuedBuild30.failedToStart().finish();
time.jumpTo(10);
final Date afterBuild30 = time.getNow();
time.jumpTo(10);
final SFinishedBuild build40 = build().in(buildConf1).finish();
time.jumpTo(10);
final SFinishedBuild build50Deleted = build().in(buildConf2).failed().finish();
final long build50DeletedId = build50Deleted.getBuildId();
myFixture.getSingletonService(BuildHistory.class).removeEntry(build50Deleted);
final SFinishedBuild build60 = build().in(buildConf2).finish();
time.jumpTo(10);
final Date afterBuild60 = time.getNow();
final SFinishedBuild build70 = build().in(buildConf1).finish();
time.jumpTo(10);
final SRunningBuild build80 = build().in(buildConf1).run();
time.jumpTo(10);
final SQueuedBuild queuedBuild110 = build().in(buildConf1).addToQueue();
time.jumpTo(10);
// preventing build from merging in the queue
final SQueuedBuild queuedBuild120 = build().in(buildConf1).parameter("a", "x").addToQueue();
time.jumpTo(10);
// preventing build from merging in the queue
final SQueuedBuild queuedBuild130 = build().in(buildConf1).parameter("a", "y").addToQueue();
// noinspection ConstantConditions
myFixture.getBuildQueue().moveTop(queuedBuild130.getItemId());
checkBuilds("finishDate:(build:(id:" + build10.getBuildId() + "),condition:after),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("finishDate:(build:(id:" + build10.getBuildId() + "),condition:after),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20));
checkBuilds("finishDate:(build:(id:" + build20.getBuildId() + "),condition:after),state:any", getBuildPromotions(build70, build60, build40, build23));
checkBuilds("finishDate:(build:(id:" + build20.getBuildId() + "),condition:after,includeInitial:true),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("finishDate:(build:(id:" + build20.getBuildId() + "),condition:before),state:any", getBuildPromotions(build10));
checkBuilds("finishDate:(build:(id:" + build20.getBuildId() + "),condition:equals),state:any", getBuildPromotions(build20));
checkBuilds("finishDate:(build:(id:" + build20.getBuildId() + ")),state:any", getBuildPromotions(build70, build60, build40, build23));
checkExceptionOnBuildsSearch(BadRequestException.class, "finishDate:(build:(id:" + queuedBuild110.getItemId() + "))");
if (build10.getFinishDate().getTime() % 1000 == 0) {
// the comparison is strict "after", but the time in locator is with seconds precision, so times without ms part are special case
checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after,includeInitial:true),state:any", getBuildPromotions(build70, build60, build40, build23, build20, build10));
checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20));
checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after,includeInitial:true),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20, build10));
} else {
checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after),state:any", getBuildPromotions(build70, build60, build40, build23, build20, build10));
checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after,includeInitial:true),state:any", getBuildPromotions(build70, build60, build40, build23, build20, build10));
checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20, build10));
checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after,includeInitial:true),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20, build10));
}
checkBuilds("finishDate:(date:" + getTimeWithMs(build10.getFinishDate()) + ",condition:after),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("finishDate:(date:" + getTimeWithMs(build10.getFinishDate()) + ",condition:after),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20));
checkBuilds("finishDate:(date:" + Util.formatTime(build20.getFinishDate()) + ",condition:after),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("finishDate:(date:" + getTimeWithMs(build20.getFinishDate()) + ",condition:after),state:any", getBuildPromotions(build70, build60, build40, build23));
checkBuilds("finishDate:(date:" + Util.formatTime(build20.getFinishDate()) + ",condition:after,includeInitial:true),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("finishDate:(date:" + Util.formatTime(build20.getFinishDate()) + ",condition:before),state:any", getBuildPromotions(build10));
checkBuilds("finishDate:(date:" + Util.formatTime(build20.getFinishDate()) + ",condition:equals),state:any", getBuildPromotions());
checkBuilds("finishDate:(date:" + getTimeWithMs(build20.getFinishDate()) + ",condition:equals),state:any", getBuildPromotions(build20));
checkBuilds("finishDate:(date:" + Util.formatTime(build20.getFinishDate()) + "),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("finishDate:(date:" + getTimeWithMs(build20.getFinishDate()) + "),state:any", getBuildPromotions(build70, build60, build40, build23));
checkBuilds("finishDate:(date:" + (new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ", Locale.ENGLISH)).format(build20.getFinishDate()) + "),state:any", getBuildPromotions(build70, build60, build40, build23));
checkBuilds("finishDate:(date:" + (new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSX", Locale.ENGLISH)).format(build20.getFinishDate()) + "),state:any", getBuildPromotions(build70, build60, build40, build23));
checkBuilds("finishDate:(date:" + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH)).format(build20.getFinishDate()) + "),state:any", // new time parsing uses ms
getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("finishDate:(date:" + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.ENGLISH)).format(build20.getFinishDate()) + "),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("startDate:(build:(id:" + build10.getBuildId() + "),condition:after)", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("startDate:(build:(id:" + build10.getBuildId() + "),condition:after),state:any", getBuildPromotions(build80, build70, build60, build40, build23, build20));
checkBuilds("startDate:(build:(id:" + build10.getBuildId() + "))", getBuildPromotions(build70, build60, build40, build23, build20));
if (build10.getStartDate().getTime() % 1000 == 0) {
checkBuilds("startDate:(date:" + Util.formatTime(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("startDate:(date:" + Util.formatTime(build10.getStartDate()) + ",includeInitial:true)", getBuildPromotions(build70, build60, build40, build23, build20, build10));
checkBuilds("startDate:(" + Util.formatTime(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20));
} else {
checkBuilds("startDate:(date:" + Util.formatTime(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20, build10));
checkBuilds("startDate:(date:" + Util.formatTime(build10.getStartDate()) + ",includeInitial:true)", getBuildPromotions(build70, build60, build40, build23, build20, build10));
checkBuilds("startDate:(" + Util.formatTime(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20, build10));
}
checkBuilds("startDate:(date:" + getTimeWithMs(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("startDate:(" + getTimeWithMs(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("queuedDate:(build:(id:" + build10.getBuildId() + "),condition:after)", getBuildPromotions(build70, build60, build40, build23, build20));
checkBuilds("queuedDate:(build:(id:" + build10.getBuildId() + "),condition:after),state:any", getBuildPromotions(queuedBuild130, queuedBuild110, queuedBuild120, build80, build70, build60, build40, build23, build20));
checkBuilds("startDate:(-10m),state:any", getBuildPromotions(build80, build70, build60, build40, build23, build20, build10));
// set time to afterBuild30 + 10 minutes
time.jumpTo(afterBuild30.getTime() + 10 * 60 * 1000 - time.getNow().getTime());
checkBuilds("startDate:(-10m),state:any", getBuildPromotions(build80, build70, build60, build40));
time.jumpTo(9);
checkBuilds("startDate:(-10m),state:any", getBuildPromotions(build80, build70, build60, build40));
time.jumpTo(1);
checkBuilds("startDate:(-10m),state:any", getBuildPromotions(build80, build70, build60));
time.jumpTo(60 * 10);
checkBuilds("startDate:(-10m),state:any");
checkBuilds("startDate:(build:(id:" + build60.getBuildId() + "),shift:-11s),state:any", getBuildPromotions(build80, build70, build60, build40));
checkBuilds("startDate:(build:(id:" + build60.getBuildId() + "),shift:-10s),state:any", getBuildPromotions(build80, build70, build60));
checkBuilds("startDate:(build:(id:" + build60.getBuildId() + "),shift:+9s),state:any", getBuildPromotions(build80, build70));
checkBuilds("startDate:(build:(id:" + build60.getBuildId() + "),shift:+10s),state:any", getBuildPromotions(build80));
checkBuilds("startDate:(condition:after,build:(id:" + build60.getBuildId() + ")" + ",shift:-11s),startDate:(condition:before,build:(id:" + build60.getBuildId() + "),shift:+11s),state:any", getBuildPromotions(build70, build60, build40));
checkBuilds("startDate:(condition:after,build:(id:" + build60.getBuildId() + ")" + ",shift:-9s),startDate:(condition:before,build:(id:" + build60.getBuildId() + "),shift:+9s),state:any", getBuildPromotions(build60));
checkBuilds("startDate:(condition:after,build:(id:" + build60.getBuildId() + ")" + ",shift:-10s),startDate:(condition:before,build:(id:" + build60.getBuildId() + "),shift:+10s),state:any", getBuildPromotions(build60));
checkExceptionOnBuildsSearch(BadRequestException.class, "finishDate:(xxx)");
checkExceptionOnBuildsSearch(LocatorProcessException.class, "finishDate:(time:20150101T000000+0000,build:(id:3))");
checkExceptionOnBuildsSearch(BadRequestException.class, "finishDate:(time:20150101T000000+0000,condition:xxx)");
}
Aggregations