diff options
author | Jonathan Nieder <jrn@google.com> | 2017-11-10 18:52:53 -0500 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2017-11-10 18:52:53 -0500 |
commit | b88204edfb6b87e87666814f5f49014b72a30329 (patch) | |
tree | 03cf6c1f377f4a5fa424afb814c5c36782c72937 /org.eclipse.jgit.test/tst | |
parent | 2ec71a7c0e5254eb588885a5d6a9d05108887e22 (diff) | |
parent | c9d25505d835e073f35d4ba305346aca134e3d6b (diff) | |
download | jgit-b88204edfb6b87e87666814f5f49014b72a30329.tar.gz jgit-b88204edfb6b87e87666814f5f49014b72a30329.zip |
Merge changes I22a8874b,I68ed4abd,I740bc4bf,Icbd17d15
* changes:
BitmapWalker: do not revisit objects in bitmap
Use bitmaps for non-commit reachability checks
Make PackWriterBitmapWalker public
UploadPackTest: construct commits in test method
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java | 105 |
1 files changed, 94 insertions, 11 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 27c7674e9c..a8127abd36 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -4,24 +4,33 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.Collections; +import org.eclipse.jgit.errors.TransportException; +import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector; import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevBlob; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.transport.UploadPack.RequestPolicy; import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.eclipse.jgit.transport.resolver.UploadPackFactory; +import org.hamcrest.Matchers; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; /** * Tests for server upload-pack utilities. */ public class UploadPackTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + private URIish uri; private TestProtocol<Object> testProtocol; @@ -32,23 +41,14 @@ public class UploadPackTest { private InMemoryRepository client; - private RevCommit commit0; - - private RevCommit commit1; - - private RevCommit tip; + private TestRepository<InMemoryRepository> remote; @Before public void setUp() throws Exception { server = newRepo("server"); client = newRepo("client"); - TestRepository<InMemoryRepository> remote = - new TestRepository<>(server); - commit0 = remote.commit().message("0").create(); - commit1 = remote.commit().message("1").parent(commit0).create(); - tip = remote.commit().message("2").parent(commit1).create(); - remote.update("master", tip); + remote = new TestRepository<>(server); } @After @@ -60,8 +60,32 @@ public class UploadPackTest { return new InMemoryRepository(new DfsRepositoryDescription(name)); } + private void generateBitmaps(InMemoryRepository repo) throws Exception { + new DfsGarbageCollector(repo).pack(null); + repo.scanForRepoChanges(); + } + + private static TestProtocol<Object> generateReachableCommitUploadPackProtocol() { + return new TestProtocol<>( + new UploadPackFactory<Object>() { + @Override + public UploadPack create(Object req, Repository db) + throws ServiceNotEnabledException, + ServiceNotAuthorizedException { + UploadPack up = new UploadPack(db); + up.setRequestPolicy(RequestPolicy.REACHABLE_COMMIT); + return up; + } + }, null); + } + @Test public void testFetchParentOfShallowCommit() throws Exception { + RevCommit commit0 = remote.commit().message("0").create(); + RevCommit commit1 = remote.commit().message("1").parent(commit0).create(); + RevCommit tip = remote.commit().message("2").parent(commit1).create(); + remote.update("master", tip); + testProtocol = new TestProtocol<>( new UploadPackFactory<Object>() { @Override @@ -87,4 +111,63 @@ public class UploadPackTest { assertTrue(client.hasObject(commit0.toObjectId())); } } + + @Test + public void testFetchUnreachableBlobWithBitmap() throws Exception { + RevBlob blob = remote.blob("foo"); + remote.commit(remote.tree(remote.file("foo", blob))); + generateBitmaps(server); + + testProtocol = generateReachableCommitUploadPackProtocol(); + uri = testProtocol.register(ctx, server); + + assertFalse(client.hasObject(blob.toObjectId())); + + try (Transport tn = testProtocol.open(uri, client, "server")) { + thrown.expect(TransportException.class); + thrown.expectMessage(Matchers.containsString( + "want " + blob.name() + " not valid")); + tn.fetch(NullProgressMonitor.INSTANCE, + Collections.singletonList(new RefSpec(blob.name()))); + } + } + + @Test + public void testFetchReachableBlobWithBitmap() throws Exception { + RevBlob blob = remote.blob("foo"); + RevCommit commit = remote.commit(remote.tree(remote.file("foo", blob))); + remote.update("master", commit); + generateBitmaps(server); + + testProtocol = generateReachableCommitUploadPackProtocol(); + uri = testProtocol.register(ctx, server); + + assertFalse(client.hasObject(blob.toObjectId())); + + try (Transport tn = testProtocol.open(uri, client, "server")) { + tn.fetch(NullProgressMonitor.INSTANCE, + Collections.singletonList(new RefSpec(blob.name()))); + assertTrue(client.hasObject(blob.toObjectId())); + } + } + + @Test + public void testFetchReachableBlobWithoutBitmap() throws Exception { + RevBlob blob = remote.blob("foo"); + RevCommit commit = remote.commit(remote.tree(remote.file("foo", blob))); + remote.update("master", commit); + + testProtocol = generateReachableCommitUploadPackProtocol(); + uri = testProtocol.register(ctx, server); + + assertFalse(client.hasObject(blob.toObjectId())); + + try (Transport tn = testProtocol.open(uri, client, "server")) { + thrown.expect(TransportException.class); + thrown.expectMessage(Matchers.containsString( + "want " + blob.name() + " not valid")); + tn.fetch(NullProgressMonitor.INSTANCE, + Collections.singletonList(new RefSpec(blob.name()))); + } + } } |