Search in sources :

Example 66 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class SearchIndexConsistencyCheckTest method testMissingAncestorDoubleCheck.

public void testMissingAncestorDoubleCheck() throws Exception {
    Session s = getHelper().getSuperuserSession();
    SearchManager searchManager = TestHelper.getSearchManager(s);
    SearchIndex searchIndex = (SearchIndex) searchManager.getQueryHandler();
    Node foo = testRootNode.addNode("foo");
    foo.addNode("bar");
    testRootNode.getSession().save();
    NodeId fooId = new NodeId(foo.getIdentifier());
    Iterator<NodeId> remove = Collections.singletonList(fooId).iterator();
    Iterator<NodeState> add = Collections.<NodeState>emptyList().iterator();
    searchIndex.updateNodes(remove, add);
    ConsistencyCheck consistencyCheck = searchIndex.runConsistencyCheck();
    List<ConsistencyCheckError> errors = consistencyCheck.getErrors();
    assertEquals("Expected 2 index consistency errors", 2, errors.size());
    remove = Collections.<NodeId>emptyList().iterator();
    add = Collections.singletonList(new NodeState(fooId, null, null, 1, true)).iterator();
    searchIndex.updateNodes(remove, add);
    consistencyCheck.doubleCheckErrors();
    assertTrue("Consistency double check of missing ancestor failed", consistencyCheck.getErrors().isEmpty());
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) SearchManager(org.apache.jackrabbit.core.SearchManager) Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.core.id.NodeId) Session(javax.jcr.Session)

Example 67 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class SearchIndexConsistencyCheckTest method testIndexMissesAncestor.

public void testIndexMissesAncestor() throws Exception {
    Session s = getHelper().getSuperuserSession();
    SearchManager searchManager = TestHelper.getSearchManager(s);
    SearchIndex searchIndex = (SearchIndex) searchManager.getQueryHandler();
    Node foo = testRootNode.addNode("foo");
    Node bar = foo.addNode("bar");
    testRootNode.getSession().save();
    NodeId fooId = new NodeId(foo.getIdentifier());
    NodeId barId = new NodeId(bar.getIdentifier());
    Iterator<NodeId> remove = Collections.singletonList(fooId).iterator();
    Iterator<NodeState> add = Collections.<NodeState>emptyList().iterator();
    searchIndex.updateNodes(remove, add);
    ConsistencyCheck consistencyCheck = searchIndex.runConsistencyCheck();
    List<ConsistencyCheckError> errors = consistencyCheck.getErrors();
    assertEquals("Expected 2 index consistency errors", 2, errors.size());
    assertEquals("Different node was reported to have missing parent", errors.get(0).id, barId);
    assertEquals("Different node was reported to be missing", errors.get(1).id, fooId);
    consistencyCheck.repair(false);
    assertTrue("Index was not repaired properly", searchIndexContainsNode(searchIndex, fooId));
    assertTrue("Consistency check still reports errors", searchIndex.runConsistencyCheck().getErrors().isEmpty());
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) SearchManager(org.apache.jackrabbit.core.SearchManager) Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.core.id.NodeId) Session(javax.jcr.Session)

Example 68 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class SearchIndexConsistencyCheckTest method testIndexMissesNode.

public void testIndexMissesNode() throws Exception {
    Session s = getHelper().getSuperuserSession();
    SearchManager searchManager = TestHelper.getSearchManager(s);
    SearchIndex searchIndex = (SearchIndex) searchManager.getQueryHandler();
    Node foo = testRootNode.addNode("foo");
    testRootNode.getSession().save();
    NodeId fooId = new NodeId(foo.getIdentifier());
    Iterator<NodeId> remove = Collections.singletonList(fooId).iterator();
    Iterator<NodeState> add = Collections.<NodeState>emptyList().iterator();
    searchIndex.updateNodes(remove, add);
    ConsistencyCheck consistencyCheck = searchIndex.runConsistencyCheck();
    List<ConsistencyCheckError> errors = consistencyCheck.getErrors();
    assertEquals("Expected 1 index consistency error", 1, errors.size());
    ConsistencyCheckError error = errors.iterator().next();
    assertEquals("Different node was reported to be missing", error.id, fooId);
    consistencyCheck.repair(false);
    assertTrue("Index was not repaired properly", searchIndexContainsNode(searchIndex, fooId));
    assertTrue("Consistency check still reports errors", searchIndex.runConsistencyCheck().getErrors().isEmpty());
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) SearchManager(org.apache.jackrabbit.core.SearchManager) Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.core.id.NodeId) Session(javax.jcr.Session)

