use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class GCEventListenerTest method doTestEventListener.
private void doTestEventListener(boolean allowPmScan) throws Exception {
Node root = testRootNode;
Session session = root.getSession();
if (root.hasNode(TEST_NODE_NAME)) {
root.getNode(TEST_NODE_NAME).remove();
session.save();
}
Node test = root.addNode(TEST_NODE_NAME);
Random random = new Random();
byte[] data = new byte[10000];
for (int i = 0; i < 10; i++) {
Node n = test.addNode("x" + i);
random.nextBytes(data);
ValueFactory vf = session.getValueFactory();
n.setProperty("data", vf.createBinary(new ByteArrayInputStream(data)));
session.save();
if (i % 2 == 0) {
n.remove();
session.save();
}
}
session.save();
SessionImpl si = (SessionImpl) session;
DataStoreGarbageCollector gc = si.createDataStoreGarbageCollector();
DataStore ds = ((GarbageCollector) gc).getDataStore();
if (ds != null) {
ds.clearInUse();
boolean pmScan = gc.isPersistenceManagerScan();
gc.setPersistenceManagerScan(allowPmScan);
gotNullNode = false;
gotNode = false;
gc.setMarkEventListener(this);
gc.mark();
if (pmScan && allowPmScan) {
assertTrue("PM scan without null Node", gotNullNode);
assertFalse("PM scan, but got a real node", gotNode);
} else {
assertFalse("Not a PM scan - but got a null Node", gotNullNode);
assertTrue("Not a PM scan - without a real node", gotNode);
}
int deleted = gc.sweep();
LOG.debug("Deleted " + deleted);
assertTrue("Should delete at least one item", deleted >= 0);
gc.close();
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class AdministratorTest method testAdminNodeCollidingWithRandomNode.
/**
* Test for collisions that would prevent from recreate the admin user.
* - a colliding node somewhere else with the same jcr:uuid.
*
* Test if creation of the administrator user forces the removal of some
* other node in the repository that by change happens to have the same
* jcr:uuid and thus inhibits the creation of the admininstrator user.
*/
public void testAdminNodeCollidingWithRandomNode() throws RepositoryException, NotExecutableException {
Authorizable admin = userMgr.getAuthorizable(adminId);
if (admin == null || !(admin instanceof AuthorizableImpl)) {
throw new NotExecutableException();
}
// access the node corresponding to the admin user and remove it
NodeImpl adminNode = ((AuthorizableImpl) admin).getNode();
NodeId nid = adminNode.getNodeId();
Session s = adminNode.getSession();
adminNode.remove();
// use session obtained from the node as usermgr may point to a dedicated
// system workspace different from the superusers workspace.
s.save();
Session s2 = null;
String collidingPath = null;
try {
// create a colliding node outside of the user tree
NameResolver nr = (SessionImpl) s;
// NOTE: testRootNode will not be present if users are stored in a distinct wsp.
// therefore use root node as start...
NodeImpl tr = (NodeImpl) s.getRootNode();
Node n = tr.addNode(nr.getQName("tmpNode"), nr.getQName(testNodeType), nid);
collidingPath = n.getPath();
s.save();
// force recreation of admin user.
s2 = getHelper().getSuperuserSession();
admin = userMgr.getAuthorizable(adminId);
assertNotNull(admin);
// the colliding node must have been removed.
assertFalse(s2.nodeExists(collidingPath));
} finally {
if (s2 != null) {
s2.logout();
}
if (collidingPath != null && s.nodeExists(collidingPath)) {
s.getNode(collidingPath).remove();
s.save();
}
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class NodeResolverTest method testFindNodes.
public void testFindNodes() throws NotExecutableException, RepositoryException {
Value[] vs = new Value[] { superuser.getValueFactory().createValue("blub"), superuser.getValueFactory().createValue("blib") };
UserImpl currentUser = getCurrentUser();
currentUser.setProperty(propertyName1, vs);
int expResultSize = 1;
Iterator<Group> it = currentUser.memberOf();
while (it.hasNext()) {
GroupImpl gr = (GroupImpl) it.next();
gr.setProperty(propertyName1, vs);
expResultSize++;
}
save();
Name propName = ((SessionImpl) superuser).getQName(propertyName1);
try {
NodeResolver nr = createNodeResolver(currentUser.getNode().getSession());
NodeIterator result = nr.findNodes(propName, "blub", UserConstants.NT_REP_USER, false);
assertTrue("expected result", result.hasNext());
assertEquals(currentUser.getNode().getPath(), result.nextNode().getPath());
assertFalse("expected no more results", result.hasNext());
result = nr.findNodes(propName, "blub", UserConstants.NT_REP_AUTHORIZABLE, false);
assertEquals(expResultSize, getSize(result));
} finally {
currentUser.removeProperty(propertyName1);
it = currentUser.memberOf();
while (it.hasNext()) {
GroupImpl gr = (GroupImpl) it.next();
gr.removeProperty(propertyName1);
}
save();
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class NodeResolverTest method testFindNodesByRelPathProperties.
/**
*
* @throws NotExecutableException
* @throws RepositoryException
*/
public void testFindNodesByRelPathProperties() throws NotExecutableException, RepositoryException {
Value[] vs = new Value[] { superuser.getValueFactory().createValue("blub"), superuser.getValueFactory().createValue("blib") };
String relPath = "relPath/" + propertyName1;
String relPath2 = "another/" + propertyName1;
String relPath3 = "relPath/relPath/" + propertyName1;
UserImpl currentUser = getCurrentUser();
currentUser.setProperty(relPath, vs);
currentUser.setProperty(relPath2, vs);
currentUser.setProperty(relPath3, vs);
save();
Path relQPath = ((SessionImpl) superuser).getQPath(relPath);
Path relQName = ((SessionImpl) superuser).getQPath(propertyName1);
try {
NodeResolver nr = createNodeResolver(currentUser.getNode().getSession());
// 1) findNodes(QPath.....
// relPath : "prop1" -> should find the currentuserNode
NodeIterator result = nr.findNodes(relQName, "blub", UserManager.SEARCH_TYPE_USER, false, Long.MAX_VALUE);
assertTrue("expected result", result.hasNext());
Node n = result.nextNode();
assertEquals(currentUser.getNode().getPath(), n.getPath());
assertFalse("expected no more results", result.hasNext());
// relPath : "relPath/prop1" -> should find the currentuserNode
result = nr.findNodes(relQPath, "blub", UserManager.SEARCH_TYPE_USER, false, Long.MAX_VALUE);
assertTrue("expected result", result.hasNext());
assertEquals(currentUser.getNode().getPath(), result.nextNode().getPath());
assertFalse("expected no more results", result.hasNext());
// 2) findNodes(Name.......)
// search by Name -> should not find deep property
Name propName = ((SessionImpl) superuser).getQName(propertyName1);
result = nr.findNodes(propName, "blub", UserConstants.NT_REP_USER, false);
assertFalse("should not find result", result.hasNext());
} finally {
currentUser.removeProperty(relPath);
currentUser.removeProperty(relPath2);
currentUser.removeProperty(relPath3);
save();
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class IndexNodeResolverTest method testFindNodesExactWithApostrophe.
public void testFindNodesExactWithApostrophe() throws NotExecutableException, RepositoryException {
UserImpl currentUser = getCurrentUser();
Value vs = superuser.getValueFactory().createValue("value ' with apostrophe");
currentUser.setProperty(propertyName1, vs);
save();
Name propName = ((SessionImpl) superuser).getQName(propertyName1);
try {
NodeResolver nr = createNodeResolver(currentUser.getNode().getSession());
NodeIterator result = nr.findNodes(propName, "value ' with apostrophe", UserConstants.NT_REP_USER, true);
assertTrue("expected result", result.hasNext());
assertEquals(currentUser.getNode().getPath(), result.nextNode().getPath());
assertFalse("expected no more results", result.hasNext());
} finally {
currentUser.removeProperty(propertyName1);
save();
}
}
Aggregations