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()); } } }
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; }
public static List<Node> nodes(final TYPE type, final int count, boolean withMetadataId, boolean withBounds, boolean withExtraData) { List<ObjectId> mdids = null; if (withMetadataId && count > 0) { mdids = new ArrayList<>(); for (int i = 0; i < count; i++) { mdids.add(RevObjectTestSupport.hashString("fakemetadata" + i)); } } return nodes(type, count, mdids, withBounds, withExtraData); }
@Test public void testCommitSerializationMultipleParents() throws IOException { testCommit.parentIds(ImmutableList.of(RevObjectTestSupport.hashString("parent1"), RevObjectTestSupport.hashString("parent2"), RevObjectTestSupport.hashString("parent3"), RevObjectTestSupport.hashString("parent4"))); RevCommit commit = testCommit.build(); testCommit(commit); }
@Test public void testReadWriteConflicts() throws Exception { Conflict conflict = new Conflict(idP1, RevObjectTestSupport.hashString("ancestor"), RevObjectTestSupport.hashString("ours"), RevObjectTestSupport.hashString("theirs")); Conflict conflict2 = new Conflict(idP2, RevObjectTestSupport.hashString("ancestor2"), RevObjectTestSupport.hashString("ours2"), RevObjectTestSupport.hashString("theirs2")); ArrayList<Conflict> conflicts = Lists.newArrayList(conflict, conflict2); geogig.command(ConflictsWriteOp.class).setConflicts(conflicts).call(); Set<Conflict> returnedConflicts = Sets .newHashSet(geogig.command(ConflictsQueryOp.class).call()); assertEquals(Sets.newHashSet(conflicts), returnedConflicts); }
@Test public void testFeatureLeafWithRepeatedMetadataIdsAndExtraData() throws IOException { RevTree tree; List<ObjectId> repeatingMdIds = ImmutableList.of(// hashString("mdid1"), // hashString("mdid2"), // hashString("mdid3")); List<Node> tNodes = nodes(TYPE.TREE, 512, repeatingMdIds, true, true); List<Node> fNodes = nodes(TYPE.FEATURE, 512, repeatingMdIds, true, true); tree = tree(2048, tNodes, fNodes, null); encodeDecode(tree); }
@Test public void testFeatureLeafWithRepeatedMetadataIdsNoExtraData() throws IOException { RevTree tree; List<ObjectId> repeatingMdIds = ImmutableList.of(// hashString("mdid1"), // hashString("mdid2"), // hashString("mdid3")); List<Node> tNodes = nodes(TYPE.TREE, 1024, repeatingMdIds, true, false); List<Node> fNodes = nodes(TYPE.FEATURE, 1024, repeatingMdIds, true, false); tree = tree(2048, tNodes, fNodes, null); encodeDecode(tree); }
@Test public void testFeatureLeafWithRepeatedMetadataIdsAndExtraData() throws IOException { RevTree tree; List<ObjectId> repeatingMdIds = ImmutableList.of(// hashString("mdid1"), // hashString("mdid2"), // hashString("mdid3")); List<Node> tNodes = nodes(TYPE.TREE, 1024, repeatingMdIds, true, true); List<Node> fNodes = nodes(TYPE.FEATURE, 1024, repeatingMdIds, true, true); tree = tree(2048, tNodes, fNodes, null); encodeDecode(tree); }
@Test public void testFeatureLeafWithRepeatedMetadataIds() throws IOException { RevTree tree; List<ObjectId> repeatingMdIds = ImmutableList.of(// hashString("mdid1"), // hashString("mdid2"), // hashString("mdid3")); List<Node> tNodes = nodes(TYPE.TREE, 512, repeatingMdIds, true, false); List<Node> fNodes = nodes(TYPE.FEATURE, 512, repeatingMdIds, true, false); tree = tree(2048, tNodes, fNodes, null); encodeDecode(tree); }
private RevTree createLeafTree(int i) { final int numNodes = 512; List<Node> nodes = new ArrayList<>(numNodes); for (int n = 0; n < numNodes; n++) { Node node = createNodeWithMetadata(n); nodes.add(node); } ObjectId id = RevObjectTestSupport.hashString("fake-tree-" + i); RevTree tree = RevObjectFactory.defaultInstance().createTree(id, numNodes, Collections.emptyList(), ImmutableList.copyOf(nodes)); return tree; }
private Node createNode(int n) { String name = "Node-" + n; ObjectId oid = RevObjectTestSupport.hashString(name); Envelope bounds = new Envelope(-1 * n, n, -1 * n, n); return objectFactory.createNode(name, oid, ObjectId.NULL, TYPE.FEATURE, bounds, null); }
private SortedSet<Bucket> createBuckets(int count) { SortedSet<Bucket> buckets = new TreeSet<>(); for (int i = 0; i < count; i++) { Bucket bucket = RevObjectFactory.defaultInstance().createBucket( RevObjectTestSupport.hashString("b" + i), i, new Envelope(i, i * 2, i, i * 2)); buckets.add(bucket); } return buckets; }
@Test public void testBucketsTree() throws IOException { RevTree tree; SortedSet<Bucket> buckets = new TreeSet<>(); buckets.add(RevObjectFactory.defaultInstance().createBucket(hashString("b1"), 1, null)); tree = tree(1024, null, null, buckets); encodeDecode(tree); }
@Test public void testBucketsTree() throws IOException { RevTree tree; SortedSet<Bucket> buckets = new TreeSet<>(); for (int i = 0; i < 32; i++) { buckets.add(RevObjectFactory.defaultInstance().createBucket(hashString("b" + i), i, new Envelope(-i, -i, i, i))); } tree = tree(1024, null, null, buckets); encodeDecode(tree); }
@Test public void testParseCompleteRef() { String refName = "refs/heads/master"; Optional<Ref> ref = command.setName(refName).call(); assertTrue(ref.isPresent()); assertEquals(refName, ref.get().getName()); assertEquals(RevObjectTestSupport.hashString(refName), ref.get().getObjectId()); refName = "refs/remotes/juan/v1.1"; testRsolvePartial(refName, refName); }
@Test public void testProperties() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); ImmutableList<ObjectId> parents = ImmutableList.of(); database.put(rootId, parents); database.setProperty(rootId, GraphDatabase.SPARSE_FLAG, "true"); assertTrue(database.getNode(rootId).isSparse()); }
@Test public void testLazyNodeGetExtaData() throws IOException { final Map<String, Object> expected = extraData(0); final Node originalNode = RevObjectFactory.defaultInstance().createNode("feature-0", RevObjectTestSupport.hashString("1"), ObjectId.NULL, TYPE.FEATURE, null, expected); NodeSet nodeset = encodedDecode(Collections.singletonList(originalNode), TYPE.FEATURE); Node lazyNode = nodeset.build().get(0); Map<String, Object> extraData = lazyNode.getExtraData(); assertEquals(expected, extraData); }
@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 testRoundTripBucketsFull() throws IOException { ObjectId id = RevObjectTestSupport.hashString("fake"); long size = 100000000; int childTreeCount = 0; SortedSet<Bucket> bucketTrees = createBuckets(32); final RevTree tree = RevObjectFactory.defaultInstance().createTree(id, size, childTreeCount, bucketTrees); RevTree roundTripped = (RevTree) read(tree.getId(), write(tree)); assertTreesAreEqual(tree, roundTripped); }
@Test public void testRevertToWrongCommit() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); exception.expect(IllegalArgumentException.class); geogig.command(RevertOp.class).addCommit(RevObjectTestSupport.hashString("wrong")).call(); }