private RevTreeBuilder createTree(final int numEntries, final boolean insertInAscendingKeyOrder) { RevTreeBuilder tree = createBuiler(); final int increment = insertInAscendingKeyOrder ? 1 : -1; final int from = insertInAscendingKeyOrder ? 0 : numEntries - 1; final int breakAt = insertInAscendingKeyOrder ? numEntries : -1; for (int i = from; i != breakAt; i += increment) { addNode(tree, i); } return tree; }
protected ObjectId createAndSaveTree(final int numEntries, final boolean insertInAscendingKeyOrder) throws Exception { List<Node> nodes = createNodes(numEntries); ObjectId treeId = createAndSaveTree(nodes, insertInAscendingKeyOrder); return treeId; }
protected List<Node> createNodes(int numEntries) { List<Node> nodes = new ArrayList<>(numEntries); for (int i = 0; i < numEntries; i++) { nodes.add(createNode(i)); } return nodes; }
@Test public void testPutRandomGet() throws Exception { final int numEntries = 20 * CanonicalNodeNameOrder.normalizedSizeLimit(0) + 1500; final ObjectId treeId; treeId = createAndSaveTree(numEntries, true); final RevTree tree = objectStore.getTree(treeId); { Map<Integer, Node> randomEdits = Maps.newHashMap(); Random randGen = new Random(); for (int i = 0; i < tree.size() / 2; i++) { int random; while (randomEdits.containsKey(random = randGen.nextInt(numEntries))) { ; // $codepro.audit.disable extraSemicolon } String name = "Feature." + random; ObjectId newid = RevObjectTestSupport.hashString(name + "changed"); Node ref = RevObjectFactory.defaultInstance().createNode(name, newid, ObjectId.NULL, TYPE.FEATURE, null, null); randomEdits.put(random, ref); } RevTreeBuilder mutable = createBuiler(tree); for (Node ref : randomEdits.values()) { mutable.put(ref); } mutable.build(); } }
private void checkTreeBounds(int size) { RevTreeBuilder b = createBuiler(); List<Node> nodes = createNodes(size); Envelope expectedBounds = new Envelope(); for (Node n : nodes) { b.put(n); n.expand(expectedBounds); } expectedBounds = RevObjects.makePrecise(expectedBounds); RevTree tree = b.build(); assertEquals(size, tree.size()); Envelope bounds = SpatialOps.boundsOf(tree); bounds = RevObjects.makePrecise(bounds); assertEquals(expectedBounds, bounds); }
@Test public void testResultingTreeSize() { testResultingTreeSize(0); testResultingTreeSize(1); testResultingTreeSize(7); testResultingTreeSize(11); testResultingTreeSize(100); testResultingTreeSize(987); testResultingTreeSize(56789); // testResultingTreeSize(1234567); }
@Before public void setUp() throws Exception { objectStore = createObjectStore(); objectStore.open(); }
@Test public void testPutIterate() throws Exception { final int numEntries = 513;// 100 * 1000; ObjectId treeId; treeId = createAndSaveTree(numEntries, true); final RevTree tree = objectStore.getTree(treeId); DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, objectStore, Strategy.CHILDREN); int counted = Iterators.size(it); assertEquals(numEntries, counted); }
/** * Assert two trees that have the same contents resolve to the same id regardless of the order * the contents were added * * @throws Exception */ @Test public void testEquality() throws Exception { testEquality(100); testEquality(100 + CanonicalNodeNameOrder.normalizedSizeLimit(0)); }
protected ObjectId createAndSaveTree(final List<Node> nodes, final boolean insertInListOrder) throws Exception { List<Node> insert = nodes; if (!insertInListOrder) { insert = new ArrayList<>(nodes); Collections.shuffle(insert); } RevTreeBuilder treeBuilder = createBuiler(); nodes.forEach((n) -> treeBuilder.put(n)); RevTree tree = treeBuilder.build(); assertTrue(objectStore.exists(tree.getId())); assertEquals(nodes.size(), tree.size()); return tree.getId(); }
private void testResultingTreeSize(int numEntries) { objectStore.close(); objectStore = new HeapObjectDatabase(); objectStore.open(); RevTreeBuilder builder = createTree(numEntries, true); RevTree tree = builder.build(); final long declaredSize = tree.size(); Iterator<NodeRef> it = new DepthTreeIterator("", ObjectId.NULL, tree, objectStore, Strategy.RECURSIVE_FEATURES_ONLY); long itSize = 0; while (it.hasNext()) { it.next(); itSize++; } assertEquals(numEntries, declaredSize); assertEquals(numEntries, itSize); }
@Test public void testPutRandomGet() throws Exception { final int numEntries = 20 * CanonicalNodeNameOrder.normalizedSizeLimit(0) + 1500; final ObjectId treeId; treeId = createAndSaveTree(numEntries, true); final RevTree tree = objectStore.getTree(treeId); { Map<Integer, Node> randomEdits = Maps.newHashMap(); Random randGen = new Random(); for (int i = 0; i < tree.size() / 2; i++) { int random; while (randomEdits.containsKey(random = randGen.nextInt(numEntries))) { ; // $codepro.audit.disable extraSemicolon } String name = "Feature." + random; ObjectId newid = RevObjectTestSupport.hashString(name + "changed"); Node ref = Node.create(name, newid, ObjectId.NULL, TYPE.FEATURE, null); randomEdits.put(random, ref); } RevTreeBuilder mutable = createBuiler(tree); for (Node ref : randomEdits.values()) { mutable.put(ref); } mutable.build(); } }
private void checkTreeBounds(int size) { RevTreeBuilder b = createBuiler(); List<Node> nodes = createNodes(size); Envelope expectedBounds = new Envelope(); for (Node n : nodes) { b.put(n); n.expand(expectedBounds); } expectedBounds = Node.makePrecise(expectedBounds); RevTree tree = b.build(); assertEquals(size, tree.size()); Envelope bounds = SpatialOps.boundsOf(tree); bounds = Node.makePrecise(bounds); assertEquals(expectedBounds, bounds); }
@Test public void testResultingTreeSize() { testResultingTreeSize(0); testResultingTreeSize(1); testResultingTreeSize(7); testResultingTreeSize(11); testResultingTreeSize(100); testResultingTreeSize(987); testResultingTreeSize(56789); // testResultingTreeSize(1234567); }
@Before public void setUp() throws Exception { objectStore = createObjectStore(); objectStore.open(); }
@Test public void testPutIterate() throws Exception { final int numEntries = 513;// 100 * 1000; ObjectId treeId; treeId = createAndSaveTree(numEntries, true); final RevTree tree = objectStore.getTree(treeId); DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, objectStore, Strategy.CHILDREN); int counted = Iterators.size(it); assertEquals(numEntries, counted); }
/** * Assert two trees that have the same contents resolve to the same id regardless of the order * the contents were added * * @throws Exception */ @Test public void testEquality() throws Exception { testEquality(100); testEquality(100 + CanonicalNodeNameOrder.normalizedSizeLimit(0)); }
protected ObjectId createAndSaveTree(final List<Node> nodes, final boolean insertInListOrder) throws Exception { List<Node> insert = nodes; if (!insertInListOrder) { insert = new ArrayList<>(nodes); Collections.shuffle(insert); } RevTreeBuilder treeBuilder = createBuiler(); nodes.forEach((n) -> treeBuilder.put(n)); RevTree tree = treeBuilder.build(); assertTrue(objectStore.exists(tree.getId())); assertEquals(nodes.size(), tree.size()); return tree.getId(); }
private void testResultingTreeSize(int numEntries) { objectStore.close(); objectStore = new HeapObjectDatabase(); objectStore.open(); RevTreeBuilder builder = createTree(numEntries, true); RevTree tree = builder.build(); final long declaredSize = tree.size(); Iterator<NodeRef> it = new DepthTreeIterator("", ObjectId.NULL, tree, objectStore, Strategy.RECURSIVE_FEATURES_ONLY); long itSize = 0; while (it.hasNext()) { it.next(); itSize++; } assertEquals(numEntries, declaredSize); assertEquals(numEntries, itSize); }
protected ObjectId createAndSaveTree(final int numEntries, final boolean insertInAscendingKeyOrder) throws Exception { List<Node> nodes = createNodes(numEntries); ObjectId treeId = createAndSaveTree(nodes, insertInAscendingKeyOrder); return treeId; }