From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, fonseca@diku.dk,
Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [JGIT PATCH 4/4] Automatically clean up any repositories created by the test cases
Date: Thu, 27 Nov 2008 22:15:35 +0100 [thread overview]
Message-ID: <1227820535-9785-5-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1227820535-9785-4-git-send-email-robin.rosenberg@dewire.com>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
.../org/spearce/jgit/lib/RepositoryTestCase.java | 21 +++++++++++++++++++-
1 files changed, 20 insertions(+), 1 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 ef4fd1b..cab65a0 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
@@ -45,6 +45,7 @@
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
+import java.util.ArrayList;
import junit.framework.TestCase;
import org.spearce.jgit.util.JGitTestUtil;
@@ -145,6 +146,8 @@ protected static void checkFile(File f, final String checkData)
private static int testcount;
private static Thread shutdownhook;
+ private ArrayList<Repository> repositoriesToClose = new ArrayList<Repository>();
+
public void setUp() throws Exception {
super.setUp();
System.gc();
@@ -192,6 +195,20 @@ copyFile(JGitTestUtil.getTestResourceFile(packs[k] + ".idx"), new File(packDir,
protected void tearDown() throws Exception {
db.close();
+ for (Repository r : repositoriesToClose) {
+ r.close();
+ }
+ // Since memory mapping is controlled by the GC we need to
+ // tell it this is a good time to clean up and unlock
+ // mmemory mapped files.
+ System.gc();
+
+ recursiveDelete(trash, false, getName());
+ for (Repository r : repositoriesToClose) {
+ recursiveDelete(r.getWorkDir(), false, getName());
+ }
+ repositoriesToClose.clear();
+
super.tearDown();
}
@@ -209,12 +226,14 @@ protected Repository createNewEmptyRepo() throws IOException {
assertTrue(unusedDir.mkdirs());
final Repository newRepo = new Repository(newTestRepo);
newRepo.create();
+ final String name = getClass().getName() + "." + getName();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
- recursiveDelete(newTestRepo);
+ recursiveDelete(newTestRepo, false, name);
}
});
+ repositoriesToClose.add(newRepo);
return newRepo;
}
--
1.6.0.3.640.g6331a
prev parent reply other threads:[~2008-11-27 21:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-27 21:15 [JGIT PATCH 0/4] RepositoryTestCase cleanups Robin Rosenberg
2008-11-27 21:15 ` [JGIT PATCH 1/4] Make the cleanup less verbose when it fails to delete temporary stuff Robin Rosenberg
2008-11-27 21:15 ` [JGIT PATCH 2/4] Add shutdown hooks to try to clean up after unit tests anyway Robin Rosenberg
2008-11-27 21:15 ` [JGIT PATCH 3/4] Cleanup malformed test cases Robin Rosenberg
2008-11-27 21:15 ` Robin Rosenberg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1227820535-9785-5-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=fonseca@diku.dk \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).