summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2023-10-24 09:37:13 -0700
committerIvan Frade <ifrade@google.com>2023-10-27 08:32:38 -0700
commit1c320d0d41a944fe7a28158103d0318a01785e46 (patch)
tree92478b4e31cbae13a500aa8771846596faed1b17
parent5f563e386ec9f696d9681720d8649b1e9b4adb7c (diff)
downloadjgit-1c320d0d41a944fe7a28158103d0318a01785e46.tar.gz
jgit-1c320d0d41a944fe7a28158103d0318a01785e46.zip
UploadPackTest: Cover using wanted-refs as advertised set
Parent change introduced using "wanted-refs" as advertised set during fetchV2, but it tested only a request without wantIds (only wanted-refs). Add a second where the request has wanted-refs AND wantId (which disables the optimization). Change the test to measure the amount of refs considered advertised, instead of relying in calls to the refdb. Change-Id: Id64ec933fd737bae1bfd429c7b8cc05b51a83870
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java62
1 files changed, 62 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 d61403f97e..09989b7ca6 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
@@ -3003,6 +3003,68 @@ public class UploadPackTest {
assertEquals(0, ((RefCallsCountingRepository)server).numRefCalls());
}
+ /*
+ * Invokes UploadPack with specified protocol version and sends it the given
+ * lines, and returns UploadPack statistics (use uploadPackSetup to get the
+ * output stream)
+ */
+ private PackStatistics uploadPackV2SetupStats(String... inputLines)
+ throws Exception {
+
+ ByteArrayInputStream send = linesAsInputStream(inputLines);
+ String version = TransferConfig.ProtocolVersion.V2.version();
+ server.getConfig().setString(ConfigConstants.CONFIG_PROTOCOL_SECTION,
+ null, ConfigConstants.CONFIG_KEY_VERSION, version);
+ UploadPack up = new UploadPack(server);
+ up.setExtraParameters(Sets.of("version=".concat(version)));
+
+ ByteArrayOutputStream recv = new ByteArrayOutputStream();
+ up.upload(send, recv, null);
+ return up.getStatistics();
+ }
+
+ @Test
+ public void testUseWantedRefsAsAdvertisedSetV2_onlyWantedRefs()
+ throws Exception {
+ server = new RefCallsCountingRepository(
+ new DfsRepositoryDescription("server"));
+ remote = new TestRepository<>(server);
+ RevCommit one = remote.commit().message("1").create();
+ RevCommit two = remote.commit().message("2").create();
+ RevCommit three = remote.commit().message("3").create();
+ remote.update("one", one);
+ remote.update("two", two);
+ remote.update("three", three);
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant",
+ true);
+ PackStatistics stats = uploadPackV2SetupStats("command=fetch\n",
+ PacketLineIn.delimiter(), "want-ref refs/heads/one\n",
+ "want-ref refs/heads/two\n", "done\n", PacketLineIn.end());
+ assertEquals("only wanted-refs", 2, stats.getAdvertised());
+ assertEquals(0, ((RefCallsCountingRepository) server).numRefCalls());
+ }
+
+ @Test
+ public void testUseWantedRefsAsAdvertisedSetV2_withWantId()
+ throws Exception {
+ server = new RefCallsCountingRepository(
+ new DfsRepositoryDescription("server"));
+ remote = new TestRepository<>(server);
+ RevCommit one = remote.commit().message("1").create();
+ RevCommit two = remote.commit().message("2").create();
+ RevCommit three = remote.commit().message("3").create();
+ remote.update("one", one);
+ remote.update("two", two);
+ remote.update("three", three);
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant",
+ true);
+ PackStatistics stats = uploadPackV2SetupStats("command=fetch\n",
+ PacketLineIn.delimiter(), "want-ref refs/heads/one\n",
+ "want " + one.getName() + "\n", "done\n", PacketLineIn.end());
+ assertEquals("all refs", 3, stats.getAdvertised());
+ assertEquals(1, ((RefCallsCountingRepository) server).numRefCalls());
+ }
+
@Test
public void testNotAdvertisedWantsV1Fetch() throws Exception {
String commonInBlob = "abcdefghijklmnopqrstuvwxyz";