use of org.apache.jackrabbit.core.TransientRepository in project jackrabbit by apache.
the class AutoFixCorruptNode method testBrokenVhrParent.
// tests recovery from a broken hierarchy in the version store
public void testBrokenVhrParent() throws Exception {
// new repository
TransientRepository rep = new TransientRepository(new File(TEST_DIR));
Session s = openSession(rep, false);
try {
Node root = s.getRootNode();
// add node /test
Node test = root.addNode("test");
test.addMixin("mix:versionable");
s.save();
Node vhr = s.getWorkspace().getVersionManager().getVersionHistory(test.getPath());
assertNotNull(vhr);
Node brokenNode = vhr.getParent().getParent();
UUID destroy = UUID.fromString(brokenNode.getIdentifier());
// disable versioning
test.removeMixin("mix:versionable");
s.save();
s.logout();
destroyBundle(destroy, "version");
s = openSession(rep, false);
ConsistencyReport report = TestHelper.checkVersionStoreConsistency(s, true, null);
assertTrue("Report should have reported broken nodes", !report.getItems().isEmpty());
s.logout();
s = openSession(rep, false);
test = s.getRootNode().getNode("test");
// versioning should still be disabled
assertFalse(test.isNodeType("mix:versionable"));
// try to enable versioning again
test.addMixin("mix:versionable");
s.save();
// try a checkout / checkin
s.getWorkspace().getVersionManager().checkout(test.getPath());
s.getWorkspace().getVersionManager().checkin(test.getPath());
} finally {
s.logout();
}
}
use of org.apache.jackrabbit.core.TransientRepository in project jackrabbit by apache.
the class AutoFixCorruptNode method testAutoFixWithConsistencyCheck.
/**
* Unit test for <a
* href="https://issues.apache.org/jira/browse/JCR-3069">JCR-3069</a>
*/
public void testAutoFixWithConsistencyCheck() throws Exception {
// new repository
TransientRepository rep = new TransientRepository(new File(TEST_DIR));
Session s = openSession(rep, false);
Node root = s.getRootNode();
// add nodes /test and /test/missing
Node test = root.addNode("test");
Node missing = test.addNode("missing");
missing.addMixin("mix:referenceable");
UUID id = UUID.fromString(missing.getIdentifier());
s.save();
s.logout();
destroyBundle(id, "workspaces/default");
s = openSession(rep, false);
try {
ConsistencyReport r = TestHelper.checkConsistency(s, false, null);
assertNotNull(r);
assertNotNull(r.getItems());
assertEquals(1, r.getItems().size());
assertEquals(test.getIdentifier(), r.getItems().iterator().next().getNodeId());
} finally {
s.logout();
rep.shutdown();
FileUtils.deleteDirectory(new File("repository"));
}
}
use of org.apache.jackrabbit.core.TransientRepository in project jackrabbit by apache.
the class ItemStateCacheSyncTest method setUp.
protected void setUp() throws Exception {
directory = new File("target", "jackrabbit-sync-test-repo");
repository = new TransientRepository(directory);
session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
// Add a tree of 100k medium-sized (~10kB) nodes
String[] data = new String[1000];
Arrays.fill(data, "something");
root = session.getRootNode();
for (int i = 0; i < 1000; i++) {
Node a = root.addNode("a" + i);
for (int j = 0; j < 100; j++) {
Node b = a.addNode("b" + j);
b.setProperty("data", data);
}
session.save();
System.out.println((i + 1) * 1000 + " nodes created");
}
}
use of org.apache.jackrabbit.core.TransientRepository in project sling by apache.
the class ReorderChildNodesCommandTest method doReorderingTest.
private void doReorderingTest(List<String> nodeNames, List<String> resourceNames, List<String> expected) throws Exception {
if (expected == null) {
expected = resourceNames;
}
File out = new File(new File("target"), "jackrabbit");
TransientRepository repo = new TransientRepository(new File(out, "repository.xml"), new File(out, "repository"));
SimpleCredentials credentials = new SimpleCredentials("admin", "admin".toCharArray());
Session session = repo.login(credentials);
List<String> finalOrder;
try {
Node content = session.getRootNode().addNode("content");
for (String nodeName : nodeNames) {
content.addNode(nodeName);
}
session.save();
ResourceProxy resource = newResource("/content", "nt:unstructured");
for (String resourceName : resourceNames) {
resource.addChild(newResource("/content/" + resourceName, "nt:unstructured"));
}
ReorderChildNodesCommand cmd = new ReorderChildNodesCommand(repo, credentials, resource, logger);
cmd.execute().get();
session.refresh(false);
finalOrder = new ArrayList<>();
NodeIterator nodes = session.getNode("/content").getNodes();
while (nodes.hasNext()) {
finalOrder.add(nodes.nextNode().getName());
}
} finally {
session.removeItem("/content");
session.save();
session.logout();
}
assertThat("Incorrect node order", finalOrder, equalTo(expected));
}
Aggregations