@Test
public void shouldSplitDocumentThatRepeatedlyContainsTooManyChildReferencesIntoMultipleSegments() throws Exception {

    MutableCachedNode nodeB = check(session1).mutableNode("/childB");
    NodeKey key = nodeB.getKey();
    // Make it optimum to start out ...
    runInTransaction(() -> optimizer.optimizeChildrenBlocks(key, null, 5, 2)); // will merge into a single block ...
    // Save the session, otherwise the database is inconsistent after the optimize operation
    session1.save();
    nodeB = check(session1).mutableNode("/childB");
    print(false);
    print(document(key), true);
    print(false);
    for (int j = 0; j != 5; ++j) {
        // Create a bunch of children ...
        for (int i = 0; i != 5; ++i) {
            NodeKey newKey = key.withId("child" + ((j * 5) + i + 1));
            nodeB.createChild(session(), newKey, name("newChild"), property("p1a", 344), property("p2", false));
        }
        session1.save();
        // Find node B again after the save ...
        nodeB = check(session1).mutableNode("/childB");
        print(false);
        print("\nOptimizing...");
        print(document(key), true);
        runInTransaction(() -> optimizer.optimizeChildrenBlocks(key, null, 5, 2)); // will split into blocks ...)
        print("\nOptimized...");
        print(document(key), true);
        print(false);
    }
    
    runInTransaction(() -> optimizer.optimizeChildrenBlocks(key, null, 5, 2));
    print(false);
    print(document(key), true);
}