aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorMinh Thai <mthai@google.com>2020-03-19 23:10:41 -0700
committerMatthias Sohn <matthias.sohn@sap.com>2020-04-05 17:26:20 -0400
commit0eeed6ad2b93f9f9712803cfec288bb0f094dd17 (patch)
tree2892eedda7d737b52cfcd368d7d325a3c9000a44 /org.eclipse.jgit.test/tst
parent3ae0b5cfeb4ffedb4078d2feb472bb18d589d86e (diff)
downloadjgit-0eeed6ad2b93f9f9712803cfec288bb0f094dd17.tar.gz
jgit-0eeed6ad2b93f9f9712803cfec288bb0f094dd17.zip
Scan through all merged reftables for max/min update indices
Since reftables might have update index ranges that are overlapped. Change-Id: I8f8215b99a0a978d4dd0155dbaf33e5e06ea8202 Signed-off-by: Minh Thai <mthai@google.com> (cherry picked from commit 06748c205c44bb4eaf6015387112de97f566c6a2)
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java117
1 files changed, 117 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
index 2a2aeb592f..a246ac9e9c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
@@ -287,6 +287,123 @@ public class MergedReftableTest {
}
@Test
+ public void nonOverlappedUpdateIndices() throws IOException {
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ ReftableWriter writer = new ReftableWriter(buf)
+ .setMinUpdateIndex(1)
+ .setMaxUpdateIndex(2)
+ .begin();
+ writer.writeRef(ref("refs/heads/a", 1), 1);
+ writer.writeRef(ref("refs/heads/b", 2), 2);
+ writer.finish();
+ byte[] base = buf.toByteArray();
+
+ buf = new ByteArrayOutputStream();
+ writer = new ReftableWriter(buf)
+ .setMinUpdateIndex(3)
+ .setMaxUpdateIndex(4)
+ .begin();
+ writer.writeRef(ref("refs/heads/a", 10), 3);
+ writer.writeRef(ref("refs/heads/b", 20), 4);
+ writer.finish();
+ byte[] delta = buf.toByteArray();
+
+ MergedReftable mr = merge(base, delta);
+ assertEquals(1, mr.minUpdateIndex());
+ assertEquals(4, mr.maxUpdateIndex());
+
+ try (RefCursor rc = mr.allRefs()) {
+ assertTrue(rc.next());
+ assertEquals("refs/heads/a", rc.getRef().getName());
+ assertEquals(id(10), rc.getRef().getObjectId());
+ assertEquals(3, rc.getRef().getUpdateIndex());
+
+ assertTrue(rc.next());
+ assertEquals("refs/heads/b", rc.getRef().getName());
+ assertEquals(id(20), rc.getRef().getObjectId());
+ assertEquals(4, rc.getRef().getUpdateIndex());
+ }
+ }
+
+ @Test
+ public void overlappedUpdateIndices() throws IOException {
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ ReftableWriter writer = new ReftableWriter(buf)
+ .setMinUpdateIndex(1)
+ .setMaxUpdateIndex(3)
+ .begin();
+ writer.writeRef(ref("refs/heads/a", 1), 1);
+ writer.writeRef(ref("refs/heads/b", 2), 3);
+ writer.finish();
+ byte[] base = buf.toByteArray();
+
+ buf = new ByteArrayOutputStream();
+ writer = new ReftableWriter(buf)
+ .setMinUpdateIndex(2)
+ .setMaxUpdateIndex(4)
+ .begin();
+ writer.writeRef(ref("refs/heads/a", 10), 2);
+ writer.writeRef(ref("refs/heads/b", 20), 4);
+ writer.finish();
+ byte[] delta = buf.toByteArray();
+
+ MergedReftable mr = merge(base, delta);
+ assertEquals(1, mr.minUpdateIndex());
+ assertEquals(4, mr.maxUpdateIndex());
+
+ try (RefCursor rc = mr.allRefs()) {
+ assertTrue(rc.next());
+ assertEquals("refs/heads/a", rc.getRef().getName());
+ assertEquals(id(10), rc.getRef().getObjectId());
+ assertEquals(2, rc.getRef().getUpdateIndex());
+
+ assertTrue(rc.next());
+ assertEquals("refs/heads/b", rc.getRef().getName());
+ assertEquals(id(20), rc.getRef().getObjectId());
+ assertEquals(4, rc.getRef().getUpdateIndex());
+ }
+ }
+
+ @Test
+ public void enclosedUpdateIndices() throws IOException {
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ ReftableWriter writer = new ReftableWriter(buf)
+ .setMinUpdateIndex(1)
+ .setMaxUpdateIndex(4)
+ .begin();
+ writer.writeRef(ref("refs/heads/a", 1), 1);
+ writer.writeRef(ref("refs/heads/b", 20), 4);
+ writer.finish();
+ byte[] base = buf.toByteArray();
+
+ buf = new ByteArrayOutputStream();
+ writer = new ReftableWriter(buf)
+ .setMinUpdateIndex(2)
+ .setMaxUpdateIndex(3)
+ .begin();
+ writer.writeRef(ref("refs/heads/a", 10), 2);
+ writer.writeRef(ref("refs/heads/b", 2), 3);
+ writer.finish();
+ byte[] delta = buf.toByteArray();
+
+ MergedReftable mr = merge(base, delta);
+ assertEquals(1, mr.minUpdateIndex());
+ assertEquals(4, mr.maxUpdateIndex());
+
+ try (RefCursor rc = mr.allRefs()) {
+ assertTrue(rc.next());
+ assertEquals("refs/heads/a", rc.getRef().getName());
+ assertEquals(id(10), rc.getRef().getObjectId());
+ assertEquals(2, rc.getRef().getUpdateIndex());
+
+ assertTrue(rc.next());
+ assertEquals("refs/heads/b", rc.getRef().getName());
+ assertEquals(id(20), rc.getRef().getObjectId());
+ assertEquals(4, rc.getRef().getUpdateIndex());
+ }
+ }
+
+ @Test
public void compaction() throws IOException {
List<Ref> delta1 = Arrays.asList(
ref("refs/heads/next", 4),