changeset 303:7b6ea35e1470 remote-run/subrepos

Test for agent-side checkout with updated subrepository url
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Thu, 08 Sep 2011 18:32:27 +0400
parents fa88221586c9
children e9cdb499350d
files mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgPathResolver.java mercurial-tests/testData/subrepos/README mercurial-tests/testData/subrepos/r1/hg/00changelog.i mercurial-tests/testData/subrepos/r1/hg/branchheads.cache mercurial-tests/testData/subrepos/r1/hg/dirstate mercurial-tests/testData/subrepos/r1/hg/last-message.txt mercurial-tests/testData/subrepos/r1/hg/requires mercurial-tests/testData/subrepos/r1/hg/store/00changelog.i mercurial-tests/testData/subrepos/r1/hg/store/00manifest.i mercurial-tests/testData/subrepos/r1/hg/store/data/.hgsub.i mercurial-tests/testData/subrepos/r1/hg/store/data/.hgsubstate.i mercurial-tests/testData/subrepos/r1/hg/store/data/a.i mercurial-tests/testData/subrepos/r1/hg/store/fncache mercurial-tests/testData/subrepos/r1/hg/store/undo mercurial-tests/testData/subrepos/r1/hg/tags.cache mercurial-tests/testData/subrepos/r1/hg/undo.branch mercurial-tests/testData/subrepos/r1/hg/undo.desc mercurial-tests/testData/subrepos/r1/hg/undo.dirstate mercurial-tests/testData/subrepos/r2/hg/00changelog.i mercurial-tests/testData/subrepos/r2/hg/dirstate mercurial-tests/testData/subrepos/r2/hg/last-message.txt mercurial-tests/testData/subrepos/r2/hg/requires mercurial-tests/testData/subrepos/r2/hg/store/00changelog.i mercurial-tests/testData/subrepos/r2/hg/store/00manifest.i mercurial-tests/testData/subrepos/r2/hg/store/data/b.i mercurial-tests/testData/subrepos/r2/hg/store/fncache mercurial-tests/testData/subrepos/r2/hg/store/undo mercurial-tests/testData/subrepos/r2/hg/undo.branch mercurial-tests/testData/subrepos/r2/hg/undo.dirstate mercurial-tests/testData/subrepos/r3/hg/00changelog.i mercurial-tests/testData/subrepos/r3/hg/dirstate mercurial-tests/testData/subrepos/r3/hg/last-message.txt mercurial-tests/testData/subrepos/r3/hg/requires mercurial-tests/testData/subrepos/r3/hg/store/00changelog.i mercurial-tests/testData/subrepos/r3/hg/store/00manifest.i mercurial-tests/testData/subrepos/r3/hg/store/data/c.i mercurial-tests/testData/subrepos/r3/hg/store/fncache mercurial-tests/testData/subrepos/r3/hg/store/undo mercurial-tests/testData/subrepos/r3/hg/tags.cache mercurial-tests/testData/subrepos/r3/hg/undo.branch mercurial-tests/testData/subrepos/r3/hg/undo.dirstate
diffstat 43 files changed, 209 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java	Thu Sep 08 13:36:01 2011 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java	Thu Sep 08 18:32:27 2011 +0400
@@ -18,16 +18,12 @@
 import jetbrains.buildServer.agent.AgentRunningBuild;
 import jetbrains.buildServer.agent.BuildAgentConfiguration;
 import jetbrains.buildServer.agent.BuildProgressLogger;
-import jetbrains.buildServer.parameters.ProcessingResult;
-import jetbrains.buildServer.parameters.ReferencesResolverUtil;
-import jetbrains.buildServer.parameters.ValueResolver;
 import jetbrains.buildServer.util.FileUtil;
 import jetbrains.buildServer.vcs.CheckoutRules;
 import jetbrains.buildServer.vcs.IncludeRule;
 import jetbrains.buildServer.vcs.VcsException;
 import jetbrains.buildServer.vcs.VcsRoot;
 import jetbrains.buildServer.vcs.impl.VcsRootImpl;
