use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class InterruptedQueryTest method testQuery.
@Test
public void testQuery() throws Exception {
if (Constants.WINDOWS) {
return;
}
for (int i = 0; i < 100; i++) {
session.getRootNode().addNode("node" + i, "nt:unstructured");
}
session.save();
final QueryManager qm = session.getWorkspace().getQueryManager();
final AtomicBoolean stop = new AtomicBoolean(false);
final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
Thread t = new Thread(new Runnable() {
@Override
public void run() {
while (!stop.get() && exceptions.isEmpty()) {
try {
// execute query
String stmt = "//*[@jcr:primaryType='nt:unstructured']";
qm.createQuery(stmt, Query.XPATH).execute();
} catch (RepositoryException e) {
if (Constants.SUN_OS) {
// on Solaris it's OK when the root cause
// of the exception is an InterruptedIOException
// the underlying file is not closed
Throwable t = e;
while (t.getCause() != null) {
t = t.getCause();
}
if (!(t instanceof InterruptedIOException)) {
exceptions.add(e);
}
} else {
exceptions.add(e);
}
}
}
}
});
t.start();
for (int i = 0; i < 200 && t.isAlive(); i++) {
t.interrupt();
Thread.sleep((long) (100.0 * Math.random()));
}
stop.set(true);
t.join();
if (!exceptions.isEmpty()) {
throw exceptions.get(0);
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class GQLTest method testFilterLimit.
public void testFilterLimit() throws RepositoryException {
final Node n1 = testRootNode.addNode("node1");
n1.setProperty("jcr:title", "a");
Node n2 = testRootNode.addNode("node2");
n2.setProperty("jcr:title", "b");
Node n3 = testRootNode.addNode("node3");
n3.setProperty("jcr:title", "c");
superuser.save();
String stmt = createStatement("order:jcr:title limit:1");
RowIterator rows = GQL.execute(stmt, superuser, null, new GQL.Filter() {
public boolean include(Row row) throws RepositoryException {
return !n1.getPath().equals(row.getValue("jcr:path").getString());
}
});
checkResultSequence(rows, new Node[] { n2 });
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class AbstractEntryTest method testHashCode.
public void testHashCode() throws RepositoryException, NotExecutableException {
Map<AccessControlEntry, AccessControlEntry> equivalent = new HashMap<AccessControlEntry, AccessControlEntry>();
JackrabbitAccessControlEntry ace = createEntry(new String[] { Privilege.JCR_ALL }, true);
// create same entry again
equivalent.put(ace, createEntry(new String[] { Privilege.JCR_ALL }, true));
// create entry with declared aggregate privileges
Privilege[] declaredAllPrivs = acMgr.privilegeFromName(Privilege.JCR_ALL).getDeclaredAggregatePrivileges();
equivalent.put(ace, createEntry(testPrincipal, declaredAllPrivs, true));
// create entry with aggregate privileges
Privilege[] aggregateAllPrivs = acMgr.privilegeFromName(Privilege.JCR_ALL).getAggregatePrivileges();
equivalent.put(ace, createEntry(testPrincipal, aggregateAllPrivs, true));
// create entry with different privilege order
List<Privilege> reordered = new ArrayList<Privilege>(Arrays.asList(aggregateAllPrivs));
reordered.add(reordered.remove(0));
equivalent.put(createEntry(testPrincipal, reordered.toArray(new Privilege[reordered.size()]), true), createEntry(testPrincipal, aggregateAllPrivs, true));
// even if entries are build with aggregated or declared aggregate privileges
equivalent.put(createEntry(testPrincipal, declaredAllPrivs, true), createEntry(testPrincipal, aggregateAllPrivs, true));
for (AccessControlEntry entry : equivalent.keySet()) {
assertEquals(entry.hashCode(), equivalent.get(entry).hashCode());
}
// and the opposite:
List<JackrabbitAccessControlEntry> otherAces = new ArrayList<JackrabbitAccessControlEntry>();
try {
// ACE template with different principal
Principal princ = new Principal() {
public String getName() {
return "a name";
}
};
Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) };
otherAces.add(createEntry(princ, privs, true));
} catch (RepositoryException e) {
}
// ACE template with different privileges
try {
otherAces.add(createEntry(new String[] { Privilege.JCR_READ }, true));
} catch (RepositoryException e) {
}
// ACE template with different 'allow' flag
try {
otherAces.add(createEntry(new String[] { Privilege.JCR_ALL }, false));
} catch (RepositoryException e) {
}
// ACE template with different privileges and 'allows
try {
otherAces.add(createEntry(new String[] { PrivilegeRegistry.REP_WRITE }, false));
} catch (RepositoryException e) {
}
// other ace impl
final Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) };
JackrabbitAccessControlEntry pe = new JackrabbitAccessControlEntry() {
public boolean isAllow() {
return true;
}
public String[] getRestrictionNames() {
return new String[0];
}
public Value getRestriction(String restrictionName) {
return null;
}
public Value[] getRestrictions(String restrictionName) throws RepositoryException {
return null;
}
public Principal getPrincipal() {
return testPrincipal;
}
public Privilege[] getPrivileges() {
return privs;
}
};
otherAces.add(pe);
for (JackrabbitAccessControlEntry otherAce : otherAces) {
assertFalse(ace.hashCode() == otherAce.hashCode());
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class TokenBasedLoginTest method testConcurrentLoginOfDifferentUsers.
/**
* Tests concurrent login of 3 different users on the Repository including
* token creation.
* Test copied and slightly adjusted from org.apache.jackrabbit.core.ConcurrentLoginTest
*/
public void testConcurrentLoginOfDifferentUsers() throws RepositoryException, NotExecutableException {
final Exception[] exception = new Exception[1];
List<Thread> testRunner = new ArrayList<Thread>();
for (int i = 0; i < 10; i++) {
testRunner.add(new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 100; i++) {
try {
SimpleCredentials c;
double rand = 3 * Math.random();
int index = (int) Math.floor(rand);
switch(index) {
case 0:
c = new SimpleCredentials(testuser.getID(), testuser.getID().toCharArray());
break;
case 1:
c = new SimpleCredentials(getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_SUPERUSER_NAME), getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_SUPERUSER_PWD).toCharArray());
break;
default:
c = new SimpleCredentials(getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_READONLY_NAME), getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_READONLY_PWD).toCharArray());
break;
}
c.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "");
Session s = getHelper().getRepository().login(c);
try {
Set<TokenCredentials> tcs = ((SessionImpl) s).getSubject().getPublicCredentials(TokenCredentials.class);
assertFalse(tcs.isEmpty());
} finally {
s.logout();
}
} catch (Exception e) {
exception[0] = e;
break;
}
}
}
}));
}
// start threads
for (Object aTestRunner : testRunner) {
((Thread) aTestRunner).start();
}
// join threads
for (Object aTestRunner : testRunner) {
try {
((Thread) aTestRunner).join();
} catch (InterruptedException e) {
fail(e.toString());
}
}
if (exception[0] != null) {
fail(exception[0].toString());
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class AbstractACLTemplateTest method testRemoveInvalidEntry.
public void testRemoveInvalidEntry() throws RepositoryException {
JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
try {
pt.removeAccessControlEntry(new JackrabbitAccessControlEntry() {
public boolean isAllow() {
return false;
}
public String[] getRestrictionNames() {
return new String[0];
}
public Value getRestriction(String restrictionName) {
return null;
}
public Value[] getRestrictions(String restrictionName) throws RepositoryException {
return null;
}
public Principal getPrincipal() {
return testPrincipal;
}
public Privilege[] getPrivileges() {
try {
return privilegesFromName(Privilege.JCR_READ);
} catch (Exception e) {
return new Privilege[0];
}
}
});
fail("Passing an unknown ACE should fail");
} catch (AccessControlException e) {
// success
}
}
Aggregations