summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2019-04-02 10:08:24 -0700
committerJonathan Tan <jonathantanmy@google.com>2019-08-20 10:54:20 -0700
commita004820858b54d18c6f72fc94dc33bce8b606d66 (patch)
treef090c0d9732c8db6665d17aedc56ce5562b939d0 /org.eclipse.jgit.test/tst/org/eclipse/jgit
parentdb0eb9f8aef0beed0a8017d455bf016f2aae7647 (diff)
downloadjgit-a004820858b54d18c6f72fc94dc33bce8b606d66.tar.gz
jgit-a004820858b54d18c6f72fc94dc33bce8b606d66.zip
UploadPack: support custom packfile-to-URI mapping
Teach UploadPack to take a provider of URIs corresponding to cached packs. When fetching, if the client supports the packfile-uri feature, and if such a cached pack were to be streamed, instead send the corresponding URI. This packfile-uri feature is implemented in the jt/fetch-cdn-offload branch of Git. There is interest in this feature [1], but it is not yet merged. [1] https://public-inbox.org/git/cover.1552073690.git.jonathantanmy@google.com/ Change-Id: I9a32dae131c9c56ad2ff4a8a9638ae3b5e44dc15 Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java54
1 files changed, 54 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 22c67c1013..528a63f9c0 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
@@ -35,6 +35,8 @@ 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.internal.storage.file.PackLock;
+import org.eclipse.jgit.internal.storage.pack.CachedPack;
+import org.eclipse.jgit.internal.storage.pack.CachedPackUriProvider;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
@@ -2150,6 +2152,58 @@ public class UploadPackTest {
}
@Test
+ public void testV2FetchPackfileUris() throws Exception {
+ // Inside the pack
+ RevCommit commit = remote.commit().message("x").create();
+ remote.update("master", commit);
+ generateBitmaps(server);
+
+ // Outside the pack
+ RevCommit commit2 = remote.commit().message("x").parent(commit).create();
+ remote.update("master", commit2);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowsidebandall", true);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ (UploadPack up) -> {
+ up.setCachedPackUriProvider(new CachedPackUriProvider() {
+ @Override
+ public PackInfo getInfo(CachedPack pack,
+ Collection<String> protocolsSupported)
+ throws IOException {
+ assertThat(protocolsSupported, hasItems("https"));
+ if (!protocolsSupported.contains("https"))
+ return null;
+ return new PackInfo("myhash", "myuri");
+ }
+
+ });
+ },
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + commit2.getName() + "\n",
+ "sideband-all\n",
+ "packfile-uris https\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ String s;
+ // skip all \002 strings
+ for (s = pckIn.readString(); s.startsWith("\002"); s = pckIn.readString()) {
+ // do nothing
+ }
+ assertThat(s, is("\001packfile-uris"));
+ assertThat(pckIn.readString(), is("\001myhash myuri"));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
+ assertThat(pckIn.readString(), is("\001packfile"));
+ parsePack(recvStream);
+
+ assertFalse(client.getObjectDatabase().has(commit.toObjectId()));
+ assertTrue(client.getObjectDatabase().has(commit2.toObjectId()));
+ }
+
+ @Test
public void testGetPeerAgentProtocolV0() throws Exception {
RevCommit one = remote.commit().message("1").create();
remote.update("one", one);