use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.
the class BuildFinderByPromotionTest 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();
// add debugging data as the test can fail occasionally
for (SBuild build : Arrays.asList(build10, build20, build30, build40, build60, build70, build80)) {
System.out.println("build id=" + build.getBuildId() + ", formatted start time=" + Util.formatTime(build.getStartDate()) + ", start time=" + build.getStartDate().getTime());
}
checkBuilds("sinceBuild:(id:" + build10.getBuildId() + ")", build70, build60, build40, build20);
checkBuilds("sinceBuild:(id:" + build10.getBuildId() + "),failedToStart:any", build70, build60, build40, build30, build20);
// see also jetbrains.buildServer.server.rest.data.BuildPromotionFinderTest.testSinceUntil()
checkBuilds("sinceBuild:(id:" + build25DeletedId + ")", build70, build60, build40);
checkBuilds("sinceBuild:(id:" + build25DeletedId + "),failedToStart:any", build70, build60, build40, build30);
checkBuilds("untilBuild:(id:" + build60.getBuildId() + ")", build60, build40, build20, build10);
checkBuilds("untilBuild:(id:" + build60.getBuildId() + "),failedToStart:any", build60, build40, build30, build20, build10);
checkBuilds("untilBuild:(id:" + build50DeletedId + "),state:any", build40, build20, build10);
checkBuilds("untilBuild:(id:" + build50DeletedId + "),state:any,failedToStart:any", build40, build30, build20, build10);
checkBuilds("sinceDate:" + fDate(build20.getStartDate()), build70, build60, build40, build20);
// documenting current behavior
checkBuilds("sinceDate:" + fDate(build20.getStartDate()) + ")", build70, build60, build40, build20);
checkBuilds("sinceDate:" + fDate(build20.getStartDate()) + "),failedToStart:any", build70, build60, build40, build30, build20);
checkBuilds("sinceDate:" + fDate(afterBuild30) + ")", build70, build60, build40);
checkBuilds("untilDate:" + fDate(build60.getStartDate()) + ")", build40, build20, build10);
checkBuilds("untilDate:" + fDate(build60.getStartDate()) + "),failedToStart:any", build40, build30, build20, build10);
checkBuilds("untilDate:" + fDate(afterBuild30) + ")", build20, build10);
checkBuilds("untilDate:" + fDate(afterBuild30) + "),failedToStart:any", build30, build20, build10);
checkBuilds("sinceBuild:(id:" + build10.getBuildId() + "),sinceDate:" + fDate(build10.getStartDate()), build70, build60, build40, build20);
checkBuilds("sinceBuild:(id:" + build10.getBuildId() + "),sinceDate:" + fDate(build10.getStartDate()) + ",failedToStart:any", 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()), build40, build20, build10);
checkBuilds("untilBuild:(id:" + build60.getBuildId() + "),untilDate:" + fDate(build60.getStartDate()) + ",failedToStart:any", build40, build30, build20, build10);
checkBuilds("untilBuild:(id:" + build60.getBuildId() + "),untilDate:" + fDate(afterBuild30), build20, build10);
checkBuilds("untilBuild:(id:" + build60.getBuildId() + "),untilDate:" + fDate(afterBuild30) + ",failedToStart:any", build30, build20, build10);
checkBuilds("sinceBuild:(id:" + build20.getBuildId() + "),untilBuild:" + build60.getBuildId(), build60, build40);
checkBuilds("sinceBuild:(id:" + build20.getBuildId() + "),untilBuild:" + build60.getBuildId() + ",failedToStart:any", build60, build40, build30);
checkBuilds("sinceBuild:(id:" + build20.getBuildId() + "),untilDate:" + fDate(afterBuild30));
checkBuilds("sinceBuild:(id:" + build20.getBuildId() + "),untilDate:" + fDate(afterBuild30) + ",failedToStart:any", build30);
checkBuilds("sinceDate:(" + fDate(afterBuild10) + "),untilDate:" + fDate(afterBuild30), build20);
checkBuilds("sinceDate:(" + fDate(afterBuild10) + "),untilDate:" + fDate(afterBuild30) + ",failedToStart:any", build30, build20);
}
use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.
the class UserFinderTest method testLastLogin.
@Test
public void testLastLogin() throws Throwable {
final SUser user10 = createUser("user10");
final SUser user20 = createUser("user20");
final SUser user30 = createUser("user30");
final MockTimeService time = new MockTimeService(Dates.now().getTime());
myServer.setTimeService(time);
user10.setLastLoginTimestamp(time.getNow());
// 10 minutes
time.jumpTo(600);
user20.setLastLoginTimestamp(time.getNow());
// another 10
time.jumpTo(600);
check(null, user10, user20, user30);
check("lastLogin:-30m", user10, user20);
check("lastLogin:-15m", user20);
check("lastLogin:-15m,username:user20", user20);
check("lastLogin:-5m");
}
use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.
the class VcsRootInstanceFinderTest method testStatusFiltering.
@SuppressWarnings("ConstantConditions")
@Test
public void testStatusFiltering() throws Exception {
final MockTimeService time = new MockTimeService(Dates.now().getTime());
myServer.setTimeService(time);
myFixture.registerVcsSupport("svn");
final ProjectEx project10 = getRootProject().createProject("project10", "Project name 10");
final SVcsRoot vcsRoot = getRootProject().createVcsRoot("svn", "id1", "VCS root 1 name");
final SBuildType bt = project10.createBuildType("id1", "name 1");
attachVcsRoot(bt, vcsRoot);
final SVcsRoot vcsRoot2 = getRootProject().createVcsRoot("svn", "id2", "VCS root 2 name");
final SBuildType bt2 = project10.createBuildType("id2", "name 2");
attachVcsRoot(bt2, vcsRoot2);
assertEquals(2, getFinder().getItems("status:not_monitored").myEntries.size());
assertEquals(0, getFinder().getItems("status:scheduled").myEntries.size());
assertEquals(0, getFinder().getItems("status:started").myEntries.size());
assertEquals(0, getFinder().getItems("status:finished").myEntries.size());
assertEquals(0, getFinder().getItems("status:unknown").myEntries.size());
((VcsRootInstanceEx) bt.getVcsRootInstances().get(0)).setStatus(VcsRootStatus.Type.FINISHED);
assertEquals(1, getFinder().getItems("status:not_monitored").myEntries.size());
assertEquals(0, getFinder().getItems("status:scheduled").myEntries.size());
assertEquals(0, getFinder().getItems("status:started").myEntries.size());
assertEquals(1, getFinder().getItems("status:finished").myEntries.size());
assertEquals(0, getFinder().getItems("status:unknown").myEntries.size());
((VcsRootInstanceEx) bt2.getVcsRootInstances().get(0)).setStatus(VcsRootStatus.Type.STARTED);
assertEquals(0, getFinder().getItems("status:not_monitored").myEntries.size());
assertEquals(0, getFinder().getItems("status:scheduled").myEntries.size());
assertEquals(1, getFinder().getItems("status:started").myEntries.size());
assertEquals(1, getFinder().getItems("status:finished").myEntries.size());
assertEquals(0, getFinder().getItems("status:unknown").myEntries.size());
checkExceptionOnItemsSearch(BadRequestException.class, "status:aaa");
assertEquals(1, getFinder().getItems("status:(current:(status:started))").myEntries.size());
((VcsRootInstanceEx) bt2.getVcsRootInstances().get(0)).setStatus(VcsRootStatus.Type.FINISHED);
assertEquals(2, getFinder().getItems("status:(current:(status:finished))").myEntries.size());
assertEquals(1, getFinder().getItems("status:(previous:(status:started))").myEntries.size());
time.jumpTo(10);
assertEquals(0, getFinder().getItems("status:(current:(timestamp:-2s))").myEntries.size());
assertEquals(2, getFinder().getItems("status:(current:(timestamp:-20s))").myEntries.size());
assertEquals(0, getFinder().getItems("checkingForChangesFinishDate:-2s").myEntries.size());
assertEquals(2, getFinder().getItems("checkingForChangesFinishDate:-20s").myEntries.size());
}
use of jetbrains.buildServer.MockTimeService in project teamcity-git by JetBrains.
the class GitHubPasswordAuthRootRegistryImplTest method test.
@Test
public void test() {
final Map<String, Long> events = new HashMap<>();
final MockTimeService timeService = new MockTimeService();
final Map<String, String> vcsProperties = CollectionsUtil.asMap(VcsUtil.VCS_NAME_PROP, Constants.VCS_NAME, Constants.AUTH_METHOD, AuthenticationMethod.PASSWORD.name(), Constants.FETCH_URL, "https://github.com/name/repo.git", Constants.PASSWORD, "%some.param%");
final Mockery mockery = new Mockery();
final ProjectManager projectManager = mockery.mock(ProjectManager.class);
final ServerResponsibility serverResponsibility = mockery.mock(ServerResponsibility.class);
mockery.checking(new Expectations() {
{
allowing(projectManager).findVcsRootById(1);
final MockSVcsRoot vcsRoot = new MockSVcsRoot(1, Constants.VCS_NAME);
vcsRoot.setProperties(vcsProperties);
will(returnValue(vcsRoot));
allowing(serverResponsibility).canCheckForChanges();
will(returnValue(true));
}
});
final GitHubPasswordAuthRootRegistryImpl registry = new GitHubPasswordAuthRootRegistryImpl(new EventDispatcher<BuildServerListener>(BuildServerListener.class) {
}, new EventDispatcher<RepositoryStateListener>(RepositoryStateListener.class) {
}, projectManager, serverResponsibility, createMultiNodesEvents(events), timeService);
vcsProperties.put(Constants.PASSWORD, "12345");
registry.update(new VcsRootImpl(1, vcsProperties));
assertTrue(registry.containsVcsRoot(1));
BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime);
BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageAdd", 1L);
events.clear();
timeService.inc();
registry.update(new VcsRootImpl(1, vcsProperties));
assertTrue(registry.containsVcsRoot(1));
BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime);
assertTrue(events.isEmpty());
timeService.inc();
final VcsRootInstanceContext context = mockery.mock(VcsRootInstanceContext.class);
mockery.checking(new Expectations() {
{
allowing(context).getTimeService();
will(returnValue(timeService));
allowing(context).getServerMetrics();
will(returnValue(null));
}
});
registry.update(new VcsRootInstanceImpl(100, Constants.VCS_NAME, 1, "My Name", vcsProperties, context));
assertTrue(registry.containsVcsRoot(1));
BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime);
assertTrue(events.isEmpty());
timeService.inc();
vcsProperties.put(Constants.PASSWORD, "1234567890abcdef1234567890abcdef12345678");
registry.update(new VcsRootImpl(1, vcsProperties));
assertTrue(registry.containsVcsRoot(1));
BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime - 1);
assertTrue(events.isEmpty());
setInternalProperty("teamcity.git.gitHubPasswordAuthHealthReport.updateIntervalSec", "300");
timeService.inc(350, TimeUnit.SECONDS);
registry.update(new VcsRootImpl(1, vcsProperties));
assertFalse(registry.containsVcsRoot(1));
assertTrue(registry.getRegistry().isEmpty());
BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageRemove", 1L);
events.clear();
timeService.inc();
vcsProperties.put(Constants.PASSWORD, "12345");
registry.update(new VcsRootImpl(1, vcsProperties));
assertTrue(registry.containsVcsRoot(1));
BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime);
BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageAdd", 1L);
events.clear();
timeService.inc();
// see TW-71026
vcsProperties.put(Constants.PASSWORD, "gho_oPan0zUSMxvI7NoWDBjjBP965641HX2NHNbu");
timeService.inc(350, TimeUnit.SECONDS);
registry.update(new VcsRootImpl(1, vcsProperties));
assertFalse(registry.containsVcsRoot(1));
assertTrue(registry.getRegistry().isEmpty());
BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageRemove", 1L);
{
// add root to registry again
events.clear();
timeService.inc();
vcsProperties.put(Constants.PASSWORD, "12345");
registry.update(new VcsRootImpl(1, vcsProperties));
assertTrue(registry.containsVcsRoot(1));
BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime);
BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageAdd", 1L);
}
{
// TW-72780
events.clear();
timeService.inc();
vcsProperties.put(Constants.AUTH_METHOD, AuthenticationMethod.ANONYMOUS.name());
timeService.inc(350, TimeUnit.SECONDS);
registry.update(new VcsRootImpl(1, vcsProperties));
assertFalse(registry.containsVcsRoot(1));
assertTrue(registry.getRegistry().isEmpty());
BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageRemove", 1L);
}
{
// TW-73295
events.clear();
timeService.inc();
timeService.inc(350, TimeUnit.SECONDS);
registry.update(new VcsRootImpl(1, vcsProperties));
assertFalse(registry.containsVcsRoot(1));
assertTrue(registry.getRegistry().isEmpty());
assertTrue(events.isEmpty());
}
}
use of jetbrains.buildServer.MockTimeService in project teamcity-rest by JetBrains.
the class BuildFinderFixedBuildSequenceTest method setUp.
@Override
@BeforeMethod
public void setUp() throws Exception {
super.setUp();
// testing BuildFinder
setInternalProperty(BuildFinder.LEGACY_BUILDS_FILTERING, "true");
// testing BuildFinder
setInternalProperty(BuildFinder.LEGACY_BUILDS_FILTERING_FORCED, "true");
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);
}
Aggregations