Search in sources :

Example 6 with ReportItem

use of org.apache.jackrabbit.core.persistence.check.ReportItem in project jackrabbit by apache.

the class ConsistencyCheckerImplTest method testFixAbandonedNode.

// Abandoned nodes are nodes that have a link to a parent but that
// parent does not have a link back to the child
public void testFixAbandonedNode() throws RepositoryException, ClusterException {
    NodePropBundle bundle1 = new NodePropBundle(new NodeId(0, 0));
    NodePropBundle bundle2 = new NodePropBundle(new NodeId(0, 1));
    // node2 has a reference to node 1 as its parent, but node 1 doesn't have
    // a corresponding child node entry
    bundle2.setParentId(bundle1.getId());
    MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle1, bundle2));
    ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null, null, master.createUpdateChannel("default"));
    // set up cluster event update listener
    final TestUpdateEventListener listener = new TestUpdateEventListener();
    final UpdateEventChannel slaveEventChannel = slave.createUpdateChannel("default");
    slaveEventChannel.setListener(listener);
    checker.check(null, false);
    Set<ReportItem> reportItems = checker.getReport().getItems();
    assertEquals(1, reportItems.size());
    ReportItem reportItem = reportItems.iterator().next();
    assertEquals(ReportItem.Type.ABANDONED, reportItem.getType());
    assertEquals(bundle2.getId().toString(), reportItem.getNodeId());
    checker.repair();
    // node1 should now have a child node entry for node2
    bundle1 = pm.loadBundle(bundle1.getId());
    assertEquals(1, bundle1.getChildNodeEntries().size());
    assertEquals(bundle2.getId(), bundle1.getChildNodeEntries().get(0).getId());
    slave.sync();
    // verify events were correctly broadcast to cluster
    assertNotNull("Cluster node did not receive update event", listener.changes);
    assertTrue("Expected node1 to be modified", listener.changes.isModified(bundle1.getId()));
}
Also used : NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) NodeId(org.apache.jackrabbit.core.id.NodeId) ConsistencyCheckerImpl(org.apache.jackrabbit.core.persistence.bundle.ConsistencyCheckerImpl) UpdateEventChannel(org.apache.jackrabbit.core.cluster.UpdateEventChannel) ReportItem(org.apache.jackrabbit.core.persistence.check.ReportItem)

Example 7 with ReportItem

use of org.apache.jackrabbit.core.persistence.check.ReportItem in project jackrabbit by apache.

the class ConsistencyCheckerImplTest method testAddOrphanedNodeToLostAndFound.

// Orphaned nodes are those nodes who's parent does not exist
public void testAddOrphanedNodeToLostAndFound() throws RepositoryException, ClusterException {
    final NodeId lostAndFoundId = new NodeId(0, 0);
    NodePropBundle lostAndFound = new NodePropBundle(lostAndFoundId);
    // lost and found must be of type nt:unstructured
    lostAndFound.setNodeTypeName(NameConstants.NT_UNSTRUCTURED);
    final NodeId orphanedId = new NodeId(0, 1);
    NodePropBundle orphaned = new NodePropBundle(orphanedId);
    // set non-existent parent node id
    orphaned.setParentId(new NodeId(1, 0));
    MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(lostAndFound, orphaned));
    ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null, lostAndFoundId.toString(), master.createUpdateChannel("default"));
    // set up cluster event update listener
    final TestUpdateEventListener listener = new TestUpdateEventListener();
    final UpdateEventChannel slaveEventChannel = slave.createUpdateChannel("default");
    slaveEventChannel.setListener(listener);
    checker.check(null, false);
    Set<ReportItem> reportItems = checker.getReport().getItems();
    assertEquals(1, reportItems.size());
    ReportItem reportItem = reportItems.iterator().next();
    assertEquals(ReportItem.Type.ORPHANED, reportItem.getType());
    assertEquals(orphanedId.toString(), reportItem.getNodeId());
    checker.repair();
    // orphan should have been added to lost+found
    lostAndFound = pm.loadBundle(lostAndFoundId);
    assertEquals(1, lostAndFound.getChildNodeEntries().size());
    assertEquals(orphanedId, lostAndFound.getChildNodeEntries().get(0).getId());
    orphaned = pm.loadBundle(orphanedId);
    assertEquals(lostAndFoundId, orphaned.getParentId());
    slave.sync();
    // verify events were correctly broadcast to cluster
    assertNotNull("Cluster node did not receive update event", listener.changes);
    assertTrue("Expected lostAndFound to be modified", listener.changes.isModified(lostAndFoundId));
    assertTrue("Expected orphan to be modified", listener.changes.isModified(orphanedId));
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) ConsistencyCheckerImpl(org.apache.jackrabbit.core.persistence.bundle.ConsistencyCheckerImpl) UpdateEventChannel(org.apache.jackrabbit.core.cluster.UpdateEventChannel) ReportItem(org.apache.jackrabbit.core.persistence.check.ReportItem)

Example 8 with ReportItem

use of org.apache.jackrabbit.core.persistence.check.ReportItem in project jackrabbit by apache.

the class ConsistencyCheckerImplTest method testDoubleCheckDisonnectedNode.

public void testDoubleCheckDisonnectedNode() throws RepositoryException {
    NodePropBundle bundle1 = new NodePropBundle(new NodeId(0, 0));
    NodePropBundle bundle2 = new NodePropBundle(new NodeId(0, 1));
    NodePropBundle bundle3 = new NodePropBundle(new NodeId(1, 0));
    // node1 has child node3
    bundle1.addChildNodeEntry(nameFactory.create("", "test"), bundle3.getId());
    // node2 also has child node3
    bundle2.addChildNodeEntry(nameFactory.create("", "test"), bundle3.getId());
    // node3 has node2 as parent
    bundle3.setParentId(bundle2.getId());
    MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle1, bundle2, bundle3));
    ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null, null, null);
    checker.check(null, false);
    Set<ReportItem> reportItems = checker.getReport().getItems();
    assertEquals(1, reportItems.size());
    ReportItem reportItem = reportItems.iterator().next();
    assertEquals(ReportItem.Type.DISCONNECTED, reportItem.getType());
    assertEquals(bundle1.getId().toString(), reportItem.getNodeId());
    checker.doubleCheckErrors();
    assertFalse("Double check removed valid error", checker.getReport().getItems().isEmpty());
    // fix the error
    bundle1.getChildNodeEntries().remove(0);
    checker.doubleCheckErrors();
    assertTrue("Double check didn't remove invalid error", checker.getReport().getItems().isEmpty());
}
Also used : NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) NodeId(org.apache.jackrabbit.core.id.NodeId) ConsistencyCheckerImpl(org.apache.jackrabbit.core.persistence.bundle.ConsistencyCheckerImpl) ReportItem(org.apache.jackrabbit.core.persistence.check.ReportItem)

Aggregations

NodeId (org.apache.jackrabbit.core.id.NodeId)8 ConsistencyCheckerImpl (org.apache.jackrabbit.core.persistence.bundle.ConsistencyCheckerImpl)8 ReportItem (org.apache.jackrabbit.core.persistence.check.ReportItem)8 NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)8 UpdateEventChannel (org.apache.jackrabbit.core.cluster.UpdateEventChannel)4