Search in sources :

Example 31 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class GitVcsSupportTest method should_update_local_ref_when_it_locked.

@TestFor(issues = "TW-16351")
@Test(dataProvider = "doFetchInSeparateProcess", dataProviderClass = FetchOptionsDataProvider.class)
public void should_update_local_ref_when_it_locked(boolean fetchInSeparateProcess) throws Exception {
    setInternalProperty(Constants.CUSTOM_CLONE_PATH_ENABLED, "true");
    File remoteRepositoryDir = new File(myTmpDir, "repo_for_fetch");
    copyRepository(dataFile("repo_for_fetch.1"), remoteRepositoryDir);
    myConfigBuilder.setSeparateProcessForFetch(fetchInSeparateProcess);
    GitVcsSupport support = getSupport();
    VcsRootImpl root = getRoot("master", false, remoteRepositoryDir);
    String branch = root.getProperty(Constants.BRANCH_NAME);
    File customRootDir = new File(myTmpDir, "custom-dir");
    root.addProperty(Constants.PATH, customRootDir.getAbsolutePath());
    RepositoryStateData state = support.getCurrentState(root);
    String v1 = GitUtils.versionRevision(state.getBranchRevisions().get(state.getDefaultBranchName()));
    support.collectChanges(root, "a7274ca8e024d98c7d59874f19f21d26ee31d41d", "add81050184d3c818560bdd8839f50024c188586", CheckoutRules.DEFAULT);
    // now remote repository contains new commits
    copyRepository(dataFile("repo_for_fetch.2"), remoteRepositoryDir);
    File branchLockFile = createBranchLockFile(customRootDir, branch);
    assertTrue(branchLockFile.exists());
    state = support.getCurrentState(root);
    String v2 = GitUtils.versionRevision(state.getBranchRevisions().get(state.getDefaultBranchName()));
    // local repository is updated
    assertFalse(v2.equals(v1));
    support.collectChanges(root, v1, v2, CheckoutRules.DEFAULT);
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) FileUtil.writeFile(jetbrains.buildServer.util.FileUtil.writeFile) File(java.io.File) LockFile(org.eclipse.jgit.internal.storage.file.LockFile) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 32 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class GitVcsSupportTest method fetch_process_should_respect_fetch_timeout.

@Test
@TestFor(issues = "TW-17910")
public void fetch_process_should_respect_fetch_timeout() throws Exception {
    // MockFetcher waits for 10 seconds
    // set teamcity.execution.timeout = 2, we should not get TimeoutException
    Properties beforeTestProperties = System.getProperties();
    final String defaultProcessExecutionTimeoutProperty = "teamcity.execution.timeout";
    System.setProperty(defaultProcessExecutionTimeoutProperty, "2");
    try {
        String classpath = myConfigBuilder.build().getFetchClasspath() + File.pathSeparator + ClasspathUtil.composeClasspath(new Class[] { MockFetcher.class }, null, null);
        myConfigBuilder.setSeparateProcessForFetch(true).setFetchClasspath(classpath).setFetcherClassName(MockFetcher.class.getName());
        final GitVcsSupport support = getSupport();
        final VcsRootImpl root = (VcsRootImpl) getRoot("master");
        support.collectChanges(root, VERSION_TEST_HEAD, MERGE_BRANCH_VERSION, CheckoutRules.DEFAULT);
    } catch (Exception e) {
        fail(e.getMessage());
    } finally {
        System.setProperties(beforeTestProperties);
    }
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) TeamCityProperties(jetbrains.buildServer.serverSide.TeamCityProperties) MissingSubmoduleCommitException(jetbrains.buildServer.buildTriggers.vcs.git.submodules.MissingSubmoduleCommitException) JSchException(com.jcraft.jsch.JSchException) NotSupportedException(org.eclipse.jgit.errors.NotSupportedException) MissingSubmoduleConfigException(jetbrains.buildServer.buildTriggers.vcs.git.submodules.MissingSubmoduleConfigException) TransportException(org.eclipse.jgit.errors.TransportException) MissingSubmoduleEntryException(jetbrains.buildServer.buildTriggers.vcs.git.submodules.MissingSubmoduleEntryException) IOException(java.io.IOException) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 33 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class GitVcsSupportTest method test_long_input_for_fetcher_process.

