use of jetbrains.buildServer.buildTriggers.vcs.git.OperationContext in project teamcity-git by JetBrains.
the class GitCommitsInfoBuilderTest method test_fetch_service_cache.
public void test_fetch_service_cache() throws Exception {
VcsRootImpl root = vcsRoot().withFetchUrl(GitUtils.toURL(myRepositoryDir)).withBranch("master").build();
root.addProperty("INCLUDE_COMMIT_INFO_SUBMODULES", "true");
GitVcsSupport vcs = gitSupport().withServerPaths(myServerPaths).build();
final GitFetchService svc = new GitFetchService(vcs);
// init cache
svc.fetchRepository(root, CheckoutRules.DEFAULT, new FetchService.FetchRepositoryCallback() {
public void update(final float progress, @NotNull final String message) {
}
});
final OperationContext oc = vcs.createContext(root, "test");
try {
assertTime(2, "cache should be used", 2, new Runnable() {
public void run() {
try {
for (int i = 0; i < 1000; i++) {
svc.getOrCreateRepositoryState(oc);
}
} catch (Throwable t) {
throw new Error(t);
}
}
});
} finally {
oc.close();
}
}
use of jetbrains.buildServer.buildTriggers.vcs.git.OperationContext in project teamcity-git by JetBrains.
the class MapFullPathTest method should_not_do_unnecessary_commit_lookup_when_repository_does_not_have_hint_revision.
public void should_not_do_unnecessary_commit_lookup_when_repository_does_not_have_hint_revision() throws Exception {
// root1 contains the commit
// root2 doesn't
final CommitLoader commitLoader = myContext.mock(CommitLoader.class);
final RevCommit commit = myContext.mock(RevCommit.class);
myMapFullPath.setCommitLoader(commitLoader);
final String hintCommit = "a7274ca8e024d98c7d59874f19f21d26ee31d41d";
final String lastCommonCommit1 = "add81050184d3c818560bdd8839f50024c188586";
final String lastCommonCommit2 = "d47dda159b27b9a8c4cee4ce98e4435eb5b17168";
final String remoteUrl1 = myRemoteRepositoryDir.getAbsolutePath();
final String remoteUrl2 = myRemoteRepositoryDir2.getAbsolutePath();
myContext.checking(new Expectations() {
{
one(commitLoader).findCommit(with(repositoryWithUrl(remoteUrl1)), with(hintCommit));
will(returnValue(commit));
// only single check for repository which doesn't contain a hint commit:
one(commitLoader).findCommit(with(repositoryWithUrl(remoteUrl2)), with(hintCommit));
will(returnValue(null));
}
});
String fullPath1 = hintCommit + "-" + lastCommonCommit1 + "||.";
String fullPath2 = hintCommit + "-" + lastCommonCommit2 + "||.";
OperationContext ctx = myGit.createContext(myRoot, "map full path");
OperationContext ctx2 = myGit.createContext(myRoot2, "map full path");
assertFalse(myMapFullPath.mapFullPath(ctx, myRootEntry, fullPath1).isEmpty());
assertTrue(myMapFullPath.mapFullPath(ctx2, myRootEntry2, fullPath1).isEmpty());
assertFalse(myMapFullPath.mapFullPath(ctx, myRootEntry, fullPath2).isEmpty());
assertTrue(myMapFullPath.mapFullPath(ctx2, myRootEntry2, fullPath2).isEmpty());
assertTrue(myMapFullPath.mapFullPath(ctx2, myRootEntry2, hintCommit + "-" + "any_other_commit").isEmpty());
myContext.assertIsSatisfied();
}
use of jetbrains.buildServer.buildTriggers.vcs.git.OperationContext in project teamcity-git by JetBrains.
the class MapFullPathTest method should_not_do_unnecessary_commit_lookup_after_fetch.
public void should_not_do_unnecessary_commit_lookup_after_fetch() throws Exception {
final String existingCommit = "a7274ca8e024d98c7d59874f19f21d26ee31d41d";
final String nonExistingCommit = "abababababababababababababababababababab";
final CommitLoader commitLoader = myContext.mock(CommitLoader.class);
final RevCommit commit = myContext.mock(RevCommit.class);
myMapFullPath.setCommitLoader(commitLoader);
myContext.checking(new Expectations() {
{
// ask for existing commit only once:
one(commitLoader).findCommit(with(any(Repository.class)), with(existingCommit));
will(returnValue(commit));
one(commitLoader).findCommit(with(any(Repository.class)), with(nonExistingCommit));
will(returnValue(null));
}
});
RepositoryStateData state0 = RepositoryStateData.createSingleVersionState("a7274ca8e024d98c7d59874f19f21d26ee31d41d");
RepositoryStateData state1 = myGit.getCurrentState(myRoot);
// fetch repository, so mapFullPath works
myGit.getCollectChangesPolicy().collectChanges(myRoot, state0, state1, CheckoutRules.DEFAULT);
OperationContext context = myGit.createContext(myRoot, "map full path");
myMapFullPath.mapFullPath(context, myRootEntry, existingCommit + "||.");
myMapFullPath.mapFullPath(context, myRootEntry, nonExistingCommit + "||.");
remoteRepositoryUpdated();
RepositoryStateData state2 = myGit.getCurrentState(myRoot);
// this fetch should not cause new commit lookup
myGit.getCollectChangesPolicy().collectChanges(myRoot, state1, state2, CheckoutRules.DEFAULT);
myGit.mapFullPath(myRootEntry, existingCommit + "||.");
myGit.mapFullPath(myRootEntry, nonExistingCommit + "||.");
myContext.assertIsSatisfied();
}
use of jetbrains.buildServer.buildTriggers.vcs.git.OperationContext in project teamcity-git by JetBrains.
the class MapFullPathTest method should_reset_cached_revision_after_fetch.
@Test(dataProvider = "fetchAction")
public void should_reset_cached_revision_after_fetch(@NotNull FetchAction fetchAction) throws Exception {
// run map full path before fetch
final String existingCommit = "a7274ca8e024d98c7d59874f19f21d26ee31d41d";
OperationContext context = myGit.createContext(myRoot, "map full path");
// will not find revision in empty repo
then(myMapFullPath.mapFullPath(context, myRootEntry, existingCommit + "||.")).isEmpty();
fetchAction.run();
then(myMapFullPath.mapFullPath(context, myRootEntry, existingCommit + "||.")).isNotEmpty();
}
Aggregations