[JGIT PATCH 4/8] Add a counter to make sure the test repo name is unique
- From
Robin Rosenberg <robin.rosenberg@dewire.com>
- Date
- Nov 30, 2008, 23:40 UTC
- Message-ID
- <1228088435-23722-5-git-send-email-robin.rosenberg@dewire.com>
- In-Reply-To
- <1228088435-23722-4-git-send-email-robin.rosenberg@dewire.com>
System.currentTimeMillis() does not have the granularity necessary to guarantee uniqueness. We keep it to make sure we have unique names between different runs, but add a counter to make it unique within the execution of a test suite.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> --- .../org/spearce/jgit/lib/RepositoryTestCase.java | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java index 3b08fa5..6ea9b45 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java @@ -150,11 +150,13 @@ protected static void checkFile(File f, final String checkData) protected Repository db; + private static int testcount; + public void setUp() throws Exception { super.setUp(); configure(); recursiveDelete(trashParent); - trash = new File(trashParent,"trash"+System.currentTimeMillis()); + trash = new File(trashParent,"trash"+System.currentTimeMillis()+"."+(testcount++)); trash_git = new File(trash, ".git"); Runtime.getRuntime().addShutdownHook(new Thread() { @@ -200,7 +202,7 @@ protected void tearDown() throws Exception { * @throws IOException */ protected Repository createNewEmptyRepo() throws IOException { - File newTestRepo = new File(trashParent, "new"+System.currentTimeMillis()+"/.git"); + File newTestRepo = new File(trashParent, "new"+System.currentTimeMillis()+"."+(testcount++)+"/.git"); assertFalse(newTestRepo.exists()); final Repository newRepo = new Repository(newTestRepo); newRepo.create();
-- 1.6.0.3.640.g6331a