git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 3/8] Turn off memory mapping in JGit unit tests by default
Date: Mon,  1 Dec 2008 00:40:30 +0100	[thread overview]
Message-ID: <1228088435-23722-4-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1228088435-23722-3-git-send-email-robin.rosenberg@dewire.com>

A system property named jgit.junit.usemmmap can be set to true to enable
memory mapping during unit testing.

The protected method configure can be overridden to do things
like configuring the JGit engine.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../org/spearce/jgit/lib/RepositoryTestCase.java   |   30 ++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 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 e164faf..3b08fa5 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
@@ -49,6 +49,19 @@
 import junit.framework.TestCase;
 import org.spearce.jgit.util.JGitTestUtil;
 
+/**
+ * Base class for most JGit unit tests.
+ *
+ * Sets up a predefined test repository and has support for creating additional
+ * repositories and destroying them when the tests are finished.
+ *
+ * A system property <em>jgit.junit.usemmmap</em> defines whether memory mapping
+ * is used. Memory mapping has an effect on the file system, in that memory
+ * mapped files in java cannot be deleted as long as they mapped arrays have not
+ * been reclaimed by the garbage collector. The programmer cannot control this
+ * with precision, though hinting using <em>{@link java.lang.System#gc}</em>
+ * often helps.
+ */
 public abstract class RepositoryTestCase extends TestCase {
 
 	protected final File trashParent = new File("trash");
@@ -66,6 +79,22 @@
 		jcommitter = new PersonIdent("J. Committer", "jcommitter@example.com");
 	}
 
+	protected boolean packedGitMMAP;
+
+	/**
+	 * Configure JGit before setting up test repositories.
+	 */
+	protected void configure() {
+		packedGitMMAP = "true".equals(System.getProperty("jgit.junit.usemmmap"));
+		WindowCache.reconfigure(128*1024, 8192, packedGitMMAP, 8192);
+	}
+
+	/**
+	 * Utility method to delete a directory recursively. It is
+	 * also used internally.
+	 *
+	 * @param dir
+	 */
 	protected static void recursiveDelete(final File dir) {
 		final File[] ls = dir.listFiles();
 		if (ls != null) {
@@ -123,6 +152,7 @@ protected static void checkFile(File f, final String checkData)
 
 	public void setUp() throws Exception {
 		super.setUp();
+		configure();
 		recursiveDelete(trashParent);
 		trash = new File(trashParent,"trash"+System.currentTimeMillis());
 		trash_git = new File(trash, ".git");
-- 
1.6.0.3.640.g6331a

  reply	other threads:[~2008-11-30 23:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-27 21:13 [JGIT PATCH 0/4] RepositoryTestCase cleanups Robin Rosenberg
2008-11-27 21:49 ` Shawn O. Pearce
2008-11-29 12:01   ` Robin Rosenberg
2008-12-01 23:18     ` Johannes Schindelin
2008-11-30 14:18   ` Robin Rosenberg
2008-11-30 23:40   ` [JGIT PATCH v2 0/8] Unit test cleanups Robin Rosenberg
2008-11-30 23:40     ` [JGIT PATCH 1/8] Drop unneeded code in unit tests Robin Rosenberg
2008-11-30 23:40       ` [JGIT PATCH 2/8] Cleanup malformed test cases Robin Rosenberg
2008-11-30 23:40         ` Robin Rosenberg [this message]
2008-11-30 23:40           ` [JGIT PATCH 4/8] Add a counter to make sure the test repo name is unique Robin Rosenberg
2008-11-30 23:40             ` [JGIT PATCH 5/8] Make the cleanup less verbose when it fails to delete temporary stuff Robin Rosenberg
2008-11-30 23:40               ` [JGIT PATCH 6/8] Cleanup after each test Robin Rosenberg
2008-11-30 23:40                 ` [JGIT PATCH 7/8] Close files opened by unit testing framework Robin Rosenberg
2008-11-30 23:40                   ` [JGIT PATCH 8/8] Hard failure on unit test cleanups if they fail Robin Rosenberg
2008-12-02 16:38     ` [JGIT PATCH v2 0/8] Unit test cleanups Shawn O. Pearce

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=1228088435-23722-4-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).