TarFiles implements Closeable { public Map<UUID, Set<UUID>> getGraph(String fileName) throws IOException { Node head; lock.readLock().lock(); try { head = readers; } finally { lock.readLock().unlock(); } Set<UUID> index = null; Map<UUID, List<UUID>> graph = null; for (TarReader reader : iterable(head)) { if (fileName.equals(reader.getFileName())) { index = reader.getUUIDs(); graph = reader.getGraph(); break; } } Map<UUID, Set<UUID>> result = new HashMap<>(); if (index != null) { for (UUID uuid : index) { result.put(uuid, emptySet()); } } if (graph != null) { for (Entry<UUID, List<UUID>> entry : graph.entrySet()) { result.put(entry.getKey(), new HashSet<>(entry.getValue())); } } return result; } private  TarFiles(Builder builder); static Builder builder(); @Override void close(); @Override String toString(); long size(); int readerCount(); int segmentCount(); void flush(); boolean containsSegment(long msb, long lsb); Buffer readSegment(long msb, long lsb); void writeSegment(UUID id, byte[] buffer, int offset, int length, GCGeneration generation, Set<UUID> references, Set<String> binaryReferences); CleanupResult cleanup(CleanupContext context); void collectBlobReferences(Consumer<String> collector, Predicate<GCGeneration> reclaim); Iterable<UUID> getSegmentIds(); Map<UUID, Set<UUID>> getGraph(String fileName); Map<String, Set<UUID>> getIndices(); FileReaper createFileReaper();  }
@Test public void testGetGraph() throws Exception { UUID a = randomUUID(); UUID b = randomUUID(); UUID c = randomUUID(); UUID d = randomUUID(); writeSegment(a); writeSegmentWithReferences(b, a); writeSegmentWithReferences(c, a); writeSegmentWithReferences(d, b, c); tarFiles.newWriter(); String file = tarFiles.getIndices().keySet().iterator().next(); Map<UUID, Set<UUID>> graph = tarFiles.getGraph(file); Map<UUID, Set<UUID>> expected = new HashMap<>(); expected.put(a, emptySet()); expected.put(b, singleton(a)); expected.put(c, singleton(a)); expected.put(d, newHashSet(b, c)); assertEquals(expected, graph); }