WritableSessionCache extends AbstractSessionCache { @Override public void save() { save((PreSave)null); } WritableSessionCache(ExecutionContext context,
                                WorkspaceCache workspaceCache,
                                TransactionalWorkspaceCaches txWorkspaceCaches,
                                RepositoryEnvironment repositoryEnvironment); @Override CachedNode getNode( NodeKey key ); @Override SessionNode mutable( NodeKey key ); @Override boolean isReadOnly(); @Override Set<NodeKey> getChangedNodeKeys(); @Override Set<NodeKey> getChangedNodeKeysAtOrBelow( CachedNode srcNode ); @Override boolean hasChanges(); @Override void checkForTransaction(); @Override void save(); @Override void save( SessionCache other,
                      PreSave preSaveOperation ); @Override void save( Set<NodeKey> toBeSaved,
                      SessionCache other,
                      PreSave preSaveOperation ); @SuppressWarnings( "finally" ) @Override void destroy( NodeKey key ); @Override boolean isDestroyed( NodeKey key ); @Override String toString();  }
@Test public void shouldAllowSessionToCreateAndAccessNewChildNodeOnExistingNodeBeforeSave() { check(cache).noNode("/childB/newChild"); print(false); MutableCachedNode nodeB = check(session1).mutableNode("/childB"); NodeKey newKey = session1.createNodeKeyWithIdentifier("newChild"); long nanos = System.nanoTime(); MutableCachedNode newChild = nodeB.createChild(session(), newKey, name("newChild"), property("p1a", 344), property("p2", false)); print("Time (createChild): " + millis(Math.abs(System.nanoTime() - nanos)) + " ms"); assertThat(newChild.getPath(session1), is(path("/childB/newChild"))); check(session1).children(nodeB, "childC", "childD", "newChild"); check(session1).property("/childB/newChild", property("p1a", 344)); check(session1).property("/childB/newChild", property("p2", false)); check(session2).children(nodeB.getKey(), "childC", "childD"); print(false); nanos = System.nanoTime(); session1.save(); print(false); print("Time (save): " + millis(Math.abs(System.nanoTime() - nanos)) + " ms"); check(session1).children(nodeB, "childC", "childD", "newChild"); check(session2).children(nodeB, "childC", "childD", "newChild"); check(session2).property("/childB/newChild", property("p1a", 344)); check(session2).property("/childB/newChild", property("p2", false)); }
@Test public void shouldAllowSessionToCreateManyChildrenWithSameNameAndThenSave() { check(cache).noNode("/childB/newChild"); print(false); MutableCachedNode nodeB = check(session1).mutableNode("/childB"); Stopwatch create = new Stopwatch(); Stopwatch total = new Stopwatch(); Stopwatch save = new Stopwatch(); total.start(); for (int i = 0; i != 1000; ++i) { create.start(); NodeKey newKey = session1.createNodeKey(); nodeB.createChild(session(), newKey, name("newChild"), property("p1a", 344), property("p2", false)); create.stop(); } save.start(); session1.save(); save.stop(); total.stop(); nodeB = check(session1).mutableNode("/childB"); print(true); print("Number of children: " + nodeB.getChildReferences(session1).size()); print("Time (create): " + create.getSimpleStatistics()); print("Time (save): " + save.getSimpleStatistics()); print("Time (total): " + total.getTotalDuration()); session1.clear(); total.reset(); total.start(); nodeB.getChildReferences(session1).getChild(name("newChild"), 9450); total.stop(); print("Time (getchild#9450): " + total.getTotalDuration()); session1.clear(); total.reset(); total.start(); nodeB.getChildReferences(session1).getChild(name("newChild"), 10); total.stop(); print("Time (getchild#10): " + total.getTotalDuration()); }
@Test public void shouldAllowSessionToCreateChildrenWithSameNameWithMultipleSaves() throws Exception { check(cache).noNode("/childB/newChild"); print(false); MutableCachedNode nodeB = check(session1).mutableNode("/childB"); NodeKey key = nodeB.getKey(); Stopwatch create = new Stopwatch(); Stopwatch total = new Stopwatch(); Stopwatch save = new Stopwatch(); Stopwatch opt = new Stopwatch(); runInTransaction(() -> optimizer.optimizeChildrenBlocks(key, null, 1000, 500)); print(true); print("Creating nodes ..."); total.start(); for (int i = 0; i != 10000; ++i) { create.start(); NodeKey newKey = key.withId("child" + i); nodeB.createChild(session1, newKey, name("newChild"), property("p1a", 344), property("p2", false)); create.stop(); if (i != 0 && i % 1000 == 0) { print(false); print("Saving..."); save.start(); session1.save(); save.stop(); print(false); print("Optimizing..."); print(false); opt.start(); runInTransaction(() ->optimizer.optimizeChildrenBlocks(key, null, 1000, 500)); opt.stop(); nodeB = check(session1).mutableNode("/childB"); } } total.stop(); print(true); print("Time (create): " + create.getSimpleStatistics()); print("Time (save): " + save.getSimpleStatistics()); print("Time (optimize): " + opt.getTotalDuration()); print("Time (total): " + total.getTotalDuration()); session1.clear(); total.reset(); total.start(); nodeB.getChildReferences(session1).getChild(name("newChild"), 9450); total.stop(); print("Time (getchild#9450): " + total.getTotalDuration()); session1.clear(); total.reset(); total.start(); nodeB.getChildReferences(session1).getChild(name("newChild"), 10); total.stop(); print("Time (getchild#10): " + total.getTotalDuration()); }
@Ignore( "Usually ignored because of memory requirements" ) @Test public void shouldAllowSessionToCreate100KChildrenWithSameNameWithMultipleSaves() throws Exception { check(cache).noNode("/childB/newChild"); print(false); MutableCachedNode nodeB = check(session1).mutableNode("/childB"); NodeKey key = nodeB.getKey(); Stopwatch create = new Stopwatch(); Stopwatch total = new Stopwatch(); Stopwatch save = new Stopwatch(); Stopwatch opt = new Stopwatch(); runInTransaction(() -> optimizer.optimizeChildrenBlocks(key, null, 1000, 500)); print(true); print("Creating nodes ..."); total.start(); for (int i = 0; i != 100000; ++i) { create.start(); NodeKey newKey = key.withId("child" + i); nodeB.createChild(session1, newKey, name("newChild"), property("p1a", 344), property("p2", false)); create.stop(); if (i != 0 && i % 1000 == 0) { print(false); print("Saving..."); save.start(); session1.save(); save.stop(); print(false); print("Optimizing..."); print(false); opt.start(); runInTransaction(() -> optimizer.optimizeChildrenBlocks(key, null, 1000, 500)); opt.stop(); nodeB = check(session1).mutableNode("/childB"); } } total.stop(); print(true); print("Time (create): " + create.getSimpleStatistics()); print("Time (save): " + save.getSimpleStatistics()); print("Time (optimize): " + opt.getTotalDuration()); print("Time (total): " + total.getTotalDuration()); session1.clear(); total.reset(); total.start(); nodeB.getChildReferences(session1).getChild(name("newChild"), 49450); total.stop(); print("Time (getchild#49450): " + total.getTotalDuration()); session1.clear(); total.reset(); total.start(); nodeB.getChildReferences(session1).getChild(name("newChild"), 10); total.stop(); print("Time (getchild#10): " + total.getTotalDuration()); }