/*
   * Test reproduces a bug in Fetcher code: Fetcher worked only if all parameters of VcsRoot
   * sent to process input as string were smaller than 512 bytes (most of the cases) or size mod 512 = 0.
   */
@TestFor(issues = "TW-13330")
@Test
public void test_long_input_for_fetcher_process() throws IOException, VcsException {
    myConfigBuilder.setSeparateProcessForFetch(true);
    GitVcsSupport support = getSupport();
    VcsRootImpl root = (VcsRootImpl) getRoot("version-test");
    root.addProperty("param", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + // with such long param size of input for fetcher process is greater than 512 bytes
    "bbbbbbbbbbbbbbbbbbbbb");
    support.collectChanges(root, "2276eaf76a658f96b5cf3eb25f3e1fda90f6b653", "f3f826ce85d6dad25156b2d7550cedeb1a422f4c", CheckoutRules.DEFAULT);
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 34 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class GitVcsSupportTest method gc_enabled_by_user.

@Test
public void gc_enabled_by_user() throws Exception {
    final File repo = createTempDir();
    ZipUtil.extract(new File(getTestDataPath(), "TW-65641-1.zip"), repo, null);
    final GitVcsSupport support = getSupport();
    final VcsRootImpl root = getRoot("master", false, repo);
    final OperationContext context = support.createContext(root, "fetch");
    final GitVcsRoot gitRoot = context.getGitRoot();
    final File mirror = gitRoot.getRepositoryDir();
    ZipUtil.extract(new File(getTestDataPath(), "TW-65641.zip"), mirror, null);
    // make sure old pack files won't be kept
    final StoredConfig config = context.getRepository().getConfig();
    config.setString("gc", null, "prunepackexpire", "now");
    // enable gc externally
    config.setInt("gc", null, "auto", 1);
    config.save();
    final File gitObjects = new File(mirror + "/objects");
    Assert.assertTrue(gitObjects.isDirectory());
    final HashSet<String> before = listObjectsRecursively(mirror);
    support.collectChanges(root, "2faa6375bf6139923245a625a47bef046e5e6550", "ba04d81036c5953d17469f532e520fc1ecbcd3f1", CheckoutRules.DEFAULT);
    // enough time for auto gc to start
    Thread.sleep(5000);
    new WaitFor() {

        @Override
        protected boolean condition() {
            return !new File(mirror, "gc.log.lock").isFile();
        }
    };
    final HashSet<String> after = listObjectsRecursively(mirror);
    Assert.assertFalse(after.containsAll(before));
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) WaitFor(jetbrains.buildServer.util.WaitFor) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) FileUtil.writeFile(jetbrains.buildServer.util.FileUtil.writeFile) File(java.io.File) LockFile(org.eclipse.jgit.internal.storage.file.LockFile) Test(org.testng.annotations.Test)

Example 35 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class GitUrlSupportTest method toGitRoot.

private GitVcsRoot toGitRoot(@NotNull VcsUrl url) throws VcsException {
    Map<String, String> properties = myUrlSupport.convertToVcsRootProperties(url, createRootContext());
    assertNotNull(properties);
    VcsRootImpl myRoot = new VcsRootImpl(1, properties);
    return new GitVcsRoot(myMirrorManager, myRoot, new URIishHelperImpl());
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl)

Aggregations

VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)51 File (java.io.File)35 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)34 TestFor (jetbrains.buildServer.util.TestFor)26 Test (org.testng.annotations.Test)25 VcsException (jetbrains.buildServer.vcs.VcsException)10 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)9 LockFile (org.eclipse.jgit.internal.storage.file.LockFile)9 StoredConfig (org.eclipse.jgit.lib.StoredConfig)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 AgentRunningBuild (jetbrains.buildServer.agent.AgentRunningBuild)6 AfterMethod (org.testng.annotations.AfterMethod)6 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)5 NotNull (org.jetbrains.annotations.NotNull)5 JSchException (com.jcraft.jsch.JSchException)4 Repository (org.eclipse.jgit.lib.Repository)4 ServerPaths (jetbrains.buildServer.serverSide.ServerPaths)3 VcsRootSshKeyManager (jetbrains.buildServer.ssh.VcsRootSshKeyManager)3