Search in sources :

Example 1 with GitMergeSupport

use of jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport in project teamcity-git by JetBrains.

the class GitMergeSupportTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    myPaths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
    GitSupportBuilder builder = gitSupport().withServerPaths(myPaths);
    myGit = builder.build();
    myRepoOperations = new GitRepoOperationsImpl(builder.getPluginConfig(), builder.getTransportFactory(), r -> null, (a, b, c) -> {
    });
    myMergeSupport = new GitMergeSupport(myGit, builder.getCommitLoader(), builder.getRepositoryManager(), builder.getPluginConfig(), myRepoOperations);
    myRoot = vcsRoot().withFetchUrl(getRemoteRepositoryDir("merge")).build();
}
Also used : GitSupportBuilder.gitSupport(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitSupportBuilder.gitSupport) TestFor(jetbrains.buildServer.util.TestFor) BeforeMethod(org.testng.annotations.BeforeMethod) VcsRootBuilder.vcsRoot(jetbrains.buildServer.buildTriggers.vcs.git.tests.VcsRootBuilder.vcsRoot) Test(org.testng.annotations.Test) Util.map(jetbrains.buildServer.util.Util.map) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) jetbrains.buildServer.vcs(jetbrains.buildServer.vcs) AfterMethod(org.testng.annotations.AfterMethod) AtomicReference(java.util.concurrent.atomic.AtomicReference) GitMergeSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Arrays.asList(java.util.Arrays.asList) PluginConfigBuilder.pluginConfig(jetbrains.buildServer.buildTriggers.vcs.git.tests.PluginConfigBuilder.pluginConfig) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) GitVcsSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport) GitMergeSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with GitMergeSupport

use of jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport in project teamcity-git by JetBrains.

the class GitMergeSupportTest method concurrent_merge.

@TestFor(issues = "TW-48463")
public void concurrent_merge() throws Exception {
    // disable merge retries
    GitSupportBuilder builder = gitSupport().withPluginConfig(pluginConfig().setPaths(myPaths).setMergeRetryAttempts(0));
    myGit = builder.build();
    myMergeSupport = new GitMergeSupport(myGit, builder.getCommitLoader(), builder.getRepositoryManager(), builder.getPluginConfig(), myRepoOperations);
    // make clone on the server, so that none of the merges perform the clone
    RepositoryStateData s1 = RepositoryStateData.createVersionState("refs/heads/master", map("refs/heads/master", "f727882267df4f8fe0bc58c18559591918aefc54"));
    RepositoryStateData s2 = RepositoryStateData.createVersionState("refs/heads/master", map("refs/heads/master", "f727882267df4f8fe0bc58c18559591918aefc54", "refs/heads/topic2", "cc69c22bd5d25779e58ad91008e685cbbe7f700a", "refs/heads/topic3", "68b73163526a29a1f5a341f3b6fcd0d928748579"));
    myGit.getCollectChangesPolicy().collectChanges(myRoot, s1, s2, CheckoutRules.DEFAULT);
    RepositoryStateData state1 = myGit.getCurrentState(myRoot);
    // run concurrent merge of topic2 and topic3 into master, one of the merges should fail since branches diverged
    CountDownLatch latch = new CountDownLatch(1);
    CountDownLatch t1Ready = new CountDownLatch(1);
    CountDownLatch t2Ready = new CountDownLatch(1);
    AtomicReference<MergeResult> result1 = new AtomicReference<>();
    AtomicReference<MergeResult> result2 = new AtomicReference<>();
    Thread t1 = new Thread(() -> {
        try {
            t1Ready.countDown();
            latch.await();
            result1.set(myMergeSupport.merge(myRoot, "cc69c22bd5d25779e58ad91008e685cbbe7f700a", "refs/heads/master", "merge", new MergeOptions()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    t1.start();
    Thread t2 = new Thread(() -> {
        try {
            t2Ready.countDown();
            latch.await();
            result2.set(myMergeSupport.merge(myRoot, "68b73163526a29a1f5a341f3b6fcd0d928748579", "refs/heads/master", "merge", new MergeOptions()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    t2.start();
    t1Ready.await();
    t2Ready.await();
    latch.countDown();
    t1.join();
    t2.join();
    RepositoryStateData state2 = myGit.getCurrentState(myRoot);
    List<ModificationData> changes = myGit.getCollectChangesPolicy().collectChanges(myRoot, state1, state2, CheckoutRules.DEFAULT);
    long successfulMergeCommitCommitCount = changes.stream().filter(m -> m.getParentRevisions().size() == 2).count();
    // either both merges succeeds and made it into repository, or one of them fails
    then(successfulMergeCommitCommitCount == 2 || result1.get().isSuccess() != result2.get().isSuccess()).overridingErrorMessage("Non-fast-forward push succeeds").isTrue();
}
Also used : GitSupportBuilder.gitSupport(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitSupportBuilder.gitSupport) TestFor(jetbrains.buildServer.util.TestFor) BeforeMethod(org.testng.annotations.BeforeMethod) VcsRootBuilder.vcsRoot(jetbrains.buildServer.buildTriggers.vcs.git.tests.VcsRootBuilder.vcsRoot) Test(org.testng.annotations.Test) Util.map(jetbrains.buildServer.util.Util.map) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) jetbrains.buildServer.vcs(jetbrains.buildServer.vcs) AfterMethod(org.testng.annotations.AfterMethod) AtomicReference(java.util.concurrent.atomic.AtomicReference) GitMergeSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Arrays.asList(java.util.Arrays.asList) PluginConfigBuilder.pluginConfig(jetbrains.buildServer.buildTriggers.vcs.git.tests.PluginConfigBuilder.pluginConfig) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) GitVcsSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) GitMergeSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 GitMergeSupport (jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport)2 GitVcsSupport (jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport)2 GitRepoOperationsImpl (jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl)2 GitSupportBuilder.gitSupport (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitSupportBuilder.gitSupport)2 PluginConfigBuilder.pluginConfig (jetbrains.buildServer.buildTriggers.vcs.git.tests.PluginConfigBuilder.pluginConfig)2 VcsRootBuilder.vcsRoot (jetbrains.buildServer.buildTriggers.vcs.git.tests.VcsRootBuilder.vcsRoot)2 ServerPaths (jetbrains.buildServer.serverSide.ServerPaths)2 TestFor (jetbrains.buildServer.util.TestFor)2 Util.map (jetbrains.buildServer.util.Util.map)2 jetbrains.buildServer.vcs (jetbrains.buildServer.vcs)2 BDDAssertions.then (org.assertj.core.api.BDDAssertions.then)2 AssertJUnit.assertEquals (org.testng.AssertJUnit.assertEquals)2 AssertJUnit.assertTrue (org.testng.AssertJUnit.assertTrue)2 AfterMethod (org.testng.annotations.AfterMethod)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Test (org.testng.annotations.Test)2