From 9da26a5a1ae098e92fc6a0b7097e63e90a57c9aa Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Wed, 12 Jul 2017 16:09:39 -0700 Subject: [PATCH] reftable: bulk operation unit tests Add more test cases that cover larger collections of references, verifying every reference is accessible both by scan and by seek. Change-Id: Icada59fdcfc92a4634f6df61baaebb1c37b75d98 --- .../storage/reftable/ReftableTest.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java index f8276b3535..5c19af3004 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java @@ -273,6 +273,62 @@ public class ReftableTest { } } + @SuppressWarnings("boxing") + @Test + public void indexScan() throws IOException { + List refs = new ArrayList<>(); + for (int i = 1; i <= 5670; i++) { + refs.add(ref(String.format("refs/heads/%04d", i), i)); + } + + byte[] table = write(refs); + assertTrue(stats.refIndexLevels() > 0); + assertTrue(stats.refIndexSize() > 0); + assertScan(refs, read(table)); + } + + @SuppressWarnings("boxing") + @Test + public void indexSeek() throws IOException { + List refs = new ArrayList<>(); + for (int i = 1; i <= 5670; i++) { + refs.add(ref(String.format("refs/heads/%04d", i), i)); + } + + byte[] table = write(refs); + assertTrue(stats.refIndexLevels() > 0); + assertTrue(stats.refIndexSize() > 0); + assertSeek(refs, read(table)); + } + + @SuppressWarnings("boxing") + @Test + public void noIndexScan() throws IOException { + List refs = new ArrayList<>(); + for (int i = 1; i <= 567; i++) { + refs.add(ref(String.format("refs/heads/%03d", i), i)); + } + + byte[] table = write(refs); + assertEquals(0, stats.refIndexLevels()); + assertEquals(0, stats.refIndexSize()); + assertEquals(table.length, stats.totalBytes()); + assertScan(refs, read(table)); + } + + @SuppressWarnings("boxing") + @Test + public void noIndexSeek() throws IOException { + List refs = new ArrayList<>(); + for (int i = 1; i <= 567; i++) { + refs.add(ref(String.format("refs/heads/%03d", i), i)); + } + + byte[] table = write(refs); + assertEquals(0, stats.refIndexLevels()); + assertSeek(refs, read(table)); + } + public void unpeeledDoesNotWrite() { try { write(new ObjectIdRef.Unpeeled(PACKED, MASTER, id(1))); @@ -312,6 +368,32 @@ public class ReftableTest { } + private static void assertScan(List refs, Reftable t) + throws IOException { + try (RefCursor rc = t.allRefs()) { + for (Ref exp : refs) { + assertTrue("has " + exp.getName(), rc.next()); + Ref act = rc.getRef(); + assertEquals(exp.getName(), act.getName()); + assertEquals(exp.getObjectId(), act.getObjectId()); + } + assertFalse(rc.next()); + } + } + + private static void assertSeek(List refs, Reftable t) + throws IOException { + for (Ref exp : refs) { + try (RefCursor rc = t.seekRef(exp.getName())) { + assertTrue("has " + exp.getName(), rc.next()); + Ref act = rc.getRef(); + assertEquals(exp.getName(), act.getName()); + assertEquals(exp.getObjectId(), act.getObjectId()); + assertFalse(rc.next()); + } + } + } + private static Ref ref(String name, int id) { return new ObjectIdRef.PeeledNonTag(PACKED, name, id(id)); } -- 2.39.5