diff options
author | Terry Parker <tparker@google.com> | 2020-09-14 09:53:43 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2020-09-14 09:53:43 -0400 |
commit | 292919b12a1e2f0584edbfb630a2b67567d4d9be (patch) | |
tree | ae2278507859c5334a258d6f8499bc2b8f44230f /org.eclipse.jgit.test | |
parent | 8cd49885ba2fbc41b79c2b3104b4f8d2f9a39547 (diff) | |
parent | 58e991b5dee510ea372716b054b78994df4d63c0 (diff) | |
download | jgit-292919b12a1e2f0584edbfb630a2b67567d4d9be.tar.gz jgit-292919b12a1e2f0584edbfb630a2b67567d4d9be.zip |
Merge "ReceivePackStats: Add size and count of unnecessary pushed objects"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java | 61 |
1 files changed, 61 insertions, 0 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 e9b4af932e..945900f14b 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 @@ -1060,6 +1060,67 @@ public class UploadPackTest { } @Test + public void testUploadNewBytes() throws Exception { + String commonInBlob = "abcdefghijklmnopqrstuvwx"; + + RevBlob parentBlob = remote.blob(commonInBlob + "a"); + RevCommit parent = remote.commit(remote.tree(remote.file("foo", parentBlob))); + RevBlob childBlob = remote.blob(commonInBlob + "b"); + RevCommit child = remote.commit(remote.tree(remote.file("foo", childBlob)), parent); + remote.update("branch1", child); + + ByteArrayInputStream recvStream = uploadPackV2( + "command=fetch\n", + PacketLineIn.delimiter(), + "want " + child.toObjectId().getName() + "\n", + "ofs-delta\n", + "done\n", + PacketLineIn.end()); + PacketLineIn pckIn = new PacketLineIn(recvStream); + assertThat(pckIn.readString(), is("packfile")); + ReceivedPackStatistics receivedStats = parsePack(recvStream); + assertTrue(receivedStats.getNumBytesDuplicated() == 0); + assertTrue(receivedStats.getNumObjectsDuplicated() == 0); + } + + @Test + public void testUploadRedundantBytes() throws Exception { + String commonInBlob = "abcdefghijklmnopqrstuvwxyz"; + + RevBlob parentBlob = remote.blob(commonInBlob + "a"); + RevCommit parent = remote.commit(remote.tree(remote.file("foo", parentBlob))); + RevBlob childBlob = remote.blob(commonInBlob + "b"); + RevCommit child = remote.commit(remote.tree(remote.file("foo", childBlob)), parent); + remote.update("branch1", child); + + TestRepository<InMemoryRepository> local = new TestRepository<>(client); + RevBlob localParentBlob = local.blob(commonInBlob + "a"); + RevCommit localParent = local.commit(local.tree(local.file("foo", localParentBlob))); + RevBlob localChildBlob = local.blob(commonInBlob + "b"); + RevCommit localChild = local.commit( + local.tree(local.file("foo", localChildBlob)), localParent); + local.update("branch1", localChild); + + ByteArrayInputStream recvStream = uploadPackV2( + "command=fetch\n", + PacketLineIn.delimiter(), + "want " + child.toObjectId().getName() + "\n", + "ofs-delta\n", + "done\n", + PacketLineIn.end()); + PacketLineIn pckIn = new PacketLineIn(recvStream); + assertThat(pckIn.readString(), is("packfile")); + ReceivedPackStatistics receivedStats = parsePack(recvStream); + + long sizeOfHeader = 12; + long sizeOfTrailer = 20; + long expectedSize = receivedStats.getNumBytesRead() - sizeOfHeader + - sizeOfTrailer; + assertTrue(receivedStats.getNumBytesDuplicated() == expectedSize); + assertTrue(receivedStats.getNumObjectsDuplicated() == 6); + } + + @Test public void testV2FetchOfsDelta() throws Exception { String commonInBlob = "abcdefghijklmnopqrstuvwxyz"; |