View Javadoc

1   package com.aragost.javahg.internals;
2   
3   import java.io.IOException;
4   
5   import org.junit.Assert;
6   import org.junit.Test;
7   
8   import com.aragost.javahg.BaseRepository;
9   import com.aragost.javahg.commands.PushCommand;
10  import com.aragost.javahg.test.AbstractTestCase;
11  
12  public class JavaHgMercurialExtensionTest extends AbstractTestCase {
13  
14      private volatile boolean inPush = false;
15  
16      @Test
17      public void testLock() throws InterruptedException {
18          final BaseRepository repo = getTestRepository2();
19          GenericCommand lockCmd = new GenericCommand(repo, "javahg-lock");
20          GenericCommand unlockCmd = new GenericCommand(repo, "javahg-unlock");
21          lockCmd.execute();
22  
23          Thread thread = new Thread("otherrepo") {
24              public void run() {
25                  try {
26                      JavaHgMercurialExtensionTest.this.inPush = true;
27                      BaseRepository other = getTestRepository();
28                      createChangeset();
29                      PushCommand.on(other).execute(repo.getDirectory().getAbsolutePath());
30                      JavaHgMercurialExtensionTest.this.inPush = false;
31                  } catch (IOException e) {
32                      throw new RuntimeIOException(e);
33                  }
34              }
35          };
36          thread.start();
37          Thread.sleep(1500);
38          Assert.assertTrue(this.inPush);
39          unlockCmd.execute();
40          Thread.sleep(1500);
41          Assert.assertFalse(this.inPush);
42          thread.join();
43          Assert.assertEquals(0, repo.tip().getRevision());
44      }
45  
46  }