-import org.jetbrains.annotations.NotNull;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.testng.annotations.BeforeMethod;
@@ -46,7 +42,7 @@
 @Test
 public class AgentSideCheckoutTest extends BaseMercurialTestCase {
 
-  private final static String HG_PATH_REFERENCE = "%" + HgDetector.AGENT_HG_PATH_PROPERTY + "%";
+  final static String HG_PATH_REFERENCE = "%" + HgDetector.AGENT_HG_PATH_PROPERTY + "%";
   private MercurialAgentSideVcsSupport myVcsSupport;
   private File myWorkDir;
   private File myMirrorsRootDir;
@@ -66,6 +62,7 @@
     final BuildAgentConfiguration agentConfig = myContext.mock(BuildAgentConfiguration.class);
     myContext.checking(new Expectations() {{
       allowing(agentConfig).getCacheDirectory("mercurial"); will(returnValue(myMirrorsRootDir));
+      allowing(agentConfig).getTempDirectory(); will(returnValue(myTempFiles.createTempDir()));
       allowing(agentConfig).getParametersResolver(); will(returnValue(new HgPathResolver()));
     }});
 
@@ -240,56 +237,4 @@
   }
 
 
-  private static class HgPathResolver implements ValueResolver {
-    @NotNull
-    public ProcessingResult resolve(@NotNull String value) {
-      if (ReferencesResolverUtil.containsReference(value)) {
-        if (value.equals(HG_PATH_REFERENCE)) {
-          try {
-            return new ResolvedPath(Util.getHgPath());
-          } catch (IOException e) {
-            return new Unresolved(value);
-          }
-        } else {
-          throw new IllegalArgumentException("Value resolver is asked to resolve " + value);
-        }
-      } else {
-        return new ResolvedPath(value);
-      }
-    }
-  }
-
-  private static class ResolvedPath implements ProcessingResult {
-    private final String myPath;
-    ResolvedPath(final @NotNull String path) {
-      myPath = path;
-    }
-    public boolean isModified() {
-      return true;
-    }
-    @NotNull
-    public String getResult() {
-      return myPath;
-    }
-    public boolean isFullyResolved() {
-      return true;
-    }
-  }
-
-  private static class Unresolved implements ProcessingResult {
-    private final String myUnresolvedValue;
-    Unresolved(@NotNull final String value) {
-      myUnresolvedValue = value;
-    }
-    public boolean isModified() {
-      return false;
-    }
-    @NotNull
-    public String getResult() {
-      return myUnresolvedValue;
-    }
-    public boolean isFullyResolved() {
-      return false;
-    }
-  }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,104 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial;
+
+import com.intellij.openapi.diagnostic.Logger;
+import jetbrains.buildServer.TempFiles;
+import jetbrains.buildServer.agent.AgentRunningBuild;
+import jetbrains.buildServer.agent.BuildAgentConfiguration;
+import jetbrains.buildServer.agent.BuildProgressLogger;
+import jetbrains.buildServer.agent.vcs.UpdateByIncludeRules2;
+import jetbrains.buildServer.log.Log4jFactory;
+import jetbrains.buildServer.util.FileUtil;
+import jetbrains.buildServer.vcs.CheckoutRules;
+import jetbrains.buildServer.vcs.IncludeRule;
+import jetbrains.buildServer.vcs.VcsException;
+import jetbrains.buildServer.vcs.VcsRoot;
+import jetbrains.buildServer.vcs.impl.VcsRootImpl;
+import org.jetbrains.annotations.NotNull;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+
+/**
+ * @author dmitry.neverov
+ */
+@Test
+public class AgentSideCheckoutWithSubreposTest {
+
+  private TempFiles myTempFiles = new TempFiles();
+  private File myOriginalRepositoriesParentDir;
+  private File myWorkDir;
+  private Mockery myContext;
+  private BuildProgressLogger myLogger;
+  private UpdateByIncludeRules2 myVcsSupport;
+  private int myBuildCounter = 0;
+  private File myR1Dir;
+
+  static {
+    Logger.setFactory(new Log4jFactory());
+  }
+
+  @BeforeMethod
+  public void setUp() throws Exception {
+    myOriginalRepositoriesParentDir = myTempFiles.createTempDir();
+    myWorkDir = new File(myOriginalRepositoriesParentDir, "agentWorkDir");
+    myContext = new Mockery();
+
+    final BuildAgentConfiguration agentConfig = myContext.mock(BuildAgentConfiguration.class);
+    myContext.checking(new Expectations() {{
+      allowing(agentConfig).getCacheDirectory("mercurial"); will(returnValue(myTempFiles.createTempDir()));
+      allowing(agentConfig).getParametersResolver(); will(returnValue(new HgPathResolver()));
+    }});
+
+    myVcsSupport = new MercurialAgentSideVcsSupport(agentConfig, new AgentHgPathProvider(agentConfig));
+
+    myLogger = myContext.mock(BuildProgressLogger.class);
+    myContext.checking(new Expectations() {{
+      allowing(myLogger).message(with(any(String.class)));
+    }});
+
+    myR1Dir = copy(new File("mercurial-tests/testData/subrepos/r1"));
+    copy(new File("mercurial-tests/testData/subrepos/r2"));
+    copy(new File("mercurial-tests/testData/subrepos/r3"));
+  }
+
+  @AfterMethod
+  public void tearDown() {
+    myTempFiles.cleanup();
+  }
+
+
+  public void subrepository_url_changed() throws Exception {
+    VcsRootImpl root = new VcsRootBuilder()
+            .repository(myR1Dir.getAbsolutePath())
+            .build();
+    doUpdate(root, "34017377d9c3");
+    doUpdate(root, "d350e7209906");
+  }
+
+
+  private void doUpdate(final VcsRoot vcsRoot, final String toVersion) throws VcsException {
+    final AgentRunningBuild build = myContext.mock(AgentRunningBuild.class, "build" + myBuildCounter++);
+    myContext.checking(new Expectations() {{
+      allowing(build).getBuildLogger(); will(returnValue(myLogger));
+      allowing(build).getSharedConfigParameters(); will(returnValue(Collections.emptyMap()));
+    }});
+    myVcsSupport.getUpdater(vcsRoot, CheckoutRules.DEFAULT, toVersion, myWorkDir, build, false).process(IncludeRule.createDefaultInstance(), myWorkDir);
+  }
+
+
+  private File copy(@NotNull File originalRepositoryDir) throws IOException {
+    String dirName = originalRepositoryDir.getName();
+    File copyDir = new File(myOriginalRepositoriesParentDir, dirName);
+    FileUtil.copyDir(originalRepositoryDir, copyDir);
+    if (new File(copyDir, "hg").isDirectory()) {
+      FileUtil.rename(new File(copyDir, "hg"), new File(copyDir, ".hg"));
+    }
+    return copyDir;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgPathResolver.java	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,64 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial;
+
+import jetbrains.buildServer.parameters.ProcessingResult;
+import jetbrains.buildServer.parameters.ReferencesResolverUtil;
+import jetbrains.buildServer.parameters.ValueResolver;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.IOException;
+
+/**
+* @author dmitry.neverov
+*/
+class HgPathResolver implements ValueResolver {
+  @NotNull
+  public ProcessingResult resolve(@NotNull String value) {
+    if (ReferencesResolverUtil.containsReference(value)) {
+      if (value.equals(AgentSideCheckoutTest.HG_PATH_REFERENCE)) {
+        try {
+          return new ResolvedPath(Util.getHgPath());
+        } catch (IOException e) {
+          return new Unresolved(value);
+        }
+      } else {
+        throw new IllegalArgumentException("Value resolver is asked to resolve " + value);
+      }
+    } else {
+      return new ResolvedPath(value);
+    }
+  }
+
+  private static class ResolvedPath implements ProcessingResult {
+    private final String myPath;
+    ResolvedPath(final @NotNull String path) {
+      myPath = path;
+    }
+    public boolean isModified() {
+      return true;
+    }
+    @NotNull
+    public String getResult() {
+      return myPath;
+    }
+    public boolean isFullyResolved() {
+      return true;
+    }
+  }
+
+  private static class Unresolved implements ProcessingResult {
+    private final String myUnresolvedValue;
+    Unresolved(@NotNull final String value) {
+      myUnresolvedValue = value;
+    }
+    public boolean isModified() {
+      return false;
+    }
+    @NotNull
+    public String getResult() {
+      return myUnresolvedValue;
+    }
+    public boolean isFullyResolved() {
+      return false;
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/README	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,11 @@
+r1 history:
+3:d350e7209906 Add different subrepository in the same path <- subrepository r2 = ../r3 (9e4a2fef1a1c)
+2:4d7b3db8779f Remove subrepository                         <- subrepository removed
+1:34017377d9c3 Add subrepository                            <- subrepository r2 = ../r2 (916933c1dd8e)
+0:e4eced2b7381 Initial commit
+
+r2 history:
+0:916933c1dd8e Initial commit
+
+r3 history:
+0:9e4a2fef1a1c Initial commit
\ No newline at end of file
Binary file mercurial-tests/testData/subrepos/r1/hg/00changelog.i has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r1/hg/branchheads.cache	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,2 @@
+4d7b3db8779f75e0ca452fdd9a057a5c69665aa3 2
+4d7b3db8779f75e0ca452fdd9a057a5c69665aa3 default
Binary file mercurial-tests/testData/subrepos/r1/hg/dirstate has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r1/hg/last-message.txt	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,1 @@
+Add different subrepository in the same path
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r1/hg/requires	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,3 @@
+revlogv1
+store
+fncache
Binary file mercurial-tests/testData/subrepos/r1/hg/store/00changelog.i has changed
Binary file mercurial-tests/testData/subrepos/r1/hg/store/00manifest.i has changed
Binary file mercurial-tests/testData/subrepos/r1/hg/store/data/.hgsub.i has changed
Binary file mercurial-tests/testData/subrepos/r1/hg/store/data/.hgsubstate.i has changed
Binary file mercurial-tests/testData/subrepos/r1/hg/store/data/a.i has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r1/hg/store/fncache	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,3 @@
+data/a.i
+data/.hgsub.i
+data/.hgsubstate.i
Binary file mercurial-tests/testData/subrepos/r1/hg/store/undo has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r1/hg/tags.cache	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,2 @@
+1 34017377d9c3d7bbcf665f845cce1e41c30bf4e9
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r1/hg/undo.branch	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,1 @@
+default
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r1/hg/undo.desc	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,2 @@
+3
+commit
Binary file mercurial-tests/testData/subrepos/r1/hg/undo.dirstate has changed
Binary file mercurial-tests/testData/subrepos/r2/hg/00changelog.i has changed
Binary file mercurial-tests/testData/subrepos/r2/hg/dirstate has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r2/hg/last-message.txt	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,1 @@
+Initial commit
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r2/hg/requires	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,3 @@
+revlogv1
+store
+fncache
Binary file mercurial-tests/testData/subrepos/r2/hg/store/00changelog.i has changed
Binary file mercurial-tests/testData/subrepos/r2/hg/store/00manifest.i has changed
Binary file mercurial-tests/testData/subrepos/r2/hg/store/data/b.i has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r2/hg/store/fncache	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,1 @@
+data/b.i
Binary file mercurial-tests/testData/subrepos/r2/hg/store/undo has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r2/hg/undo.branch	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,1 @@
+default
\ No newline at end of file
Binary file mercurial-tests/testData/subrepos/r2/hg/undo.dirstate has changed
Binary file mercurial-tests/testData/subrepos/r3/hg/00changelog.i has changed
Binary file mercurial-tests/testData/subrepos/r3/hg/dirstate has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r3/hg/last-message.txt	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,1 @@
+Initial commit
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r3/hg/requires	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,3 @@
+revlogv1
+store
+fncache
Binary file mercurial-tests/testData/subrepos/r3/hg/store/00changelog.i has changed
Binary file mercurial-tests/testData/subrepos/r3/hg/store/00manifest.i has changed
Binary file mercurial-tests/testData/subrepos/r3/hg/store/data/c.i has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r3/hg/store/fncache	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,1 @@
+data/c.i
Binary file mercurial-tests/testData/subrepos/r3/hg/store/undo has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r3/hg/tags.cache	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,2 @@
+0 9e4a2fef1a1c04623a0d89edb4f3ba290cf2666e
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/subrepos/r3/hg/undo.branch	Thu Sep 08 18:32:27 2011 +0400
@@ -0,0 +1,1 @@
+default
\ No newline at end of file
Binary file mercurial-tests/testData/subrepos/r3/hg/undo.dirstate has changed