Package com.aragost.javahg

Examples of com.aragost.javahg.Repository


        // 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


public class BookmarksCommandTest extends AbstractTestCase {

    @Test
    public void testNoBookmarks() {
        Repository repo = getTestRepository();
        Assert.assertTrue(BookmarksCommand.on(repo).list().isEmpty());
    }
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

        Assert.assertTrue(BookmarksCommand.on(repo).list().isEmpty());
    }

    @Test
    public void testDelete() throws IOException {
        Repository repo = getTestRepository();
        createChangeset();
        BookmarksCommand.on(repo).create("a");
        Assert.assertEquals(1, BookmarksCommand.on(repo).list().size());
        BookmarksCommand.on(repo).delete("a");
        Assert.assertEquals(0, BookmarksCommand.on(repo).list().size());
View Full Code Here

        Assert.assertEquals(0, BookmarksCommand.on(repo).list().size());
    }

    @Test
    public void testRename() throws IOException {
        Repository repo = getTestRepository();
        createChangeset();
        BookmarksCommand.on(repo).create("a");
        Assert.assertEquals(1, BookmarksCommand.on(repo).list().size());
        BookmarksCommand.on(repo).rename("a", "b");
        List<Bookmark> list = BookmarksCommand.on(repo).list();
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

        Assert.assertTrue("b", bm.isActive());
    }

    @Test
    public void testActive() throws IOException {
        Repository repo = getTestRepository();
        createChangeset();
        BookmarksCommand.on(repo).create("a");
        Bookmark bm = Utils.single(BookmarksCommand.on(repo).list());
        Assert.assertTrue(bm.isActive());
View Full Code Here

        Assert.assertTrue(bm.isActive());
    }

    @Test
    public void test() throws IOException {
        Repository repo = getTestRepository();
       
        Assert.assertTrue(BookmarksCommand.on(repo).list().isEmpty());
       
        BookmarksCommand.on(repo).inactive().create("bookmark");
        createChangeset();
View Full Code Here

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

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

        final Thread executor = new Thread() {
           
            @Override
            public void run() {
                try {
                    Thread.sleep(500);
                    Assert.assertEquals(0, repo.getServerPool().getNumIdleServers());
                    cmd2.execute();
                    assertFailedExecution(cmd);
                } catch (CancelledExecutionException e) {
                    // Expected
                } catch (InterruptedException e) {
                    throw Utils.asRuntime(e);
                }
            }
        };
       
        Thread executioner = new Thread() {
           
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw Utils.asRuntime(e);
                }
                Assert.assertEquals(AbstractCommand.State.QUEUED, cmd2.getState());
                cmd2.cancel();
                try {
                    executor.join();
                } catch (InterruptedException e) {
                    throw Utils.asRuntime(e);
                }
                cmd.cancel();
            }
        };

        Assert.assertEquals(1, repo.getServerPool().getNumIdleServers());
        executor.start();
        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

public class RenameCommandTest extends AbstractTestCase {

    @Test
    public void testCopyFileToFile() throws IOException {
        Repository repo = getTestRepository();
        writeFile("x", "");
        commit();

        Map<String, String> result = RenameCommand.on(repo).execute("x", "y");
        Assert.assertEquals(1, result.size());
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.