public static void verifySameContents(Repository source, Repository copy) { Set<ObjectId> sourceIds = verifyRepositoryContents(source); Set<ObjectId> copyIds = verifyRepositoryContents(copy); if (!copyIds.containsAll(sourceIds)) { Set<ObjectId> missing = Sets.difference(sourceIds, copyIds); fail(missing.size() + " missing ids on copy:"); } }
/** * Verifies that all the reachable objects from all the refs in the repo exist in the repo's * database */ public static Set<ObjectId> verifyRepositoryContents(Repository repo) { Map<String, Ref> allRefs = Maps.uniqueIndex(repo.command(ForEachRef.class).call(), (r) -> r.getName()); allRefs = Maps.filterKeys(allRefs, (k) -> !k.equals(Ref.STAGE_HEAD) && !k.equals(Ref.WORK_HEAD)); return veifyRepositoryContents(repo, allRefs); }
public static void verifyAllReachableContents(Repository repo, RevTree tree, Stack<String> pathToObject, Set<ObjectId> allIds) { ObjectStore store = repo.objectDatabase(); Set<Node> nodes = RevObjectTestSupport.getTreeNodes(tree, store); for (Node node : nodes) { pathToObject.push(node.getName()); Optional<ObjectId> metadataId = node.getMetadataId(); if (metadataId.isPresent()) { pathToObject.push("metadata"); verifyAllReachableContents(repo, metadataId.get(), pathToObject, allIds); pathToObject.pop(); } verifyAllReachableContents(repo, node.getObjectId(), pathToObject, allIds); pathToObject.pop(); } tree.getBuckets().forEach(bucket -> { pathToObject.push("bucket[" + bucket.getIndex() + "]"); verifyAllReachableContents(repo, bucket.getObjectId(), pathToObject, allIds); pathToObject.pop(); }); } }
TestSupport.verifySameRefs(remoteRepo, cloneRepo); TestSupport.verifySameContents(remoteRepo, cloneRepo); assertTrue(localTags.contains(tag)); TestSupport.verifyRepositoryContents(cloneRepo);
TestSupport.verifySameRefs(remoteRepo, cloneRepo); TestSupport.verifySameContents(remoteRepo, cloneRepo);
TestSupport.verifySameContents(remoteRepo, cloneRepo); TestSupport.verifyRepositoryContents(cloneRepo);
@Test public void testFetchSpecificRemote() throws Exception { // fetch from the remote FetchOp fetch = fetchOp(); TransferSummary summary = fetch.addRemote("upstream").call(); assertEquals(1, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(upstream.getFetchURL())); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamMaster); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamTag); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamBranch1); TestSupport.verifySameContents(upstreamRepo, localRepo); }
TestSupport.verifySameRefs(remoteRepo, cloneRepo); TestSupport.verifySameContents(remoteRepo, cloneRepo); assertTrue(localTags.contains(tag)); TestSupport.verifyRepositoryContents(cloneRepo);
TestSupport.verifySameRefs(remoteRepo, cloneRepo); TestSupport.verifySameContents(remoteRepo, cloneRepo); verifyBranchConfig(remoteRepo, cloneRepo);
@Test public void testFetchSpecificRemote() throws Exception { // fetch from the remote FetchOp fetch = fetchOp(); TransferSummary summary = fetch.addRemote("upstream").call(); assertEquals(1, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(upstream.getFetchURL())); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamMaster); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamTag); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamBranch1); TestSupport.verifySameContents(upstreamRepo, localRepo); }
public static void verifySameContents(Repository source, Repository copy) { Set<ObjectId> sourceIds = verifyRepositoryContents(source); Set<ObjectId> copyIds = verifyRepositoryContents(copy); if (!copyIds.containsAll(sourceIds)) { Set<ObjectId> missing = Sets.difference(sourceIds, copyIds); fail(missing.size() + " missing ids on copy:"); } }
TestSupport.verifySameRefs(remoteRepo, cloneRepo); TestSupport.verifySameContents(remoteRepo, cloneRepo);
public static void verifyAllReachableContents(Repository repo, RevTree tree, Stack<String> pathToObject, Set<ObjectId> allIds) { ObjectStore store = repo.objectDatabase(); Set<Node> nodes = RevObjectTestSupport.getTreeNodes(tree, store); for (Node node : nodes) { pathToObject.push(node.getName()); Optional<ObjectId> metadataId = node.getMetadataId(); if (metadataId.isPresent()) { pathToObject.push("metadata"); verifyAllReachableContents(repo, metadataId.get(), pathToObject, allIds); pathToObject.pop(); } verifyAllReachableContents(repo, node.getObjectId(), pathToObject, allIds); pathToObject.pop(); } tree.buckets().forEach((index, bucket) -> { pathToObject.push("bucket[" + index + "]"); verifyAllReachableContents(repo, bucket.getObjectId(), pathToObject, allIds); pathToObject.pop(); }); } }
TestSupport.verifySameContents(remoteRepo, localRepo);
/** * Verifies that all the reachable objects from the specified refs in the repo exist in the * repo's database */ public static Set<ObjectId> verifyRepositoryContents(Repository repo, String... refs) { final Set<String> filter = Sets.newHashSet(refs); Map<String, Ref> allRefs = Maps.uniqueIndex( repo.command(ForEachRef.class).setFilter(r -> filter.contains(r.getName())).call(), (r) -> r.getName()); for (String expected : filter) { Preconditions.checkState(allRefs.containsKey(expected), "Ref %s not found", expected); } return veifyRepositoryContents(repo, allRefs); }
@Test public void testCloneEmptyRepo() throws Exception { CloneOp clone = cloneOp(); // clone.setRepositoryURL(remoteGeogig.envHome.toURI().toString()).call(); clone.setRemoteURI(remoteGeogig.envHome.toURI()).setCloneURI(localGeogig.envHome.toURI()) .call(); TestSupport.verifyRepositoryContents(cloneRepo); }
TestSupport.verifySameRefs(remoteRepo, cloneRepo); TestSupport.verifySameContents(remoteRepo, cloneRepo);
private static Set<ObjectId> veifyRepositoryContents(Repository repo, Map<String, Ref> allRefs) { Set<ObjectId> allIds = Sets.newConcurrentHashSet(); for (Ref ref : allRefs.values()) { if (ref instanceof SymRef) { Ref target = ref.peel(); assertTrue(format("symref points to a non existent ref: %s", ref), allRefs.containsKey(target.getName())); } else { Stack<String> pathToObject = new Stack<>(); pathToObject.push(ref.getName()); verifyAllReachableContents(repo, ref.getObjectId(), pathToObject, allIds); pathToObject.pop(); } } return allIds; }
TestSupport.verifySameContents(remoteRepo, localRepo);
@Test public void testCloneEmptyRepo() throws Exception { CloneOp clone = cloneOp(); // clone.setRepositoryURL(remoteGeogig.envHome.toURI().toString()).call(); clone.setRemoteURI(remoteGeogig.envHome.toURI()).setCloneURI(localGeogig.envHome.toURI()) .call(); TestSupport.verifyRepositoryContents(cloneRepo); }