Search in sources :

Example 6 with SearchManager

use of org.apache.jackrabbit.core.SearchManager 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 7 with SearchManager

use of org.apache.jackrabbit.core.SearchManager 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)

Example 8 with SearchManager

use of org.apache.jackrabbit.core.SearchManager in project jackrabbit by apache.

the class SearchIndexConsistencyCheckTest method testIndexContainsMultipleEntries.

public void testIndexContainsMultipleEntries() 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());
    NodeState nodeState = new NodeState(fooId, null, null, 1, false);
    Iterator<NodeId> remove = Collections.<NodeId>emptyList().iterator();
    Iterator<NodeState> add = Arrays.asList(nodeState).iterator();
    searchIndex.updateNodes(remove, add);
    searchIndex.flush();
    remove = Collections.<NodeId>emptyList().iterator();
    add = Arrays.asList(nodeState).iterator();
    searchIndex.updateNodes(remove, add);
    ConsistencyCheck consistencyCheck = searchIndex.runConsistencyCheck();
    List<ConsistencyCheckError> errors = consistencyCheck.getErrors();
    assertEquals("Expected 1 index consistency error", 1, errors.size());
    assertEquals("Different node was reported to be duplicate", errors.get(0).id, fooId);
    consistencyCheck.doubleCheckErrors();
    errors = consistencyCheck.getErrors();
    assertEquals("Expected 1 index consistency error after double check", 1, errors.size());
    assertEquals("Different node was reported to be duplicate after double check", errors.get(0).id, fooId);
    consistencyCheck.repair(false);
    assertTrue("Index was not repaired properly", searchIndexContainsNode(searchIndex, fooId));
    consistencyCheck.doubleCheckErrors();
    errors = consistencyCheck.getErrors();
    assertTrue("Consistency double check of multiple entries failed", errors.isEmpty());
    assertTrue("Consistency check still finds 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)

Aggregations

Session (javax.jcr.Session)8 SearchManager (org.apache.jackrabbit.core.SearchManager)8 NodeId (org.apache.jackrabbit.core.id.NodeId)7 NodeState (org.apache.jackrabbit.core.state.NodeState)7 Node (javax.jcr.Node)6 RepositoryException (javax.jcr.RepositoryException)1