Search in sources :

Example 1 with RepositoryCleaner

use of org.pentaho.platform.repository2.unified.jcr.RepositoryCleaner in project pentaho-platform by pentaho.

the class RepositoryGCOrphanTest method testOrphanNodePurge.

@Test
public void testOrphanNodePurge() throws Exception {
    GarbageCollector collector = mock(GarbageCollector.class);
    RepositoryImpl repository = mock(RepositoryImpl.class);
    RepositoryContext context = mock(RepositoryContext.class);
    when(repository.getRepositoryContext()).thenReturn(context);
    RepositoryImpl.WorkspaceInfo workspaceInfo = mock(RepositoryImpl.WorkspaceInfo.class);
    when(repository.getWorkspaceInfo("default")).thenReturn(workspaceInfo);
    WorkspaceConfig config = mock(WorkspaceConfig.class);
    when(workspaceInfo.getConfig()).thenReturn(config);
    when(repository.createDataStoreGarbageCollector()).thenReturn(collector);
    RepositoryCleaner cleaner = new RepositoryCleaner();
    Session systemSession = mock(Session.class);
    IPentahoSystemSessionFactory sessionFactory = mock(IPentahoSystemSessionFactory.class);
    when(sessionFactory.create(repository)).thenReturn(systemSession);
    cleaner.setSystemSessionFactory(sessionFactory);
    Node rootNode = mock(Node.class);
    when(systemSession.getNode("/jcr:system/jcr:versionStorage")).thenReturn(rootNode);
    when(rootNode.getName()).thenReturn("jcr:frozenNode");
    Property uuid = mock(Property.class);
    when(rootNode.getProperty("jcr:frozenUuid")).thenReturn(uuid);
    when(rootNode.hasProperty("jcr:frozenUuid")).thenReturn(true);
    Value value = mock(Value.class);
    when(uuid.getValue()).thenReturn(value);
    when(uuid.getString()).thenReturn("Foo");
    when(systemSession.getNodeByIdentifier(anyString())).thenThrow(new RepositoryException("err"));
    Version parent = mock(Version.class);
    VersionHistory grandParent = mock(VersionHistory.class);
    when(rootNode.getParent()).thenReturn(parent);
    when(parent.getParent()).thenReturn(grandParent);
    when(parent.getName()).thenReturn("Bar");
    NodeIterator nodes = mock(NodeIterator.class);
    when(rootNode.getNodes()).thenReturn(nodes);
    when(nodes.hasNext()).thenReturn(false);
    MicroPlatform mp = new MicroPlatform(getSolutionPath());
    mp.defineInstance(Repository.class, repository);
    mp.defineInstance("jcrRepository", repository);
    mp.start();
    try {
        cleaner.gc();
    } finally {
        mp.stop();
    }
    verify(grandParent, times(1)).removeVersion("Bar");
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) RepositoryCleaner(org.pentaho.platform.repository2.unified.jcr.RepositoryCleaner) Version(javax.jcr.version.Version) Value(javax.jcr.Value) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) WorkspaceConfig(org.apache.jackrabbit.core.config.WorkspaceConfig) Property(javax.jcr.Property) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector) Session(javax.jcr.Session) Test(org.junit.Test)

Example 2 with RepositoryCleaner

use of org.pentaho.platform.repository2.unified.jcr.RepositoryCleaner in project pentaho-platform by pentaho.

the class RepositoryGcJob method execute.

@Override
public void execute() throws Exception {
    logger.info("Starting repository GC");
    new RepositoryCleaner().gc();
    logger.info("Repository GC has been finished");
}
Also used : RepositoryCleaner(org.pentaho.platform.repository2.unified.jcr.RepositoryCleaner)

Aggregations

RepositoryCleaner (org.pentaho.platform.repository2.unified.jcr.RepositoryCleaner)2 Node (javax.jcr.Node)1 NodeIterator (javax.jcr.NodeIterator)1 Property (javax.jcr.Property)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 Value (javax.jcr.Value)1 Version (javax.jcr.version.Version)1 VersionHistory (javax.jcr.version.VersionHistory)1 WorkspaceConfig (org.apache.jackrabbit.core.config.WorkspaceConfig)1 GarbageCollector (org.apache.jackrabbit.core.gc.GarbageCollector)1 Test (org.junit.Test)1 MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)1