@Test public void shouldFailIfZipCorrupted() throws Throwable { String filename = "corrupt.zip"; Node parent = createNodeWithContentFromFile(filename, filename); Node outputNode = parent.getNode("jcr:content"); expectSequencingFailure(outputNode); Map<?, ?> sequencingEventInfo = assertSequencingEventInfo(outputNode, session.getUserID(), "ZIP sequencer", outputNode.getPath(), "/zip"); assertEquals(EOFException.class.getName(), sequencingEventInfo.get(Event.Sequencing.SEQUENCING_FAILURE_CAUSE) .getClass() .getName()); }
@Override public synchronized void logout() { // get the user id first, because calling terminate may cleanup the security context and loose this information String userID = getUserID(); terminate(true); try { RunningState running = repository.runningState(); long lifetime = Math.abs(System.nanoTime() - this.nanosCreated); Map<String, String> payload = Collections.singletonMap("userId", userID); running.statistics().recordDuration(DurationMetric.SESSION_LIFETIME, lifetime, TimeUnit.NANOSECONDS, payload); running.statistics().decrement(ValueMetric.SESSION_COUNT); running.removeSession(this); } catch (IllegalStateException e) { // The repository has been shutdown } finally { if (bufferMgr != null) { try { bufferMgr.close(); } finally { bufferMgr = null; } } } }
@Override public synchronized void logout() { // get the user id first, because calling terminate may cleanup the security context and loose this information String userID = getUserID(); terminate(true); try { RunningState running = repository.runningState(); long lifetime = Math.abs(System.nanoTime() - this.nanosCreated); Map<String, String> payload = Collections.singletonMap("userId", userID); running.statistics().recordDuration(DurationMetric.SESSION_LIFETIME, lifetime, TimeUnit.NANOSECONDS, payload); running.statistics().decrement(ValueMetric.SESSION_COUNT); running.removeSession(this); } catch (IllegalStateException e) { // The repository has been shutdown } finally { if (bufferMgr != null) { try { bufferMgr.close(); } finally { bufferMgr = null; } } } }
@Test @FixFor( "MODE-2424" ) public void shouldAllowAddingMixinOnLockedNodeForLockOwner() throws Exception { final AbstractJcrNode testNode = session.getRootNode().addNode("test"); final String path = testNode.getPath(); testNode.addMixin("mix:lockable"); session.save(); session.getWorkspace().getLockManager().lock(path, false, true, Long.MAX_VALUE, session.getUserID()); testNode.addMixin("mix:created"); session.save(); }
final String owner = ownerInfo != null ? ownerInfo : session.getUserID();
final String owner = ownerInfo != null ? ownerInfo : session.getUserID();
@Test public void shouldSequenceZip2() throws Exception { String filename = "test-files.zip"; Node parent = createNodeWithContentFromFile(filename, filename); Node outputNode = parent.getNode("jcr:content"); Node outputZip = getOutputNode(rootNode, "zip/" + filename); assertNotNull(outputZip); assertEquals(ZipLexicon.FILE, outputZip.getPrimaryNodeType().getName()); assertSequencingEventInfo(outputNode, session.getUserID(), "ZIP sequencer", outputNode.getPath(), "/zip"); // Find the sequenced node ... String path = "/zip/test-files.zip"; assertNode(path + "/MODE-966-fix.patch", JcrConstants.NT_FILE); assertNode(path + "/MODE-966-fix.patch/jcr:content", JcrConstants.NT_RESOURCE); assertNode(path + "/testFolder", JcrConstants.NT_FOLDER); assertNode(path + "/testFolder/MODE-962-fix.patch", JcrConstants.NT_FILE); assertNode(path + "/testFolder/MODE-962-fix.patch/jcr:content", JcrConstants.NT_RESOURCE); assertNode(path + "/testFolder/testInnerFolder", JcrConstants.NT_FOLDER); assertNode(path + "/testFolder/testInnerFolder/MODE-960-fix.patch", JcrConstants.NT_FILE); assertNode(path + "/testFolder/testInnerFolder/MODE-960-fix.patch/jcr:content", JcrConstants.NT_RESOURCE); assertNode(path + "/testFolder/testInnerFolder/MODE-960-fix2.patch", JcrConstants.NT_FILE); assertNode(path + "/testFolder/testInnerFolder/MODE-960-fix2.patch/jcr:content", JcrConstants.NT_RESOURCE); }
private void fireSequencingEvent( AbstractJcrNode sequencedNode, List<AbstractJcrNode> outputNodes, JcrSession outputSession, String sequencerName ) throws RepositoryException { final ExecutionContext context = outputSession.context(); RecordingChanges sequencingChanges = new RecordingChanges(outputSession.sessionId(), context.getProcessId(), outputSession.getRepository().repositoryKey(), outputSession.workspaceName(), outputSession.getRepository() .journalId()); Name primaryType = sequencedNode.getPrimaryTypeName(); Set<Name> mixinTypes = sequencedNode.getMixinTypeNames(); for (AbstractJcrNode outputNode : outputNodes) { sequencingChanges.nodeSequenced(sequencedNode.key(), sequencedNode.path(), primaryType, mixinTypes, outputNode.key(), outputNode.path(), work.getOutputPath(), work.getUserId(), work.getSelectedPath(), sequencerName); } sequencingChanges.freeze(outputSession.getUserID(), null, context.getValueFactories().getDateFactory().create()); repository.changeBus().notify(sequencingChanges); }
private void fireSequencingEvent( AbstractJcrNode sequencedNode, List<AbstractJcrNode> outputNodes, JcrSession outputSession, String sequencerName ) throws RepositoryException { final ExecutionContext context = outputSession.context(); RecordingChanges sequencingChanges = new RecordingChanges(outputSession.sessionId(), context.getProcessId(), outputSession.getRepository().repositoryKey(), outputSession.workspaceName(), outputSession.getRepository() .journalId()); Name primaryType = sequencedNode.getPrimaryTypeName(); Set<Name> mixinTypes = sequencedNode.getMixinTypeNames(); for (AbstractJcrNode outputNode : outputNodes) { sequencingChanges.nodeSequenced(sequencedNode.key(), sequencedNode.path(), primaryType, mixinTypes, outputNode.key(), outputNode.path(), work.getOutputPath(), work.getUserId(), work.getSelectedPath(), sequencerName); } sequencingChanges.freeze(outputSession.getUserID(), null, context.getValueFactories().getDateFactory().create()); repository.changeBus().notify(sequencingChanges); }
@FixFor( "MODE-2623" ) @Test public void shouldAllowLockUnlockWithinTransaction() throws Exception { final String path = "/test"; Node parent = session.getRootNode().addNode("test"); parent.addMixin("mix:lockable"); session.save(); startTransaction(); LockManager lockMgr = session.getWorkspace().getLockManager(); lockMgr.lock(path, true, true, Long.MAX_VALUE, session.getUserID()); lockMgr.unlock(path); commitTransaction(); assertFalse(session.getNode(path).isLocked()); }
@Test @FixFor( "MODE-2342" ) public void lockTokensShouldBeRemovedFromSessionUponLogout() throws Exception { final AbstractJcrNode testNode = session.getRootNode().addNode("test"); final String path = testNode.getPath(); testNode.addMixin("mix:lockable"); session.save(); final Lock lock = session.getWorkspace().getLockManager().lock(path, false, false, Long.MAX_VALUE, session.getUserID()); final String token = lock.getLockToken(); Assert.assertNotNull(token); session.logout(); Session session2 = repository.login(); final LockManager lockManager = session2.getWorkspace().getLockManager(); lockManager.addLockToken(token); Assert.assertTrue("New session should now own the lock.", lockManager.getLock(path).isLockOwningSession()); }
@Test @FixFor( "MODE-2450" ) public void shouldCleanupCorruptedLocks() throws Exception { final AbstractJcrNode testNode = session.getRootNode().addNode("test"); final String path = testNode.getPath(); testNode.addMixin("mix:lockable"); session.save(); final org.modeshape.jcr.RepositoryLockManager.Lock lock = (RepositoryLockManager.Lock) session.getWorkspace().getLockManager().lock(path, false, false, Long.MAX_VALUE, session.getUserID()); Assert.assertNotNull(lock); session.logout(); //forcibly remove the lock node from the system area... String lockKey = lock.lockKey().toString(); assertTrue(runInTransaction(() -> repository.documentStore().remove(lockKey))); //and then force a refresh RepositoryLockManager lockManager = repository.lockManager(); lockManager.refreshFromSystem(); //check that the lock has been removed session = repository.login(); assertFalse(session.getWorkspace().getLockManager().isLocked("/test")); // issue another refresh and verify the node is still unlocked lockManager.refreshFromSystem(); assertFalse(session.getWorkspace().getLockManager().isLocked("/test")); }