Search in sources :

Example 1 with CleanUpAuditLogResult

use of com.enonic.xp.audit.CleanUpAuditLogResult in project xp by enonic.

the class AuditLogServiceImplTest method cleanUpOneBatch.

@Test
public void cleanUpOneBatch() {
    when(nodeService.deleteById(ArgumentMatchers.isA(NodeId.class))).thenAnswer(answer -> NodeIds.from((NodeId) answer.getArgument(0)));
    when(config.ageThreshold()).thenReturn("PT1s");
    final FindNodesByQueryResult.Builder queryResult = FindNodesByQueryResult.create().totalHits(3).hits(3);
    createHits(3).forEach(queryResult::addNodeHit);
    when(nodeService.findByQuery(any(NodeQuery.class))).thenReturn(queryResult.build()).thenReturn(FindNodesByQueryResult.create().build());
    final CleanUpAuditLogListener listener = mock(CleanUpAuditLogListener.class);
    final CleanUpAuditLogResult result = auditLogService.cleanUp(CleanUpAuditLogParams.create().listener(listener).build());
    assertEquals(3, result.getDeleted());
    verify(listener, times(1)).start(10_000);
    verify(listener, times(3)).processed();
    verify(listener, times(1)).finished();
}
Also used : CleanUpAuditLogResult(com.enonic.xp.audit.CleanUpAuditLogResult) CleanUpAuditLogListener(com.enonic.xp.audit.CleanUpAuditLogListener) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeId(com.enonic.xp.node.NodeId) Test(org.junit.jupiter.api.Test)

Example 2 with CleanUpAuditLogResult

use of com.enonic.xp.audit.CleanUpAuditLogResult in project xp by enonic.

the class CleanUpAuditLogCommand method doCleanUp.

private CleanUpAuditLogResult doCleanUp() {
    final CleanUpAuditLogResult.Builder result = CleanUpAuditLogResult.create();
    final NodeQuery query = createQuery();
    nodeService.refresh(RefreshMode.ALL);
    FindNodesByQueryResult nodesToDelete = nodeService.findByQuery(query);
    long hits = nodesToDelete.getHits();
    final long totalHits = nodesToDelete.getTotalHits();
    if (totalHits == 0) {
        return CleanUpAuditLogResult.empty();
    }
    listener.start(BATCH_SIZE);
    while (hits > 0) {
        for (NodeHit nodeHit : nodesToDelete.getNodeHits()) {
            result.deleted(nodeService.deleteById(nodeHit.getNodeId()).getSize());
            listener.processed();
        }
        nodesToDelete = nodeService.findByQuery(query);
        hits = nodesToDelete.getHits();
    }
    listener.finished();
    return result.build();
}
Also used : CleanUpAuditLogResult(com.enonic.xp.audit.CleanUpAuditLogResult) NodeHit(com.enonic.xp.node.NodeHit) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 3 with CleanUpAuditLogResult

use of com.enonic.xp.audit.CleanUpAuditLogResult in project xp by enonic.

the class AuditLogServiceImplTest method cleanUpOneEmpty.

@Test
public void cleanUpOneEmpty() {
    when(nodeService.deleteById(ArgumentMatchers.isA(NodeId.class))).thenAnswer(answer -> NodeIds.from((NodeId) answer.getArgument(0)));
    when(config.ageThreshold()).thenReturn("PT1s");
    when(nodeService.findByQuery(any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().build());
    final CleanUpAuditLogListener listener = mock(CleanUpAuditLogListener.class);
    final CleanUpAuditLogResult result = auditLogService.cleanUp(CleanUpAuditLogParams.create().listener(listener).build());
    assertEquals(0, result.getDeleted());
    verify(listener, times(0)).start(anyInt());
    verify(listener, times(0)).processed();
    verify(listener, times(0)).finished();
}
Also used : CleanUpAuditLogResult(com.enonic.xp.audit.CleanUpAuditLogResult) CleanUpAuditLogListener(com.enonic.xp.audit.CleanUpAuditLogListener) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) Test(org.junit.jupiter.api.Test)

Example 4 with CleanUpAuditLogResult

use of com.enonic.xp.audit.CleanUpAuditLogResult in project xp by enonic.

the class AuditLogServiceImplTest method cleanUpMultipleBatch.

@Test
public void cleanUpMultipleBatch() {
    when(nodeService.deleteById(ArgumentMatchers.isA(NodeId.class))).thenAnswer(answer -> NodeIds.from((NodeId) answer.getArgument(0)));
    when(config.ageThreshold()).thenReturn("PT1s");
    final FindNodesByQueryResult.Builder queryResult1 = FindNodesByQueryResult.create().totalHits(10500).hits(10000);
    createHits(10000).forEach(queryResult1::addNodeHit);
    final FindNodesByQueryResult.Builder queryResult2 = FindNodesByQueryResult.create().totalHits(10500).hits(500);
    createHits(500).forEach(queryResult2::addNodeHit);
    when(nodeService.findByQuery(any(NodeQuery.class))).thenReturn(queryResult1.build()).thenReturn(queryResult2.build()).thenReturn(FindNodesByQueryResult.create().build());
    final CleanUpAuditLogListener listener = mock(CleanUpAuditLogListener.class);
    final CleanUpAuditLogResult result = auditLogService.cleanUp(CleanUpAuditLogParams.create().listener(listener).build());
    assertEquals(10500, result.getDeleted());
    verify(listener, times(1)).start(10_000);
    verify(listener, times(10_500)).processed();
    verify(listener, times(1)).finished();
}
Also used : CleanUpAuditLogResult(com.enonic.xp.audit.CleanUpAuditLogResult) CleanUpAuditLogListener(com.enonic.xp.audit.CleanUpAuditLogListener) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) Test(org.junit.jupiter.api.Test)

Aggregations

CleanUpAuditLogResult (com.enonic.xp.audit.CleanUpAuditLogResult)4 CleanUpAuditLogListener (com.enonic.xp.audit.CleanUpAuditLogListener)3 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)3 NodeId (com.enonic.xp.node.NodeId)3 NodeQuery (com.enonic.xp.node.NodeQuery)3 Test (org.junit.jupiter.api.Test)3 NodeHit (com.enonic.xp.node.NodeHit)1