Re: [PATCH JGit 05/19] Made tests for listLocalPacks function on ObjectDirectory and made them pass

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



söndag 13 september 2009 20:44:21 skrev mr.gaffo@xxxxxxxxx:
> From: mike.gaffney <mike.gaffney@xxxxxxxxxxxxxx>
> 
> ---
>  .../org/spearce/jgit/lib/ObjectDirectoryTest.java  |   24 ++++++++++++++++++++
>  .../jgit/lib/UpdateDirectoryInfoCacheTest.java     |   11 +++++++++
>  .../tst/org/spearce/jgit/util/JGitTestUtil.java    |   21 ++++++++++++++++-
>  .../src/org/spearce/jgit/lib/ObjectDirectory.java  |    6 +++++
>  .../spearce/jgit/lib/UpdateDirectoryInfoCache.java |   22 ++++++++++++++++++
>  5 files changed, 83 insertions(+), 1 deletions(-)
>  create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
>  create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
> 
> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
> index fe019af..8e4d8e5 100644
> --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
> @@ -1,11 +1,17 @@
>  package org.spearce.jgit.lib;
>  
>  import java.io.File;
> +import java.util.List;
>  import java.util.UUID;
>  
> +import org.spearce.jgit.util.JGitTestUtil;
> +
>  import junit.framework.TestCase;
>  
>  public class ObjectDirectoryTest extends TestCase {
> +	private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f";
> +	private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack");
> +	private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx");
>  	
>  	private File testDir;
>  
> @@ -58,6 +64,24 @@ public void testGettingObjectFile() throws Exception {
>  				 od.fileFor(ObjectId.fromString("b052a1272310d8df34de72f60204dee7e28a43d0")));
>  	}
>  	
> +	public void testListLocalPacksNotCreated() throws Exception {
> +		assertEquals(0, new ObjectDirectory(testDir).listLocalPacks().size());
> +	}
> +	
> +	public void testListLocalPacksWhenThereIsAPack() throws Exception {
> +		createTestDir();
> +		File packsDir = new File(testDir, "pack");
> +		packsDir.mkdirs();
> +		
> +		JGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName()));
> +		JGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName()));
> +
> +		ObjectDirectory od = new ObjectDirectory(testDir);
> +		List<PackFile> localPacks = od.listLocalPacks();
> +		assertEquals(1, localPacks.size());
> +		assertEquals(TEST_PACK.getName(), localPacks.get(0).getPackFile().getName());
> +	}
> +	
>  	public boolean deleteDir(File dir) {
>          if (dir.isDirectory()) {
>              String[] children = dir.list();
> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
> new file mode 100644
> index 0000000..11d183e
> --- /dev/null
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
> @@ -0,0 +1,11 @@
> +package org.spearce.jgit.lib;
> +
> +import junit.framework.TestCase;
> +
> +public class UpdateDirectoryInfoCacheTest extends TestCase {
> +	
> +	public void testBase() throws Exception {
> +		fail("nyi");
> +	}
> +
> +}
> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
> index eee0c14..04184d7 100644
> --- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
> @@ -38,6 +38,12 @@
>  package org.spearce.jgit.util;
>  
>  import java.io.File;
> +import java.io.FileInputStream;
> +import java.io.FileNotFoundException;
> +import java.io.FileOutputStream;
> +import java.io.IOException;
> +import java.io.InputStream;
> +import java.io.OutputStream;
>  import java.net.URISyntaxException;
>  import java.net.URL;
>  
> @@ -60,11 +66,24 @@ public static File getTestResourceFile(final String fileName) {
>  		}
>  		try {
>  			return new File(url.toURI());
> -		} catch(URISyntaxException e) {
> +		} catch (URISyntaxException e) {
>  			return new File(url.getPath());
>  		}
>  	}
>  
> +	public static void copyFile(final File fromFile, final File toFile) throws IOException {
> +		InputStream in = new FileInputStream(fromFile);
> +		OutputStream out = new FileOutputStream(toFile);
> +
> +		byte[] buf = new byte[1024];
> +		int len;
> +		while ((len = in.read(buf)) > 0) {
> +			out.write(buf, 0, len);
> +		}
> +		in.close();
> +		out.close();
> +	}

You need to check for short reads, i.e. read could retrieve
fewer bytes than requested, Less important, a larger buffer size could
perhaps be used too (like 8192 which is the default BufferedReader buffer size).

>  	private static ClassLoader cl() {
>  		return JGitTestUtil.class.getClassLoader();
>  	}
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
> index fe219c6..a90ae00 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
> @@ -511,6 +511,12 @@ boolean tryAgain(final long currLastModified) {
>  
>  	@Override
>  	public List<PackFile> listLocalPacks() {
> +		tryAgain1();
mmmm. probably good.

> +	public void execute() {
> +//		File objectFile = objectDatabase.
> +//		String packsContents = new PacksFileContentsCreator(this.objectDatabase.listLocalPacks()).toString();

Out commented code is a no-no.

-- robin
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]