Package com.aragost.javahg

Examples of com.aragost.javahg.Repository


public class PullCommandTest extends AbstractTestCase {

    @Test
    public void testEmptyPull() throws IOException {
        Repository repo = getTestRepository();
        File dir = repo.getDirectory();

        List<Changeset> changesets = PullCommand.on(repo).execute(dir.getPath());
        Assert.assertEquals(0, changesets.size());
    }
View Full Code Here


        Assert.assertEquals(0, changesets.size());
    }

    @Test
    public void testPull() throws IOException {
        Repository repoA = getTestRepository();
        File dirA = repoA.getDirectory();

        writeFile("x", "abc");

        AddCommand add = AddCommand.on(repoA);
        add.execute();

        CommitCommand commit = CommitCommand.on(repoA);
        commit.message("added x").user("user");
        commit.execute();

        Repository repoB = getTestRepository2();

        List<Changeset> changesets = PullCommand.on(repoB).execute(dirA.getPath());
        Assert.assertEquals(1, changesets.size());
        Changeset cs = changesets.get(0);
        Assert.assertEquals("user", cs.getUser());
View Full Code Here

        Assert.assertEquals("added x", cs.getMessage());
    }

    @Test
    public void testHTTPPull() throws IOException {
        Repository repoA = getTestRepository();

        writeFile("x", "abc");

        AddCommand add = AddCommand.on(repoA);
        add.execute();

        CommitCommand commit = CommitCommand.on(repoA);
        commit.message("added x").user("user");
        commit.execute();

        ServeState serveState = startServing(repoA);
        try {
            int port = serveState.getPort();

            Repository repoB = getTestRepository2();
            List<Changeset> changesets = PullCommand.on(repoB).execute("http://localhost:" + port);
            Assert.assertEquals(1, changesets.size());
            Changeset cs = changesets.get(0);
            Assert.assertEquals("user", cs.getUser());
            Assert.assertEquals("added x", cs.getMessage());
View Full Code Here

        }
    }

    @Test(expected = ExecutionException.class)
    public void testPullWithNoDefault() throws IOException {
        Repository repo = getTestRepository();
        PullCommand.on(repo).execute();
    }
View Full Code Here

        PullCommand.on(repo).execute();
    }

    @Test(expected = NullPointerException.class)
    public void testPullNullSource() throws IOException {
        Repository repo = getTestRepository();
        PullCommand.on(repo).execute(null);
    }
View Full Code Here

        PullCommand.on(repo).execute(null);
    }

    @Test
    public void testWithDivergingBookmarks() throws IOException {
        Repository repo1 = getTestRepository();
        createChangeset();
        BookmarksCommand.on(repo1).create("bm");
        BookmarksCommand.on(repo1).list();

        File cloneDir = Files.createTempDir();
        Repository clone = Repository.clone(cloneDir, repo1.getDirectory().getAbsolutePath());
        Assert.assertEquals(1, BookmarksCommand.on(clone).list().size());

        Files.write("abc".getBytes(), new File(cloneDir, "clone"));
        AddCommand.on(clone).execute("clone");
        CommitCommand.on(clone).user("user").message("m").execute();
        BookmarksCommand.on(clone).force().create("bm");
        BookmarksCommand.on(clone).list();

        createChangeset();

        PullCommand.on(repo1).execute(clone.getDirectory().getAbsolutePath());
        BookmarksCommand.on(repo1).list();

        clone.close();
        deleteTempDir(cloneDir);
    }
View Full Code Here

    public void testPhasesUnknownRev() throws IOException {
        Assume.assumeTrue(isPhasesSupported());

      createChangeset();
     
      Repository repo = getTestRepository();
     
      try
      {
         repo.phases("abcdef124");
      }
      catch (ExecutionException e)
      {
      }
     
      try
      {
         repo.phases("abcdef124");
      }
      catch (ExecutionException e)
      {
      }
     
      try
      {
         repo.phases("abcdef124");
      }
      catch (ExecutionException e)
      {
      }
     

      try
      {
         repo.phases("abcdef124");
      }
      catch (ExecutionException e)
      {
      }
    }
