Search in sources :

Example 96 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class GitVcsRootTest method disabling_custom_clones.

@TestFor(issues = "TW-36401")
public void disabling_custom_clones() throws Exception {
    File cloneDir = new File("");
    VcsRoot root = vcsRoot().withRepositoryPathOnServer(cloneDir.getAbsolutePath()).withFetchUrl("http://some.org/repo").build();
    GitVcsRoot gitRoot1 = new GitVcsRoot(myMirrorManager, root, new URIishHelperImpl());
    assertTrue(FileUtil.isAncestor(myDefaultCachesDir, gitRoot1.getRepositoryDir(), true));
    setInternalProperty(Constants.CUSTOM_CLONE_PATH_ENABLED, "true");
    GitVcsRoot gitRoot2 = new GitVcsRoot(myMirrorManager, root, new URIishHelperImpl());
    assertEquals(cloneDir.getAbsoluteFile(), gitRoot2.getRepositoryDir());
}
Also used : VcsRoot(jetbrains.buildServer.vcs.VcsRoot) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Example 97 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class MapFullPathTest method mapFullPath_should_report_up_to_date_info.

@TestFor(issues = "TW-21185")
@Test
public void mapFullPath_should_report_up_to_date_info() throws Exception {
    RepositoryStateData state0 = RepositoryStateData.createSingleVersionState("a7274ca8e024d98c7d59874f19f21d26ee31d41d");
    RepositoryStateData state1 = myGit.getCurrentState(myRoot);
    myGit.getCollectChangesPolicy().collectChanges(myRoot, state0, state1, CheckoutRules.DEFAULT);
    Collection<String> paths = myGit.mapFullPath(myRootEntry, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168||.");
    assertTrue(paths.isEmpty());
    paths = myGit.mapFullPath(myRootEntry, "252771029d6ac61aaa78d282d5818d210812a4e5||.");
    assertTrue(paths.isEmpty());
    remoteRepositoryUpdated();
    RepositoryStateData state2 = myGit.getCurrentState(myRoot);
    // now we have d47dda159b27b9a8c4cee4ce98e4435eb5b17168
    myGit.getCollectChangesPolicy().collectChanges(myRoot, state1, state2, CheckoutRules.DEFAULT);
    paths = myGit.mapFullPath(myRootEntry, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168||.");
    assertFalse("mapFullPath returns outdated info", paths.isEmpty());
    paths = myGit.mapFullPath(myRootEntry, "252771029d6ac61aaa78d282d5818d210812a4e5||.");
    assertFalse("mapFullPath returns outdated info", paths.isEmpty());
}
Also used : RepositoryStateData(jetbrains.buildServer.vcs.RepositoryStateData) TestFor(jetbrains.buildServer.util.TestFor)

Example 98 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class GitCommitSupportTest method concurrent_commit.

@TestFor(issues = "TW-48463")
public void concurrent_commit() throws Exception {
    // 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"));
    myGit.getCollectChangesPolicy().collectChanges(myRoot, s1, s2, CheckoutRules.DEFAULT);
    RepositoryStateData state1 = myGit.getCurrentState(myRoot);
    CountDownLatch latch = new CountDownLatch(1);
    CountDownLatch t1Ready = new CountDownLatch(1);
    CountDownLatch t2Ready = new CountDownLatch(1);
    AtomicReference<VcsException> error1 = new AtomicReference<>();
    AtomicReference<VcsException> error2 = new AtomicReference<>();
    Thread t1 = new Thread(() -> {
        CommitPatchBuilder patchBuilder = null;
        try {
            patchBuilder = myCommitSupport.getCommitPatchBuilder(myRoot);
            patchBuilder.createFile("file-to-commit", new ByteArrayInputStream("content1".getBytes()));
            t1Ready.countDown();
            latch.await();
            patchBuilder.commit(new CommitSettingsImpl("user", "Commit1"));
        } catch (VcsException e) {
            error1.set(e);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (patchBuilder != null)
                patchBuilder.dispose();
        }
    });
    t1.start();
    Thread t2 = new Thread(() -> {
        CommitPatchBuilder patchBuilder = null;
        try {
            patchBuilder = myCommitSupport.getCommitPatchBuilder(myRoot);
            patchBuilder.createFile("file-to-commit", new ByteArrayInputStream("content2".getBytes()));
            t2Ready.countDown();
            latch.await();
            patchBuilder.commit(new CommitSettingsImpl("user", "Commit2"));
        } catch (VcsException e) {
            error2.set(e);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (patchBuilder != null)
                patchBuilder.dispose();
        }
    });
    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);
    // either both commits succeeds, or one finishes with an error
    then(changes.size() == 2 || (error1.get() != null || error2.get() != null)).overridingErrorMessage("Non-fast-forward push succeeds").isTrue();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) TestFor(jetbrains.buildServer.util.TestFor)

Example 99 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class GitCommitSupportTest method test_directory_remove.

@TestFor(issues = "TW-42737")
public void test_directory_remove() throws Exception {
    // create the dir directory with the a file
    CommitPatchBuilder patchBuilder = myCommitSupport.getCommitPatchBuilder(myRoot);
    patchBuilder.createFile("dir/file", new ByteArrayInputStream("content".getBytes()));
    patchBuilder.createFile("dir2/file", new ByteArrayInputStream("content".getBytes()));
    patchBuilder.commit(new CommitSettingsImpl("user", "Create dir with file"));
    patchBuilder.dispose();
    RepositoryStateData state1 = myGit.getCurrentState(myRoot);
    patchBuilder = myCommitSupport.getCommitPatchBuilder(myRoot);
    patchBuilder.deleteDirectory("dir");
    patchBuilder.commit(new CommitSettingsImpl("user", "Delete dir"));
    patchBuilder.dispose();
    RepositoryStateData state2 = myGit.getCurrentState(myRoot);
    List<ModificationData> changes = myGit.getCollectChangesPolicy().collectChanges(myRoot, state1, state2, CheckoutRules.DEFAULT);
    then(changes).hasSize(1);
    then(changes.get(0).getChanges()).extracting("fileName", "type").containsOnly(Tuple.tuple("dir/file", VcsChange.Type.REMOVED));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TestFor(jetbrains.buildServer.util.TestFor)

Example 100 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class CollectChangesTest method fetch_remote_refs_factor.

@Test
@TestFor(issues = "TW-71924")
public void fetch_remote_refs_factor() throws Exception {
    setInternalProperty("teamcity.git.nativeOperationsEnabled", "true");
    myConfig.setFetchRemoteBranchesFactor(0.01f);
    ServerPluginConfig config = myConfig.build();
    GitVcsSupport vcs = gitSupport().withPluginConfig(config).build();
    File repo = copyRepository(myTempFiles, dataFile("repo.git"), "repo.git");
    VcsRoot root = vcsRoot().withFetchUrl(repo).build();
    final RepositoryStateData from = createVersionState("refs/heads/master", map("refs/heads/master", "5711cbfe566b6c92e331f95d4b236483f4532eed", "refs/heads/TW-66105", "465ad9f630e451b9f2b782ffb09804c6a98c4bb9"));
    final RepositoryStateData to = createVersionState("refs/heads/master", map("refs/heads/master", "465ad9f630e451b9f2b782ffb09804c6a98c4bb9", "refs/heads/TW-66105", "7574b5358ac09d61ec5cb792d4462230de1d00c2"));
    vcs.getCollectChangesPolicy().collectChanges(root, from, to, CheckoutRules.DEFAULT).get(0);
    final RepositoryManager repositoryManager = vcs.getRepositoryManager();
    final String fetchUrl = repo.getCanonicalPath();
    assertNotNull(vcs.getCommitLoader().findCommit(repositoryManager.openRepository(new URIish(fetchUrl)), "b96aa6a603a178bcf34ac0aff54c004104381f41"));
}
Also used : URIish(org.eclipse.jgit.transport.URIish) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

TestFor (jetbrains.buildServer.util.TestFor)129 Test (org.testng.annotations.Test)81 File (java.io.File)65 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)56 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)26 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)21 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)17 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)12 VcsException (jetbrains.buildServer.vcs.VcsException)11 URIish (org.eclipse.jgit.transport.URIish)11 Repository (org.eclipse.jgit.lib.Repository)9 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)7 AfterMethod (org.testng.annotations.AfterMethod)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 GitTestUtil.copyRepository (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository)6 Build (jetbrains.buildServer.server.rest.model.build.Build)6 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)6 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)6