Search in sources :

Example 6 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class ConsistencyCheckerImplTest method testFixMultipleAbandonedNodesBySameParent.

/*
     * There was a bug where when there were multiple abandoned nodes by the same parent
     * only one of them was fixed. Hence this separate test case for this scenario.
     */
public void testFixMultipleAbandonedNodesBySameParent() 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));
    // node2 and node3 have a reference to node1 as its parent, but node1 doesn't have
    // corresponding child node entries
    bundle2.setParentId(bundle1.getId());
    bundle3.setParentId(bundle1.getId());
    MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle1, bundle2, bundle3));
    ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null, null, null);
    checker.check(null, false);
    checker.repair();
    // node1 should now have child node entries for node2 and node3
    bundle1 = pm.loadBundle(bundle1.getId());
    assertEquals(2, bundle1.getChildNodeEntries().size());
    assertEquals(bundle2.getId(), bundle1.getChildNodeEntries().get(0).getId());
    assertEquals(bundle3.getId(), bundle1.getChildNodeEntries().get(1).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)

Example 7 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class ConsistencyCheckerImplTest method testDoubleCheckAbandonedNode.

public void testDoubleCheckAbandonedNode() throws RepositoryException {
    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, null);
    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.doubleCheckErrors();
    assertFalse("Double check removed valid error", checker.getReport().getItems().isEmpty());
    // fix the error
    bundle1.addChildNodeEntry(nameFactory.create("", "test"), bundle2.getId());
    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)

Example 8 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class ConsistencyCheckerImplTest method testFixMissingNode.

public void testFixMissingNode() throws RepositoryException, ClusterException {
    NodePropBundle bundle = new NodePropBundle(new NodeId(0, 0));
    bundle.addChildNodeEntry(nameFactory.create("", "test"), new NodeId(0, 1));
    MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle));
    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.MISSING, reportItem.getType());
    assertEquals(bundle.getId().toString(), reportItem.getNodeId());
    checker.repair();
    // node should have no child no entries
    assertTrue(bundle.getChildNodeEntries().isEmpty());
    slave.sync();
    // verify events were correctly broadcast to cluster
    assertNotNull("Cluster node did not receive update event", listener.changes);
    assertTrue("Expected node to be modified", listener.changes.isModified(bundle.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 9 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class ConsistencyCheckerImplTest method testDoubleCheckOrphanedNode.

public void testDoubleCheckOrphanedNode() throws RepositoryException {
    NodePropBundle orphaned = new NodePropBundle(new NodeId(0, 1));
    orphaned.setParentId(new NodeId(1, 0));
    MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(orphaned));
    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.ORPHANED, reportItem.getType());
    assertEquals(orphaned.getId().toString(), reportItem.getNodeId());
    checker.doubleCheckErrors();
    assertFalse("Double check removed valid error", checker.getReport().getItems().isEmpty());
    // fix the error
    NodePropBundle parent = new NodePropBundle(orphaned.getParentId());
    pm.bundles.put(parent.getId(), parent);
    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)

Example 10 with NodePropBundle

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

Aggregations

NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)19 NodeId (org.apache.jackrabbit.core.id.NodeId)14 ConsistencyCheckerImpl (org.apache.jackrabbit.core.persistence.bundle.ConsistencyCheckerImpl)9 ReportItem (org.apache.jackrabbit.core.persistence.check.ReportItem)8 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)5 UpdateEventChannel (org.apache.jackrabbit.core.cluster.UpdateEventChannel)4 RepositoryException (javax.jcr.RepositoryException)3 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ClusterException (org.apache.jackrabbit.core.cluster.ClusterException)2 PropertyId (org.apache.jackrabbit.core.id.PropertyId)2 NodeInfo (org.apache.jackrabbit.core.persistence.util.NodeInfo)2 PropertyEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry)2 Name (org.apache.jackrabbit.spi.Name)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1