Skip to content

Commit f6102e1

Browse files
committed
Added new test for indirect pins with multiple parents surviving gc after removing one parent
1 parent a4aa830 commit f6102e1

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/test/java/org/ipfs/api/Test.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,48 @@ public void pinTest() {
7575
List<Multihash> add2 = ipfs.pin.add(hash);
7676
// adding something already pinned should succeed
7777
List<Multihash> add3 = ipfs.pin.add(hash);
78-
Map<Multihash, Object> ls = ipfs.pin.ls();
78+
Map<Multihash, Object> ls = ipfs.pin.ls(IPFS.PinType.recursive);
79+
ipfs.repo.gc();
80+
// object should still be present after gc
81+
Map<Multihash, Object> ls2 = ipfs.pin.ls(IPFS.PinType.recursive);
82+
boolean stillPinned = ls2.containsKey(hash);
7983
System.out.println(ls);
8084
} catch (IOException e) {
8185
throw new RuntimeException(e);
8286
}
8387
}
8488

89+
@org.junit.Test
90+
public void indirectPinTest() {
91+
try {
92+
Multihash EMPTY = ipfs.object._new(Optional.empty()).hash;
93+
org.ipfs.api.MerkleNode data = ipfs.object.patch(EMPTY, "set-data", Optional.of("childdata".getBytes()), Optional.empty(), Optional.empty());
94+
Multihash child = data.hash;
95+
96+
org.ipfs.api.MerkleNode tmp1 = ipfs.object.patch(EMPTY, "set-data", Optional.of("parent1_data".getBytes()), Optional.empty(), Optional.empty());
97+
Multihash parent1 = ipfs.object.patch(tmp1.hash, "add-link", Optional.empty(), Optional.of(child.toString()), Optional.of(child)).hash;
98+
ipfs.pin.add(parent1);
99+
100+
org.ipfs.api.MerkleNode tmp2 = ipfs.object.patch(EMPTY, "set-data", Optional.of("parent2_data".getBytes()), Optional.empty(), Optional.empty());
101+
Multihash parent2 = ipfs.object.patch(tmp2.hash, "add-link", Optional.empty(), Optional.of(child.toString()), Optional.of(child)).hash;
102+
ipfs.pin.add(parent2);
103+
ipfs.pin.rm(parent1, true);
104+
105+
Map<Multihash, Object> ls = ipfs.pin.ls(IPFS.PinType.all);
106+
boolean childPresent = ls.containsKey(child);
107+
if (!childPresent)
108+
throw new IllegalStateException("Child not present!");
109+
110+
ipfs.repo.gc();
111+
Map<Multihash, Object> ls2 = ipfs.pin.ls(IPFS.PinType.all);
112+
boolean childPresentAfterGC = ls2.containsKey(child);
113+
if (!childPresentAfterGC)
114+
throw new IllegalStateException("Child not present!");
115+
} catch (IOException e) {
116+
throw new RuntimeException(e);
117+
}
118+
}
119+
85120
@org.junit.Test
86121
public void objectPatch() {
87122
try {

0 commit comments

Comments
 (0)