]> source.dussan.org Git - jgit.git/commitdiff
reftable: lookup by ObjectId unit tests 75/101775/17
authorShawn Pearce <spearce@spearce.org>
Fri, 21 Jul 2017 19:40:33 +0000 (12:40 -0700)
committerShawn Pearce <spearce@spearce.org>
Thu, 17 Aug 2017 22:06:51 +0000 (15:06 -0700)
Change-Id: Ic819a04e285094e271435dcd027d8006e5897785

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

index 3abd3d3950b24d1700be50943aa145b3679a68c1..b53853b2e54b72e2df3d3d24e678f9ccd6f28365 100644 (file)
@@ -515,6 +515,68 @@ public class ReftableTest {
                }
        }
 
+       @SuppressWarnings("boxing")
+       @Test
+       public void byObjectIdOneRefNoIndex() throws IOException {
+               List<Ref> refs = new ArrayList<>();
+               for (int i = 1; i <= 200; i++) {
+                       refs.add(ref(String.format("refs/heads/%02d", i), i));
+               }
+               refs.add(ref("refs/heads/master", 100));
+
+               ReftableReader t = read(write(refs));
+               assertEquals(0, stats.objIndexSize());
+
+               try (RefCursor rc = t.byObjectId(id(42))) {
+                       assertTrue("has 42", rc.next());
+                       assertEquals("refs/heads/42", rc.getRef().getName());
+                       assertEquals(id(42), rc.getRef().getObjectId());
+                       assertFalse(rc.next());
+               }
+               try (RefCursor rc = t.byObjectId(id(100))) {
+                       assertTrue("has 100", rc.next());
+                       assertEquals("refs/heads/100", rc.getRef().getName());
+                       assertEquals(id(100), rc.getRef().getObjectId());
+
+                       assertTrue("has master", rc.next());
+                       assertEquals("refs/heads/master", rc.getRef().getName());
+                       assertEquals(id(100), rc.getRef().getObjectId());
+
+                       assertFalse(rc.next());
+               }
+       }
+
+       @SuppressWarnings("boxing")
+       @Test
+       public void byObjectIdOneRefWithIndex() throws IOException {
+               List<Ref> refs = new ArrayList<>();
+               for (int i = 1; i <= 5200; i++) {
+                       refs.add(ref(String.format("refs/heads/%02d", i), i));
+               }
+               refs.add(ref("refs/heads/master", 100));
+
+               ReftableReader t = read(write(refs));
+               assertTrue(stats.objIndexSize() > 0);
+
+               try (RefCursor rc = t.byObjectId(id(42))) {
+                       assertTrue("has 42", rc.next());
+                       assertEquals("refs/heads/42", rc.getRef().getName());
+                       assertEquals(id(42), rc.getRef().getObjectId());
+                       assertFalse(rc.next());
+               }
+               try (RefCursor rc = t.byObjectId(id(100))) {
+                       assertTrue("has 100", rc.next());
+                       assertEquals("refs/heads/100", rc.getRef().getName());
+                       assertEquals(id(100), rc.getRef().getObjectId());
+
+                       assertTrue("has master", rc.next());
+                       assertEquals("refs/heads/master", rc.getRef().getName());
+                       assertEquals(id(100), rc.getRef().getObjectId());
+
+                       assertFalse(rc.next());
+               }
+       }
+
        @Test
        public void unpeeledDoesNotWrite() {
                try {