/** * Verify that sync() on a cluster node will continue fetching results until no more changes are * detected. * * @throws Exception */ public void testSyncAllChanges() throws Exception { // create channel on master and slave LockEventChannel channel = master.createLockChannel(DEFAULT_WORKSPACE); slave.createLockChannel(DEFAULT_WORKSPACE).setListener(new SimpleEventListener()); // add blocking consumer to slave, this will block on the first non-empty sync() BlockingConsumer consumer = new BlockingConsumer(); slave.getJournal().register(consumer); // add first entry LockEvent event = new LockEvent(NodeId.randomId(), true, "admin"); channel.create(event.getNodeId(), event.isDeep(), event.getUserId()).ended(true); // start a manual sync on the slave and ... Thread syncOnce = new Thread( new Runnable() { public void run() { try { slave.sync(); } catch (ClusterException e) { /* ignore */ } } }); syncOnce.start(); // ... wait until it blocks consumer.waitUntilBlocked(); // add second entry event = new LockEvent(NodeId.randomId(), true, "admin"); channel.create(event.getNodeId(), event.isDeep(), event.getUserId()).ended(true); // now unblock slave consumer.unblock(); // wait for the sync to finish syncOnce.join(); assertEquals(master.getRevision(), slave.getRevision()); }
public void testIsLocal() throws NotExecutableException, RepositoryException { acl = getPolicy(acMgr, testPath, testUser.getPrincipal()); modifyPrivileges(testPath, Privilege.JCR_READ, true); NodeImpl aclNode = (NodeImpl) superuser.getNode(acl.getPath() + "/rep:policy"); List<Entry> entries = Entry.readEntries(aclNode, testRootNode.getPath()); assertTrue(!entries.isEmpty()); assertEquals(1, entries.size()); Entry entry = entries.iterator().next(); // false since acl has been created from path only -> no id assertTrue(entry.isLocal(((NodeImpl) testRootNode).getNodeId())); // false since internal id is null -> will never match. assertFalse(entry.isLocal(NodeId.randomId())); }
/** * Tests that an XML document with an internal reference is correctly imported. This functionality * got broken by JCR-569. * * @throws Exception if an unexpected error occurs */ public void testReferenceImport() throws Exception { try { NodeId id = NodeId.randomId(); String xml = "<sv:node sv:name=\"a\"" + " xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"" + " xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"" + " xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\">" + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" + "<sv:value>nt:unstructured</sv:value></sv:property>" + "<sv:node sv:name=\"b\">" + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" + "<sv:value>nt:unstructured</sv:value></sv:property>" + "<sv:property sv:name=\"jcr:mixinTypes\" sv:type=\"Name\">" + "<sv:value>mix:referenceable</sv:value></sv:property>" + "<sv:property sv:name=\"jcr:uuid\" sv:type=\"String\">" + "<sv:value>" + id + "</sv:value></sv:property>" + "</sv:node>" + "<sv:node sv:name=\"c\">" + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" + "<sv:value>nt:unstructured</sv:value></sv:property>" + "<sv:property sv:name=\"ref\" sv:type=\"Reference\">" + "<sv:value>" + id + "</sv:value></sv:property>" + "</sv:node>" + "</sv:node>"; superuser .getWorkspace() .importXML( root.getPath(), new ByteArrayInputStream(xml.getBytes("UTF-8")), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); Node b = root.getNode("a/b"); Node c = root.getNode("a/c"); assertTrue( "Imported reference points to the correct node", b.isSame(c.getProperty("ref").getNode())); } catch (PathNotFoundException e) { fail("Imported node or property not found"); } catch (RepositoryException e) { fail("Failed to import an XML document with an internal reference"); } }
/** * Recursively collects all ACLs that are effective on the specified node. * * @param node the Node to collect the ACLs for, which must NOT be part of the structure defined * by mix:AccessControllable. * @param permissions * @param acls List used to collect the effective acls. * @throws RepositoryException if an error occurs */ private void collectAcls( NodeImpl node, CompiledPermissions permissions, List<AccessControlList> acls) throws RepositoryException { // if the given node is access-controlled, construct a new ACL and add // it to the list if (isAccessControlled(node)) { if (permissions.grants(node.getPrimaryPath(), Permission.READ_AC)) { acls.add(getACL(node, N_POLICY, node.getPath())); } else { throw new AccessDeniedException("Access denied at " + node.getPath()); } } // then, recursively look for access controlled parents up the hierarchy. if (!rootNodeId.equals(node.getId())) { NodeImpl parentNode = (NodeImpl) node.getParent(); collectAcls(parentNode, permissions, acls); } }
/** {@inheritDoc} */ public NodeReferences getNodeReferences(NodeId id) throws NoSuchItemStateException, ItemStateException { throw new NoSuchItemStateException(id.toString()); }