]> source.dussan.org Git - jgit.git/commitdiff
reftable: bulk operation unit tests 51/101151/24
authorShawn Pearce <spearce@spearce.org>
Wed, 12 Jul 2017 23:09:39 +0000 (16:09 -0700)
committerShawn Pearce <spearce@spearce.org>
Thu, 17 Aug 2017 22:06:51 +0000 (15:06 -0700)
Add more test cases that cover larger collections of
references, verifying every reference is accessible
both by scan and by seek.

Change-Id: Icada59fdcfc92a4634f6df61baaebb1c37b75d98

org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java

index f8276b35358c1beb11fef986ecb020214d696e93..5c19af3004a5d24c4ea2b48a04e493e75fd03dbb 100644 (file)
@@ -273,6 +273,62 @@ public class ReftableTest {
                }
        }
 
+       @SuppressWarnings("boxing")
+       @Test
+       public void indexScan() throws IOException {
+               List<Ref> 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<Ref> 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<Ref> 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<Ref> 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<Ref> 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<Ref> 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));
        }