Example 69 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class SearchIndexConsistencyCheckTest method testUnknownNodeDoubleCheck.

public void testUnknownNodeDoubleCheck() throws Exception {
    Session s = getHelper().getSuperuserSession();
    SearchManager searchManager = TestHelper.getSearchManager(s);
    SearchIndex searchIndex = (SearchIndex) searchManager.getQueryHandler();
    NodeId nodeId = new NodeId(0, 0);
    NodeState nodeState = new NodeState(nodeId, null, null, 1, false);
    Iterator<NodeId> remove = Collections.<NodeId>emptyList().iterator();
    Iterator<NodeState> add = Collections.singletonList(nodeState).iterator();
    searchIndex.updateNodes(remove, add);
    ConsistencyCheck consistencyCheck = searchIndex.runConsistencyCheck();
    List<ConsistencyCheckError> errors = consistencyCheck.getErrors();
    assertEquals("Expected 1 index consistency error", 1, errors.size());
    // now remove the unknown node from the index again so that double check finds a false positive
    remove = Collections.singletonList(nodeId).iterator();
    add = Collections.<NodeState>emptyList().iterator();
    searchIndex.updateNodes(remove, add);
    consistencyCheck.doubleCheckErrors();
    assertTrue("Consistency double check of deleted node failed", consistencyCheck.getErrors().isEmpty());
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) SearchManager(org.apache.jackrabbit.core.SearchManager) NodeId(org.apache.jackrabbit.core.id.NodeId) Session(javax.jcr.Session)

Example 70 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class SearchIndexConsistencyCheckTest method testMissingNodeDoubleCheck.

public void testMissingNodeDoubleCheck() throws Exception {
    Session s = getHelper().getSuperuserSession();
    SearchManager searchManager = TestHelper.getSearchManager(s);
    SearchIndex searchIndex = (SearchIndex) searchManager.getQueryHandler();
    Node foo = testRootNode.addNode("foo");
    testRootNode.getSession().save();
    NodeId fooId = new NodeId(foo.getIdentifier());
    Iterator<NodeId> remove = Collections.singletonList(fooId).iterator();
    Iterator<NodeState> add = Collections.<NodeState>emptyList().iterator();
    searchIndex.updateNodes(remove, add);
    ConsistencyCheck consistencyCheck = searchIndex.runConsistencyCheck();
    List<ConsistencyCheckError> errors = consistencyCheck.getErrors();
    assertEquals("Expected 1 index consistency error", 1, errors.size());
    // now add foo to the index again so that double check finds a false positive
    remove = Collections.<NodeId>emptyList().iterator();
    add = Collections.singletonList(new NodeState(fooId, null, null, 1, false)).iterator();
    searchIndex.updateNodes(remove, add);
    consistencyCheck.doubleCheckErrors();
    assertTrue("Consistency double check of missing node failed", consistencyCheck.getErrors().isEmpty());
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) SearchManager(org.apache.jackrabbit.core.SearchManager) Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.core.id.NodeId) Session(javax.jcr.Session)

Aggregations

NodeState (org.apache.jackrabbit.core.state.NodeState)114 RepositoryException (javax.jcr.RepositoryException)53 NodeId (org.apache.jackrabbit.core.id.NodeId)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)44 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)34 Name (org.apache.jackrabbit.spi.Name)28 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)26 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 Path (org.apache.jackrabbit.spi.Path)24 PropertyId (org.apache.jackrabbit.core.id.PropertyId)23 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)16 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)16 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 ArrayList (java.util.ArrayList)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)12 InternalValue (org.apache.jackrabbit.core.value.InternalValue)12 HashSet (java.util.HashSet)10 ItemExistsException (javax.jcr.ItemExistsException)10 IOException (java.io.IOException)8 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)7