public NodeId newNodeId() throws RepositoryException { if (createRandom) { return NodeId.randomId(); } long lsb = nextLsb++; if (lsb >= storedLsb) { store(lsb + cacheSize); } return new NodeId(msb, lsb); }
public NodeId newNodeId() throws RepositoryException { if (createRandom) { return NodeId.randomId(); } long lsb = nextLsb++; if (lsb >= storedLsb) { store(lsb + cacheSize); } return new NodeId(msb, lsb); }
public void testPerformance() { NodeId id = NodeId.randomId(); long time = System.currentTimeMillis(); for (int i = 0; i < 1000 * 1000; i++) { new IDField(id); } time = System.currentTimeMillis() - time; System.out.println("IDField: " + time + " ms."); for (int i = 0; i < 50; i++) { createNodes(id.toString(), i % 2 == 0); } }
protected void doInit() throws IOException { // sleep for 10 seconds then try to read from the item state manager // the repository.xml is configured with a 5 second maxIdleTime try { Thread.sleep(INITIALIZATION_DELAY); } catch (InterruptedException e) { // ignore } getContext().getItemStateManager().hasItemState(NodeId.randomId()); super.doInit(); }
public void testVersionIterator() throws Exception { InternalVersion version = new DummyInternalVersion(new InternalVersion[] {}, NodeId.randomId()); for (int i = 1; i < VERSION_COUNT; i++) { version = new DummyInternalVersion(new InternalVersion[] {version}, NodeId.randomId()); } try { VersionIteratorImpl versionIteratorImpl = new VersionIteratorImpl(null, version); assertEquals(VERSION_COUNT, versionIteratorImpl.getSize()); } catch (StackOverflowError e) { fail("Should be able to handle " + VERSION_COUNT + " versions."); } }
/** * Create a node state. * * @return node state */ protected NodeState createNodeState() { Name ntName = nameFactory.create("{}testnt"); NodeState n = new NodeState( NodeId.randomId(), ntName, ROOT_NODE_ID, NodeState.STATUS_EXISTING, false); n.setMixinTypeNames(Collections.EMPTY_SET); return n; }
public void testCheckPermissionWithUnknowId() throws RepositoryException, NotExecutableException { Session s = getHelper().getReadOnlySession(); NodeId id = NodeId.randomId(); try { AccessManager acMgr = getAccessManager(s); acMgr.checkPermission(id, AccessManager.READ); fail("AccessManager.checkPermission should throw ItemNotFoundException with a random (unknown) item id."); } catch (ItemNotFoundException e) { // ok } finally { s.logout(); } }
/** * JCR-3014 Identifier paths for inexistent items throw exception * * @see <a href="https://issues.apache.org/jira/browse/JCR-3014">JCR-3014</a> */ public void testCheckNonExistingItem() throws Exception { String dummyPath = "[" + NodeId.randomId() + "]"; assertFalse(superuser.itemExists(dummyPath)); assertFalse(superuser.nodeExists(dummyPath)); }
/** * Add an item state and then modify it. Make sure the entry is still * in the added states. */ public void testAddModify() throws Exception { PropertyId id = new PropertyId(NodeId.randomId(), factory.create("", "a")); ItemState state = new PropertyState(id, ItemState.STATUS_NEW, false); ChangeLog log = new ChangeLog(); log.added(state); log.modified(state); assertTrue("State still in added collection", log.addedStates().iterator().hasNext()); assertFalse("State not in modified collection", log.modifiedStates().iterator().hasNext()); }
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())); }
public void testEmptyBundle() throws Exception { NodePropBundle bundle = new NodePropBundle(NodeId.randomId()); bundle.setParentId(new NodeId(1, 2)); bundle.setNodeTypeName(NameConstants.NT_UNSTRUCTURED); bundle.setMixinTypeNames(Collections.<Name>emptySet()); bundle.setSharedSet(Collections.<NodeId>emptySet()); assertBundleRoundtrip(bundle); assertBundleSerialization(bundle, new byte[] { 2, 0, 0, 1, 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0 }); }
/** * Add an item state and then delete it. Make sure there is no * entry in either the added nor the removed states */ public void testAddDelete() throws Exception { PropertyId id = new PropertyId(NodeId.randomId(), factory.create("", "a")); ItemState state = new PropertyState(id, ItemState.STATUS_NEW, false); ChangeLog log = new ChangeLog(); log.added(state); log.deleted(state); assertFalse("State not in added collection", log.addedStates().iterator().hasNext()); assertFalse("State not in deleted collection", log.deletedStates().iterator().hasNext()); }
protected void setUp() throws Exception { super.setUp(); locking = createISMLocking(); NodeId id = NodeId.randomId(); state = new NodeState(id, NameConstants.NT_BASE, null, ItemState.STATUS_EXISTING, true); refs = new NodeReferences(state.getNodeId()); logs = new ArrayList<ChangeLog>(); ChangeLog log = new ChangeLog(); log.added(state); logs.add(log); log = new ChangeLog(); log.deleted(state); logs.add(log); log = new ChangeLog(); log.modified(state); logs.add(log); log = new ChangeLog(); log.modified(refs); logs.add(log); }
protected void setUp() throws Exception { factory = InternalValueFactory.getInstance(); rootPath = PathFactoryImpl.getInstance().getRootPath(); testName = NameFactoryImpl.getInstance().create(Name.NS_JCR_URI, "data"); reference = NodeId.randomId().toString(); }
protected void setUp() throws Exception { factory = InternalValueFactory.getInstance(); rootPath = PathFactoryImpl.getInstance().getRootPath(); testName = NameFactoryImpl.getInstance().create(Name.NS_JCR_URI, "data"); reference = NodeId.randomId().toString(); }
/** * Add some item states. Retrieve them again and make sure the order is * preserved. */ public void testPreserveOrder() throws Exception { ItemState[] states = new ItemState[10]; for (int i = 0; i < states.length; i++) { PropertyId id = new PropertyId(NodeId.randomId(), factory.create("", "a" + i)); states[i] = new PropertyState(id, ItemState.STATUS_NEW, false); } ChangeLog log = new ChangeLog(); for (int i = 0; i < states.length; i++) { log.added(states[i]); } int i = 0; for (ItemState state : log.addedStates()) { assertTrue("Added states preserve order.", state.equals(states[i++])); } } }
private void assertValueSerialization(InternalValue value) throws Exception { NodePropBundle bundle = new NodePropBundle(NodeId.randomId()); bundle.setParentId(NodeId.randomId()); bundle.setNodeTypeName(NameConstants.NT_UNSTRUCTURED); bundle.setMixinTypeNames(Collections.<Name>emptySet()); bundle.setSharedSet(Collections.<NodeId>emptySet()); Name name = factory.create("", "test"); PropertyEntry property = new PropertyEntry(new PropertyId(bundle.getId(), name)); property.setType(value.getType()); property.setMultiValued(false); property.setValues(new InternalValue[] { value }); bundle.addProperty(property); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); binding.writeBundle(buffer, bundle); byte[] bytes = buffer.toByteArray(); NodePropBundle result = binding.readBundle(new ByteArrayInputStream(bytes), bundle.getId()); assertEquals(value, result.getPropertyEntry(name).getValues()[0]); }
/** * Test producing and consuming an unlock operation. * @throws Exception */ public void testUnlockOperation() throws Exception { UnlockEvent event = new UnlockEvent(NodeId.randomId()); master.createLockChannel(DEFAULT_WORKSPACE).create(event.getNodeId()).ended(true); SimpleEventListener listener = new SimpleEventListener(); slave.createLockChannel(DEFAULT_WORKSPACE).setListener(listener); slave.sync(); assertEquals(1, listener.getClusterEvents().size()); assertEquals(listener.getClusterEvents().get(0), event); }
/** * Test producing and consuming a lock operation. * @throws Exception */ public void testLockOperation() throws Exception { LockEvent event = new LockEvent(NodeId.randomId(), true, "admin"); master.createLockChannel(DEFAULT_WORKSPACE).create(event.getNodeId(), event.isDeep(), event.getUserId()).ended(true); SimpleEventListener listener = new SimpleEventListener(); slave.createLockChannel(DEFAULT_WORKSPACE).setListener(listener); slave.sync(); assertEquals(1, listener.getClusterEvents().size()); assertEquals(listener.getClusterEvents().get(0), event); }
public void testUuidFormat() { long maxHigh = 0, maxLow = 0, minHigh = -1L, minLow = -1L; for (int i = 0; i < 100; i++) { NodeId id = NodeId.randomId(); assertUuidFormat(id); maxHigh |= id.getMostSignificantBits(); maxLow |= id.getLeastSignificantBits(); minHigh &= id.getMostSignificantBits(); minLow &= id.getLeastSignificantBits(); } NodeId max = new NodeId(maxHigh, maxLow); assertEquals("ffffffff-ffff-4fff-bfff-ffffffffffff", max.toString()); NodeId min = new NodeId(minHigh, minLow); assertEquals("00000000-0000-4000-8000-000000000000", min.toString()); }