public void run() { try { for (int i = 0; i < 100; i++) { ObjectId root = RevObjectTestSupport.hashString(key + "_commit_" + i); ObjectId commit = RevObjectTestSupport.hashString(key + "_commit_" + (i + 1)); database.put(commit, ImmutableList.of(root)); } } catch (Exception e) { errorLog.offer(e.toString()); } } }
private void assertTreeContents(RevTree tree, List<Node> expected) { Set<Node> expectedNodes = new HashSet<>(expected); Preconditions.checkArgument(expectedNodes.size() == expected.size()); Set<Node> actual = RevObjectTestSupport.getTreeNodes(tree, support.store()); assertEquals(expectedNodes, actual); }
private RevFeature fakeFeature(ObjectId forcedId) { // String oidString = objectId.toString(); // ObjectId treeId = ObjectId.forString("tree" + oidString); // ImmutableList<ObjectId> parentIds = ImmutableList.of(); // RevPerson author = new RevPersonImpl("Gabriel", "groldan@boundlessgeo.com", 1000, -3); // RevPerson committer = new RevPersonImpl("Gabriel", "groldan@boundlessgeo.com", 1000, -3); // String message = "message " + oidString; // return new RevCommitImpl(objectId, treeId, parentIds, author, committer, message); if (fakeGeom == null) { try { fakeGeom = new WKTReader().read( "MULTIPOLYGON (((-121.3647138 38.049474, -121.3646902 38.049614, -121.3646159 38.0496058, -121.3646188 38.049587, -121.3645936 38.049586, -121.3645924 38.0496222, -121.3645056 38.0496178, -121.3645321 38.0494567, -121.3647138 38.049474)))"); } catch (ParseException e) { throw new RuntimeException(e); } } return featureForceId(forcedId, fakeGeom, "Some string value " + forcedId); }
@Before public void before() { ObjectStore store = new HeapObjectStore(); store.open(); cache = mock(TreeCache.class); featuresTree = createFeaturesTree(store, "f", 512); treesTree = createTreesTree(store, 2, 200, RevObjectTestSupport.hashString("test")); }
@Test public void testGetIfPresent() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); for (RevObject o : expected) { assertTrue(db.put(o)); } for (RevObject o : expected) { assertEquals(o, db.getIfPresent(o.getId())); } assertNull(db.getIfPresent(RevObjectTestSupport.hashString("notfound"))); }
@Before public void beforeTest() { leftSource = new HeapObjectDatabase(); rightSource = new HeapObjectDatabase(); leftSource.open(); rightSource.open(); consumer = mock(Consumer.class); when(consumer.feature(any(NodeRef.class), any(NodeRef.class))).thenReturn(true); testSupport = new RevObjectTestSupport(); testSupport.setBuildSpatialTrees(true); }
@Test public void testPutAll() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); db.putAll(expected.iterator()); for (RevObject o : expected) { assertEquals(o, db.get(o.getId())); } }
@Test public void testGetAllOfASpecificType() { final RevFeature f1 = feature(0, null, "some value"); final RevFeature f2 = feature(1, "value", new Integer(111)); final RevFeature f3 = feature(2, (Object) null); final RevTree t1 = RevTree.EMPTY; final RevTree t2 = RevObjectTestSupport.INSTANCE.createFeaturesTree(db, "t", 10); final RevTree t3 = RevObjectTestSupport.INSTANCE.createFeaturesTree(db, "t", 100);
public static Set<RevTree> getAllTrees(ObjectStore source, RevTree tree) { Set<RevTree> trees = new HashSet<>(); trees.add(tree); if (tree.bucketsSize() > 0) { Iterable<ObjectId> ids = Iterables.transform(tree.getBuckets(), Bucket::getObjectId); List<RevTree> buckets = Lists .newArrayList(source.getAll(ids, BulkOpListener.NOOP_LISTENER, RevTree.class)); trees.addAll(buckets); for (RevTree bucket : buckets) { trees.addAll(getAllTrees(source, bucket)); } } return trees; }
@Test public void testGetIfPresent() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); for (RevObject o : expected) { assertTrue(db.put(o)); } for (RevObject o : expected) { assertEquals(o, db.getIfPresent(o.getId())); } assertNull(db.getIfPresent(RevObjectTestSupport.hashString("notfound"))); }
@Test public void testPutAll() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); db.putAll(expected.iterator()); for (RevObject o : expected) { assertEquals(o, db.get(o.getId())); } }
@Test public void testGetAllOfASpecificType() { final RevFeature f1 = feature(0, null, "some value"); final RevFeature f2 = feature(1, "value", new Integer(111)); final RevFeature f3 = feature(2, (Object) null); final RevTree t1 = RevTree.EMPTY; final RevTree t2 = createFeaturesTree(db, "t", 10); final RevTree t3 = createFeaturesTree(db, "t", 100);
public static Set<RevTree> getAllTrees(ObjectStore source, ObjectId rootTree) { RevTree root = rootTree.equals(RevTree.EMPTY_TREE_ID) ? RevTree.EMPTY : source.getTree(rootTree); return getAllTrees(source, root); }
public void run() { try { for (int i = 0; i < 100; i++) { ObjectId root = RevObjectTestSupport.hashString(key + "_commit_" + i); ObjectId commit = RevObjectTestSupport.hashString(key + "_commit_" + (i + 1)); database.put(commit, ImmutableList.of(root)); } } catch (Exception e) { errorLog.offer(e.toString()); } } }
@Test public void testDeleteAll() { ImmutableList<RevObject> objs = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null)); for (RevObject o : objs) { assertTrue(db.put(o)); } ObjectId notInDb1 = RevObjectTestSupport.hashString("fake1"); ObjectId notInDb2 = RevObjectTestSupport.hashString("fake2"); Function<RevObject, ObjectId> toId = p -> p.getId(); List<ObjectId> ids = Lists.newArrayList(concat(singletonIterator(notInDb1), transform(objs.iterator(), toId), singletonIterator(notInDb2))); db.deleteAll(ids.iterator()); for (ObjectId id : ids) { assertFalse(db.exists(id)); } }
private void assertTreeContents(RevTree tree, List<Node> expected) { Set<Node> expectedNodes = new HashSet<>(expected); Preconditions.checkArgument(expectedNodes.size() == expected.size()); Set<Node> actual = RevObjectTestSupport.getTreeNodes(tree, support.store()); assertEquals(expectedNodes, actual); }
private RevFeature fakeFeature(ObjectId forcedId) { // String oidString = objectId.toString(); // ObjectId treeId = ObjectId.forString("tree" + oidString); // ImmutableList<ObjectId> parentIds = ImmutableList.of(); // RevPerson author = new RevPersonImpl("Gabriel", "groldan@boundlessgeo.com", 1000, -3); // RevPerson committer = new RevPersonImpl("Gabriel", "groldan@boundlessgeo.com", 1000, -3); // String message = "message " + oidString; // return new RevCommitImpl(objectId, treeId, parentIds, author, committer, message); if (fakeGeom == null) { try { fakeGeom = new WKTReader().read( "MULTIPOLYGON (((-121.3647138 38.049474, -121.3646902 38.049614, -121.3646159 38.0496058, -121.3646188 38.049587, -121.3645936 38.049586, -121.3645924 38.0496222, -121.3645056 38.0496178, -121.3645321 38.0494567, -121.3647138 38.049474)))"); } catch (Exception e) { throw Throwables.propagate(e); } } return featureForceId(forcedId, fakeGeom, "Some string value " + forcedId); }
@Test public void testGetAll() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); for (RevObject o : expected) { assertTrue(db.put(o)); } assertTrue(db.put(feature(5, "not queried 1"))); assertTrue(db.put(feature(6, "not queried 2"))); Function<RevObject, ObjectId> toId = p -> p.getId(); Iterable<ObjectId> ids = Iterables.transform(expected, toId); Iterator<RevObject> iterator = db.getAll(ids); List<RevObject> actual = ImmutableList.copyOf(iterator); assertEquals(Sets.newHashSet(ids), Sets.newHashSet(Iterables.transform(actual, toId))); }
public static void verifySameIndexContents(Repository local, Repository remote, IndexInfo indexInfo, Optional<String> localRef, Optional<String> remoteRef) { Set<IndexTreeMapping> remoteIndexMappings = getIndexMappings(indexInfo, remote, remoteRef); Set<IndexTreeMapping> localIndexMappings = getIndexMappings(indexInfo, local, localRef); Map<ObjectId, ObjectId> remoteByCanonical = remoteIndexMappings.stream() .collect(Collectors.toMap(m -> m.featureTree, m -> m.indexTree)); Map<ObjectId, ObjectId> localByCanonical = localIndexMappings.stream() .collect(Collectors.toMap(m -> m.featureTree, m -> m.indexTree)); assertEquals(remoteByCanonical.size(), localByCanonical.size()); assertEquals(remoteByCanonical, localByCanonical); localByCanonical.forEach((canonicalId, indexId) -> { Set<RevTree> allRemoteIndexContents = RevObjectTestSupport .getAllTrees(remote.indexDatabase(), indexId); Set<RevTree> allLocalIndexContents = RevObjectTestSupport .getAllTrees(local.indexDatabase(), indexId); assertEquals(allRemoteIndexContents.size(), allLocalIndexContents.size()); if (!allRemoteIndexContents.equals(allLocalIndexContents)) { System.err.println("wtf: " + allRemoteIndexContents.equals(allLocalIndexContents)); } assertEquals(allRemoteIndexContents, allLocalIndexContents); }); log.info("Index {} cloned correctly", indexInfo); }
protected Conflict createTestConflict(String path) { Preconditions.checkArgument(!Strings.isNullOrEmpty(path)); ObjectId ancestor = RevObjectTestSupport.hashString(NodeRef.parentPath(path)); ObjectId ours = RevObjectTestSupport.hashString(path); ObjectId theirs = RevObjectTestSupport.hashString(path + "1"); Conflict c = new Conflict(path, ancestor, ours, theirs); return c; }