Search in sources :

Example 11 with MockTimeService

use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.

the class BuildFinderFixedBuildSequenceByPromotionTest method setUp.

@Override
@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    // testing BuildPromotionFinder
    setInternalProperty(BuildFinder.LEGACY_BUILDS_FILTERING, "false");
    myTimeService = new MockTimeService(Dates.now().getTime());
    myServer.setTimeService(myTimeService);
    // do not need this in finally, do we?     myServer.setTimeService(SystemTimeService.getInstance());
    myUser = createUser("uuser");
    myBuildConf = registerBuildType("buildConf1", "project");
    myBuildConf2 = registerBuildType("buildConf2", "project");
    myBuild1 = build().in(myBuildConf).finish();
    myBuild2failed = build().in(myBuildConf).failed().finish();
    myDeleted = build().in(myBuildConf).failed().finish();
    myFixture.getHistory().removeEntry(myDeleted);
    myTimeService.jumpTo(10);
    myBuild3tagged = build().in(myBuildConf).finish();
    myBuild3tagged.setTags(Arrays.asList("tag1", "tag2"));
    myTimeService.jumpTo(10);
    myBuild4conf2FailedPinned = build().in(myBuildConf2).failed().finish();
    myBuild4conf2FailedPinned.setPinned(true, myUser, "pin comment");
    myTimeService.jumpTo(10);
    myTimeAfterBuild4 = myTimeService.getNow();
    myTimeService.jumpTo(10);
    myBuild5personal = build().in(myBuildConf).personalForUser(myUser.getUsername()).finish();
    myBuild6personalFailed = build().in(myBuildConf2).personalForUser(myUser.getUsername()).failed().finish();
    RunningBuildEx build7running = startBuild(myBuildConf);
    build7running.stop(myUser, "cancel comment");
    myBuild7canceled = finishBuild(build7running, false);
    final RunningBuildEx build8running = startBuild(myBuildConf);
    // make the build failed
    build8running.addBuildProblem(createBuildProblem());
    build8running.stop(myUser, "cancel comment");
    myBuild8canceledFailed = finishBuild(build8running, true);
    myBuild9failedToStart = build().in(myBuildConf).failedToStart().finish();
    myTimeService.jumpTo(10);
    myBuild10byUser = build().in(myBuildConf).by(myUser).finish();
    myTimeService.jumpTo(10);
    myBuild11inBranch = build().in(myBuildConf).withBranch("branch").finish();
    myTimeService.jumpTo(10);
    myBuild12 = build().in(myBuildConf).finish();
    myBuild13running = startBuild(myBuildConf);
    myBuild14queued = addToQueue(myBuildConf);
}
Also used : RunningBuildEx(jetbrains.buildServer.serverSide.RunningBuildEx) MockTimeService(jetbrains.buildServer.MockTimeService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 12 with MockTimeService

use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.

the class BuildPromotionFinderTest method testTimesISO.

@Test
public void testTimesISO() {
    final MockTimeService time = new MockTimeService(new DateTime(2016, 2, 16, 16, 47, 43, 0, DateTimeZone.forOffsetHours(1)).getMillis());
    myServer.setTimeService(time);
    // recreate finders to let time service sink in
    initFinders();
    final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
    // 20160216T164743.000+0100
    final SFinishedBuild build10 = build().in(buildConf1).finish();
    // +1 week
    time.jumpTo(7L * 24 * 60 * 60 * 1000);
    time.jumpTo(10);
    // 20160223T164753.000+0100
    final SFinishedBuild build15 = build().in(buildConf1).finish();
    // +1 day
    time.jumpTo(24 * 60 * 60);
    // 20160224T164753.000+0100
    final SFinishedBuild build20 = build().in(buildConf1).finish();
    time.jumpTo(10050L);
    // 20160224T164803.050+0100
    final SFinishedBuild build30 = build().in(buildConf1).finish();
    time.jumpTo(100L);
    // 20160224T164803.150+0100
    final SFinishedBuild build35 = build().in(buildConf1).finish();
    // +1 day
    time.jumpTo(24 * 60 * 60);
    time.jumpTo(10);
    // 20160225T164813.050+0100
    final SFinishedBuild build40 = build().in(buildConf1).finish();
    checkBuilds(null, getBuildPromotions(build40, build35, build30, build20, build15, build10));
    checkBuilds("finishDate:(date:20160224T164803.0+0100)", getBuildPromotions(build40, build35, build30));
    checkBuilds("finishDate:(date:20160224T164803.050+0100)", getBuildPromotions(build40, build35));
    checkBuilds("finishDate:(date:20160224T164803.049+0100)", getBuildPromotions(build40, build35, build30));
    checkBuilds("finishDate:(date:20160224T154803.049Z)", getBuildPromotions(build40, build35, build30));
    checkBuilds("finishDate:(date:20160224T154803Z)", getBuildPromotions(build40, build35, build30));
    checkBuilds("finishDate:(date:20160224T154803.0Z)", getBuildPromotions(build40, build35, build30));
    checkBuilds("finishDate:(date:20160224T154803.999Z)", getBuildPromotions(build40));
    checkBuilds("finishDate:(date:20160224T154804Z)", getBuildPromotions(build40));
    setInternalProperty("rest.timeMatching.roundEntityTimeToSeconds", "true");
    // this uses compatibility approach comparing the build time to be strongly > by seconds
    checkBuilds("finishDate:(date:20160224T154803Z)", getBuildPromotions(build40));
    removeInternalProperty("rest.timeMatching.roundEntityTimeToSeconds");
    checkBuilds("finishDate:(date:2016-02-24T16:48:03.049+0100)", getBuildPromotions(build40, build35, build30));
    checkBuilds("finishDate:(date:2016-02-24T16:48:03+0100)", getBuildPromotions(build40, build35, build30));
    checkBuilds("finishDate:(date:2016-02-24T16:48:03.049Z)", getBuildPromotions(build40));
    checkBuilds("finishDate:(date:2016-02-24T15:48:03.049Z)", getBuildPromotions(build40, build35, build30));
    checkBuilds("finishDate:(date:2016-02-24T15:48:03Z)", getBuildPromotions(build40, build35, build30));
    checkBuilds("finishDate:(date:20160224T164803.0+01)", getBuildPromotions(build40, build35, build30));
    checkBuilds("finishDate:(date:2016-02-24)", getBuildPromotions(build40, build35, build30, build20));
    checkBuilds("finishDate:(date:2016-2-23)", getBuildPromotions(build40, build35, build30, build20, build15));
    checkBuilds("finishDate:(date:2016-02-23)", getBuildPromotions(build40, build35, build30, build20, build15));
    checkBuilds("finishDate:(date:2016-W8)", getBuildPromotions(build40, build35, build30, build20, build15));
    checkBuilds("finishDate:(shift:-1d)", getBuildPromotions(build40));
    checkBuilds("finishDate:(shift:-1d10s1ms)", getBuildPromotions(build40, build35));
    checkBuilds("finishDate:(date:00:00)", getBuildPromotions(build40));
    checkBuilds("finishDate:(date:00:00,shift:-1d)", getBuildPromotions(build40, build35, build30, build20));
    checkBuilds("finishDate:(date:00:00,shift:+1m)", getBuildPromotions(build40));
    checkBuilds("finishDate:(date:0,shift:-48h)", getBuildPromotions(build40, build35, build30, build20, build15));
    checkExceptionOnBuildsSearch(BadRequestException.class, "finishDate:(date:20160224T164803+0100xxx)");
}
Also used : MockTimeService(jetbrains.buildServer.MockTimeService) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

MockTimeService (jetbrains.buildServer.MockTimeService)12 Test (org.testng.annotations.Test)10 Date (java.util.Date)2 RunningBuildEx (jetbrains.buildServer.serverSide.RunningBuildEx)2 DateTime (org.joda.time.DateTime)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 BuildBuilder (jetbrains.buildServer.buildTriggers.vcs.BuildBuilder)1 GitHubPasswordAuthRootRegistryImpl (jetbrains.buildServer.buildTriggers.vcs.git.GitHubPasswordAuthRootRegistryImpl)1 BuildServerListener (jetbrains.buildServer.serverSide.BuildServerListener)1 ProjectManager (jetbrains.buildServer.serverSide.ProjectManager)1 ServerResponsibility (jetbrains.buildServer.serverSide.ServerResponsibility)1 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)1 VcsRootInstanceContext (jetbrains.buildServer.serverSide.impl.beans.VcsRootInstanceContext)1 SUser (jetbrains.buildServer.users.SUser)1 MockSVcsRoot (jetbrains.buildServer.vcs.MockSVcsRoot)1 RepositoryStateListener (jetbrains.buildServer.vcs.RepositoryStateListener)1 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)1 VcsRootInstanceImpl (jetbrains.buildServer.vcs.impl.VcsRootInstanceImpl)1