use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.
the class DepthSearchTest method addTree.
private RevTreeBuilder addTree(RevTreeBuilder root, final String treePath, String... singleNodeNames) {
Context mockInjector = mock(Context.class);
when(mockInjector.objectDatabase()).thenReturn(odb);
CreateTree op = new CreateTree().setIndex(false);
op.setContext(mockInjector);
RevTreeBuilder subTreeBuilder = op.call();
if (singleNodeNames != null) {
for (String singleNodeName : singleNodeNames) {
String nodePath = NodeRef.appendChild(treePath, singleNodeName);
ObjectId fakeFeatureOId = ObjectId.forString(nodePath);
// forString(treePath);
ObjectId fakeTypeOId = ObjectId.NULL;
subTreeBuilder.put(Node.create(singleNodeName, fakeFeatureOId, fakeTypeOId, TYPE.FEATURE, null));
}
}
RevTree subtree = subTreeBuilder.build();
WriteBack writeBack = fakeGeogig.command(WriteBack.class).setAncestor(root).setChildPath(treePath).setTree(subtree).setMetadataId(fakeTreeMetadataId);
ObjectId newRootId = writeBack.call();
return fakeGeogig.command(RevObjectParse.class).setObjectId(newRootId).call(RevTree.class).get().builder(odb);
}
use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.
the class RevTreeBuilderTest method createAndSaveTree.
private ObjectId createAndSaveTree(final int numEntries, final boolean insertInAscendingKeyOrder) throws Exception {
RevTreeBuilder treeBuilder = createTree(numEntries, insertInAscendingKeyOrder);
RevTree tree = treeBuilder.build();
odb.put(tree);
return tree.getId();
}
use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.
the class RevTreeBuilderTest method testRemoveSplittedTree.
@Test
public void testRemoveSplittedTree() throws Exception {
final int numEntries = (int) (1.5 * RevTree.NORMALIZED_SIZE_LIMIT);
final ObjectId treeId = createAndSaveTree(numEntries, true);
final RevTree tree = odb.getTree(treeId);
// collect some keys to remove
final Set<String> removedKeys = new HashSet<String>();
{
int i = 0;
DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, odb, Strategy.CHILDREN);
for (; it.hasNext(); i++) {
NodeRef entry = it.next();
if (i % 10 == 0) {
removedKeys.add(entry.path());
}
}
assertTrue(removedKeys.size() > 0);
}
RevTreeBuilder builder = tree.builder(odb);
for (String key : removedKeys) {
assertTrue(key, builder.get(key).isPresent());
builder.remove(key);
assertFalse(key, builder.get(key).isPresent());
}
for (String key : removedKeys) {
assertFalse(builder.get(key).isPresent());
}
final RevTree tree2 = builder.build();
for (String key : removedKeys) {
assertFalse(key, repo.getTreeChild(tree2, key).isPresent());
}
}
use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.
the class RevTreeBuilderTest method testRemove.
@Test
public void testRemove() throws Exception {
final int numEntries = 1000;
ObjectId treeId = createAndSaveTree(numEntries, true);
final RevTree tree = odb.getTree(treeId);
// collect some keys to remove
final Set<String> removedKeys = new HashSet<String>();
{
int i = 0;
DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, odb, Strategy.CHILDREN);
for (; it.hasNext(); i++) {
NodeRef entry = it.next();
if (i % 10 == 0) {
removedKeys.add(entry.path());
}
}
assertEquals(100, removedKeys.size());
}
final RevTreeBuilder builder = tree.builder(odb);
for (String key : removedKeys) {
assertTrue(builder.get(key).isPresent());
builder.remove(key);
assertFalse(builder.get(key).isPresent());
}
final RevTree tree2 = builder.build();
for (String key : removedKeys) {
assertFalse(repo.getTreeChild(tree2, key).isPresent());
}
}
use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.
the class WriteBack method _call.
/**
* Executes the write back operation.
*
* @return the {@link ObjectId id} of the resulting new ancestor tree.
*/
@Override
protected ObjectId _call() {
checkNotNull(tree, "child tree not set");
checkNotNull(childPath, "child tree path not set");
String ancestorPath = resolveAncestorPath();
checkArgument(NodeRef.isChild(ancestorPath, childPath), String.format("child path '%s' is not a child of ancestor path '%s'", childPath, ancestorPath));
RevTree tree = this.tree.get();
checkState(null != tree, "child tree supplier returned null");
ObjectDatabase targetDb = indexDb ? stagingDatabase() : objectDatabase();
RevTreeBuilder root = resolveAncestor();
return writeBack(root, ancestorPath, tree, childPath, targetDb, metadataId.or(ObjectId.NULL));
}
Aggregations