diff options
author | Han-Wen Nienhuys <hanwen@google.com> | 2019-09-18 15:18:51 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2019-09-20 01:48:11 +0200 |
commit | e5880d9531f17cbaac4d3f2c3428d116532caa6d (patch) | |
tree | 1fb7d654a4826e374ec6dd0dd2cba4a57207b748 /org.eclipse.jgit.test | |
parent | d75a6b5d813710ea1b21e05c50c6c32219e5f83a (diff) | |
download | jgit-e5880d9531f17cbaac4d3f2c3428d116532caa6d.tar.gz jgit-e5880d9531f17cbaac4d3f2c3428d116532caa6d.zip |
reftable: pass OutputStream at construction time
This makes the intended use of the classes more clear. It also
simplifies generic functions that write reftables: they only need a
ReftableWriter as argument, as the stream is carried within the
ReftableWriter.
Change-Id: Idbb06f89ae33100f0c0b562cc38e5b3b026d5181
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
4 files changed, 82 insertions, 76 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java index 5a5ae1d7a3..cfc275a7de 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java @@ -723,7 +723,7 @@ public class DfsGarbageCollectorTest { DfsPackDescription t1 = odb.newPack(INSERT); try (DfsOutputStream out = odb.writeFile(t1, REFTABLE)) { - new ReftableWriter().begin(out).finish(); + new ReftableWriter(out).begin().finish(); t1.addFileExt(REFTABLE); } odb.commitPack(Collections.singleton(t1), null); @@ -755,7 +755,7 @@ public class DfsGarbageCollectorTest { DfsPackDescription t1 = odb.newPack(INSERT); try (DfsOutputStream out = odb.writeFile(t1, REFTABLE)) { - new ReftableWriter().begin(out).finish(); + new ReftableWriter(out).begin().finish(); t1.addFileExt(REFTABLE); } odb.commitPack(Collections.singleton(t1), null); @@ -795,10 +795,10 @@ public class DfsGarbageCollectorTest { Ref next = new ObjectIdRef.PeeledNonTag(Ref.Storage.LOOSE, "refs/heads/next", commit0.copy()); try (DfsOutputStream out = odb.writeFile(t1, REFTABLE)) { - ReftableWriter w = new ReftableWriter(); + ReftableWriter w = new ReftableWriter(out); w.setMinUpdateIndex(42); w.setMaxUpdateIndex(42); - w.begin(out); + w.begin(); w.sortAndWriteRefs(Collections.singleton(next)); w.finish(); t1.addFileExt(REFTABLE); @@ -877,10 +877,10 @@ public class DfsGarbageCollectorTest { Ref newNext = new ObjectIdRef.PeeledNonTag(Ref.Storage.LOOSE, NEXT, commit1); try (DfsOutputStream out = odb.writeFile(t1, REFTABLE)) { - ReftableWriter w = new ReftableWriter(); - w.setMinUpdateIndex(1); - w.setMaxUpdateIndex(1); - w.begin(out); + ReftableWriter w = new ReftableWriter(out) + .setMinUpdateIndex(1) + .setMaxUpdateIndex(1) + .begin(); w.writeRef(newNext, 1); w.finish(); t1.addFileExt(REFTABLE); @@ -929,10 +929,10 @@ public class DfsGarbageCollectorTest { Ref newNext = new ObjectIdRef.PeeledNonTag(Ref.Storage.LOOSE, NEXT, commit1); try (DfsOutputStream out = odb.writeFile(t1, REFTABLE)) { - ReftableWriter w = new ReftableWriter(); - w.setMinUpdateIndex(1); - w.setMaxUpdateIndex(1); - w.begin(out); + ReftableWriter w = new ReftableWriter(out) + .setMinUpdateIndex(1) + .setMaxUpdateIndex(1) + .begin(); w.writeRef(newNext, 1); w.finish(); t1.addFileExt(REFTABLE); 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 11d6439931..dd42aa0b38 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 @@ -297,10 +297,10 @@ public class MergedReftableTest { @Test public void missedUpdate() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(buf) .setMinUpdateIndex(1) .setMaxUpdateIndex(3) - .begin(buf); + .begin(); writer.writeRef(ref("refs/heads/a", 1), 1); writer.writeRef(ref("refs/heads/c", 3), 3); writer.finish(); @@ -337,13 +337,13 @@ public class MergedReftableTest { List<Ref> delta2 = Arrays.asList(delete("refs/heads/next")); List<Ref> delta3 = Arrays.asList(ref("refs/heads/master", 8)); - ReftableCompactor compactor = new ReftableCompactor(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ReftableCompactor compactor = new ReftableCompactor(out); compactor.addAll(Arrays.asList( read(write(delta1)), read(write(delta2)), read(write(delta3)))); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - compactor.compact(out); + compactor.compact(); byte[] table = out.toByteArray(); ReftableReader reader = read(table); @@ -461,10 +461,10 @@ public class MergedReftableTest { private byte[] write(Collection<Ref> refs, long updateIndex) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - new ReftableWriter() + new ReftableWriter(buffer) .setMinUpdateIndex(updateIndex) .setMaxUpdateIndex(updateIndex) - .begin(buffer) + .begin() .sortAndWriteRefs(refs) .finish(); return buffer.toByteArray(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableCompactorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableCompactorTest.java index 1ea73097fe..9a7f240951 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableCompactorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableCompactorTest.java @@ -67,9 +67,10 @@ public class ReftableCompactorTest { @Test public void noTables() throws IOException { - ReftableCompactor compactor = new ReftableCompactor(); + ReftableCompactor compactor; try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { - compactor.compact(out); + compactor = new ReftableCompactor(out); + compactor.compact(); } Stats stats = compactor.getStats(); assertEquals(0, stats.minUpdateIndex()); @@ -81,10 +82,10 @@ public class ReftableCompactorTest { public void oneTable() throws IOException { byte[] inTab; try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(inBuf) .setMinUpdateIndex(0) .setMaxUpdateIndex(0) - .begin(inBuf); + .begin(); writer.writeRef(ref(MASTER, 1)); writer.finish(); @@ -92,10 +93,11 @@ public class ReftableCompactorTest { } byte[] outTab; - ReftableCompactor compactor = new ReftableCompactor(); + ReftableCompactor compactor; try (ByteArrayOutputStream outBuf = new ByteArrayOutputStream()) { + compactor = new ReftableCompactor(outBuf); compactor.tryAddFirst(read(inTab)); - compactor.compact(outBuf); + compactor.compact(); outTab = outBuf.toByteArray(); } Stats stats = compactor.getStats(); @@ -116,10 +118,10 @@ public class ReftableCompactorTest { public void twoTablesOneRef() throws IOException { byte[] inTab1; try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(inBuf) .setMinUpdateIndex(0) .setMaxUpdateIndex(0) - .begin(inBuf); + .begin(); writer.writeRef(ref(MASTER, 1)); writer.finish(); @@ -128,10 +130,10 @@ public class ReftableCompactorTest { byte[] inTab2; try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(inBuf) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) - .begin(inBuf); + .begin(); writer.writeRef(ref(MASTER, 2)); writer.finish(); @@ -139,10 +141,11 @@ public class ReftableCompactorTest { } byte[] outTab; - ReftableCompactor compactor = new ReftableCompactor(); + ReftableCompactor compactor; try (ByteArrayOutputStream outBuf = new ByteArrayOutputStream()) { + compactor = new ReftableCompactor(outBuf); compactor.addAll(Arrays.asList(read(inTab1), read(inTab2))); - compactor.compact(outBuf); + compactor.compact(); outTab = outBuf.toByteArray(); } Stats stats = compactor.getStats(); @@ -163,10 +166,10 @@ public class ReftableCompactorTest { public void twoTablesTwoRefs() throws IOException { byte[] inTab1; try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(inBuf) .setMinUpdateIndex(0) .setMaxUpdateIndex(0) - .begin(inBuf); + .begin(); writer.writeRef(ref(MASTER, 1)); writer.writeRef(ref(NEXT, 2)); @@ -176,10 +179,10 @@ public class ReftableCompactorTest { byte[] inTab2; try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(inBuf) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) - .begin(inBuf); + .begin(); writer.writeRef(ref(MASTER, 3)); writer.finish(); @@ -187,10 +190,11 @@ public class ReftableCompactorTest { } byte[] outTab; - ReftableCompactor compactor = new ReftableCompactor(); + ReftableCompactor compactor; try (ByteArrayOutputStream outBuf = new ByteArrayOutputStream()) { + compactor = new ReftableCompactor(outBuf); compactor.addAll(Arrays.asList(read(inTab1), read(inTab2))); - compactor.compact(outBuf); + compactor.compact(); outTab = outBuf.toByteArray(); } Stats stats = compactor.getStats(); @@ -216,10 +220,10 @@ public class ReftableCompactorTest { public void twoTablesIncludeOneDelete() throws IOException { byte[] inTab1; try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(inBuf) .setMinUpdateIndex(0) .setMaxUpdateIndex(0) - .begin(inBuf); + .begin(); writer.writeRef(ref(MASTER, 1)); writer.finish(); @@ -228,10 +232,10 @@ public class ReftableCompactorTest { byte[] inTab2; try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(inBuf) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) - .begin(inBuf); + .begin(); writer.writeRef(tombstone(MASTER)); writer.finish(); @@ -239,11 +243,12 @@ public class ReftableCompactorTest { } byte[] outTab; - ReftableCompactor compactor = new ReftableCompactor(); + ReftableCompactor compactor; try (ByteArrayOutputStream outBuf = new ByteArrayOutputStream()) { + compactor = new ReftableCompactor(outBuf); compactor.setIncludeDeletes(true); compactor.addAll(Arrays.asList(read(inTab1), read(inTab2))); - compactor.compact(outBuf); + compactor.compact(); outTab = outBuf.toByteArray(); } Stats stats = compactor.getStats(); @@ -261,10 +266,10 @@ public class ReftableCompactorTest { public void twoTablesNotIncludeOneDelete() throws IOException { byte[] inTab1; try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(inBuf) .setMinUpdateIndex(0) .setMaxUpdateIndex(0) - .begin(inBuf); + .begin(); writer.writeRef(ref(MASTER, 1)); writer.finish(); @@ -273,10 +278,10 @@ public class ReftableCompactorTest { byte[] inTab2; try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(inBuf) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) - .begin(inBuf); + .begin(); writer.writeRef(tombstone(MASTER)); writer.finish(); @@ -284,11 +289,12 @@ public class ReftableCompactorTest { } byte[] outTab; - ReftableCompactor compactor = new ReftableCompactor(); + ReftableCompactor compactor; try (ByteArrayOutputStream outBuf = new ByteArrayOutputStream()) { + compactor = new ReftableCompactor(outBuf); compactor.setIncludeDeletes(false); compactor.addAll(Arrays.asList(read(inTab1), read(inTab2))); - compactor.compact(outBuf); + compactor.compact(); outTab = outBuf.toByteArray(); } Stats stats = compactor.getStats(); 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 a45548d1e7..1c04733f63 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 @@ -137,9 +137,9 @@ public class ReftableTest { byte[] table; ReftableConfig cfg = new ReftableConfig(); cfg.setIndexObjects(false); - ReftableWriter writer = new ReftableWriter().setConfig(cfg); try (ByteArrayOutputStream buf = new ByteArrayOutputStream()) { - writer.begin(buf); + ReftableWriter writer = new ReftableWriter(buf).setConfig(cfg); + writer.begin(); assertEquals(92, writer.estimateTotalBytes()); writer.writeRef(exp); assertEquals(expBytes, writer.estimateTotalBytes()); @@ -163,9 +163,9 @@ public class ReftableTest { int expBytes = 147860; byte[] table; - ReftableWriter writer = new ReftableWriter().setConfig(cfg); try (ByteArrayOutputStream buf = new ByteArrayOutputStream()) { - writer.begin(buf); + ReftableWriter writer = new ReftableWriter(buf).setConfig(cfg); + writer.begin(); writer.sortAndWriteRefs(refs); assertEquals(expBytes, writer.estimateTotalBytes()); writer.finish(); @@ -424,10 +424,10 @@ public class ReftableTest { public void invalidRefWriteOrder() throws IOException { Ref master = ref(MASTER, 1); Ref next = ref(NEXT, 2); - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(new ByteArrayOutputStream()) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) - .begin(new ByteArrayOutputStream()); + .begin(); writer.writeRef(next); IllegalArgumentException e = assertThrows( @@ -438,10 +438,10 @@ public class ReftableTest { @Test public void invalidReflogWriteOrderUpdateIndex() throws IOException { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(new ByteArrayOutputStream()) .setMinUpdateIndex(1) .setMaxUpdateIndex(2) - .begin(new ByteArrayOutputStream()); + .begin(); PersonIdent who = new PersonIdent("Log", "Ger", 1500079709, -8 * 60); String msg = "test"; @@ -454,10 +454,10 @@ public class ReftableTest { @Test public void invalidReflogWriteOrderName() throws IOException { - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(new ByteArrayOutputStream()) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) - .begin(new ByteArrayOutputStream()); + .begin(); PersonIdent who = new PersonIdent("Log", "Ger", 1500079709, -8 * 60); String msg = "test"; @@ -476,10 +476,10 @@ public class ReftableTest { String msg = "test"; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(buffer) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) - .begin(buffer); + .begin(); writer.writeRef(master); writer.writeRef(next); @@ -531,8 +531,8 @@ public class ReftableTest { Ref next = ref(NEXT, 2); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ReftableWriter writer = new ReftableWriter().setMinUpdateIndex(1) - .setMaxUpdateIndex(1).begin(buffer); + ReftableWriter writer = new ReftableWriter(buffer).setMinUpdateIndex(1) + .setMaxUpdateIndex(1).begin(); writer.writeRef(master); writer.writeRef(next); @@ -573,11 +573,11 @@ public class ReftableTest { cfg.setRefBlockSize(1024); cfg.setLogBlockSize(1024); cfg.setAlignBlocks(true); - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(buffer) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) .setConfig(cfg) - .begin(buffer); + .begin(); PersonIdent who = new PersonIdent("Log", "Ger", 1500079709, -8 * 60); // Fill out the 1st ref block. @@ -611,10 +611,10 @@ public class ReftableTest { String msgNext = "test next"; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(buffer) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) - .begin(buffer); + .begin(); writer.writeLog(MASTER, 1, who, ObjectId.zeroId(), id(1), msg); writer.writeLog(NEXT, 1, who, ObjectId.zeroId(), id(2), msgNext); @@ -654,10 +654,10 @@ public class ReftableTest { PersonIdent who = new PersonIdent("Log", "Ger", 1500079709, -8 * 60); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(buffer) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) - .begin(buffer); + .begin(); writer.writeLog("branchname", 1, who, ObjectId.zeroId(), id(1), "branchname"); @@ -678,10 +678,10 @@ public class ReftableTest { String msg = "test"; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ReftableWriter writer = new ReftableWriter() + ReftableWriter writer = new ReftableWriter(buffer) .setMinUpdateIndex(1) .setMaxUpdateIndex(1) - .begin(buffer); + .begin(); writer.writeLog(MASTER, 1, who, ObjectId.zeroId(), id(1), msg); writer.writeLog(NEXT, 1, who, ObjectId.zeroId(), id(2), msg); writer.finish(); @@ -730,8 +730,8 @@ public class ReftableTest { cfg.setLogBlockSize(2048); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ReftableWriter writer = new ReftableWriter(cfg); - writer.setMinUpdateIndex(1).setMaxUpdateIndex(1).begin(buffer); + ReftableWriter writer = new ReftableWriter(cfg, buffer); + writer.setMinUpdateIndex(1).setMaxUpdateIndex(1).begin(); List<Ref> refs = new ArrayList<>(); for (int i = 1; i <= 5670; i++) { @@ -850,7 +850,7 @@ public class ReftableTest { cfg.setRefBlockSize(64); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ReftableWriter writer = new ReftableWriter(cfg).begin(buffer); + ReftableWriter writer = new ReftableWriter(cfg, buffer).begin(); writer.writeRef(ref("refs/heads/i-am-not-a-teapot", 1)); writer.finish(); fail("expected BlockSizeTooSmallException"); @@ -935,8 +935,8 @@ public class ReftableTest { private byte[] write(Collection<Ref> refs) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - stats = new ReftableWriter() - .begin(buffer) + stats = new ReftableWriter(buffer) + .begin() .sortAndWriteRefs(refs) .finish() .getStats(); |