diff options
author | Yunjie Li <yunjieli@google.com> | 2020-03-25 10:59:06 -0700 |
---|---|---|
committer | Yunjie Li <yunjieli@google.com> | 2020-09-11 16:19:57 -0700 |
commit | 58e991b5dee510ea372716b054b78994df4d63c0 (patch) | |
tree | 7ebefaa34380091bfa4953478053cd6be511e950 /org.eclipse.jgit.test | |
parent | 0b487b4fcd3ff710738ad2ecaad10e28bb9902d3 (diff) | |
download | jgit-58e991b5dee510ea372716b054b78994df4d63c0.tar.gz jgit-58e991b5dee510ea372716b054b78994df4d63c0.zip |
ReceivePackStats: Add size and count of unnecessary pushed objects
Since there is no negotiation for a push, the client is probably sending
redundant objects and bytes which already exist in the server.
Add more metrics in the stats to quantify it. Duplicated size and number
to measure the size and the number of duplicated objects which should
not be pushed.
Change-Id: Iaacd4761ee9366a0a7ec4e26c508eff45c8744de
Signed-off-by: Yunjie Li <yunjieli@google.com>
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"; |