View Full Code Here

        // This test case has historical not fail consistently so
        // execute it 10 times
        for (int i = 0; i < 10; i++) {
            File dir = Files.createTempDir();

            final Repository repo = Repository.create(REPO_CONF, dir);
            GenericCommand cmd = new GenericCommand(repo, "javahg-hang");

            Thread executioner = new Thread() {
                /**
                 * Sleep 1/2 seconds to allow cmd to exit normally if
                 * the 'javahg-hang' doesn't make it hang and then
                 * kill server process
                 */
                @Override
                public void run() {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        throw Utils.asRuntime(e);
                    }
                    getFirstServer(repo).getProcess().destroy();
                }
            };

            executioner.start();
            try {
                cmd.execute();
                assertFailedExecution(cmd);
            } catch (UnexpectedServerTerminationException e) {
                // When process is kill we get an IOException with
                // Stream closed, it is a
                // BlockInputStream.InvalidStreamException exception
                Throwable cause = e.getCause();
                if (cause instanceof IOException) {
                    String msg = ((IOException) cause).getMessage();
                    Assert.assertTrue(
                            "Unexpected message. Got \"" + msg + "\"",
                            msg.equals("Bad file descriptor")
                                    || msg.equals("Stream Closed")
                                    || msg.equals("Stream closed"));
                } else {
                    Assert.assertEquals(BlockInputStream.InvalidStreamException.class, cause.getClass());
                }
            } catch (ExecutionException e) {
                // System.err.println("Got 'killed!' on 'e' channel");
                Assert.assertEquals("killed!", e.getMessage());
            }
            // TODO There seems to be some kind of race condition.
            // Sometimes an UnexpectedServerTerminationException is
            // thrown, and sometimes an ExecutionException
            // Analysis so far: Mercurial server process writes
            // 'killed!' when the process is destroyed, sometimes it
            // writes it to
            // the actual stderr stream (typically case, gives
            // UnexpectedServerTerminationException), and
            // sometimes to the 'e'
            // channel (rare case, gives ExecutionException).
            //
            // TODO also try to access the server on stdout and stdin

            repo.close();
            deleteTempDir(dir);
        }
    }
View Full Code Here

   
    @Test
    public void testCancel() throws IOException {
        File dir = Files.createTempDir();

        final Repository repo = Repository.create(REPO_CONF, dir);
        final GenericCommand cmd = new GenericCommand(repo, "javahg-hang");

        Thread executioner = new Thread() {
            @Override
            public void run() {
                while (cmd.getState() != GenericCommand.State.RUNNING) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        throw Utils.asRuntime(e);
                    }
                }
                cmd.cancel();
            }
        };

        executioner.start();
        try {
            cmd.execute();
            assertFailedExecution(cmd);
        } catch (CancelledExecutionException e) {
            // Expected
        } catch (Throwable e) {
            Assert.fail("CancelledExecutionException expected. Got:" + e);
        }

        VersionCommand.on(repo).execute();
       
        repo.close();
        deleteTempDir(dir);
    }
View Full Code Here

    @Test
    public void testPreCancel() throws IOException {
        File dir = Files.createTempDir();

        final Repository repo = Repository.create(REPO_CONF, dir);
        final GenericCommand cmd = new GenericCommand(repo, "javahg-hang");

        cmd.cancel();

        try {
            cmd.execute();
            assertFailedExecution(cmd);
        } catch (CancelledExecutionException e) {
            // Expected
        } catch (Throwable e) {
            Assert.fail("CancelledExecutionException expected. Got:" + e);
        }

        VersionCommand.on(repo).execute();

        repo.close();
        deleteTempDir(dir);
    }
View Full Code Here

TOP

Related Classes of com.aragost.javahg.Repository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.